@inflatable-cookie/longhorn 0.5.0 → 0.6.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/package.json +1 -1
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +35 -20
- package/src/agent-control/shim.ts +302 -144
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +3 -2
- package/src/bridge/generated/protocol.ts +7 -3
- package/src/bridge/job.ts +4 -14
- package/src/bridge/loopback.ts +7 -25
- package/src/bridge/operation.ts +13 -43
- package/src/bridge/router.ts +10 -23
- package/src/bridge/runtime/connection.ts +77 -105
- package/src/bridge/runtime/policy.ts +8 -28
- package/src/bridge/runtime/retry.ts +6 -18
- package/src/bridge/session.ts +4 -14
- package/src/bridge/stream/connection.ts +16 -38
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +7 -12
- package/src/bridge/supervision.ts +11 -26
- package/src/bridge/validation/base.ts +17 -39
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +27 -37
- package/src/bridge/validation/operations.ts +28 -52
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +21 -26
- package/src/commands/controller.ts +32 -47
- package/src/commands/generated/fields.ts +3 -2
- package/src/commands/generated/protocol.ts +4 -0
- package/src/commands/keyboard.ts +92 -89
- package/src/commands/ports.ts +6 -12
- package/src/commands/projectors.ts +50 -48
- package/src/commands/validation.ts +70 -97
- package/src/config/client.ts +6 -19
- package/src/config/generated/fields.ts +2 -2
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +5 -17
- package/src/config/validation/outcomes.ts +31 -39
- package/src/config/validation/primitives.ts +36 -53
- package/src/config/validation/projection.ts +66 -94
- package/src/core/connection.ts +70 -61
- package/src/core/record.ts +4 -0
- package/src/core/transport.ts +4 -15
- package/src/core/wire-copy.ts +6 -0
- package/src/history/client.ts +6 -12
- package/src/history/controller.ts +46 -46
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +2 -2
- package/src/history/ports.ts +4 -6
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +71 -55
- package/src/history-tree/client.ts +87 -11
- package/src/history-tree/controller.ts +313 -70
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +2 -2
- package/src/history-tree/ports.ts +3 -1
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +262 -63
- package/src/layout/generated/protocol.ts +2 -2
- package/src/layout/ratio.ts +2 -8
- package/src/layout/validation.ts +10 -19
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +44 -7
- package/src/licence/controller.ts +76 -40
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +2 -2
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +1 -1
- package/src/licence/key.ts +40 -12
- package/src/licence/ports.ts +3 -1
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +120 -36
- package/src/native-content/client.ts +178 -236
- package/src/native-content/generated/fields.ts +2 -2
- package/src/native-content/ports.ts +9 -15
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -50
- package/src/native-content/validation/messages.ts +21 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +87 -31
- package/src/notifications/controller.ts +215 -61
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +2 -2
- package/src/notifications/ports.ts +7 -3
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/validation.ts +147 -43
- package/src/operation/bridge.ts +117 -50
- package/src/operation/client.ts +38 -24
- package/src/operation/controller.ts +33 -42
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +2 -2
- package/src/operation/ports.ts +10 -9
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +152 -65
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +26 -40
- package/src/settings/generated/fields.ts +3 -3
- package/src/settings/generated/protocol.ts +9 -4
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +19 -17
- package/src/settings/validation/command.ts +17 -37
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +26 -42
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +25 -73
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +2 -2
- package/src/surface-transfer/validation.ts +31 -49
- package/src/surfaces/client.ts +12 -22
- package/src/surfaces/generated/fields.ts +2 -2
- package/src/surfaces/validation.ts +40 -49
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +12 -20
- package/src/transfer/generated/fields.ts +5 -5
- package/src/transfer/generated/protocol.ts +4 -4
- package/src/transfer/payload.ts +13 -31
- package/src/transfer/validation.ts +39 -75
- package/src/update/client.ts +59 -9
- package/src/update/controller.ts +113 -48
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +3 -3
- package/src/update/generated/protocol.ts +7 -3
- package/src/update/generated/variant-fields.ts +1 -0
- package/src/update/ports.ts +6 -2
- package/src/update/serialized.ts +34 -10
- package/src/update/validation.ts +115 -35
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isRecord } from "../core/record.ts";
|
|
1
2
|
import { LICENCE_FIELDS } from "./generated/fields.ts";
|
|
2
3
|
import {
|
|
3
4
|
LICENCE_CHANGED_KINDS,
|
|
@@ -7,14 +8,16 @@ import {
|
|
|
7
8
|
LICENCE_REJECTION_CODES,
|
|
8
9
|
LICENCE_TRUST_BASIS_KINDS,
|
|
9
10
|
LICENCE_USABILITY_STATES,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
} from "./generated/protocol.ts";
|
|
12
|
+
import type {
|
|
13
|
+
LicenceActivateCommand,
|
|
14
|
+
LicenceChangedEvent,
|
|
15
|
+
LicenceDeactivateCommand,
|
|
16
|
+
LicenceOutcomeProjection,
|
|
17
|
+
LicenceRefreshCommand,
|
|
18
|
+
LicenceReleaseSeatCommand,
|
|
19
|
+
LicenceRenameSeatCommand,
|
|
20
|
+
LicenceSnapshot,
|
|
18
21
|
} from "./generated/protocol.ts";
|
|
19
22
|
import {
|
|
20
23
|
LICENCE_VARIANT_FIELDS,
|
|
@@ -39,7 +42,9 @@ export function assertLicenceSnapshot(value: unknown): asserts value is LicenceS
|
|
|
39
42
|
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
40
43
|
// Absent means unlicensed, which is the absence of a licence rather than a
|
|
41
44
|
// licence that cannot be used. Card 193 kept those apart deliberately.
|
|
42
|
-
if (root.licence !== null)
|
|
45
|
+
if (root.licence !== null) {
|
|
46
|
+
held(root.licence, "$.licence");
|
|
47
|
+
}
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
export function assertLicenceOutcome(value: unknown): asserts value is LicenceOutcomeProjection {
|
|
@@ -47,7 +52,9 @@ export function assertLicenceOutcome(value: unknown): asserts value is LicenceOu
|
|
|
47
52
|
const root = object(value, "$");
|
|
48
53
|
oneOf(root.status, "$.status", LICENCE_OUTCOME_STATUSES);
|
|
49
54
|
exact(root, "$", variantFields("LicenceOutcomeProjection", root, "$"));
|
|
50
|
-
if (root.status === "rejected")
|
|
55
|
+
if (root.status === "rejected") {
|
|
56
|
+
oneOf(root.code, "$.code", LICENCE_REJECTION_CODES);
|
|
57
|
+
}
|
|
51
58
|
assertLicenceSnapshot(root.snapshot);
|
|
52
59
|
}
|
|
53
60
|
|
|
@@ -74,14 +81,20 @@ export function assertLicenceActivateCommand(
|
|
|
74
81
|
// The one place credential material crosses, and it crosses inward only.
|
|
75
82
|
// Checked for shape, never echoed: `noCredential` runs on everything coming
|
|
76
83
|
// back and would reject a projection that returned any of this.
|
|
77
|
-
if (credential.kind === "key")
|
|
78
|
-
|
|
84
|
+
if (credential.kind === "key") {
|
|
85
|
+
nonEmpty(credential.key, "$.credential.key");
|
|
86
|
+
}
|
|
87
|
+
if (credential.kind === "accountToken") {
|
|
88
|
+
nonEmpty(credential.token, "$.credential.token");
|
|
89
|
+
}
|
|
79
90
|
if (credential.kind === "licenceFile") {
|
|
80
91
|
nonEmpty(credential.contentsBase64, "$.credential.contentsBase64");
|
|
81
92
|
}
|
|
82
93
|
// The label a customer gives this machine, asked for at the only moment it
|
|
83
94
|
// can be without inventing a settings screen. Absent is fine.
|
|
84
|
-
if (root.label !== null)
|
|
95
|
+
if (root.label !== null) {
|
|
96
|
+
nonEmpty(root.label, "$.label");
|
|
97
|
+
}
|
|
85
98
|
}
|
|
86
99
|
|
|
87
100
|
export function assertLicenceDeactivateCommand(
|
|
@@ -110,7 +123,9 @@ export function assertLicenceRenameSeatCommand(
|
|
|
110
123
|
nonEmpty(root.machineId, "$.machineId");
|
|
111
124
|
// Null clears the label back to unnamed; an empty string is a mistake
|
|
112
125
|
// wearing null's clothes and is refused rather than stored.
|
|
113
|
-
if (root.label !== null)
|
|
126
|
+
if (root.label !== null) {
|
|
127
|
+
nonEmpty(root.label, "$.label");
|
|
128
|
+
}
|
|
114
129
|
}
|
|
115
130
|
|
|
116
131
|
function held(value: unknown, path: string): void {
|
|
@@ -131,7 +146,9 @@ function held(value: unknown, path: string): void {
|
|
|
131
146
|
// checks it is present and never what it says, because anything derived
|
|
132
147
|
// from the host would be a different value wearing the same field.
|
|
133
148
|
nonEmpty(seat.machineId, `${at}.machineId`);
|
|
134
|
-
if (seat.label !== null)
|
|
149
|
+
if (seat.label !== null) {
|
|
150
|
+
nonEmpty(seat.label, `${at}.label`);
|
|
151
|
+
}
|
|
135
152
|
boolean(seat.thisMachine, `${at}.thisMachine`);
|
|
136
153
|
});
|
|
137
154
|
array(licence.entitlements, `${path}.entitlements`).forEach((entry, index) => {
|
|
@@ -141,7 +158,9 @@ function held(value: unknown, path: string): void {
|
|
|
141
158
|
// Opaque by design: Longhorn enumerates no features, so this checks that
|
|
142
159
|
// an id is present and never what it says.
|
|
143
160
|
nonEmpty(entitlement.id, `${at}.id`);
|
|
144
|
-
if (entitlement.atMost !== null)
|
|
161
|
+
if (entitlement.atMost !== null) {
|
|
162
|
+
positive(entitlement.atMost, `${at}.atMost`);
|
|
163
|
+
}
|
|
145
164
|
});
|
|
146
165
|
}
|
|
147
166
|
|
|
@@ -152,7 +171,9 @@ function usability(value: unknown, path: string): void {
|
|
|
152
171
|
// `clockRefused` carries no timestamp on purpose: a licence refused because
|
|
153
172
|
// the machine clock moved is not expired, and giving it a date would invite
|
|
154
173
|
// a surface to render it as one.
|
|
155
|
-
if (root.state === "inGrace")
|
|
174
|
+
if (root.state === "inGrace") {
|
|
175
|
+
timestamp(root.until, `${path}.until`);
|
|
176
|
+
}
|
|
156
177
|
if (root.state === "useWindowExpired" || root.state === "leaseLapsed") {
|
|
157
178
|
timestamp(root.at, `${path}.at`);
|
|
158
179
|
}
|
|
@@ -162,10 +183,12 @@ function trustBasis(value: unknown, path: string): void {
|
|
|
162
183
|
const root = object(value, path);
|
|
163
184
|
oneOf(root.kind, `${path}.kind`, LICENCE_TRUST_BASIS_KINDS);
|
|
164
185
|
exact(root, path, variantFields("LicenceTrustBasisProjection", root, path));
|
|
165
|
-
if (root.kind === "remoteAssertion")
|
|
186
|
+
if (root.kind === "remoteAssertion") {
|
|
187
|
+
timestamp(root.checked, `${path}.checked`);
|
|
188
|
+
}
|
|
166
189
|
}
|
|
167
190
|
|
|
168
|
-
function commandBase(value: unknown, expected:
|
|
191
|
+
function commandBase(value: unknown, expected: ReadonlyArray<string>): Record<string, unknown> {
|
|
169
192
|
const root = object(value, "$");
|
|
170
193
|
exact(root, "$", expected);
|
|
171
194
|
protocol(root.protocolVersion, "$.protocolVersion");
|
|
@@ -187,8 +210,10 @@ function commandBase(value: unknown, expected: readonly string[]): Record<string
|
|
|
187
210
|
function noCredential(value: unknown): void {
|
|
188
211
|
const forbidden = ["credential", "secret", "signature", "token", "privatekey", "keyid"];
|
|
189
212
|
const visit = (candidate: unknown, path: string): void => {
|
|
190
|
-
if (Array.isArray(candidate))
|
|
191
|
-
|
|
213
|
+
if (Array.isArray(candidate)) {
|
|
214
|
+
return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
|
|
215
|
+
}
|
|
216
|
+
if (candidate !== null && typeof candidate === "object") {
|
|
192
217
|
for (const [key, child] of Object.entries(candidate)) {
|
|
193
218
|
const lowered = key.toLocaleLowerCase();
|
|
194
219
|
if (forbidden.some((needle) => lowered.includes(needle))) {
|
|
@@ -196,6 +221,7 @@ function noCredential(value: unknown): void {
|
|
|
196
221
|
}
|
|
197
222
|
visit(child, `${path}.${key}`);
|
|
198
223
|
}
|
|
224
|
+
}
|
|
199
225
|
};
|
|
200
226
|
visit(value, "$");
|
|
201
227
|
}
|
|
@@ -204,23 +230,81 @@ function variantFields(
|
|
|
204
230
|
type: string,
|
|
205
231
|
value: Record<string, unknown>,
|
|
206
232
|
path: string,
|
|
207
|
-
):
|
|
233
|
+
): ReadonlyArray<string> {
|
|
208
234
|
const discriminant = value[LICENCE_VARIANT_FIELDS_DISCRIMINANTS[type] ?? "kind"];
|
|
209
|
-
const fields =
|
|
210
|
-
|
|
235
|
+
const fields =
|
|
236
|
+
typeof discriminant === "string" ? LICENCE_VARIANT_FIELDS[type]?.[discriminant] : undefined;
|
|
237
|
+
if (fields === undefined) {
|
|
238
|
+
fail(path, `no generated fields for ${type}.${String(discriminant)}`);
|
|
239
|
+
}
|
|
211
240
|
return fields;
|
|
212
241
|
}
|
|
213
242
|
|
|
214
|
-
function object(value: unknown, path: string): Record<string, unknown> {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
function
|
|
243
|
+
function object(value: unknown, path: string): Record<string, unknown> {
|
|
244
|
+
if (!isRecord(value)) {
|
|
245
|
+
fail(path, "expected object");
|
|
246
|
+
}
|
|
247
|
+
return value;
|
|
248
|
+
}
|
|
249
|
+
function array(value: unknown, path: string): Array<unknown> {
|
|
250
|
+
if (!Array.isArray(value)) {
|
|
251
|
+
fail(path, "expected array");
|
|
252
|
+
}
|
|
253
|
+
return value;
|
|
254
|
+
}
|
|
255
|
+
function exact(
|
|
256
|
+
value: Record<string, unknown>,
|
|
257
|
+
path: string,
|
|
258
|
+
expected: ReadonlyArray<string>,
|
|
259
|
+
): void {
|
|
260
|
+
const actual = Object.keys(value).sort();
|
|
261
|
+
const wanted = [...expected].sort();
|
|
262
|
+
if (actual.length !== wanted.length || actual.some((key, index) => key !== wanted[index])) {
|
|
263
|
+
fail(path, `unexpected keys: ${actual.join(",")}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function protocol(value: unknown, path: string): void {
|
|
267
|
+
if (value !== LICENCE_PROTOCOL_VERSION) {
|
|
268
|
+
fail(path, `expected exact protocol ${LICENCE_PROTOCOL_VERSION}`);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function positive(value: unknown, path: string): void {
|
|
272
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
273
|
+
fail(path, "expected positive safe integer");
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function string(value: unknown, path: string): asserts value is string {
|
|
277
|
+
if (typeof value !== "string") {
|
|
278
|
+
fail(path, "expected string");
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function nonEmpty(value: unknown, path: string): void {
|
|
282
|
+
string(value, path);
|
|
283
|
+
if (value.length === 0) {
|
|
284
|
+
fail(path, "expected a non-empty string");
|
|
285
|
+
}
|
|
286
|
+
}
|
|
221
287
|
/** Unix seconds, and negative is a real point in time. */
|
|
222
|
-
function timestamp(value: unknown, path: string): void {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
288
|
+
function timestamp(value: unknown, path: string): void {
|
|
289
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value)) {
|
|
290
|
+
fail(path, "expected a unix-second timestamp");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function optionalTimestamp(value: unknown, path: string): void {
|
|
294
|
+
if (value !== null) {
|
|
295
|
+
timestamp(value, path);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function boolean(value: unknown, path: string): void {
|
|
299
|
+
if (typeof value !== "boolean") {
|
|
300
|
+
fail(path, "expected boolean");
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
|
|
304
|
+
if (typeof value !== "string" || !values.includes(value)) {
|
|
305
|
+
fail(path, "unsupported value");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function fail(path: string, message: string): never {
|
|
309
|
+
throw new LicenceValidationError(path, message);
|
|
310
|
+
}
|