@inflatable-cookie/longhorn 0.5.0 → 0.7.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/README.md +2 -2
- package/package.json +1 -7
- package/src/agent-control/generated/protocol.ts +228 -0
- package/src/agent-control/index.ts +1 -5
- package/src/agent-control/inject.ts +4 -1
- package/src/agent-control/selection.ts +42 -25
- package/src/agent-control/shim.ts +428 -198
- package/src/bridge/direct.ts +1 -1
- package/src/bridge/generated/fields.ts +4 -3
- package/src/bridge/generated/protocol.ts +62 -7
- package/src/bridge/generated/variant-fields.ts +1 -1
- package/src/bridge/job.ts +49 -12
- 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 +78 -109
- 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 +24 -55
- package/src/bridge/stream/source.ts +2 -6
- package/src/bridge/stream/tracker.ts +12 -12
- package/src/bridge/supervision.ts +104 -97
- package/src/bridge/validation/base.ts +21 -63
- package/src/bridge/validation/jobs.ts +11 -25
- package/src/bridge/validation/negotiation.ts +28 -43
- package/src/bridge/validation/operations.ts +29 -65
- package/src/bridge/validation/streams.ts +3 -10
- package/src/commands/client.ts +37 -28
- package/src/commands/controller.ts +119 -96
- package/src/commands/generated/fields.ts +7 -6
- package/src/commands/generated/protocol.ts +28 -1
- package/src/commands/generated/variant-fields.ts +1 -1
- package/src/commands/keyboard.ts +94 -100
- package/src/commands/physical-code.ts +11 -0
- package/src/commands/ports.ts +8 -13
- package/src/commands/projectors.ts +100 -75
- package/src/commands/validation.ts +434 -241
- package/src/config/client.ts +9 -22
- package/src/config/generated/base.ts +22 -6
- package/src/config/generated/fields.ts +4 -3
- package/src/config/generated/label-template.ts +1 -1
- package/src/config/generated/labels.ts +1 -1
- package/src/config/generated/protocol.ts +1 -1
- package/src/config/generated/restore.ts +35 -12
- package/src/config/generated/variant-fields.ts +1 -1
- package/src/config/names.ts +6 -12
- package/src/config/validation/commands.ts +11 -25
- package/src/config/validation/outcomes.ts +163 -70
- package/src/config/validation/primitives.ts +35 -80
- package/src/config/validation/projection.ts +100 -128
- package/src/core/connection.ts +187 -83
- package/src/core/controller-lifecycle.ts +144 -0
- package/src/core/generated/identifiers.ts +4 -0
- package/src/core/identifiers.ts +40 -0
- package/src/core/index.ts +10 -1
- package/src/core/json-value.ts +58 -0
- package/src/core/listeners.ts +35 -0
- package/src/core/record.ts +80 -0
- package/src/core/transport.ts +9 -11
- package/src/core/wire-copy.ts +7 -0
- package/src/history/client.ts +11 -13
- package/src/history/controller.ts +106 -108
- package/src/history/direct.ts +1 -3
- package/src/history/generated/fields.ts +4 -3
- package/src/history/generated/protocol.ts +8 -5
- package/src/history/generated/variant-fields.ts +1 -1
- package/src/history/ports.ts +7 -4
- package/src/history/serialized.ts +9 -13
- package/src/history/validation.ts +69 -75
- package/src/history-tree/client.ts +89 -11
- package/src/history-tree/controller.ts +380 -96
- package/src/history-tree/direct.ts +3 -1
- package/src/history-tree/generated/fields.ts +5 -3
- package/src/history-tree/generated/protocol.ts +43 -7
- package/src/history-tree/generated/variant-fields.ts +7 -1
- package/src/history-tree/ports.ts +12 -5
- package/src/history-tree/serialized.ts +39 -11
- package/src/history-tree/validation.ts +286 -78
- package/src/layout/generated/protocol.ts +4 -3
- package/src/layout/generated/variant-fields.ts +47 -0
- package/src/layout/index.ts +1 -1
- package/src/layout/ratio.ts +10 -9
- package/src/layout/validation.ts +98 -32
- package/src/layout/visibility.ts +1 -2
- package/src/licence/client.ts +48 -7
- package/src/licence/controller.ts +127 -70
- package/src/licence/direct.ts +3 -1
- package/src/licence/generated/fields.ts +4 -3
- package/src/licence/generated/key-conformance.json +28 -0
- package/src/licence/generated/protocol.ts +9 -5
- package/src/licence/generated/variant-fields.ts +1 -1
- package/src/licence/key.ts +42 -18
- package/src/licence/ports.ts +10 -3
- package/src/licence/serialized.ts +32 -9
- package/src/licence/validation.ts +134 -43
- package/src/native-content/client.ts +207 -234
- package/src/native-content/generated/fields.ts +6 -6
- package/src/native-content/generated/protocol.ts +16 -5
- package/src/native-content/generated/variant-fields.ts +1 -1
- package/src/native-content/ports.ts +11 -16
- package/src/native-content/serialized.ts +12 -19
- package/src/native-content/validation/base.ts +57 -80
- package/src/native-content/validation/messages.ts +24 -35
- package/src/native-content/validation/state.ts +31 -33
- package/src/notifications/client.ts +85 -51
- package/src/notifications/controller.ts +400 -145
- package/src/notifications/direct.ts +3 -1
- package/src/notifications/generated/fields.ts +4 -3
- package/src/notifications/generated/labels.ts +1 -1
- package/src/notifications/generated/protocol.ts +5 -1
- package/src/notifications/generated/variant-fields.ts +1 -1
- package/src/notifications/ports.ts +9 -4
- package/src/notifications/serialized.ts +11 -9
- package/src/notifications/tone.ts +1 -1
- package/src/notifications/validation.ts +165 -71
- package/src/operation/bridge.ts +187 -60
- package/src/operation/client.ts +48 -62
- package/src/operation/controller.ts +67 -97
- package/src/operation/direct.ts +1 -3
- package/src/operation/generated/fields.ts +4 -3
- package/src/operation/generated/labels.ts +1 -1
- package/src/operation/generated/protocol.ts +5 -1
- package/src/operation/generated/variant-fields.ts +1 -1
- package/src/operation/ports.ts +12 -10
- package/src/operation/serialized.ts +8 -9
- package/src/operation/validation.ts +189 -104
- package/src/settings/client.ts +11 -44
- package/src/settings/connection.ts +35 -53
- package/src/settings/generated/fields.ts +5 -4
- package/src/settings/generated/protocol.ts +14 -5
- package/src/settings/generated/variant-fields.ts +1 -1
- package/src/settings/names.ts +2 -4
- package/src/settings/registry.ts +23 -25
- package/src/settings/validation/authority.ts +21 -19
- package/src/settings/validation/command.ts +22 -41
- package/src/settings/validation/error.ts +2 -8
- package/src/settings/validation/primitives.ts +46 -97
- package/src/settings/validation/projection.ts +8 -24
- package/src/settings/validation/registry.ts +33 -79
- package/src/surface-transfer/client.ts +6 -18
- package/src/surface-transfer/generated/fields.ts +3 -3
- package/src/surface-transfer/generated/protocol.ts +3 -3
- package/src/surface-transfer/generated/variant-fields.ts +1 -1
- package/src/surface-transfer/validation.ts +91 -86
- package/src/surfaces/client.ts +33 -55
- package/src/surfaces/generated/fields.ts +3 -3
- package/src/surfaces/generated/protocol.ts +1 -1
- package/src/surfaces/generated/variant-fields.ts +1 -1
- package/src/surfaces/validation.ts +227 -99
- package/src/transfer/client.ts +26 -60
- package/src/transfer/connection.ts +29 -51
- package/src/transfer/generated/fields.ts +7 -6
- package/src/transfer/generated/protocol.ts +13 -5
- package/src/transfer/generated/variant-fields.ts +1 -1
- package/src/transfer/index.ts +8 -1
- package/src/transfer/payload.ts +20 -35
- package/src/transfer/validation.ts +169 -119
- package/src/update/client.ts +86 -9
- package/src/update/controller.ts +264 -116
- package/src/update/direct.ts +3 -1
- package/src/update/generated/fields.ts +5 -4
- package/src/update/generated/protocol.ts +25 -9
- package/src/update/generated/variant-fields.ts +4 -2
- package/src/update/ports.ts +14 -6
- package/src/update/serialized.ts +36 -10
- package/src/update/validation.ts +118 -48
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by `effigy generate:
|
|
1
|
+
// @generated by `effigy generate:bindings`; do not edit.
|
|
2
2
|
// Allowed field names per tagged-union variant, from the Rust enums.
|
|
3
3
|
// Keyed by type, then by discriminant. The discriminant itself is in
|
|
4
4
|
// each list, because `exact()` compares every key.
|
package/src/licence/key.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The licence key format, in TypeScript.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* locally: a mistyped key must never produce a message implying the key is
|
|
7
|
-
* invalid, and telling those apart after a round trip is too late — the
|
|
8
|
-
* authority answers `notRecognised`, which sends a customer to check their
|
|
9
|
-
* purchase when they should check their typing.
|
|
4
|
+
* Check the format locally so a mistyped key can be corrected before the
|
|
5
|
+
* authority answers `notRecognised`.
|
|
10
6
|
*
|
|
11
7
|
* The two implementations are bound by `key-conformance.json`, generated from
|
|
12
8
|
* the Rust and asserted against here. Neither can change the format without
|
|
@@ -68,7 +64,9 @@ export function isProbablyATypo(problem: LicenceKeyProblem): boolean {
|
|
|
68
64
|
*/
|
|
69
65
|
export function parseLicenceKey(input: string): LicenceKeyResult {
|
|
70
66
|
const normalized = normalize(input);
|
|
71
|
-
if (!normalized.ok)
|
|
67
|
+
if (!normalized.ok) {
|
|
68
|
+
return normalized;
|
|
69
|
+
}
|
|
72
70
|
|
|
73
71
|
const value = normalized.value;
|
|
74
72
|
if (value.length < MINIMUM_KEY_SYMBOLS) {
|
|
@@ -87,22 +85,45 @@ export function parseLicenceKey(input: string): LicenceKeyResult {
|
|
|
87
85
|
|
|
88
86
|
/** Renders a normalized key as `XXXXX-XXXXX-…`. */
|
|
89
87
|
export function group(key: string): string {
|
|
90
|
-
const groups: string
|
|
91
|
-
for (let at = 0; at < key.length; at += GROUP)
|
|
88
|
+
const groups: Array<string> = [];
|
|
89
|
+
for (let at = 0; at < key.length; at += GROUP) {
|
|
90
|
+
groups.push(key.slice(at, at + GROUP));
|
|
91
|
+
}
|
|
92
92
|
return groups.join("-");
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
/** Matches Rust's `char::is_whitespace` (Unicode `White_Space`: includes U+0085, excludes U+FEFF). */
|
|
96
|
+
const UNICODE_WHITESPACE = /\p{White_Space}/u;
|
|
97
|
+
|
|
98
|
+
/** Matches Rust's `char::to_ascii_uppercase` so non-ASCII letters like U+017F never fold into ASCII. */
|
|
99
|
+
function toAsciiUpper(character: string): string {
|
|
100
|
+
const code = character.charCodeAt(0);
|
|
101
|
+
if (code >= 0x61 && code <= 0x7a) {
|
|
102
|
+
return String.fromCharCode(code - 0x20);
|
|
103
|
+
}
|
|
104
|
+
return character;
|
|
105
|
+
}
|
|
106
|
+
|
|
95
107
|
function normalize(
|
|
96
108
|
input: string,
|
|
97
|
-
):
|
|
98
|
-
|
|
109
|
+
):
|
|
110
|
+
| { readonly ok: true; readonly value: string }
|
|
111
|
+
| { readonly ok: false; readonly problem: LicenceKeyProblem } {
|
|
112
|
+
const symbols: Array<{ readonly original: string; readonly mapped: string }> = [];
|
|
99
113
|
for (const character of input) {
|
|
100
|
-
if (character === "-" ||
|
|
101
|
-
|
|
114
|
+
if (character === "-" || UNICODE_WHITESPACE.test(character)) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const upper = toAsciiUpper(character);
|
|
102
118
|
// The confusions Crockford excluded the symbols to avoid.
|
|
103
119
|
const mapped = upper === "I" || upper === "L" ? "1" : upper === "O" ? "0" : upper;
|
|
104
|
-
|
|
105
|
-
|
|
120
|
+
symbols.push({ original: character, mapped });
|
|
121
|
+
}
|
|
122
|
+
let output = "";
|
|
123
|
+
for (const [index, { original, mapped }] of symbols.entries()) {
|
|
124
|
+
const alphabet = index + 1 < symbols.length ? ALPHABET : CHECK_ALPHABET;
|
|
125
|
+
if (mapped.length !== 1 || !alphabet.includes(mapped)) {
|
|
126
|
+
return { ok: false, problem: { kind: "unexpectedSymbol", symbol: original } };
|
|
106
127
|
}
|
|
107
128
|
output += mapped;
|
|
108
129
|
}
|
|
@@ -118,8 +139,11 @@ function normalize(
|
|
|
118
139
|
function checkSymbol(body: string): string {
|
|
119
140
|
let sum = 0;
|
|
120
141
|
for (let index = 0; index < body.length; index += 1) {
|
|
121
|
-
const value = ALPHABET.indexOf(body
|
|
122
|
-
|
|
142
|
+
const value = ALPHABET.indexOf(body.charAt(index));
|
|
143
|
+
if (value === -1) {
|
|
144
|
+
throw new Error(`normalized key body contains unexpected symbol: ${body[index]}`);
|
|
145
|
+
}
|
|
146
|
+
sum += value * (index + 1);
|
|
123
147
|
}
|
|
124
|
-
return CHECK_ALPHABET
|
|
148
|
+
return CHECK_ALPHABET.charAt(sum % 37);
|
|
125
149
|
}
|
package/src/licence/ports.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ConnectionFailureReporter } from "../core/connection.ts";
|
|
2
|
+
import type { Unlisten } from "../core/transport.ts";
|
|
1
3
|
import type {
|
|
2
4
|
LicenceActivateCommand,
|
|
3
5
|
LicenceChangedEvent,
|
|
@@ -9,7 +11,7 @@ import type {
|
|
|
9
11
|
LicenceSnapshot,
|
|
10
12
|
} from "./generated/protocol.ts";
|
|
11
13
|
|
|
12
|
-
export type LicenceUnlisten =
|
|
14
|
+
export type LicenceUnlisten = Unlisten;
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* The raw seam.
|
|
@@ -24,7 +26,9 @@ export interface LicencePort {
|
|
|
24
26
|
refresh(command: LicenceRefreshCommand): Promise<unknown>;
|
|
25
27
|
releaseSeat(command: LicenceReleaseSeatCommand): Promise<unknown>;
|
|
26
28
|
renameSeat(command: LicenceRenameSeatCommand): Promise<unknown>;
|
|
27
|
-
listen
|
|
29
|
+
listen?:
|
|
30
|
+
| ((listener: (event: unknown) => void) => LicenceUnlisten | Promise<LicenceUnlisten>)
|
|
31
|
+
| undefined;
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
/** The same seam after validation. */
|
|
@@ -35,5 +39,8 @@ export interface CheckedLicencePort {
|
|
|
35
39
|
refresh(command: LicenceRefreshCommand): Promise<LicenceOutcomeProjection>;
|
|
36
40
|
releaseSeat(command: LicenceReleaseSeatCommand): Promise<LicenceOutcomeProjection>;
|
|
37
41
|
renameSeat(command: LicenceRenameSeatCommand): Promise<LicenceOutcomeProjection>;
|
|
38
|
-
listen(
|
|
42
|
+
listen(
|
|
43
|
+
listener: (event: LicenceChangedEvent) => void,
|
|
44
|
+
onFailure?: ConnectionFailureReporter,
|
|
45
|
+
): Promise<LicenceUnlisten>;
|
|
39
46
|
}
|
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { wireCopy } from "../core/wire-copy.ts";
|
|
2
|
+
import type {
|
|
3
|
+
LicenceActivateCommand,
|
|
4
|
+
LicenceDeactivateCommand,
|
|
5
|
+
LicenceRefreshCommand,
|
|
6
|
+
LicenceReleaseSeatCommand,
|
|
7
|
+
LicenceRenameSeatCommand,
|
|
8
|
+
} from "./generated/protocol.ts";
|
|
2
9
|
import type { LicencePort, LicenceUnlisten } from "./ports.ts";
|
|
3
10
|
export class SerializedLicencePort implements LicencePort {
|
|
4
11
|
constructor(readonly inner: LicencePort) {}
|
|
5
|
-
async snapshot(): Promise<unknown> {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
async
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
async
|
|
12
|
+
async snapshot(): Promise<unknown> {
|
|
13
|
+
return wireCopy(await this.inner.snapshot());
|
|
14
|
+
}
|
|
15
|
+
async activate(command: LicenceActivateCommand): Promise<unknown> {
|
|
16
|
+
return wireCopy(await this.inner.activate(wireCopy(command)));
|
|
17
|
+
}
|
|
18
|
+
async deactivate(command: LicenceDeactivateCommand): Promise<unknown> {
|
|
19
|
+
return wireCopy(await this.inner.deactivate(wireCopy(command)));
|
|
20
|
+
}
|
|
21
|
+
async refresh(command: LicenceRefreshCommand): Promise<unknown> {
|
|
22
|
+
return wireCopy(await this.inner.refresh(wireCopy(command)));
|
|
23
|
+
}
|
|
24
|
+
async releaseSeat(command: LicenceReleaseSeatCommand): Promise<unknown> {
|
|
25
|
+
return wireCopy(await this.inner.releaseSeat(wireCopy(command)));
|
|
26
|
+
}
|
|
27
|
+
async renameSeat(command: LicenceRenameSeatCommand): Promise<unknown> {
|
|
28
|
+
return wireCopy(await this.inner.renameSeat(wireCopy(command)));
|
|
29
|
+
}
|
|
30
|
+
async listen(listener: (event: unknown) => void): Promise<LicenceUnlisten> {
|
|
31
|
+
if (this.inner.listen === undefined) {
|
|
32
|
+
return () => {};
|
|
33
|
+
}
|
|
34
|
+
return this.inner.listen((event) => listener(wireCopy(event)));
|
|
35
|
+
}
|
|
12
36
|
}
|
|
13
|
-
function clone<T>(value: T): T { return JSON.parse(JSON.stringify(value)) as T; }
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { checkWireFields, readWireRecord, wireVariantFields } 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,
|
|
@@ -37,9 +40,10 @@ export function assertLicenceSnapshot(value: unknown): asserts value is LicenceS
|
|
|
37
40
|
exact(root, "$", LICENCE_FIELDS.LicenceSnapshot);
|
|
38
41
|
protocol(root.protocolVersion, "$.protocolVersion");
|
|
39
42
|
positive(root.authorityEpoch, "$.authorityEpoch");
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
// A held licence reports its usability even when that usability is blocked.
|
|
44
|
+
if (root.licence !== null) {
|
|
45
|
+
held(root.licence, "$.licence");
|
|
46
|
+
}
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
export function assertLicenceOutcome(value: unknown): asserts value is LicenceOutcomeProjection {
|
|
@@ -47,7 +51,9 @@ export function assertLicenceOutcome(value: unknown): asserts value is LicenceOu
|
|
|
47
51
|
const root = object(value, "$");
|
|
48
52
|
oneOf(root.status, "$.status", LICENCE_OUTCOME_STATUSES);
|
|
49
53
|
exact(root, "$", variantFields("LicenceOutcomeProjection", root, "$"));
|
|
50
|
-
if (root.status === "rejected")
|
|
54
|
+
if (root.status === "rejected") {
|
|
55
|
+
oneOf(root.code, "$.code", LICENCE_REJECTION_CODES);
|
|
56
|
+
}
|
|
51
57
|
assertLicenceSnapshot(root.snapshot);
|
|
52
58
|
}
|
|
53
59
|
|
|
@@ -74,14 +80,20 @@ export function assertLicenceActivateCommand(
|
|
|
74
80
|
// The one place credential material crosses, and it crosses inward only.
|
|
75
81
|
// Checked for shape, never echoed: `noCredential` runs on everything coming
|
|
76
82
|
// back and would reject a projection that returned any of this.
|
|
77
|
-
if (credential.kind === "key")
|
|
78
|
-
|
|
83
|
+
if (credential.kind === "key") {
|
|
84
|
+
nonEmpty(credential.key, "$.credential.key");
|
|
85
|
+
}
|
|
86
|
+
if (credential.kind === "accountToken") {
|
|
87
|
+
nonEmpty(credential.token, "$.credential.token");
|
|
88
|
+
}
|
|
79
89
|
if (credential.kind === "licenceFile") {
|
|
80
|
-
|
|
90
|
+
base64(credential.contentsBase64, "$.credential.contentsBase64");
|
|
81
91
|
}
|
|
82
92
|
// The label a customer gives this machine, asked for at the only moment it
|
|
83
93
|
// can be without inventing a settings screen. Absent is fine.
|
|
84
|
-
if (root.label !== null)
|
|
94
|
+
if (root.label !== null) {
|
|
95
|
+
nonEmpty(root.label, "$.label");
|
|
96
|
+
}
|
|
85
97
|
}
|
|
86
98
|
|
|
87
99
|
export function assertLicenceDeactivateCommand(
|
|
@@ -110,7 +122,9 @@ export function assertLicenceRenameSeatCommand(
|
|
|
110
122
|
nonEmpty(root.machineId, "$.machineId");
|
|
111
123
|
// Null clears the label back to unnamed; an empty string is a mistake
|
|
112
124
|
// wearing null's clothes and is refused rather than stored.
|
|
113
|
-
if (root.label !== null)
|
|
125
|
+
if (root.label !== null) {
|
|
126
|
+
nonEmpty(root.label, "$.label");
|
|
127
|
+
}
|
|
114
128
|
}
|
|
115
129
|
|
|
116
130
|
function held(value: unknown, path: string): void {
|
|
@@ -131,7 +145,9 @@ function held(value: unknown, path: string): void {
|
|
|
131
145
|
// checks it is present and never what it says, because anything derived
|
|
132
146
|
// from the host would be a different value wearing the same field.
|
|
133
147
|
nonEmpty(seat.machineId, `${at}.machineId`);
|
|
134
|
-
if (seat.label !== null)
|
|
148
|
+
if (seat.label !== null) {
|
|
149
|
+
nonEmpty(seat.label, `${at}.label`);
|
|
150
|
+
}
|
|
135
151
|
boolean(seat.thisMachine, `${at}.thisMachine`);
|
|
136
152
|
});
|
|
137
153
|
array(licence.entitlements, `${path}.entitlements`).forEach((entry, index) => {
|
|
@@ -141,7 +157,9 @@ function held(value: unknown, path: string): void {
|
|
|
141
157
|
// Opaque by design: Longhorn enumerates no features, so this checks that
|
|
142
158
|
// an id is present and never what it says.
|
|
143
159
|
nonEmpty(entitlement.id, `${at}.id`);
|
|
144
|
-
if (entitlement.atMost !== null)
|
|
160
|
+
if (entitlement.atMost !== null) {
|
|
161
|
+
positive(entitlement.atMost, `${at}.atMost`);
|
|
162
|
+
}
|
|
145
163
|
});
|
|
146
164
|
}
|
|
147
165
|
|
|
@@ -152,7 +170,9 @@ function usability(value: unknown, path: string): void {
|
|
|
152
170
|
// `clockRefused` carries no timestamp on purpose: a licence refused because
|
|
153
171
|
// the machine clock moved is not expired, and giving it a date would invite
|
|
154
172
|
// a surface to render it as one.
|
|
155
|
-
if (root.state === "inGrace")
|
|
173
|
+
if (root.state === "inGrace") {
|
|
174
|
+
timestamp(root.until, `${path}.until`);
|
|
175
|
+
}
|
|
156
176
|
if (root.state === "useWindowExpired" || root.state === "leaseLapsed") {
|
|
157
177
|
timestamp(root.at, `${path}.at`);
|
|
158
178
|
}
|
|
@@ -162,10 +182,12 @@ function trustBasis(value: unknown, path: string): void {
|
|
|
162
182
|
const root = object(value, path);
|
|
163
183
|
oneOf(root.kind, `${path}.kind`, LICENCE_TRUST_BASIS_KINDS);
|
|
164
184
|
exact(root, path, variantFields("LicenceTrustBasisProjection", root, path));
|
|
165
|
-
if (root.kind === "remoteAssertion")
|
|
185
|
+
if (root.kind === "remoteAssertion") {
|
|
186
|
+
timestamp(root.checked, `${path}.checked`);
|
|
187
|
+
}
|
|
166
188
|
}
|
|
167
189
|
|
|
168
|
-
function commandBase(value: unknown, expected:
|
|
190
|
+
function commandBase(value: unknown, expected: ReadonlyArray<string>): Record<string, unknown> {
|
|
169
191
|
const root = object(value, "$");
|
|
170
192
|
exact(root, "$", expected);
|
|
171
193
|
protocol(root.protocolVersion, "$.protocolVersion");
|
|
@@ -187,8 +209,10 @@ function commandBase(value: unknown, expected: readonly string[]): Record<string
|
|
|
187
209
|
function noCredential(value: unknown): void {
|
|
188
210
|
const forbidden = ["credential", "secret", "signature", "token", "privatekey", "keyid"];
|
|
189
211
|
const visit = (candidate: unknown, path: string): void => {
|
|
190
|
-
if (Array.isArray(candidate))
|
|
191
|
-
|
|
212
|
+
if (Array.isArray(candidate)) {
|
|
213
|
+
return candidate.forEach((item, index) => visit(item, `${path}[${index}]`));
|
|
214
|
+
}
|
|
215
|
+
if (candidate !== null && typeof candidate === "object") {
|
|
192
216
|
for (const [key, child] of Object.entries(candidate)) {
|
|
193
217
|
const lowered = key.toLocaleLowerCase();
|
|
194
218
|
if (forbidden.some((needle) => lowered.includes(needle))) {
|
|
@@ -196,6 +220,7 @@ function noCredential(value: unknown): void {
|
|
|
196
220
|
}
|
|
197
221
|
visit(child, `${path}.${key}`);
|
|
198
222
|
}
|
|
223
|
+
}
|
|
199
224
|
};
|
|
200
225
|
visit(value, "$");
|
|
201
226
|
}
|
|
@@ -204,23 +229,89 @@ function variantFields(
|
|
|
204
229
|
type: string,
|
|
205
230
|
value: Record<string, unknown>,
|
|
206
231
|
path: string,
|
|
207
|
-
):
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
function
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
232
|
+
): ReadonlyArray<string> {
|
|
233
|
+
return wireVariantFields(
|
|
234
|
+
LICENCE_VARIANT_FIELDS,
|
|
235
|
+
LICENCE_VARIANT_FIELDS_DISCRIMINANTS,
|
|
236
|
+
type,
|
|
237
|
+
value,
|
|
238
|
+
(discriminant) => fail(path, `no generated fields for ${type}.${String(discriminant)}`),
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function object(value: unknown, path: string): Record<string, unknown> {
|
|
243
|
+
const result = readWireRecord(value, () => fail(path, "expected object"));
|
|
244
|
+
return result;
|
|
245
|
+
}
|
|
246
|
+
function array(value: unknown, path: string): Array<unknown> {
|
|
247
|
+
if (!Array.isArray(value)) {
|
|
248
|
+
fail(path, "expected array");
|
|
249
|
+
}
|
|
250
|
+
return value;
|
|
251
|
+
}
|
|
252
|
+
function exact(
|
|
253
|
+
value: Record<string, unknown>,
|
|
254
|
+
path: string,
|
|
255
|
+
expected: ReadonlyArray<string>,
|
|
256
|
+
): void {
|
|
257
|
+
checkWireFields(value, expected, () =>
|
|
258
|
+
fail(path, `unexpected keys: ${Object.keys(value).sort().join(",")}`),
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
function protocol(value: unknown, path: string): void {
|
|
262
|
+
if (value !== LICENCE_PROTOCOL_VERSION) {
|
|
263
|
+
fail(path, `expected exact protocol ${LICENCE_PROTOCOL_VERSION}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function positive(value: unknown, path: string): void {
|
|
267
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
268
|
+
fail(path, "expected positive safe integer");
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
function string(value: unknown, path: string): asserts value is string {
|
|
272
|
+
if (typeof value !== "string") {
|
|
273
|
+
fail(path, "expected string");
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function nonEmpty(value: unknown, path: string): void {
|
|
277
|
+
string(value, path);
|
|
278
|
+
if (value.length === 0) {
|
|
279
|
+
fail(path, "expected a non-empty string");
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
function base64(value: unknown, path: string): void {
|
|
283
|
+
string(value, path);
|
|
284
|
+
// Canonical padded standard base64, including zero pad bits.
|
|
285
|
+
if (
|
|
286
|
+
!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value) ||
|
|
287
|
+
value.length === 0 ||
|
|
288
|
+
(value.endsWith("==") && !/[AQgw]==$/.test(value)) ||
|
|
289
|
+
(value.endsWith("=") && !value.endsWith("==") && !/[AEIMQUYcgkosw048]=$/.test(value))
|
|
290
|
+
) {
|
|
291
|
+
fail(path, "expected padded standard base64");
|
|
292
|
+
}
|
|
293
|
+
}
|
|
221
294
|
/** Unix seconds, and negative is a real point in time. */
|
|
222
|
-
function timestamp(value: unknown, path: string): void {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
295
|
+
function timestamp(value: unknown, path: string): void {
|
|
296
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value)) {
|
|
297
|
+
fail(path, "expected a unix-second timestamp");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function optionalTimestamp(value: unknown, path: string): void {
|
|
301
|
+
if (value !== null) {
|
|
302
|
+
timestamp(value, path);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function boolean(value: unknown, path: string): void {
|
|
306
|
+
if (typeof value !== "boolean") {
|
|
307
|
+
fail(path, "expected boolean");
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function oneOf(value: unknown, path: string, values: ReadonlyArray<string>): void {
|
|
311
|
+
if (typeof value !== "string" || !values.includes(value)) {
|
|
312
|
+
fail(path, "unsupported value");
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function fail(path: string, message: string): never {
|
|
316
|
+
throw new LicenceValidationError(path, message);
|
|
317
|
+
}
|