@inflatable-cookie/longhorn 0.1.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/LICENSE +21 -0
- package/README.md +38 -0
- package/package.json +205 -0
- package/src/agent-control/index.ts +20 -0
- package/src/agent-control/inject.ts +4 -0
- package/src/agent-control/shim.ts +722 -0
- package/src/bridge/direct.ts +22 -0
- package/src/bridge/generated/fields.ts +32 -0
- package/src/bridge/generated/protocol.ts +218 -0
- package/src/bridge/generated/variant-fields.ts +10 -0
- package/src/bridge/index.ts +15 -0
- package/src/bridge/job.ts +51 -0
- package/src/bridge/loopback.ts +84 -0
- package/src/bridge/operation.ts +166 -0
- package/src/bridge/router.ts +71 -0
- package/src/bridge/runtime/connection.ts +318 -0
- package/src/bridge/runtime/policy.ts +89 -0
- package/src/bridge/runtime/retry.ts +60 -0
- package/src/bridge/runtime.ts +3 -0
- package/src/bridge/session.ts +67 -0
- package/src/bridge/stream/connection.ts +146 -0
- package/src/bridge/stream/source.ts +61 -0
- package/src/bridge/stream/tracker.ts +109 -0
- package/src/bridge/stream.ts +6 -0
- package/src/bridge/supervision.ts +204 -0
- package/src/bridge/validation/base.ts +164 -0
- package/src/bridge/validation/jobs.ts +105 -0
- package/src/bridge/validation/negotiation.ts +242 -0
- package/src/bridge/validation/operations.ts +213 -0
- package/src/bridge/validation/streams.ts +47 -0
- package/src/bridge/validation.ts +5 -0
- package/src/commands/client.ts +124 -0
- package/src/commands/controller.ts +411 -0
- package/src/commands/generated/fields.ts +43 -0
- package/src/commands/generated/protocol.ts +876 -0
- package/src/commands/generated/variant-fields.ts +88 -0
- package/src/commands/index.ts +13 -0
- package/src/commands/keyboard.ts +361 -0
- package/src/commands/ports.ts +82 -0
- package/src/commands/projectors.ts +306 -0
- package/src/commands/validation.ts +444 -0
- package/src/config/client.ts +215 -0
- package/src/config/generated/base.ts +714 -0
- package/src/config/generated/fields.ts +54 -0
- package/src/config/generated/label-template.ts +14 -0
- package/src/config/generated/labels.ts +30 -0
- package/src/config/generated/protocol.ts +3 -0
- package/src/config/generated/restore.ts +658 -0
- package/src/config/generated/variant-fields.ts +129 -0
- package/src/config/index.ts +12 -0
- package/src/config/names.ts +19 -0
- package/src/config/validation/commands.ts +155 -0
- package/src/config/validation/outcomes.ts +243 -0
- package/src/config/validation/primitives.ts +174 -0
- package/src/config/validation/projection.ts +351 -0
- package/src/config/validation.ts +7 -0
- package/src/core/connection.ts +252 -0
- package/src/core/index.ts +2 -0
- package/src/core/transport.ts +24 -0
- package/src/history/client.ts +65 -0
- package/src/history/controller.ts +385 -0
- package/src/history/direct.ts +21 -0
- package/src/history/generated/fields.ts +18 -0
- package/src/history/generated/protocol.ts +389 -0
- package/src/history/generated/variant-fields.ts +27 -0
- package/src/history/index.ts +13 -0
- package/src/history/ports.ts +31 -0
- package/src/history/serialized.ts +38 -0
- package/src/history/validation.ts +334 -0
- package/src/history-tree/client.ts +16 -0
- package/src/history-tree/controller.ts +199 -0
- package/src/history-tree/direct.ts +3 -0
- package/src/history-tree/generated/fields.ts +26 -0
- package/src/history-tree/generated/protocol.ts +711 -0
- package/src/history-tree/generated/variant-fields.ts +39 -0
- package/src/history-tree/index.ts +13 -0
- package/src/history-tree/ports.ts +43 -0
- package/src/history-tree/serialized.ts +15 -0
- package/src/history-tree/validation.ts +269 -0
- package/src/layout/generated/protocol.ts +289 -0
- package/src/layout/index.ts +4 -0
- package/src/layout/ratio.ts +22 -0
- package/src/layout/validation.ts +110 -0
- package/src/layout/visibility.ts +30 -0
- package/src/licence/client.ts +32 -0
- package/src/licence/controller.ts +301 -0
- package/src/licence/direct.ts +3 -0
- package/src/licence/generated/fields.ts +17 -0
- package/src/licence/generated/key-conformance.json +42 -0
- package/src/licence/generated/protocol.ts +249 -0
- package/src/licence/generated/variant-fields.ts +34 -0
- package/src/licence/index.ts +14 -0
- package/src/licence/key.ts +125 -0
- package/src/licence/ports.ts +39 -0
- package/src/licence/serialized.ts +13 -0
- package/src/licence/validation.ts +226 -0
- package/src/native-content/client.ts +474 -0
- package/src/native-content/direct.ts +16 -0
- package/src/native-content/generated/fields.ts +32 -0
- package/src/native-content/generated/protocol.ts +498 -0
- package/src/native-content/generated/variant-fields.ts +77 -0
- package/src/native-content/index.ts +12 -0
- package/src/native-content/ports.ts +46 -0
- package/src/native-content/serialized.ts +50 -0
- package/src/native-content/validation/base.ts +194 -0
- package/src/native-content/validation/messages.ts +192 -0
- package/src/native-content/validation/state.ts +404 -0
- package/src/native-content/validation.ts +7 -0
- package/src/notifications/client.ts +106 -0
- package/src/notifications/controller.ts +240 -0
- package/src/notifications/direct.ts +12 -0
- package/src/notifications/generated/fields.ts +19 -0
- package/src/notifications/generated/labels.ts +20 -0
- package/src/notifications/generated/protocol.ts +522 -0
- package/src/notifications/generated/variant-fields.ts +37 -0
- package/src/notifications/index.ts +16 -0
- package/src/notifications/ports.ts +22 -0
- package/src/notifications/serialized.ts +27 -0
- package/src/notifications/toast.ts +41 -0
- package/src/notifications/tone.ts +27 -0
- package/src/notifications/validation.ts +246 -0
- package/src/operation/bridge.ts +168 -0
- package/src/operation/client.ts +167 -0
- package/src/operation/controller.ts +321 -0
- package/src/operation/direct.ts +15 -0
- package/src/operation/generated/fields.ts +20 -0
- package/src/operation/generated/labels.ts +15 -0
- package/src/operation/generated/protocol.ts +762 -0
- package/src/operation/generated/variant-fields.ts +60 -0
- package/src/operation/index.ts +14 -0
- package/src/operation/ports.ts +29 -0
- package/src/operation/serialized.ts +39 -0
- package/src/operation/validation.ts +479 -0
- package/src/settings/client.ts +142 -0
- package/src/settings/connection.ts +246 -0
- package/src/settings/generated/fields.ts +34 -0
- package/src/settings/generated/protocol.ts +668 -0
- package/src/settings/generated/variant-fields.ts +26 -0
- package/src/settings/index.ts +12 -0
- package/src/settings/names.ts +8 -0
- package/src/settings/registry.ts +141 -0
- package/src/settings/validation/authority.ts +66 -0
- package/src/settings/validation/command.ts +165 -0
- package/src/settings/validation/error.ts +33 -0
- package/src/settings/validation/primitives.ts +203 -0
- package/src/settings/validation/projection.ts +50 -0
- package/src/settings/validation/registry.ts +170 -0
- package/src/settings/validation.ts +4 -0
- package/src/surface-transfer/client.ts +54 -0
- package/src/surface-transfer/generated/fields.ts +12 -0
- package/src/surface-transfer/generated/protocol.ts +61 -0
- package/src/surface-transfer/generated/variant-fields.ts +30 -0
- package/src/surface-transfer/index.ts +9 -0
- package/src/surface-transfer/validation.ts +209 -0
- package/src/surfaces/client.ts +140 -0
- package/src/surfaces/generated/fields.ts +19 -0
- package/src/surfaces/generated/protocol.ts +217 -0
- package/src/surfaces/generated/variant-fields.ts +42 -0
- package/src/surfaces/index.ts +9 -0
- package/src/surfaces/validation.ts +199 -0
- package/src/transfer/client.ts +133 -0
- package/src/transfer/connection.ts +87 -0
- package/src/transfer/generated/fields.ts +23 -0
- package/src/transfer/generated/protocol.ts +171 -0
- package/src/transfer/generated/variant-fields.ts +45 -0
- package/src/transfer/index.ts +11 -0
- package/src/transfer/payload.ts +71 -0
- package/src/transfer/validation.ts +282 -0
- package/src/update/client.ts +29 -0
- package/src/update/controller.ts +255 -0
- package/src/update/direct.ts +3 -0
- package/src/update/generated/fields.ts +14 -0
- package/src/update/generated/protocol.ts +238 -0
- package/src/update/generated/variant-fields.ts +44 -0
- package/src/update/index.ts +14 -0
- package/src/update/ports.ts +36 -0
- package/src/update/serialized.ts +12 -0
- package/src/update/validation.ts +191 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LayoutRatio } from "./generated/protocol.ts";
|
|
2
|
+
|
|
3
|
+
export const LAYOUT_RATIO_ONE_MILLIONTHS = 1_000_000;
|
|
4
|
+
|
|
5
|
+
export function layoutRatioFromMillionths(value: number): LayoutRatio {
|
|
6
|
+
if (
|
|
7
|
+
!Number.isSafeInteger(value) ||
|
|
8
|
+
value < 0 ||
|
|
9
|
+
value > LAYOUT_RATIO_ONE_MILLIONTHS
|
|
10
|
+
) {
|
|
11
|
+
throw new RangeError(
|
|
12
|
+
`layout ratio must be an integer from 0 through ${LAYOUT_RATIO_ONE_MILLIONTHS}; received ${String(value)}`,
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function layoutRatioToUnitInterval(value: LayoutRatio): number {
|
|
19
|
+
return (
|
|
20
|
+
layoutRatioFromMillionths(value) / LAYOUT_RATIO_ONE_MILLIONTHS
|
|
21
|
+
);
|
|
22
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LAYOUT_MUTATION_COMMAND_KINDS,
|
|
3
|
+
LAYOUT_MUTATION_OUTCOME_KINDS,
|
|
4
|
+
LAYOUT_MUTATION_REJECTION_CODES,
|
|
5
|
+
LAYOUT_PROTOCOL_VERSION,
|
|
6
|
+
type LayoutMutationCommand,
|
|
7
|
+
type LayoutMutationOutcome,
|
|
8
|
+
type LayoutMutationRejectionCode,
|
|
9
|
+
} from "./generated/protocol.ts";
|
|
10
|
+
|
|
11
|
+
export type LayoutProtocolValidationCode =
|
|
12
|
+
| "unsupported_protocol_version"
|
|
13
|
+
| "unknown_command"
|
|
14
|
+
| "unknown_outcome"
|
|
15
|
+
| "unknown_rejection_code";
|
|
16
|
+
|
|
17
|
+
export class LayoutProtocolValidationError extends Error {
|
|
18
|
+
readonly code: LayoutProtocolValidationCode;
|
|
19
|
+
readonly received: unknown;
|
|
20
|
+
|
|
21
|
+
constructor(code: LayoutProtocolValidationCode, received: unknown) {
|
|
22
|
+
super(message(code, received));
|
|
23
|
+
this.name = "LayoutProtocolValidationError";
|
|
24
|
+
this.code = code;
|
|
25
|
+
this.received = received;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function assertLayoutProtocolVersion(
|
|
30
|
+
version: unknown,
|
|
31
|
+
): asserts version is typeof LAYOUT_PROTOCOL_VERSION {
|
|
32
|
+
if (version !== LAYOUT_PROTOCOL_VERSION) {
|
|
33
|
+
throw new LayoutProtocolValidationError(
|
|
34
|
+
"unsupported_protocol_version",
|
|
35
|
+
version,
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function assertValidLayoutMutationCommand(
|
|
41
|
+
value: unknown,
|
|
42
|
+
): asserts value is LayoutMutationCommand {
|
|
43
|
+
assertKnownKind(value, LAYOUT_MUTATION_COMMAND_KINDS, "unknown_command");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function assertValidLayoutMutationOutcome(
|
|
47
|
+
value: unknown,
|
|
48
|
+
): asserts value is LayoutMutationOutcome {
|
|
49
|
+
assertKnownKind(value, LAYOUT_MUTATION_OUTCOME_KINDS, "unknown_outcome");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function assertValidLayoutMutationRejectionCode(
|
|
53
|
+
value: unknown,
|
|
54
|
+
): asserts value is LayoutMutationRejectionCode {
|
|
55
|
+
if (
|
|
56
|
+
typeof value !== "string" ||
|
|
57
|
+
!LAYOUT_MUTATION_REJECTION_CODES.includes(
|
|
58
|
+
value as (typeof LAYOUT_MUTATION_REJECTION_CODES)[number],
|
|
59
|
+
)
|
|
60
|
+
) {
|
|
61
|
+
throw new LayoutProtocolValidationError(
|
|
62
|
+
"unknown_rejection_code",
|
|
63
|
+
value,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function assertKnownKind(
|
|
69
|
+
value: unknown,
|
|
70
|
+
known: readonly string[],
|
|
71
|
+
code: "unknown_command" | "unknown_outcome",
|
|
72
|
+
): asserts value is Record<"kind", string> {
|
|
73
|
+
if (
|
|
74
|
+
typeof value !== "object" ||
|
|
75
|
+
value === null ||
|
|
76
|
+
!("kind" in value) ||
|
|
77
|
+
typeof value.kind !== "string" ||
|
|
78
|
+
!known.includes(value.kind)
|
|
79
|
+
) {
|
|
80
|
+
throw new LayoutProtocolValidationError(code, value);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function message(
|
|
85
|
+
code: LayoutProtocolValidationCode,
|
|
86
|
+
received: unknown,
|
|
87
|
+
): string {
|
|
88
|
+
switch (code) {
|
|
89
|
+
case "unsupported_protocol_version":
|
|
90
|
+
return `unsupported layout protocol version ${String(received)}; expected ${LAYOUT_PROTOCOL_VERSION}`;
|
|
91
|
+
case "unknown_command":
|
|
92
|
+
return `unknown layout mutation command ${kindOf(received)}`;
|
|
93
|
+
case "unknown_outcome":
|
|
94
|
+
return `unknown layout mutation outcome ${kindOf(received)}`;
|
|
95
|
+
case "unknown_rejection_code":
|
|
96
|
+
return `unknown layout mutation rejection code ${String(received)}`;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function kindOf(value: unknown): string {
|
|
101
|
+
if (
|
|
102
|
+
typeof value === "object" &&
|
|
103
|
+
value !== null &&
|
|
104
|
+
"kind" in value &&
|
|
105
|
+
typeof value.kind === "string"
|
|
106
|
+
) {
|
|
107
|
+
return value.kind;
|
|
108
|
+
}
|
|
109
|
+
return String(value);
|
|
110
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RegionDefinition,
|
|
3
|
+
RegionState,
|
|
4
|
+
RegionVisibility,
|
|
5
|
+
RegionVisibilityState,
|
|
6
|
+
} from "./generated/protocol.ts";
|
|
7
|
+
|
|
8
|
+
export function projectOrdinaryRegionVisibility(
|
|
9
|
+
definition: RegionDefinition,
|
|
10
|
+
state: RegionState,
|
|
11
|
+
): RegionVisibility {
|
|
12
|
+
if (definition.id !== state.region_id) {
|
|
13
|
+
throw new RangeError(
|
|
14
|
+
`region definition ${definition.id} does not match state ${state.region_id}`,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
region_id: definition.id,
|
|
20
|
+
state:
|
|
21
|
+
state.panel_instance_ids.length > 0 ||
|
|
22
|
+
definition.empty_policy === "keep_visible"
|
|
23
|
+
? "visible"
|
|
24
|
+
: "hidden",
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function isRegionPresented(state: RegionVisibilityState): boolean {
|
|
29
|
+
return state !== "hidden";
|
|
30
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
LicenceActivateCommand,
|
|
3
|
+
LicenceChangedEvent,
|
|
4
|
+
LicenceDeactivateCommand,
|
|
5
|
+
LicenceOutcomeProjection,
|
|
6
|
+
LicenceRefreshCommand,
|
|
7
|
+
LicenceReleaseSeatCommand,
|
|
8
|
+
LicenceRenameSeatCommand,
|
|
9
|
+
LicenceSnapshot,
|
|
10
|
+
} from "./generated/protocol.ts";
|
|
11
|
+
import type { CheckedLicencePort, LicencePort, LicenceUnlisten } from "./ports.ts";
|
|
12
|
+
import {
|
|
13
|
+
assertLicenceActivateCommand,
|
|
14
|
+
assertLicenceChangedEvent,
|
|
15
|
+
assertLicenceDeactivateCommand,
|
|
16
|
+
assertLicenceOutcome,
|
|
17
|
+
assertLicenceRefreshCommand,
|
|
18
|
+
assertLicenceReleaseSeatCommand,
|
|
19
|
+
assertLicenceRenameSeatCommand,
|
|
20
|
+
assertLicenceSnapshot,
|
|
21
|
+
} from "./validation.ts";
|
|
22
|
+
|
|
23
|
+
export class LicenceClient implements CheckedLicencePort {
|
|
24
|
+
constructor(readonly port: LicencePort) {}
|
|
25
|
+
async snapshot(): Promise<LicenceSnapshot> { const value = await this.port.snapshot(); assertLicenceSnapshot(value); return value; }
|
|
26
|
+
async activate(command: LicenceActivateCommand): Promise<LicenceOutcomeProjection> { assertLicenceActivateCommand(command); const value = await this.port.activate(command); assertLicenceOutcome(value); return value; }
|
|
27
|
+
async deactivate(command: LicenceDeactivateCommand): Promise<LicenceOutcomeProjection> { assertLicenceDeactivateCommand(command); const value = await this.port.deactivate(command); assertLicenceOutcome(value); return value; }
|
|
28
|
+
async refresh(command: LicenceRefreshCommand): Promise<LicenceOutcomeProjection> { assertLicenceRefreshCommand(command); const value = await this.port.refresh(command); assertLicenceOutcome(value); return value; }
|
|
29
|
+
async releaseSeat(command: LicenceReleaseSeatCommand): Promise<LicenceOutcomeProjection> { assertLicenceReleaseSeatCommand(command); const value = await this.port.releaseSeat(command); assertLicenceOutcome(value); return value; }
|
|
30
|
+
async renameSeat(command: LicenceRenameSeatCommand): Promise<LicenceOutcomeProjection> { assertLicenceRenameSeatCommand(command); const value = await this.port.renameSeat(command); assertLicenceOutcome(value); return value; }
|
|
31
|
+
async listen(listener: (event: LicenceChangedEvent) => void): Promise<LicenceUnlisten> { if (this.port.listen === undefined) return () => {}; return this.port.listen((value) => { assertLicenceChangedEvent(value); listener(value); }); }
|
|
32
|
+
}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { LicenceClient } from "./client.ts";
|
|
2
|
+
import {
|
|
3
|
+
LICENCE_PROTOCOL_VERSION,
|
|
4
|
+
type HeldLicenceProjection,
|
|
5
|
+
type LicenceCredentialProjection,
|
|
6
|
+
type LicenceRejectionCode,
|
|
7
|
+
type LicenceSeatProjection,
|
|
8
|
+
type LicenceSnapshot,
|
|
9
|
+
type LicenceTrustBasisProjection,
|
|
10
|
+
type LicenceUsabilityProjection,
|
|
11
|
+
} from "./generated/protocol.ts";
|
|
12
|
+
import type { LicencePort, LicenceUnlisten } from "./ports.ts";
|
|
13
|
+
|
|
14
|
+
export type LicenceControllerStatus =
|
|
15
|
+
| { readonly kind: "idle" }
|
|
16
|
+
| { readonly kind: "loading" }
|
|
17
|
+
| { readonly kind: "ready" }
|
|
18
|
+
| { readonly kind: "failed"; readonly error: unknown };
|
|
19
|
+
|
|
20
|
+
export interface LicenceControllerOptions {
|
|
21
|
+
readonly port: LicencePort;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* What the operator should be told, if anything.
|
|
26
|
+
*
|
|
27
|
+
* A predicate rather than a rendering, and Longhorn's rather than a surface's,
|
|
28
|
+
* for the same reason `UpdateController.presence` is: deriving it means
|
|
29
|
+
* reading five usability states against a trust basis and two windows, and two
|
|
30
|
+
* surfaces deriving it separately would disagree.
|
|
31
|
+
*
|
|
32
|
+
* - `none` — nothing to say. Includes an in-lease renewal that has not yet
|
|
33
|
+
* succeeded, which is the one this exists to get right.
|
|
34
|
+
* - `informational` — worth showing where the operator is already looking, not
|
|
35
|
+
* worth interrupting for.
|
|
36
|
+
* - `actionable` — the operator must do something or lose access.
|
|
37
|
+
*/
|
|
38
|
+
export type LicenceAttention = "none" | "informational" | "actionable";
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Holds licence state for a surface.
|
|
42
|
+
*
|
|
43
|
+
* Reports entitlement; never enforces. What a missing entitlement *does* is
|
|
44
|
+
* the application's decision, which is contract 019's line and the reason this
|
|
45
|
+
* exposes state rather than permissions.
|
|
46
|
+
*/
|
|
47
|
+
export class LicenceController {
|
|
48
|
+
readonly #client: LicenceClient;
|
|
49
|
+
readonly #observers = new Set<() => void>();
|
|
50
|
+
#status: LicenceControllerStatus = { kind: "idle" };
|
|
51
|
+
#snapshot?: LicenceSnapshot;
|
|
52
|
+
#lastRejection?: LicenceRejectionCode;
|
|
53
|
+
#started = false;
|
|
54
|
+
#lifecycle = 0;
|
|
55
|
+
#pending = false;
|
|
56
|
+
#unlisten: LicenceUnlisten[] = [];
|
|
57
|
+
|
|
58
|
+
constructor(options: LicenceControllerOptions) {
|
|
59
|
+
this.#client = new LicenceClient(options.port);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get status(): LicenceControllerStatus { return this.#status; }
|
|
63
|
+
get snapshot(): LicenceSnapshot | undefined { return this.#snapshot; }
|
|
64
|
+
get licence(): HeldLicenceProjection | undefined { return this.#snapshot?.licence ?? undefined; }
|
|
65
|
+
get usability(): LicenceUsabilityProjection | undefined { return this.licence?.usability; }
|
|
66
|
+
get trustBasis(): LicenceTrustBasisProjection | undefined { return this.licence?.trustBasis; }
|
|
67
|
+
get pending(): boolean { return this.#pending; }
|
|
68
|
+
get lastRejection(): LicenceRejectionCode | undefined { return this.#lastRejection; }
|
|
69
|
+
|
|
70
|
+
/** Whether a licence is held at all. Absence is not a usability state. */
|
|
71
|
+
get activated(): boolean { return this.licence !== undefined; }
|
|
72
|
+
|
|
73
|
+
/** Whether the software may be used. Grace counts, which is its point. */
|
|
74
|
+
get usable(): boolean {
|
|
75
|
+
const state = this.usability?.state;
|
|
76
|
+
return state === "active" || state === "inGrace";
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* When use stops being permitted, and when updates stop being covered.
|
|
81
|
+
*
|
|
82
|
+
* Two reads rather than one, because they are two different sentences. "Your
|
|
83
|
+
* subscription lapsed" and "your updates lapsed but the app keeps working"
|
|
84
|
+
* are not the same message, and conflating them on a perpetual licence reads
|
|
85
|
+
* as the application breaking.
|
|
86
|
+
*/
|
|
87
|
+
get useUntil(): number | undefined { return this.licence?.useUntil ?? undefined; }
|
|
88
|
+
get updateUntil(): number | undefined { return this.licence?.updateUntil ?? undefined; }
|
|
89
|
+
|
|
90
|
+
/** Entitlement ids held, opaque by design. Longhorn enumerates no features. */
|
|
91
|
+
get entitlements(): readonly string[] {
|
|
92
|
+
return this.licence?.entitlements.map((entitlement) => entitlement.id) ?? [];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Whether an entitlement is held. The application decides what that means. */
|
|
96
|
+
holds(id: string): boolean {
|
|
97
|
+
return this.licence?.entitlements.some((entitlement) => entitlement.id === id) ?? false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The bound on an entitlement, or `undefined` for unlimited or unheld. */
|
|
101
|
+
limit(id: string): number | undefined {
|
|
102
|
+
return this.licence?.entitlements.find((entitlement) => entitlement.id === id)?.atMost ?? undefined;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* What to tell the operator.
|
|
107
|
+
*
|
|
108
|
+
* `inGrace` is deliberately `none`. A renewal that has not yet succeeded,
|
|
109
|
+
* inside its lease, is a backend outage rather than the customer's problem —
|
|
110
|
+
* and a surface that raises it turns an outage into a support ticket from
|
|
111
|
+
* someone who has already paid.
|
|
112
|
+
*
|
|
113
|
+
* `clockRefused` is `actionable` and is not an expiry. The remedy is to fix
|
|
114
|
+
* the clock, and a surface that showed it as expired would send the operator
|
|
115
|
+
* to buy something they already own.
|
|
116
|
+
*/
|
|
117
|
+
get attention(): LicenceAttention {
|
|
118
|
+
if (!this.activated) return "actionable";
|
|
119
|
+
switch (this.usability?.state) {
|
|
120
|
+
case "active":
|
|
121
|
+
case "inGrace":
|
|
122
|
+
break;
|
|
123
|
+
case "useWindowExpired":
|
|
124
|
+
case "leaseLapsed":
|
|
125
|
+
case "clockRefused":
|
|
126
|
+
return "actionable";
|
|
127
|
+
default:
|
|
128
|
+
return "none";
|
|
129
|
+
}
|
|
130
|
+
// Usable, but updates are no longer covered. Worth saying where the
|
|
131
|
+
// operator is already looking; not worth interrupting for, because
|
|
132
|
+
// nothing stops working.
|
|
133
|
+
return this.updateUntil !== undefined ? "informational" : "none";
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
observe(observer: () => void): () => void {
|
|
137
|
+
this.#observers.add(observer);
|
|
138
|
+
return () => this.#observers.delete(observer);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async start(): Promise<void> {
|
|
142
|
+
if (this.#started) return;
|
|
143
|
+
this.#started = true;
|
|
144
|
+
const lifecycle = ++this.#lifecycle;
|
|
145
|
+
this.#setStatus({ kind: "loading" });
|
|
146
|
+
try {
|
|
147
|
+
const unlisten = await this.#client.listen(() => void this.refresh());
|
|
148
|
+
if (!this.#started || lifecycle !== this.#lifecycle) {
|
|
149
|
+
await unlisten();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
this.#unlisten.push(unlisten);
|
|
153
|
+
await this.refresh();
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (this.#started && lifecycle === this.#lifecycle) this.#setStatus({ kind: "failed", error });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async stop(): Promise<void> {
|
|
160
|
+
this.#started = false;
|
|
161
|
+
this.#lifecycle += 1;
|
|
162
|
+
const unlisten = this.#unlisten;
|
|
163
|
+
this.#unlisten = [];
|
|
164
|
+
for (const stop of unlisten) await stop();
|
|
165
|
+
this.#setStatus({ kind: "idle" });
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async refresh(): Promise<void> {
|
|
169
|
+
const lifecycle = this.#lifecycle;
|
|
170
|
+
try {
|
|
171
|
+
const snapshot = await this.#client.snapshot();
|
|
172
|
+
if (lifecycle !== this.#lifecycle) return;
|
|
173
|
+
this.#snapshot = snapshot;
|
|
174
|
+
this.#setStatus({ kind: "ready" });
|
|
175
|
+
} catch (error) {
|
|
176
|
+
if (lifecycle === this.#lifecycle) this.#setStatus({ kind: "failed", error });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Every seat held under this licence, this machine included.
|
|
182
|
+
*
|
|
183
|
+
* Empty when the authority does not account for seats, which is a different
|
|
184
|
+
* state from a licence with one seat.
|
|
185
|
+
*/
|
|
186
|
+
get seats(): readonly LicenceSeatProjection[] { return this.licence?.seats ?? []; }
|
|
187
|
+
|
|
188
|
+
/** The seats that are not this machine — the ones a release would free. */
|
|
189
|
+
get otherSeats(): readonly LicenceSeatProjection[] {
|
|
190
|
+
return this.seats.filter((seat) => !seat.thisMachine);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Presents a credential. One command for all three routes, as Card 193 set.
|
|
195
|
+
*
|
|
196
|
+
* `label` is what the customer calls this machine in the seat list, asked
|
|
197
|
+
* for at the only moment it can be without inventing a settings screen.
|
|
198
|
+
*/
|
|
199
|
+
async activate(
|
|
200
|
+
credential: LicenceCredentialProjection,
|
|
201
|
+
label: string | null = null,
|
|
202
|
+
): Promise<void> {
|
|
203
|
+
await this.#command((client, epoch) =>
|
|
204
|
+
client.activate({
|
|
205
|
+
protocolVersion: LICENCE_PROTOCOL_VERSION,
|
|
206
|
+
authorityEpoch: epoch,
|
|
207
|
+
credential,
|
|
208
|
+
label,
|
|
209
|
+
}),
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Releases another machine's seat.
|
|
215
|
+
*
|
|
216
|
+
* The answer to "I got a new laptop": free the seats that are not this one
|
|
217
|
+
* without a support conversation. Separate from `deactivate`, which leaves
|
|
218
|
+
* the machine you are sitting at.
|
|
219
|
+
*/
|
|
220
|
+
async releaseSeat(machineId: string): Promise<void> {
|
|
221
|
+
await this.#command((client, epoch) =>
|
|
222
|
+
client.releaseSeat({
|
|
223
|
+
protocolVersion: LICENCE_PROTOCOL_VERSION,
|
|
224
|
+
authorityEpoch: epoch,
|
|
225
|
+
machineId,
|
|
226
|
+
}),
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** Releases this machine's seat. */
|
|
231
|
+
async deactivate(): Promise<void> {
|
|
232
|
+
await this.#command((client, epoch) =>
|
|
233
|
+
client.deactivate({ protocolVersion: LICENCE_PROTOCOL_VERSION, authorityEpoch: epoch }),
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Re-checks the lease now. */
|
|
238
|
+
async refreshLease(): Promise<void> {
|
|
239
|
+
await this.#command((client, epoch) =>
|
|
240
|
+
client.refresh({ protocolVersion: LICENCE_PROTOCOL_VERSION, authorityEpoch: epoch }),
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Renames a seat — this machine's or another's.
|
|
246
|
+
*
|
|
247
|
+
* `null` clears the label back to unnamed. The label stays the customer's
|
|
248
|
+
* word: this is the one write that can change it after activation.
|
|
249
|
+
*/
|
|
250
|
+
async renameSeat(machineId: string, label: string | null): Promise<void> {
|
|
251
|
+
await this.#command((client, epoch) =>
|
|
252
|
+
client.renameSeat({
|
|
253
|
+
protocolVersion: LICENCE_PROTOCOL_VERSION,
|
|
254
|
+
authorityEpoch: epoch,
|
|
255
|
+
machineId,
|
|
256
|
+
label,
|
|
257
|
+
}),
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async #command(
|
|
262
|
+
run: (
|
|
263
|
+
client: LicenceClient,
|
|
264
|
+
epoch: number,
|
|
265
|
+
) => Promise<import("./generated/protocol.ts").LicenceOutcomeProjection>,
|
|
266
|
+
): Promise<void> {
|
|
267
|
+
const epoch = this.#snapshot?.authorityEpoch;
|
|
268
|
+
if (epoch === undefined) {
|
|
269
|
+
// Inventing one would have the authority refuse it as stale, which reads
|
|
270
|
+
// as a protocol fault rather than as "nothing has been read yet".
|
|
271
|
+
this.#setStatus({ kind: "failed", error: new Error("licence state has not been read yet") });
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const lifecycle = this.#lifecycle;
|
|
275
|
+
this.#pending = true;
|
|
276
|
+
this.#notify();
|
|
277
|
+
try {
|
|
278
|
+
const outcome = await run(this.#client, epoch);
|
|
279
|
+
if (lifecycle !== this.#lifecycle) return;
|
|
280
|
+
this.#snapshot = outcome.snapshot;
|
|
281
|
+
this.#lastRejection = outcome.status === "rejected" ? outcome.code : undefined;
|
|
282
|
+
this.#setStatus({ kind: "ready" });
|
|
283
|
+
} catch (error) {
|
|
284
|
+
if (lifecycle === this.#lifecycle) this.#setStatus({ kind: "failed", error });
|
|
285
|
+
} finally {
|
|
286
|
+
if (lifecycle === this.#lifecycle) {
|
|
287
|
+
this.#pending = false;
|
|
288
|
+
this.#notify();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
#setStatus(status: LicenceControllerStatus): void {
|
|
294
|
+
this.#status = status;
|
|
295
|
+
this.#notify();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
#notify(): void {
|
|
299
|
+
for (const observer of this.#observers) observer();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @generated by `effigy generate:licence`; do not edit.
|
|
2
|
+
// Allowed field names per protocol type, from the Rust structs.
|
|
3
|
+
// A `record()` given one of these rejects unknown and missing keys —
|
|
4
|
+
// contract 010's Boundary Validation Target.
|
|
5
|
+
|
|
6
|
+
export const LICENCE_FIELDS: Record<string, readonly string[]> = {
|
|
7
|
+
"LicenceEntitlementProjection": ["id", "atMost"],
|
|
8
|
+
"LicenceSeatProjection": ["machineId", "label", "thisMachine"],
|
|
9
|
+
"HeldLicenceProjection": ["product", "usability", "trustBasis", "entitlements", "useUntil", "updateUntil", "seats"],
|
|
10
|
+
"LicenceSnapshot": ["protocolVersion", "authorityEpoch", "licence"],
|
|
11
|
+
"LicenceActivateCommand": ["protocolVersion", "authorityEpoch", "credential", "label"],
|
|
12
|
+
"LicenceDeactivateCommand": ["protocolVersion", "authorityEpoch"],
|
|
13
|
+
"LicenceRefreshCommand": ["protocolVersion", "authorityEpoch"],
|
|
14
|
+
"LicenceReleaseSeatCommand": ["protocolVersion", "authorityEpoch", "machineId"],
|
|
15
|
+
"LicenceRenameSeatCommand": ["protocolVersion", "authorityEpoch", "machineId", "label"],
|
|
16
|
+
"LicenceChangedEvent": ["protocolVersion", "authorityEpoch", "kind"],
|
|
17
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"input": "ABCDE12345FGHJK67894",
|
|
4
|
+
"outcome": "ok:ABCDE-12345-FGHJK-67894"
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
"input": "abcde12345fghjk67894",
|
|
8
|
+
"outcome": "ok:ABCDE-12345-FGHJK-67894"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"input": "ABCDE-12345-FGHJK-67894",
|
|
12
|
+
"outcome": "ok:ABCDE-12345-FGHJK-67894"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"input": " ABCDE 12345 FGHJK 67894 ",
|
|
16
|
+
"outcome": "ok:ABCDE-12345-FGHJK-67894"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"input": "IOIOI23456789ABCDEFP",
|
|
20
|
+
"outcome": "ok:10101-23456-789AB-CDEFP"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"input": "LOLOL23456789ABCDEFP",
|
|
24
|
+
"outcome": "ok:10101-23456-789AB-CDEFP"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"input": "BACDE12345FGHJK67894",
|
|
28
|
+
"outcome": "checkFailed"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"input": "",
|
|
32
|
+
"outcome": "tooShort:20:0"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"input": "ABCDE12345",
|
|
36
|
+
"outcome": "tooShort:20:10"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"input": "ABCDE!2345FGHJK6789X",
|
|
40
|
+
"outcome": "unexpectedSymbol:!"
|
|
41
|
+
}
|
|
42
|
+
]
|