@serve.zone/interfaces 32.115.0 → 32.117.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 (38) hide show
  1. package/changelog.md +16 -0
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts/data/controlledtakeover.d.ts +125 -0
  4. package/dist_ts/data/controlledtakeover.js +217 -0
  5. package/dist_ts/data/corestorereplication.d.ts +13 -0
  6. package/dist_ts/data/corestorereplication.js +27 -4
  7. package/dist_ts/data/diskencryption.d.ts +100 -0
  8. package/dist_ts/data/diskencryption.js +176 -0
  9. package/dist_ts/data/gatewayarearows.d.ts +17 -7
  10. package/dist_ts/data/gatewayarearows.js +31 -14
  11. package/dist_ts/data/index.d.ts +3 -0
  12. package/dist_ts/data/index.js +4 -1
  13. package/dist_ts/data/locationlock.d.ts +98 -0
  14. package/dist_ts/data/locationlock.js +175 -0
  15. package/dist_ts/index.d.ts +2 -0
  16. package/dist_ts/index.js +3 -1
  17. package/dist_ts/requests/controlledtakeover.d.ts +78 -0
  18. package/dist_ts/requests/controlledtakeover.js +45 -0
  19. package/dist_ts/requests/diskencryption.d.ts +73 -0
  20. package/dist_ts/requests/diskencryption.js +2 -0
  21. package/dist_ts/requests/index.d.ts +3 -0
  22. package/dist_ts/requests/index.js +4 -1
  23. package/dist_ts/requests/locationlock.d.ts +104 -0
  24. package/dist_ts/requests/locationlock.js +2 -0
  25. package/package.json +25 -1
  26. package/readme.md +34 -3
  27. package/ts/00_commitinfo_data.ts +1 -1
  28. package/ts/data/controlledtakeover.ts +338 -0
  29. package/ts/data/corestorereplication.ts +37 -3
  30. package/ts/data/diskencryption.ts +275 -0
  31. package/ts/data/gatewayarearows.ts +49 -18
  32. package/ts/data/index.ts +3 -0
  33. package/ts/data/locationlock.ts +280 -0
  34. package/ts/index.ts +2 -0
  35. package/ts/requests/controlledtakeover.ts +167 -0
  36. package/ts/requests/diskencryption.ts +81 -0
  37. package/ts/requests/index.ts +3 -0
  38. package/ts/requests/locationlock.ts +119 -0
@@ -0,0 +1,280 @@
1
+ import { validateControllerIdentifier, validateControllerStrictJson } from '../private/controllercontract.js';
2
+ import { hasExactKeys, readDataElements, readDataProperties, readExactDataRecord } from '../private/dataproperties.js';
3
+ import { isClusterNodeId } from '../private/nodeidentifier.js';
4
+ import { isBoundedInteger } from '../private/runtimepolicy.js';
5
+ import { validateServiceId } from './coremail.runtime.js';
6
+ import { isSha256Digest, type TSha256Digest } from './immutableimage.js';
7
+ import { isLocationMemberKind, isLocationName, type ILocationMember } from './location.js';
8
+
9
+ const lockModes = ['lock-now', 'evacuate-then-lock'] as const;
10
+ const lockPhases = [
11
+ 'recorded', 'locking-machines', 'promoting-peer', 'activating-fast-services', 'self-locking', 'locked', 'unlocked',
12
+ ] as const;
13
+ const machineStatuses = ['pending', 'confirmed', 'unreachable', 'self-demoting', 'edge-revoked'] as const;
14
+ const destroyStatuses = ['pending-confirmation', 'executing', 'destroyed', 'cancelled', 'expired'] as const;
15
+
16
+ export type TLocationLockMode = typeof lockModes[number];
17
+ export type TLocationLockPhase = typeof lockPhases[number];
18
+ export type TLocationLockMachineStatus = typeof machineStatuses[number];
19
+ export type TLocationDestroyStatus = typeof destroyStatuses[number];
20
+
21
+ export const locationLockRefusals = Object.freeze([
22
+ 'location-not-found', 'membership-unconfirmed', 'membership-changed', 'already-locked', 'not-locked',
23
+ 'already-destroyed', 'fresh-passkey-required', 'cloud-access-forbidden', 'same-administrator-forbidden',
24
+ 'destroy-not-found', 'destroy-expired', 'destroy-not-pending', 'lock-not-found', 'conflict', 'request-invalid',
25
+ ] as const);
26
+
27
+ export type TLocationLockRefusal = typeof locationLockRefusals[number];
28
+
29
+ export const locationLockBounds = Object.freeze({
30
+ maximumMachines: 1024,
31
+ maximumServices: 1024,
32
+ maximumSecrets: 1024,
33
+ maximumDetailBytes: 256,
34
+ // A list page carries complete machine snapshots. Keep it under the TypedSocket text frame limit.
35
+ operationsPerPage: 8,
36
+ });
37
+
38
+ export interface ILocationLockMachineState {
39
+ member: ILocationMember;
40
+ status: TLocationLockMachineStatus;
41
+ confirmedAt: number | null;
42
+ lastAttemptAt: number | null;
43
+ /** Bounded diagnostic text. Never include credentials or key material. */
44
+ detail?: string;
45
+ }
46
+
47
+ export interface ILocationLockPlan {
48
+ locationId: string;
49
+ locationName: string;
50
+ membershipDigest: TSha256Digest;
51
+ membershipConfirmed: boolean;
52
+ mode: TLocationLockMode;
53
+ controllerInLocation: boolean;
54
+ edgeOnlyLocation: boolean;
55
+ machines: ILocationMember[];
56
+ fastServiceIds: string[];
57
+ blockingReasons: TLocationLockRefusal[];
58
+ }
59
+
60
+ /** One durable forward-only operation. Times are Unix milliseconds. */
61
+ export interface ILocationLockOperation {
62
+ id: string;
63
+ locationId: string;
64
+ membershipDigest: TSha256Digest;
65
+ mode: TLocationLockMode;
66
+ phase: TLocationLockPhase;
67
+ controllerInLocation: boolean;
68
+ edgeOnlyLocation: boolean;
69
+ machines: ILocationLockMachineState[];
70
+ fastServiceIds: string[];
71
+ fastServicesTriggeredAt: number | null;
72
+ initiatedBy: string;
73
+ initiatedAt: number;
74
+ unlockedBy: string | null;
75
+ unlockedAt: number | null;
76
+ revision: number;
77
+ updatedAt: number;
78
+ }
79
+
80
+ export interface ILocationDestroyPlan {
81
+ locationId: string;
82
+ locationName: string;
83
+ membershipDigest: TSha256Digest;
84
+ membershipConfirmed: boolean;
85
+ locked: boolean;
86
+ controllerInLocation: boolean;
87
+ wrappedKeyCount: number;
88
+ hasOfflineRecoveryKey: boolean;
89
+ credentialsToRevoke: number;
90
+ /** Secret identifiers only. */
91
+ secretsToRotate: string[];
92
+ blockingReasons: TLocationLockRefusal[];
93
+ }
94
+
95
+ /** Irreversible operation. Cloudly verifies direct access and two distinct human administrators. */
96
+ export interface ILocationDestroyOperation {
97
+ id: string;
98
+ locationId: string;
99
+ membershipDigest: TSha256Digest;
100
+ status: TLocationDestroyStatus;
101
+ directOnly: true;
102
+ initiatorActorId: string;
103
+ initiatedAt: number;
104
+ expiresAt: number;
105
+ confirmerActorId: string | null;
106
+ confirmedAt: number | null;
107
+ completedAt: number | null;
108
+ wrappedKeysDestroyed: boolean;
109
+ offlineRecoveryKeyDestroyed: boolean;
110
+ credentialsRevoked: boolean;
111
+ secretsRotated: boolean;
112
+ revision: number;
113
+ }
114
+
115
+ const invalid = (): never => { throw new Error('Location lock and destroy contract rejected.'); };
116
+
117
+ const exact = (value: unknown, keys: readonly string[]) => readExactDataRecord(value, keys) ?? invalid();
118
+ const identifier = (value: unknown): string =>
119
+ typeof value === 'string' && validateControllerIdentifier(value, 'identifier').length === 0 ? value : invalid();
120
+ const integer = (value: unknown, minimum: number): number =>
121
+ isBoundedInteger(value, minimum, Number.MAX_SAFE_INTEGER) ? value : invalid();
122
+ const timestamp = (value: unknown): number | null => value === null ? null : integer(value, 1);
123
+ const booleanOf = (value: unknown): boolean => typeof value === 'boolean' ? value : invalid();
124
+ const digest = (value: unknown): TSha256Digest =>
125
+ typeof value === 'string' && isSha256Digest(value) ? value : invalid();
126
+ const choice = <T extends string>(value: unknown, choices: readonly T[]): T =>
127
+ choices.find((candidate) => candidate === value) ?? invalid();
128
+
129
+ const uniqueList = <T>(
130
+ value: unknown, maximum: number, snapshot: (entry: unknown) => T, keyOf: (entry: T) => string,
131
+ ): T[] => {
132
+ const entries = (readDataElements(value, maximum) ?? invalid()).map(snapshot);
133
+ if (new Set(entries.map(keyOf)).size !== entries.length) return invalid();
134
+ return entries;
135
+ };
136
+
137
+ const memberOf = (value: unknown): ILocationMember => {
138
+ const member = exact(value, ['kind', 'id']);
139
+ const { kind, id } = member;
140
+ if (!isLocationMemberKind(kind)) return invalid();
141
+ return { kind, id: kind === 'node' ? (isClusterNodeId(id) ? id : invalid()) : identifier(id) };
142
+ };
143
+
144
+ const memberKey = ({ kind, id }: ILocationMember): string => kind + ':' + id;
145
+ const serviceIdOf = (value: unknown): string =>
146
+ typeof value === 'string' && validateServiceId(value).length === 0 ? value : invalid();
147
+ const servicesOf = (value: unknown): string[] =>
148
+ uniqueList(value, locationLockBounds.maximumServices, serviceIdOf, (id) => id);
149
+
150
+ export const snapshotLocationLockRefusal = (value: unknown): TLocationLockRefusal => choice(value, locationLockRefusals);
151
+
152
+ const planKeys = [
153
+ 'locationId', 'locationName', 'membershipDigest', 'membershipConfirmed', 'controllerInLocation', 'blockingReasons',
154
+ ] as const;
155
+
156
+ const planOf = (plan: Record<string, unknown>) => ({
157
+ locationId: identifier(plan.locationId),
158
+ locationName: isLocationName(plan.locationName) ? plan.locationName : invalid(),
159
+ membershipDigest: digest(plan.membershipDigest),
160
+ membershipConfirmed: booleanOf(plan.membershipConfirmed),
161
+ controllerInLocation: booleanOf(plan.controllerInLocation),
162
+ blockingReasons: uniqueList(
163
+ plan.blockingReasons, locationLockRefusals.length, snapshotLocationLockRefusal, (code) => code,
164
+ ),
165
+ });
166
+
167
+ const machineStateKeys = ['member', 'status', 'confirmedAt', 'lastAttemptAt'] as const;
168
+ const encoder = new TextEncoder();
169
+
170
+ export const snapshotLocationLockMachineState = (value: unknown): ILocationLockMachineState => {
171
+ const state = readDataProperties(value) ?? invalid();
172
+ if (!hasExactKeys(state, machineStateKeys, ['detail'])) return invalid();
173
+ const snapshot = {
174
+ member: memberOf(state.member),
175
+ status: choice(state.status, machineStatuses),
176
+ confirmedAt: timestamp(state.confirmedAt),
177
+ lastAttemptAt: timestamp(state.lastAttemptAt),
178
+ };
179
+ if (!Object.hasOwn(state, 'detail')) return snapshot;
180
+ const { detail } = state;
181
+ const limit = locationLockBounds.maximumDetailBytes;
182
+ if (typeof detail !== 'string' || detail.length > limit || /[\u0000-\u001f\u007f-\u009f]/u.test(detail)
183
+ || encoder.encode(detail).length > limit || validateControllerStrictJson(detail, 'detail').length !== 0) return invalid();
184
+ return { ...snapshot, detail };
185
+ };
186
+
187
+ export const snapshotLocationLockPlan = (value: unknown): ILocationLockPlan => {
188
+ const plan = exact(value, [...planKeys, 'mode', 'edgeOnlyLocation', 'machines', 'fastServiceIds']);
189
+ return {
190
+ ...planOf(plan),
191
+ mode: choice(plan.mode, lockModes),
192
+ edgeOnlyLocation: booleanOf(plan.edgeOnlyLocation),
193
+ machines: uniqueList(plan.machines, locationLockBounds.maximumMachines, memberOf, memberKey),
194
+ fastServiceIds: servicesOf(plan.fastServiceIds),
195
+ };
196
+ };
197
+
198
+ export const snapshotLocationLockOperation = (value: unknown): ILocationLockOperation => {
199
+ const operation = exact(value, [
200
+ 'id', 'locationId', 'membershipDigest', 'mode', 'phase', 'controllerInLocation', 'edgeOnlyLocation', 'machines',
201
+ 'fastServiceIds', 'fastServicesTriggeredAt', 'initiatedBy', 'initiatedAt', 'unlockedBy', 'unlockedAt', 'revision',
202
+ 'updatedAt',
203
+ ]);
204
+ const phase = choice(operation.phase, lockPhases);
205
+ const initiatedAt = integer(operation.initiatedAt, 1);
206
+ const updatedAt = integer(operation.updatedAt, initiatedAt);
207
+ const fastServicesTriggeredAt = timestamp(operation.fastServicesTriggeredAt);
208
+ const unlockedBy = operation.unlockedBy === null ? null : identifier(operation.unlockedBy);
209
+ const unlockedAt = timestamp(operation.unlockedAt);
210
+ if ((phase === 'unlocked') !== (unlockedBy !== null) || (phase === 'unlocked') !== (unlockedAt !== null)) {
211
+ return invalid();
212
+ }
213
+ const machines = uniqueList(
214
+ operation.machines, locationLockBounds.maximumMachines, snapshotLocationLockMachineState, (state) => memberKey(state.member),
215
+ );
216
+ const withinOperation = (time: number | null) => time === null || (time >= initiatedAt && time <= updatedAt);
217
+ if (!withinOperation(fastServicesTriggeredAt) || !withinOperation(unlockedAt)
218
+ || machines.some(({ confirmedAt, lastAttemptAt }) => !withinOperation(confirmedAt) || !withinOperation(lastAttemptAt))) {
219
+ return invalid();
220
+ }
221
+ return {
222
+ id: identifier(operation.id), locationId: identifier(operation.locationId), membershipDigest: digest(operation.membershipDigest),
223
+ mode: choice(operation.mode, lockModes), phase,
224
+ controllerInLocation: booleanOf(operation.controllerInLocation), edgeOnlyLocation: booleanOf(operation.edgeOnlyLocation),
225
+ machines, fastServiceIds: servicesOf(operation.fastServiceIds), fastServicesTriggeredAt,
226
+ initiatedBy: identifier(operation.initiatedBy), initiatedAt, unlockedBy, unlockedAt,
227
+ revision: integer(operation.revision, 1), updatedAt,
228
+ };
229
+ };
230
+
231
+ export const snapshotLocationDestroyPlan = (value: unknown): ILocationDestroyPlan => {
232
+ const plan = exact(value, [
233
+ ...planKeys, 'locked', 'wrappedKeyCount', 'hasOfflineRecoveryKey', 'credentialsToRevoke', 'secretsToRotate',
234
+ ]);
235
+ return {
236
+ ...planOf(plan),
237
+ locked: booleanOf(plan.locked),
238
+ wrappedKeyCount: integer(plan.wrappedKeyCount, 0),
239
+ hasOfflineRecoveryKey: booleanOf(plan.hasOfflineRecoveryKey),
240
+ credentialsToRevoke: integer(plan.credentialsToRevoke, 0),
241
+ secretsToRotate: uniqueList(plan.secretsToRotate, locationLockBounds.maximumSecrets, identifier, (id) => id),
242
+ };
243
+ };
244
+
245
+ export const snapshotLocationDestroyOperation = (value: unknown): ILocationDestroyOperation => {
246
+ const operation = exact(value, [
247
+ 'id', 'locationId', 'membershipDigest', 'status', 'directOnly', 'initiatorActorId', 'initiatedAt', 'expiresAt',
248
+ 'confirmerActorId', 'confirmedAt', 'completedAt', 'wrappedKeysDestroyed', 'offlineRecoveryKeyDestroyed',
249
+ 'credentialsRevoked', 'secretsRotated', 'revision',
250
+ ]);
251
+ if (operation.directOnly !== true) return invalid();
252
+ const status = choice(operation.status, destroyStatuses);
253
+ const initiatorActorId = identifier(operation.initiatorActorId);
254
+ const confirmerActorId = operation.confirmerActorId === null ? null : identifier(operation.confirmerActorId);
255
+ if (confirmerActorId === initiatorActorId) return invalid();
256
+
257
+ const initiatedAt = integer(operation.initiatedAt, 1);
258
+ const expiresAt = integer(operation.expiresAt, 1);
259
+ const confirmedAt = timestamp(operation.confirmedAt);
260
+ const completedAt = timestamp(operation.completedAt);
261
+ const authorized = status === 'executing' || status === 'destroyed';
262
+ if (expiresAt <= initiatedAt || authorized !== (confirmerActorId !== null) || authorized !== (confirmedAt !== null)
263
+ || (confirmedAt !== null && (confirmedAt < initiatedAt || confirmedAt >= expiresAt))
264
+ || (status === 'destroyed' && completedAt === null) || (status === 'executing' && completedAt !== null)
265
+ || (status === 'pending-confirmation' && completedAt !== null)
266
+ || (completedAt !== null && completedAt < (confirmedAt ?? initiatedAt))) return invalid();
267
+
268
+ const progress = {
269
+ wrappedKeysDestroyed: booleanOf(operation.wrappedKeysDestroyed),
270
+ offlineRecoveryKeyDestroyed: booleanOf(operation.offlineRecoveryKeyDestroyed),
271
+ credentialsRevoked: booleanOf(operation.credentialsRevoked),
272
+ secretsRotated: booleanOf(operation.secretsRotated),
273
+ };
274
+ if (!authorized && Object.values(progress).some(Boolean)) return invalid();
275
+ return {
276
+ id: identifier(operation.id), locationId: identifier(operation.locationId), membershipDigest: digest(operation.membershipDigest),
277
+ status, directOnly: true, initiatorActorId, initiatedAt, expiresAt, confirmerActorId, confirmedAt, completedAt,
278
+ ...progress, revision: integer(operation.revision, 1),
279
+ };
280
+ };
package/ts/index.ts CHANGED
@@ -20,3 +20,5 @@ export { dcstorage } from './requests/index.js';
20
20
  export { preparedimages } from './requests/index.js';
21
21
  /** Corestore replication TypedRequest contracts are also available at requests.corestorereplication. */
22
22
  export { corestorereplication } from './requests/index.js';
23
+ /** Controlled takeover TypedRequest contracts are also available at requests.controlledtakeover. */
24
+ export { controlledtakeover } from './requests/index.js';
@@ -0,0 +1,167 @@
1
+ import type * as plugins from '../plugins.js';
2
+ import { readExactDataRecord } from '../private/dataproperties.js';
3
+ import { validateControllerIdentifier } from '../private/controllercontract.js';
4
+ import { isBoundedInteger } from '../private/runtimepolicy.js';
5
+ import {
6
+ snapshotControlledTakeoverAbortInput,
7
+ snapshotControlledTakeoverGetInput,
8
+ snapshotControlledTakeoverListInput,
9
+ snapshotControlledTakeoverStartInput,
10
+ snapshotNupstWebhookEndpointConfigureInput,
11
+ snapshotNupstWebhookEndpointConfig,
12
+ snapshotNupstWebhookEndpointRotateInput,
13
+ } from '../data/controlledtakeover.js';
14
+ import type {
15
+ IControlledTakeoverAbortInput,
16
+ IControlledTakeoverGetInput,
17
+ IControlledTakeoverListInput,
18
+ IControlledTakeoverListResponse,
19
+ IControlledTakeoverOperationResponse,
20
+ IControlledTakeoverStartInput,
21
+ INupstWebhookEndpointConfigureInput,
22
+ INupstWebhookEndpointConfig,
23
+ INupstWebhookEndpointResponse,
24
+ INupstWebhookEndpointRotateInput,
25
+ TControlledTakeoverAbortResponse,
26
+ } from '../data/controlledtakeover.js';
27
+ import type { IIdentityCredential } from '../data/user.js';
28
+
29
+ export interface IControlledTakeoverAdminRequest<TInput> {
30
+ identity: IIdentityCredential;
31
+ input: TInput;
32
+ }
33
+
34
+ /** Verify the administrator independently. The contract reader only checks the credential shape. */
35
+ const adminRequestOf = <TInput>(
36
+ value: unknown, readInput: (input: unknown) => TInput,
37
+ ): IControlledTakeoverAdminRequest<TInput> => {
38
+ const request = readExactDataRecord(value, ['identity', 'input']);
39
+ const identity = request && readExactDataRecord(request.identity, ['jwt']);
40
+ if (!request || typeof identity?.jwt !== 'string' || identity.jwt.length === 0) {
41
+ throw new Error('Controlled takeover administrator request rejected.');
42
+ }
43
+ return { identity: { jwt: identity.jwt }, input: readInput(request.input) };
44
+ };
45
+
46
+ export const snapshotStartControlledTakeoverRequest = (value: unknown) =>
47
+ adminRequestOf(value, snapshotControlledTakeoverStartInput);
48
+ export const snapshotGetControlledTakeoverOperationRequest = (value: unknown) =>
49
+ adminRequestOf(value, snapshotControlledTakeoverGetInput);
50
+ export const snapshotGetControlledTakeoverOperationsRequest = (value: unknown) =>
51
+ adminRequestOf(value, snapshotControlledTakeoverListInput);
52
+ export const snapshotAbortControlledTakeoverRequest = (value: unknown) =>
53
+ adminRequestOf(value, snapshotControlledTakeoverAbortInput);
54
+ export const snapshotConfigureNupstWebhookEndpointRequest = (value: unknown) =>
55
+ adminRequestOf(value, snapshotNupstWebhookEndpointConfigureInput);
56
+ export const snapshotRotateNupstWebhookEndpointSecretRequest = (value: unknown) =>
57
+ adminRequestOf(value, snapshotNupstWebhookEndpointRotateInput);
58
+
59
+ /** Operator admission. Cloudly derives locations and the service plan. The answer reports the
60
+ * operation as stored after admission, including when answering a retry of the same start. */
61
+ export interface IReq_Admin_Cloudly_StartControlledTakeover extends plugins.typedrequestInterfaces.implementsTR<
62
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_StartControlledTakeover
63
+ > {
64
+ method: 'startControlledTakeover';
65
+ request: IControlledTakeoverAdminRequest<IControlledTakeoverStartInput>;
66
+ response: IControlledTakeoverOperationResponse;
67
+ }
68
+
69
+ /** Read the recorded operation without advancing it. */
70
+ export interface IReq_Admin_Cloudly_GetControlledTakeoverOperation extends plugins.typedrequestInterfaces.implementsTR<
71
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_GetControlledTakeoverOperation
72
+ > {
73
+ method: 'getControlledTakeoverOperation';
74
+ request: IControlledTakeoverAdminRequest<IControlledTakeoverGetInput>;
75
+ response: IControlledTakeoverOperationResponse;
76
+ }
77
+
78
+ /** Read one page by operation ID. No delegated administrator scope admits these requests. */
79
+ export interface IReq_Admin_Cloudly_GetControlledTakeoverOperations extends plugins.typedrequestInterfaces.implementsTR<
80
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_GetControlledTakeoverOperations
81
+ > {
82
+ method: 'getControlledTakeoverOperations';
83
+ request: IControlledTakeoverAdminRequest<IControlledTakeoverListInput>;
84
+ response: IControlledTakeoverListResponse;
85
+ }
86
+
87
+ /** Cloudly checks the observed revision and the irreversible commit fence in the same transaction. */
88
+ export interface IReq_Admin_Cloudly_AbortControlledTakeover extends plugins.typedrequestInterfaces.implementsTR<
89
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_AbortControlledTakeover
90
+ > {
91
+ method: 'abortControlledTakeover';
92
+ request: IControlledTakeoverAdminRequest<IControlledTakeoverAbortInput>;
93
+ response: TControlledTakeoverAbortResponse;
94
+ }
95
+
96
+ /** Configure the endpoint's site binding, enabled state and margin. Secret state is server-owned. */
97
+ export interface IReq_Admin_Cloudly_ConfigureNupstWebhookEndpoint extends plugins.typedrequestInterfaces.implementsTR<
98
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_ConfigureNupstWebhookEndpoint
99
+ > {
100
+ method: 'configureNupstWebhookEndpoint';
101
+ request: IControlledTakeoverAdminRequest<INupstWebhookEndpointConfigureInput>;
102
+ response: INupstWebhookEndpointResponse;
103
+ }
104
+
105
+ /** Rotate against the observed secret version. Provisioning the sender happens outside this RPC. */
106
+ export interface IReq_Admin_Cloudly_RotateNupstWebhookEndpointSecret extends plugins.typedrequestInterfaces.implementsTR<
107
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_RotateNupstWebhookEndpointSecret
108
+ > {
109
+ method: 'rotateNupstWebhookEndpointSecret';
110
+ request: IControlledTakeoverAdminRequest<INupstWebhookEndpointRotateInput>;
111
+ response: INupstWebhookEndpointResponse;
112
+ }
113
+
114
+ /** The public endpoint snapshot contains metadata only. */
115
+ export type INupstWebhookEndpoint = INupstWebhookEndpointConfig;
116
+
117
+ /**
118
+ * Fresh human administrator on the HTTP credential endpoint only. Cloudly fences the rotation
119
+ * against the observed secret version, commits it, then may show the new secret to that same
120
+ * administrator once. A withheld credential still acknowledges the rotation.
121
+ */
122
+ export interface IReq_Admin_Cloudly_RotateNupstWebhookEndpointSecretWithDisclosure
123
+ extends plugins.typedrequestInterfaces.implementsTR<
124
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_RotateNupstWebhookEndpointSecretWithDisclosure
125
+ > {
126
+ method: 'rotateNupstWebhookEndpointSecretWithDisclosure';
127
+ request: {
128
+ identity: IIdentityCredential;
129
+ endpointId: string;
130
+ /** The observed secret version, or zero for a configured endpoint with no secret yet. */
131
+ expectedRevision: number;
132
+ };
133
+ response: {
134
+ endpoint: INupstWebhookEndpoint;
135
+ credential: { kind: 'shown'; secret: string } | { kind: 'withheld' };
136
+ };
137
+ }
138
+
139
+ const invalidDisclosure = (): never => { throw new Error('Nupst webhook secret disclosure contract rejected.'); };
140
+
141
+ export const snapshotRotateNupstWebhookEndpointSecretWithDisclosureRequest = (
142
+ value: unknown,
143
+ ): IReq_Admin_Cloudly_RotateNupstWebhookEndpointSecretWithDisclosure['request'] => {
144
+ const request = readExactDataRecord(value, ['identity', 'endpointId', 'expectedRevision']);
145
+ const identity = readExactDataRecord(request?.identity, ['jwt']);
146
+ if (!request || typeof identity?.jwt !== 'string' || identity.jwt.length === 0
147
+ || typeof request.endpointId !== 'string' || validateControllerIdentifier(request.endpointId, 'endpointId').length
148
+ || !isBoundedInteger(request.expectedRevision, 0, Number.MAX_SAFE_INTEGER)) return invalidDisclosure();
149
+ return { identity: { jwt: identity.jwt }, endpointId: request.endpointId, expectedRevision: request.expectedRevision };
150
+ };
151
+
152
+ /** Credential-bearing. Consume only on the HTTP credential path and keep out of logs and storage. */
153
+ export const snapshotRotateNupstWebhookEndpointSecretWithDisclosureResponse = (
154
+ value: unknown,
155
+ ): IReq_Admin_Cloudly_RotateNupstWebhookEndpointSecretWithDisclosure['response'] => {
156
+ const response = readExactDataRecord(value, ['endpoint', 'credential']) ?? invalidDisclosure();
157
+ const endpoint = snapshotNupstWebhookEndpointConfig(response.endpoint);
158
+ const withheld = readExactDataRecord(response.credential, ['kind']);
159
+ if (withheld?.kind === 'withheld') return { endpoint, credential: { kind: 'withheld' } };
160
+ const shown = readExactDataRecord(response.credential, ['kind', 'secret']);
161
+ // 32 bytes in padded RFC 4648 base64: 42 full sextets, four data bits, then one pad.
162
+ if (!endpoint.secretConfigured || shown?.kind !== 'shown' || typeof shown.secret !== 'string'
163
+ || shown.secret.length !== 50 || !/^whsec_[A-Za-z0-9+/]{42}[AEIMQUYcgkosw048]=$/.test(shown.secret)) {
164
+ return invalidDisclosure();
165
+ }
166
+ return { endpoint, credential: { kind: 'shown', secret: shown.secret } };
167
+ };
@@ -0,0 +1,81 @@
1
+ import type * as plugins from '../plugins.js';
2
+ import type {
3
+ IDiskEncryptionKeyReleaseChallenge, IDiskEncryptionKeyReleaseProof, IDiskEncryptionLocationRecoveryKey,
4
+ IDiskEncryptionNodeIdentity, IDiskEncryptionUnlockApproval, TDiskEncryptionKeyReleaseOutcome,
5
+ } from '../data/diskencryption.js';
6
+ import type { IIdentityCredential } from '../data/user.js';
7
+
8
+ interface IDiskEncryptionAdministratorRequest {
9
+ identity: IIdentityCredential;
10
+ }
11
+
12
+ interface IDiskEncryptionMachineRequest {
13
+ machineId: string;
14
+ }
15
+
16
+ /** Cloudly verifies TPM binding and owns the enrollment audit fields and revision. */
17
+ export interface IReq_Admin_Cloudly_EnrollDiskEncryptionIdentity extends plugins.typedrequestInterfaces.implementsTR<
18
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_EnrollDiskEncryptionIdentity
19
+ > {
20
+ method: 'enrollDiskEncryptionIdentity';
21
+ request: IDiskEncryptionAdministratorRequest & Pick<IDiskEncryptionNodeIdentity,
22
+ 'machineId' | 'machineKind' | 'locationId' | 'keyAlgorithm' | 'publicKeyPem' | 'tpmAttestationDigest'>;
23
+ response: { nodeIdentity: IDiskEncryptionNodeIdentity };
24
+ }
25
+
26
+ export interface IReq_Admin_Cloudly_RevokeDiskEncryptionIdentity extends plugins.typedrequestInterfaces.implementsTR<
27
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_RevokeDiskEncryptionIdentity
28
+ > {
29
+ method: 'revokeDiskEncryptionIdentity';
30
+ request: IDiskEncryptionAdministratorRequest & IDiskEncryptionMachineRequest & { expectedRevision: number };
31
+ response: { nodeIdentity: IDiskEncryptionNodeIdentity };
32
+ }
33
+
34
+ /** Issuing a challenge grants no authority. Cloudly binds it to the machine and its own current epoch. */
35
+ export interface IReq_Machine_Cloudly_RequestDiskEncryptionChallenge extends plugins.typedrequestInterfaces.implementsTR<
36
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Machine_Cloudly_RequestDiskEncryptionChallenge
37
+ > {
38
+ method: 'requestDiskEncryptionChallenge';
39
+ request: IDiskEncryptionMachineRequest;
40
+ response: { challenge: IDiskEncryptionKeyReleaseChallenge };
41
+ }
42
+
43
+ /**
44
+ * Cloudly consumes the exact challenge once after authenticating the TPM-signed proof. It checks
45
+ * the current machine, location and approval before releasing a key wrapped to the ephemeral key.
46
+ */
47
+ export interface IReq_Machine_Cloudly_ReleaseDiskEncryptionKey extends plugins.typedrequestInterfaces.implementsTR<
48
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Machine_Cloudly_ReleaseDiskEncryptionKey
49
+ > {
50
+ method: 'releaseDiskEncryptionKey';
51
+ request: { proof: IDiskEncryptionKeyReleaseProof };
52
+ response: TDiskEncryptionKeyReleaseOutcome;
53
+ }
54
+
55
+ /** A fresh human administrator approves one pending unexpired request. */
56
+ export interface IReq_Admin_Cloudly_ApproveDiskEncryptionUnlock extends plugins.typedrequestInterfaces.implementsTR<
57
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_ApproveDiskEncryptionUnlock
58
+ > {
59
+ method: 'approveDiskEncryptionUnlock';
60
+ request: IDiskEncryptionAdministratorRequest & { approvalId: string };
61
+ response: { approval: IDiskEncryptionUnlockApproval };
62
+ }
63
+
64
+ /** Machine-scoped observation. Neither wrapped keys nor challenge proofs appear here. */
65
+ export interface IReq_Admin_Cloudly_GetDiskEncryptionStatus extends plugins.typedrequestInterfaces.implementsTR<
66
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_GetDiskEncryptionStatus
67
+ > {
68
+ method: 'getDiskEncryptionStatus';
69
+ request: IDiskEncryptionAdministratorRequest & IDiskEncryptionMachineRequest;
70
+ response: { nodeIdentity: IDiskEncryptionNodeIdentity | null; pendingApproval: IDiskEncryptionUnlockApproval | null };
71
+ }
72
+
73
+ /** Registers the fingerprint of the separately provisioned offline key. */
74
+ export interface IReq_Admin_Cloudly_RegisterLocationRecoveryKey extends plugins.typedrequestInterfaces.implementsTR<
75
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_RegisterLocationRecoveryKey
76
+ > {
77
+ method: 'registerLocationRecoveryKey';
78
+ request: IDiskEncryptionAdministratorRequest & Pick<IDiskEncryptionLocationRecoveryKey,
79
+ 'locationId' | 'recoveryKeyId' | 'keyFingerprintSha256'>;
80
+ response: { recoveryKey: IDiskEncryptionLocationRecoveryKey };
81
+ }
@@ -110,3 +110,6 @@ export * as gatewaycertificatestore from './gatewaycertificatestore.js';
110
110
  export * as dcstorage from './dcstorage.js';
111
111
  export * as preparedimages from './preparedimages.js';
112
112
  export * as corestorereplication from './corestorereplication.js';
113
+ export * as controlledtakeover from './controlledtakeover.js';
114
+ export * as diskencryption from './diskencryption.js';
115
+ export * as locationlock from './locationlock.js';
@@ -0,0 +1,119 @@
1
+ import type * as plugins from '../plugins.js';
2
+ import type { TSha256Digest } from '../data/immutableimage.js';
3
+ import type {
4
+ ILocationDestroyOperation, ILocationDestroyPlan, ILocationLockOperation, ILocationLockPlan, TLocationLockMode,
5
+ } from '../data/locationlock.js';
6
+ import type { IIdentityCredential } from '../data/user.js';
7
+
8
+ interface ILocationAdministratorRequest {
9
+ identity: IIdentityCredential;
10
+ }
11
+
12
+ interface ILocationTargetRequest extends ILocationAdministratorRequest {
13
+ locationId: string;
14
+ }
15
+
16
+ interface ILocationOperationRequest extends ILocationAdministratorRequest {
17
+ operationId: string;
18
+ }
19
+
20
+ interface ILocationOperationMutation extends ILocationOperationRequest {
21
+ expectedRevision: number;
22
+ }
23
+
24
+ /*
25
+ * Cloudly verifies administrator authority and derives actors from the verified session.
26
+ * Fresh passkey checks, direct transport and revision/membership comparisons are server-owned.
27
+ * Refusals use locationLockRefusals. No delegated administrator scope admits these requests.
28
+ */
29
+
30
+ export interface IReq_Admin_Cloudly_PlanLocationLock extends plugins.typedrequestInterfaces.implementsTR<
31
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_PlanLocationLock
32
+ > {
33
+ method: 'planLocationLock';
34
+ request: ILocationTargetRequest & { mode: TLocationLockMode };
35
+ response: { plan: ILocationLockPlan };
36
+ }
37
+
38
+ /** Fresh passkey required. Cloud access may carry Lock. An answer acknowledges the durable record. */
39
+ export interface IReq_Admin_Cloudly_StartLocationLock extends plugins.typedrequestInterfaces.implementsTR<
40
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_StartLocationLock
41
+ > {
42
+ method: 'startLocationLock';
43
+ request: IReq_Admin_Cloudly_PlanLocationLock['request'] & { membershipDigest: TSha256Digest };
44
+ response: { operation: ILocationLockOperation };
45
+ }
46
+
47
+ export interface IReq_Admin_Cloudly_GetLocationLock extends plugins.typedrequestInterfaces.implementsTR<
48
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_GetLocationLock
49
+ > {
50
+ method: 'getLocationLock';
51
+ request: ILocationOperationRequest;
52
+ response: { operation: ILocationLockOperation };
53
+ }
54
+
55
+ export interface IReq_Admin_Cloudly_ListLocationLocks extends plugins.typedrequestInterfaces.implementsTR<
56
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_ListLocationLocks
57
+ > {
58
+ method: 'listLocationLocks';
59
+ request: ILocationAdministratorRequest & { after: string | null };
60
+ response: {
61
+ /** Up to locationLockBounds.operationsPerPage entries, strictly ascending by operation ID. */
62
+ operations: ILocationLockOperation[];
63
+ /** Last returned ID if another page exists, otherwise null. */
64
+ nextAfter: string | null;
65
+ };
66
+ }
67
+
68
+ /** Fresh passkey required. Cloudly compares the observed lock revision before unlocking. */
69
+ export interface IReq_Admin_Cloudly_UnlockLocation extends plugins.typedrequestInterfaces.implementsTR<
70
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_UnlockLocation
71
+ > {
72
+ method: 'unlockLocation';
73
+ request: ILocationOperationMutation;
74
+ response: { operation: ILocationLockOperation };
75
+ }
76
+
77
+ /** Destroy administration is direct-only. Cloudly refuses cloud-access sessions. */
78
+ export interface IReq_Admin_Cloudly_PlanLocationDestroy extends plugins.typedrequestInterfaces.implementsTR<
79
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_PlanLocationDestroy
80
+ > {
81
+ method: 'planLocationDestroy';
82
+ request: ILocationTargetRequest;
83
+ response: { plan: ILocationDestroyPlan };
84
+ }
85
+
86
+ /** A fresh human administrator records a pending request over direct access. */
87
+ export interface IReq_Admin_Cloudly_InitiateLocationDestroy extends plugins.typedrequestInterfaces.implementsTR<
88
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_InitiateLocationDestroy
89
+ > {
90
+ method: 'initiateLocationDestroy';
91
+ request: ILocationTargetRequest & { membershipDigest: TSha256Digest };
92
+ response: { operation: ILocationDestroyOperation };
93
+ }
94
+
95
+ /** A different human administrator with a fresh passkey confirms the exact pending revision over direct access. */
96
+ export interface IReq_Admin_Cloudly_ConfirmLocationDestroy extends plugins.typedrequestInterfaces.implementsTR<
97
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_ConfirmLocationDestroy
98
+ > {
99
+ method: 'confirmLocationDestroy';
100
+ request: ILocationOperationMutation;
101
+ response: { operation: ILocationDestroyOperation };
102
+ }
103
+
104
+ /** Only a still-pending Destroy can be cancelled. Direct access and fresh passkey required. */
105
+ export interface IReq_Admin_Cloudly_CancelLocationDestroy extends plugins.typedrequestInterfaces.implementsTR<
106
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_CancelLocationDestroy
107
+ > {
108
+ method: 'cancelLocationDestroy';
109
+ request: ILocationOperationMutation;
110
+ response: { operation: ILocationDestroyOperation };
111
+ }
112
+
113
+ export interface IReq_Admin_Cloudly_GetLocationDestroy extends plugins.typedrequestInterfaces.implementsTR<
114
+ plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_GetLocationDestroy
115
+ > {
116
+ method: 'getLocationDestroy';
117
+ request: ILocationOperationRequest;
118
+ response: { operation: ILocationDestroyOperation };
119
+ }