@serve.zone/interfaces 32.22.0 → 32.24.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 (36) hide show
  1. package/changelog.md +76 -0
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts/data/corestorelegacyadoption.d.ts +182 -0
  4. package/dist_ts/data/corestorelegacyadoption.js +292 -0
  5. package/dist_ts/data/index.d.ts +2 -0
  6. package/dist_ts/data/index.js +3 -1
  7. package/dist_ts/data/networkprotection.d.ts +13 -0
  8. package/dist_ts/data/networkprotection.js +8 -2
  9. package/dist_ts/data/runtimelocalstorageclaim.d.ts +73 -10
  10. package/dist_ts/data/runtimelocalstorageclaim.js +89 -2
  11. package/dist_ts/data/service.d.ts +15 -1
  12. package/dist_ts/data/service.js +1 -1
  13. package/dist_ts/data/serviceruntime.d.ts +8 -3
  14. package/dist_ts/data/serviceruntime.js +3 -2
  15. package/dist_ts/data/servicevolumeinitialization.d.ts +91 -0
  16. package/dist_ts/data/servicevolumeinitialization.js +93 -0
  17. package/dist_ts/platform/types.d.ts +45 -0
  18. package/dist_ts/platform/types.js +27 -2
  19. package/dist_ts/requests/corestore.d.ts +60 -0
  20. package/dist_ts/requests/corestore.js +1 -1
  21. package/dist_ts/requests/platform.d.ts +6 -1
  22. package/dist_ts/requests/service.d.ts +23 -0
  23. package/package.json +1 -1
  24. package/readme.md +186 -16
  25. package/ts/00_commitinfo_data.ts +1 -1
  26. package/ts/data/corestorelegacyadoption.ts +481 -0
  27. package/ts/data/index.ts +2 -0
  28. package/ts/data/networkprotection.ts +20 -1
  29. package/ts/data/runtimelocalstorageclaim.ts +169 -10
  30. package/ts/data/service.ts +16 -0
  31. package/ts/data/serviceruntime.ts +8 -2
  32. package/ts/data/servicevolumeinitialization.ts +159 -0
  33. package/ts/platform/types.ts +75 -0
  34. package/ts/requests/corestore.ts +79 -0
  35. package/ts/requests/platform.ts +6 -0
  36. package/ts/requests/service.ts +28 -0
@@ -0,0 +1,481 @@
1
+ import type { IObjectStorageRetentionIntent } from '../platform/objectstorageretention.js';
2
+ import {
3
+ objectStorageRetentionIntentsEqual,
4
+ validateObjectStorageRetentionIntent,
5
+ } from '../platform/objectstorageretention.js';
6
+ import { validatePlatformObjectStorageBucketName } from '../platform/objectstorage.js';
7
+ import type { TPlatformBindingStatusReason } from '../platform/types.js';
8
+ import { platformBindingStatusReasons } from '../platform/types.js';
9
+ import {
10
+ canonicalizeStrictJson,
11
+ compareWireTokens,
12
+ createCanonicalJsonSha256Hex,
13
+ } from '../private/canonicaljson.js';
14
+ import { hasExactKeys, isPlainRecord } from '../private/dataproperties.js';
15
+ import { isClusterNodeId } from '../private/nodeidentifier.js';
16
+
17
+ /**
18
+ * Moving a service's legacy Corestore resources into credential bindings.
19
+ *
20
+ * A Corestore root converted from a release before 32 still holds the databases and buckets
21
+ * `/resources/provision` created, one per service and capability, in its manifest. Corestore
22
+ * refuses a credential binding beside such a resource until an operator authorizes that exact
23
+ * binding to adopt it, offline, with a plan file. The flow across the three owners:
24
+ *
25
+ * 1. Corestore answers `GET /control/legacy-resources` with its `ICorestoreLegacyResourceInventory`;
26
+ * the cluster relay reads it for Cloudly (`getClusterCorestoreLegacyResources`).
27
+ * 2. `adoptCorestoreLegacyResources` checks the admin's selection against that inventory at an
28
+ * exact digest, creates each adopting binding with the legacy bucket and retention intent, and
29
+ * answers the plan (`ICorestoreLegacyResourceAdoptionPlanEntry[]`).
30
+ * 3. The operator stops Corestore and runs its `legacy-resource-adoption` migration with that plan.
31
+ * Until then Corestore refuses the binding, which reports `legacy-adoption-pending`.
32
+ */
33
+
34
+ export type TCorestoreLegacyCapability = 'database' | 'objectstorage';
35
+
36
+ /**
37
+ * Why Corestore's offline adoption would refuse an unadopted resource:
38
+ *
39
+ * - `not-adoptable`: its identity is not what a credential binding can adopt (an
40
+ * allocation-managed database, another provider, a resource name that differs from its database
41
+ * or bucket name, or a bucket name that is not a canonical S3 name);
42
+ * - `ordinary-credentials-rotated`: its credentials were rotated, so the delivered ones are no
43
+ * longer the generation a binding adopts;
44
+ * - `owned-by-binding`: a credential binding or a named storage binding already owns the service
45
+ * capability, the resource or the bucket;
46
+ * - `fence-lineage-conflict`: the bucket's object-storage fence lineage cannot move to the adopting
47
+ * binding, because the bucket has more than one lineage, or its lineage does not validate,
48
+ * belongs to another authority or has an unfinished mutation. Only a bucket has a fence lineage,
49
+ * so a database never names it.
50
+ */
51
+ export type TCorestoreLegacyResourceBlocker =
52
+ | 'not-adoptable'
53
+ | 'ordinary-credentials-rotated'
54
+ | 'owned-by-binding'
55
+ | 'fence-lineage-conflict';
56
+
57
+ /**
58
+ * `unadopted` names what would stop the offline adoption, or `null` when nothing would;
59
+ * `authorized` names the binding the operator authorized, which is the only binding Corestore will
60
+ * let take the resource. A consumed adoption leaves no legacy resource behind, so it never appears.
61
+ */
62
+ export type TCorestoreLegacyResourceAdoption =
63
+ | { state: 'unadopted'; blocker: TCorestoreLegacyResourceBlocker | null }
64
+ | { state: 'authorized'; bindingId: string };
65
+
66
+ /**
67
+ * One legacy resource, by the identity Corestore's manifest states. A database is named by its
68
+ * database name, a bucket by its bucket name and its retention intent, `null` when it has none.
69
+ */
70
+ export type TCorestoreLegacyResource =
71
+ | { capability: 'database'; databaseName: string; adoption: TCorestoreLegacyResourceAdoption }
72
+ | {
73
+ capability: 'objectstorage';
74
+ bucketName: string;
75
+ retention: IObjectStorageRetentionIntent | null;
76
+ adoption: TCorestoreLegacyResourceAdoption;
77
+ };
78
+
79
+ /** One service's legacy resources, at most one per capability, `database` first. */
80
+ export interface ICorestoreLegacyServiceResources {
81
+ serviceId: string;
82
+ resources: TCorestoreLegacyResource[];
83
+ }
84
+
85
+ /** What Corestore answers on `GET /control/legacy-resources`: every service, sorted by id. */
86
+ export interface ICorestoreLegacyResourceInventory {
87
+ services: ICorestoreLegacyServiceResources[];
88
+ }
89
+
90
+ /**
91
+ * One node's legacy resources as the cluster relay read them. An unreachable node names why and
92
+ * lists nothing, because a silent empty list would read as a node with nothing to adopt.
93
+ */
94
+ export type TClusterCorestoreLegacyResourceInventory =
95
+ | { nodeId: string; checkedAt: number; reachable: true; services: ICorestoreLegacyServiceResources[] }
96
+ | {
97
+ nodeId: string;
98
+ checkedAt: number;
99
+ reachable: false;
100
+ errorCode: 'CORESTORE_ENDPOINT_UNKNOWN' | 'CORESTORE_UNREACHABLE';
101
+ };
102
+
103
+ /** One resource an administrator selects for adoption. */
104
+ export interface ICorestoreLegacyResourceSelection {
105
+ serviceId: string;
106
+ capability: TCorestoreLegacyCapability;
107
+ }
108
+
109
+ /**
110
+ * One entry of Corestore's offline adoption plan, exactly the object its
111
+ * `legacy-resource-adoption` migration reads: the service, the capability and the binding that may
112
+ * adopt its legacy resource. The legacy identity is Corestore's own and is not restated here.
113
+ */
114
+ export interface ICorestoreLegacyResourceAdoptionPlanEntry {
115
+ serviceId: string;
116
+ capability: TCorestoreLegacyCapability;
117
+ bindingId: string;
118
+ }
119
+
120
+ /**
121
+ * Why `adoptCorestoreLegacyResources` wrote nothing:
122
+ *
123
+ * - `legacy-inventory-unreachable`: the relay could not read the node's Corestore (retryable);
124
+ * - `legacy-inventory-changed`: the inventory no longer has `expectedInventorySha256`;
125
+ * - `legacy-resource-absent`: a selected service has no legacy resource of that capability;
126
+ * - `legacy-resource-blocked`: a selected resource is unadopted with a blocker;
127
+ * - `legacy-resource-authorized-elsewhere`: a selected resource is authorized for a binding Cloudly
128
+ * does not hold as that resource's adoption;
129
+ * - `service-absent`: Cloudly has no such service;
130
+ * - `binding-exists`: the service already has a binding of that capability that adopts nothing,
131
+ * or adopts another resource.
132
+ */
133
+ export type TCorestoreLegacyAdoptionRefusal =
134
+ | 'legacy-inventory-unreachable'
135
+ | 'legacy-inventory-changed'
136
+ | 'legacy-resource-absent'
137
+ | 'legacy-resource-blocked'
138
+ | 'legacy-resource-authorized-elsewhere'
139
+ | 'service-absent'
140
+ | 'binding-exists';
141
+
142
+ /** The named refusal of `adoptCorestoreLegacyResources`, sent as `TypedResponseError.errorData`. */
143
+ export interface ICorestoreLegacyAdoptionErrorData {
144
+ code: TCorestoreLegacyAdoptionRefusal;
145
+ /** True for `legacy-inventory-unreachable` only; every other refusal needs a new read first. */
146
+ retryable: boolean;
147
+ }
148
+
149
+ export const corestoreLegacyAdoptionContract = Object.freeze({
150
+ /** Corestore's control path for its legacy inventory, bearer-authenticated like every other. */
151
+ inventoryPath: '/control/legacy-resources',
152
+ /** Corestore's own plan bound, which also bounds a selection and an inventory. */
153
+ maximumPlanEntries: 4096,
154
+ maximumServices: 4096,
155
+ maximumNameLength: 255,
156
+ digestDomain: 'serve.zone/corestore-legacy-resources',
157
+ } as const);
158
+
159
+ const identifierPattern = /^[A-Za-z0-9][A-Za-z0-9:._-]{0,199}$/;
160
+ const printableNamePattern = /^[\x21-\x7e]+$/;
161
+ const bareSha256Pattern = /^[a-f0-9]{64}$/;
162
+ const blockers: readonly TCorestoreLegacyResourceBlocker[] = [
163
+ 'not-adoptable', 'ordinary-credentials-rotated', 'owned-by-binding', 'fence-lineage-conflict',
164
+ ];
165
+
166
+ const isIdentifier = (valueArg: unknown): valueArg is string => (
167
+ typeof valueArg === 'string' && identifierPattern.test(valueArg)
168
+ );
169
+
170
+ const isLegacyName = (valueArg: unknown): valueArg is string => (
171
+ typeof valueArg === 'string'
172
+ && valueArg.length <= corestoreLegacyAdoptionContract.maximumNameLength
173
+ && printableNamePattern.test(valueArg)
174
+ );
175
+
176
+ const isCapability = (valueArg: unknown): valueArg is TCorestoreLegacyCapability => (
177
+ valueArg === 'database' || valueArg === 'objectstorage'
178
+ );
179
+
180
+ const validateAdoption = (
181
+ valueArg: unknown, capabilityArg: TCorestoreLegacyCapability, pathArg: string,
182
+ ): string[] => {
183
+ if (!isPlainRecord(valueArg)) return [`${pathArg} must use its exact schema`];
184
+ if (valueArg.state === 'unadopted') {
185
+ if (!hasExactKeys(valueArg, ['state', 'blocker'])) return [`${pathArg} must use its exact schema`];
186
+ if (valueArg.blocker !== null && !(blockers as readonly unknown[]).includes(valueArg.blocker)) {
187
+ return [`${pathArg} blocker must be null or a named blocker`];
188
+ }
189
+ return valueArg.blocker === 'fence-lineage-conflict' && capabilityArg !== 'objectstorage'
190
+ ? [`${pathArg} blocker fence-lineage-conflict must name a bucket`]
191
+ : [];
192
+ }
193
+ if (valueArg.state === 'authorized') {
194
+ if (!hasExactKeys(valueArg, ['state', 'bindingId'])) return [`${pathArg} must use its exact schema`];
195
+ return isIdentifier(valueArg.bindingId) ? [] : [`${pathArg} bindingId must be a canonical identifier`];
196
+ }
197
+ return [`${pathArg} state must be unadopted or authorized`];
198
+ };
199
+
200
+ /** An adoptable resource is one the offline adoption could authorize or already did. */
201
+ const isAdoptable = (adoptionArg: unknown): boolean => (
202
+ isPlainRecord(adoptionArg) && (adoptionArg.state === 'authorized' || adoptionArg.blocker === null)
203
+ );
204
+
205
+ const validateResource = (valueArg: unknown, pathArg: string): string[] => {
206
+ if (!isPlainRecord(valueArg)) return [`${pathArg} must use its exact schema`];
207
+ if (valueArg.capability === 'database') {
208
+ if (!hasExactKeys(valueArg, ['capability', 'databaseName', 'adoption'])) {
209
+ return [`${pathArg} must use its exact schema`];
210
+ }
211
+ const errors = validateAdoption(valueArg.adoption, 'database', `${pathArg} adoption`);
212
+ if (!isLegacyName(valueArg.databaseName)) errors.push(`${pathArg} databaseName must be a bounded printable name`);
213
+ return errors;
214
+ }
215
+ if (valueArg.capability === 'objectstorage') {
216
+ if (!hasExactKeys(valueArg, ['capability', 'bucketName', 'retention', 'adoption'])) {
217
+ return [`${pathArg} must use its exact schema`];
218
+ }
219
+ const errors = validateAdoption(valueArg.adoption, 'objectstorage', `${pathArg} adoption`);
220
+ if (!isLegacyName(valueArg.bucketName)) {
221
+ errors.push(`${pathArg} bucketName must be a bounded printable name`);
222
+ } else if (errors.length === 0 && isAdoptable(valueArg.adoption)) {
223
+ // A binding request carries only a canonical bucket, so an adoptable bucket has to be one.
224
+ errors.push(...validatePlatformObjectStorageBucketName(valueArg.bucketName, `${pathArg} bucketName`));
225
+ }
226
+ if (valueArg.retention !== null) {
227
+ errors.push(...validateObjectStorageRetentionIntent(valueArg.retention, `${pathArg} retention`));
228
+ }
229
+ return errors;
230
+ }
231
+ return [`${pathArg} capability must be database or objectstorage`];
232
+ };
233
+
234
+ const validateServices = (valueArg: unknown, pathArg: string): string[] => {
235
+ if (!Array.isArray(valueArg) || valueArg.length > corestoreLegacyAdoptionContract.maximumServices) {
236
+ return [`${pathArg} must be a bounded array`];
237
+ }
238
+ const errors: string[] = [];
239
+ let previousServiceId: string | undefined;
240
+ for (const [index, service] of valueArg.entries()) {
241
+ const servicePath = `${pathArg}[${index}]`;
242
+ if (!isPlainRecord(service) || !hasExactKeys(service, ['serviceId', 'resources'])) {
243
+ errors.push(`${servicePath} must use its exact schema`);
244
+ continue;
245
+ }
246
+ if (!isIdentifier(service.serviceId)) {
247
+ errors.push(`${servicePath} serviceId must be a canonical identifier`);
248
+ } else {
249
+ if (previousServiceId !== undefined && compareWireTokens(previousServiceId, service.serviceId) >= 0) {
250
+ errors.push(`${pathArg} must be sorted by serviceId without repeats`);
251
+ }
252
+ previousServiceId = service.serviceId;
253
+ }
254
+ if (!Array.isArray(service.resources) || service.resources.length < 1 || service.resources.length > 2) {
255
+ errors.push(`${servicePath} resources must list one or two resources`);
256
+ continue;
257
+ }
258
+ for (const [resourceIndex, resource] of service.resources.entries()) {
259
+ errors.push(...validateResource(resource, `${servicePath} resources[${resourceIndex}]`));
260
+ }
261
+ if (service.resources.length === 2
262
+ && !(isPlainRecord(service.resources[0]) && service.resources[0].capability === 'database'
263
+ && isPlainRecord(service.resources[1]) && service.resources[1].capability === 'objectstorage')) {
264
+ errors.push(`${servicePath} resources must hold one database before one objectstorage resource`);
265
+ }
266
+ }
267
+ return errors;
268
+ };
269
+
270
+ /** Validates Corestore's answer on its legacy inventory path and names every reason it is refused. */
271
+ export const validateCorestoreLegacyResourceInventory = (
272
+ valueArg: unknown,
273
+ pathArg = 'corestore legacy resource inventory',
274
+ ): string[] => {
275
+ if (!isPlainRecord(valueArg) || !hasExactKeys(valueArg, ['services'])) {
276
+ return [`${pathArg} must use its exact schema`];
277
+ }
278
+ return validateServices(valueArg.services, `${pathArg} services`);
279
+ };
280
+
281
+ /** Validates one node's legacy inventory as the relay reports it. Shape only. */
282
+ export const validateClusterCorestoreLegacyResourceInventory = (
283
+ valueArg: unknown,
284
+ pathArg = 'cluster corestore legacy resource inventory',
285
+ ): string[] => {
286
+ if (!isPlainRecord(valueArg)) return [`${pathArg} must use its exact schema`];
287
+ const reachable = valueArg.reachable;
288
+ if (reachable === true
289
+ ? !hasExactKeys(valueArg, ['nodeId', 'checkedAt', 'reachable', 'services'])
290
+ : reachable !== false || !hasExactKeys(valueArg, ['nodeId', 'checkedAt', 'reachable', 'errorCode'])) {
291
+ return [`${pathArg} must use its exact schema`];
292
+ }
293
+ const errors: string[] = [];
294
+ if (!isClusterNodeId(valueArg.nodeId)) errors.push(`${pathArg} nodeId must be a node id`);
295
+ if (!Number.isSafeInteger(valueArg.checkedAt) || (valueArg.checkedAt as number) < 0) {
296
+ errors.push(`${pathArg} checkedAt must be a non-negative safe integer`);
297
+ }
298
+ if (reachable === true) {
299
+ errors.push(...validateServices(valueArg.services, `${pathArg} services`));
300
+ } else if (valueArg.errorCode !== 'CORESTORE_ENDPOINT_UNKNOWN' && valueArg.errorCode !== 'CORESTORE_UNREACHABLE') {
301
+ errors.push(`${pathArg} errorCode must name why the node could not be read`);
302
+ }
303
+ return errors;
304
+ };
305
+
306
+ const failDigest = (reasonArg: string): never => {
307
+ throw new Error(reasonArg);
308
+ };
309
+
310
+ /**
311
+ * The digest an adoption is checked against: the node and its services, not the read time, so two
312
+ * reads of an unchanged Corestore agree. Throws for an invalid or unreachable inventory.
313
+ */
314
+ export const computeClusterCorestoreLegacyResourceInventorySha256 = async (
315
+ inventoryArg: TClusterCorestoreLegacyResourceInventory,
316
+ ): Promise<string> => {
317
+ const errors = validateClusterCorestoreLegacyResourceInventory(inventoryArg);
318
+ if (errors.length > 0) throw new Error(errors[0]);
319
+ if (inventoryArg.reachable !== true) throw new Error('an unreachable legacy inventory has no digest');
320
+ return createCanonicalJsonSha256Hex(canonicalizeStrictJson({
321
+ domain: corestoreLegacyAdoptionContract.digestDomain,
322
+ nodeId: inventoryArg.nodeId,
323
+ services: inventoryArg.services,
324
+ }, failDigest, 'corestore legacy resource inventory'), failDigest);
325
+ };
326
+
327
+ const selectionKey = (entryArg: { serviceId: string; capability: string }): string =>
328
+ `${entryArg.serviceId}\u0000${entryArg.capability}`;
329
+
330
+ /** Validates an administrator's selection: 1..4096 exact entries, sorted by service then capability. */
331
+ export const validateCorestoreLegacyResourceSelections = (
332
+ valueArg: unknown,
333
+ pathArg = 'corestore legacy resource selection',
334
+ ): string[] => {
335
+ if (!Array.isArray(valueArg) || valueArg.length < 1
336
+ || valueArg.length > corestoreLegacyAdoptionContract.maximumPlanEntries) {
337
+ return [`${pathArg} must be a non-empty bounded array`];
338
+ }
339
+ const errors: string[] = [];
340
+ let previous: string | undefined;
341
+ for (const [index, entry] of valueArg.entries()) {
342
+ if (!isPlainRecord(entry) || !hasExactKeys(entry, ['serviceId', 'capability'])
343
+ || !isIdentifier(entry.serviceId) || !isCapability(entry.capability)) {
344
+ errors.push(`${pathArg}[${index}] must be an exact { serviceId, capability }`);
345
+ continue;
346
+ }
347
+ const key = selectionKey(entry as unknown as ICorestoreLegacyResourceSelection);
348
+ if (previous !== undefined && compareWireTokens(previous, key) >= 0) {
349
+ errors.push(`${pathArg} must be sorted by serviceId then capability without repeats`);
350
+ }
351
+ previous = key;
352
+ }
353
+ return errors;
354
+ };
355
+
356
+ /**
357
+ * Validates an adoption plan by the rules Corestore's migration applies: a non-empty array of at
358
+ * most 4096 exact `{ serviceId, capability, bindingId }` entries, canonical identifiers, and no
359
+ * service capability or binding id twice. Order is free.
360
+ */
361
+ export const validateCorestoreLegacyResourceAdoptionPlan = (
362
+ valueArg: unknown,
363
+ pathArg = 'adoption plan',
364
+ ): string[] => {
365
+ if (!Array.isArray(valueArg) || valueArg.length === 0
366
+ || valueArg.length > corestoreLegacyAdoptionContract.maximumPlanEntries) {
367
+ return [`${pathArg} must be a non-empty bounded array`];
368
+ }
369
+ const errors: string[] = [];
370
+ const serviceCapabilities = new Set<string>();
371
+ const bindingIds = new Set<string>();
372
+ for (const [index, entry] of valueArg.entries()) {
373
+ if (!isPlainRecord(entry) || !hasExactKeys(entry, ['serviceId', 'capability', 'bindingId'])
374
+ || !isIdentifier(entry.serviceId) || !isIdentifier(entry.bindingId) || !isCapability(entry.capability)) {
375
+ errors.push(`${pathArg} entry ${index} must be an exact { serviceId, capability, bindingId }`);
376
+ continue;
377
+ }
378
+ const serviceCapability = selectionKey(entry as unknown as ICorestoreLegacyResourceSelection);
379
+ if (serviceCapabilities.has(serviceCapability) || bindingIds.has(entry.bindingId as string)) {
380
+ errors.push(`${pathArg} entry ${index} repeats a service capability or binding id`);
381
+ }
382
+ serviceCapabilities.add(serviceCapability);
383
+ bindingIds.add(entry.bindingId as string);
384
+ }
385
+ return errors;
386
+ };
387
+
388
+ /** The binding fields an adoption judges; a full `IPlatformBinding` satisfies it. */
389
+ export interface ICorestoreLegacyAdoptionBindingView {
390
+ id: string;
391
+ serviceId: string;
392
+ capability: string;
393
+ objectstorageBucketName?: string;
394
+ objectstorageRetention?: { intent: IObjectStorageRetentionIntent };
395
+ corestoreLegacyAdoption?: { nodeId: string; resourceName: string; inventorySha256: string };
396
+ }
397
+
398
+ /**
399
+ * Content check of one adopting binding against the inventory it was adopted at, and the one rule
400
+ * that lets a binding carry a legacy bucket name: the binding names this node, this inventory
401
+ * digest and the legacy resource's name; the resource is unadopted without a blocker or authorized
402
+ * for exactly this binding; an adopted bucket's `objectstorageBucketName` is the legacy bucket and
403
+ * its retention intent the legacy intent exactly, absent when the legacy bucket has none; a
404
+ * database binding carries neither. Whether the digest is current is the caller's to check.
405
+ */
406
+ export const validatePlatformBindingCorestoreLegacyAdoption = (
407
+ bindingArg: ICorestoreLegacyAdoptionBindingView,
408
+ inventoryArg: TClusterCorestoreLegacyResourceInventory,
409
+ inventorySha256Arg: string,
410
+ pathArg = 'platform binding corestoreLegacyAdoption',
411
+ ): string[] => {
412
+ if (validateClusterCorestoreLegacyResourceInventory(inventoryArg).length > 0 || inventoryArg.reachable !== true
413
+ || typeof inventorySha256Arg !== 'string' || !bareSha256Pattern.test(inventorySha256Arg)) {
414
+ return [`${pathArg} needs a valid reachable inventory and its digest`];
415
+ }
416
+ const adoption = bindingArg.corestoreLegacyAdoption;
417
+ if (!isPlainRecord(adoption) || !hasExactKeys(adoption, ['nodeId', 'resourceName', 'inventorySha256'])) {
418
+ return [`${pathArg} must use its exact schema`];
419
+ }
420
+ if (adoption.nodeId !== inventoryArg.nodeId || adoption.inventorySha256 !== inventorySha256Arg) {
421
+ return [`${pathArg} must name the inventory's node and digest`];
422
+ }
423
+ if (!isCapability(bindingArg.capability)) return [`${pathArg} needs a database or objectstorage binding`];
424
+ const resource = inventoryArg.services.find((serviceArg) => serviceArg.serviceId === bindingArg.serviceId)
425
+ ?.resources.find((resourceArg) => resourceArg.capability === bindingArg.capability);
426
+ if (!resource) return [`${pathArg} names no legacy resource of the service and capability`];
427
+ const errors: string[] = [];
428
+ const legacyName = resource.capability === 'database' ? resource.databaseName : resource.bucketName;
429
+ if (adoption.resourceName !== legacyName) errors.push(`${pathArg} resourceName must be the legacy resource's name`);
430
+ if (resource.adoption.state === 'unadopted' ? resource.adoption.blocker !== null
431
+ : resource.adoption.bindingId !== bindingArg.id) {
432
+ errors.push(`${pathArg} names a resource that is blocked or authorized for another binding`);
433
+ }
434
+ if (resource.capability === 'objectstorage') {
435
+ if (bindingArg.objectstorageBucketName !== resource.bucketName) {
436
+ errors.push(`${pathArg} objectstorageBucketName must be the legacy bucket`);
437
+ }
438
+ if (resource.retention === null
439
+ ? bindingArg.objectstorageRetention !== undefined
440
+ : !objectStorageRetentionIntentsEqual(bindingArg.objectstorageRetention?.intent, resource.retention)) {
441
+ errors.push(`${pathArg} retention intent must be the legacy bucket's exactly`);
442
+ }
443
+ } else if (bindingArg.objectstorageBucketName !== undefined || bindingArg.objectstorageRetention !== undefined) {
444
+ errors.push(`${pathArg} database binding must carry no bucket or retention`);
445
+ }
446
+ return errors;
447
+ };
448
+
449
+ /**
450
+ * The plan for every adopting binding, sorted by service then capability, in the exact entry shape
451
+ * Corestore's migration reads. Throws unless every binding adopts a legacy resource and the result
452
+ * is a valid plan.
453
+ */
454
+ export const createCorestoreLegacyResourceAdoptionPlan = (
455
+ bindingsArg: readonly ICorestoreLegacyAdoptionBindingView[],
456
+ ): ICorestoreLegacyResourceAdoptionPlanEntry[] => {
457
+ const plan = bindingsArg.map((bindingArg) => {
458
+ if (bindingArg.corestoreLegacyAdoption === undefined || !isCapability(bindingArg.capability)) {
459
+ throw new Error(`binding ${bindingArg.id} adopts no legacy Corestore resource`);
460
+ }
461
+ return { serviceId: bindingArg.serviceId, capability: bindingArg.capability, bindingId: bindingArg.id };
462
+ }).sort((leftArg, rightArg) => compareWireTokens(selectionKey(leftArg), selectionKey(rightArg)));
463
+ const errors = validateCorestoreLegacyResourceAdoptionPlan(plan);
464
+ if (errors.length > 0) throw new Error(errors[0]);
465
+ return plan;
466
+ };
467
+
468
+ /**
469
+ * The binding status reason a Corestore control answer names: a 409 whose body is
470
+ * `{ ok: false, error, code }` with `code` one of the legacy adoption reasons. Every other answer,
471
+ * including a 409 with another code, names none and keeps its ordinary failure handling.
472
+ */
473
+ export const readCorestoreLegacyAdoptionRefusal = (
474
+ statusCodeArg: number,
475
+ bodyArg: unknown,
476
+ ): TPlatformBindingStatusReason | null => (
477
+ statusCodeArg === 409 && isPlainRecord(bodyArg) && bodyArg.ok === false
478
+ && (platformBindingStatusReasons as readonly unknown[]).includes(bodyArg.code)
479
+ ? bodyArg.code as TPlatformBindingStatusReason
480
+ : null
481
+ );
package/ts/data/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from './clusteringressdesignation.js';
7
7
  export * from './clusterrelaycredential.js';
8
8
  export * from './config.js';
9
9
  export * from './corestore.js';
10
+ export * from './corestorelegacyadoption.js';
10
11
  export * from './coremail.js';
11
12
  export * from './coremail.runtime.js';
12
13
  export * from './deployment.js';
@@ -67,6 +68,7 @@ export * from './service.js';
67
68
  export * from './servicecredential.js';
68
69
  export * from './serviceports.js';
69
70
  export * from './serviceruntime.js';
71
+ export * from './servicevolumeinitialization.js';
70
72
  export * from './status.js';
71
73
  export * from './taskexecution.js';
72
74
  export * from './traffic.js';
@@ -42,6 +42,18 @@ export interface IReportRuntimeNetworkProtectionRequest {
42
42
  * Absent from a node that has not stated one; never defaulted, never guessed.
43
43
  */
44
44
  uplinkAddress?: string;
45
+ /**
46
+ * Every IPv4 address the node's host carries on interfaces the node does not manage itself, as
47
+ * the node observed them: sorted as strings, unique, never empty when present, at most
48
+ * `runtimeNetworkProtectionContract.maximumHostAddresses`, and each one an address
49
+ * `runtimeNodeUplinkAddress` admits. Workload bridges and the managed VPN interface are the
50
+ * node's own and are left out.
51
+ *
52
+ * Cloudly names a platform endpoint in the node's `hostPlatformEndpointIds` when its address is
53
+ * one of these, which is how a host without a relay registration (a Corestore beside the node on
54
+ * one machine) states that an endpoint is local. Absent states nothing; never defaulted.
55
+ */
56
+ hostAddresses?: string[];
45
57
  }
46
58
  export interface IReportRuntimeNetworkProtectionResponse {
47
59
  status: 'accepted' | 'replay';
@@ -57,6 +69,7 @@ export const runtimeNetworkProtectionContract = Object.freeze({
57
69
  unavailable: 'null-native-barrier-removes-allocation-eligibility',
58
70
  historical: 'retain-for-outbox-replay-never-current-allocation-eligibility',
59
71
  quarantine: 'no-release-authority',
72
+ maximumHostAddresses: 32,
60
73
  } as const);
61
74
 
62
75
  const scopeOf = (value: IRuntimeNetworkNodeScope): IRuntimeNetworkNodeScope =>
@@ -123,7 +136,7 @@ export const admitRuntimeNetworkProtectionReceipt = async (
123
136
  };
124
137
 
125
138
  export const snapshotReportRuntimeNetworkProtectionRequest = (value: unknown): IReportRuntimeNetworkProtectionRequest => networkSafe(() => {
126
- const item = networkRecord(captureNetwork(value), ['session', 'receipt'], ['uplinkAddress']);
139
+ const item = networkRecord(captureNetwork(value), ['session', 'receipt'], ['uplinkAddress', 'hostAddresses']);
127
140
  const request: IReportRuntimeNetworkProtectionRequest = {
128
141
  session: snapshotRuntimeSessionBinding(item.session),
129
142
  receipt: snapshotRuntimeNetworkProtectionReceipt(item.receipt),
@@ -131,6 +144,12 @@ export const snapshotReportRuntimeNetworkProtectionRequest = (value: unknown): I
131
144
  if (Object.hasOwn(item, 'uplinkAddress')) {
132
145
  request.uplinkAddress = runtimeNodeUplinkAddress(item.uplinkAddress);
133
146
  }
147
+ if (Object.hasOwn(item, 'hostAddresses')) {
148
+ const hostAddresses = networkSorted(networkList(item.hostAddresses,
149
+ runtimeNetworkProtectionContract.maximumHostAddresses, runtimeNodeUplinkAddress), (address) => address);
150
+ requireNetwork(hostAddresses.length > 0);
151
+ request.hostAddresses = hostAddresses;
152
+ }
134
153
  return request;
135
154
  });
136
155