@serve.zone/interfaces 32.114.0 → 32.116.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 (82) hide show
  1. package/changelog.md +20 -0
  2. package/dist_ts/00_commitinfo_data.js +1 -1
  3. package/dist_ts/data/backup/index.d.ts +2 -0
  4. package/dist_ts/data/backup/index.js +3 -0
  5. package/dist_ts/data/controlledtakeover.d.ts +125 -0
  6. package/dist_ts/data/controlledtakeover.js +217 -0
  7. package/dist_ts/data/coremail/index.d.ts +2 -0
  8. package/dist_ts/data/coremail/index.js +3 -0
  9. package/dist_ts/data/corestorereplication.d.ts +90 -0
  10. package/dist_ts/data/corestorereplication.js +129 -0
  11. package/dist_ts/data/dcstorage.d.ts +206 -0
  12. package/dist_ts/data/dcstorage.js +322 -0
  13. package/dist_ts/data/delegatedadmintoken.d.ts +4 -2
  14. package/dist_ts/data/delegatedadmintoken.js +9 -3
  15. package/dist_ts/data/gateway.d.ts +13 -0
  16. package/dist_ts/data/gateway.js +6 -2
  17. package/dist_ts/data/gatewayarearows.d.ts +30 -14
  18. package/dist_ts/data/gatewayarearows.js +54 -21
  19. package/dist_ts/data/gatewayareas.d.ts +12 -2
  20. package/dist_ts/data/gatewayareas.js +5 -2
  21. package/dist_ts/data/gatewayareas.validation.js +11 -5
  22. package/dist_ts/data/index.d.ts +4 -0
  23. package/dist_ts/data/index.js +5 -1
  24. package/dist_ts/data/preparedimages.d.ts +80 -0
  25. package/dist_ts/data/preparedimages.js +154 -0
  26. package/dist_ts/index.d.ts +10 -2
  27. package/dist_ts/index.js +11 -3
  28. package/dist_ts/requests/backup.d.ts +1 -1
  29. package/dist_ts/requests/backup.js +2 -2
  30. package/dist_ts/requests/controlledtakeover.d.ts +50 -0
  31. package/dist_ts/requests/controlledtakeover.js +18 -0
  32. package/dist_ts/requests/corestore.d.ts +1 -1
  33. package/dist_ts/requests/corestore.js +1 -2
  34. package/dist_ts/requests/corestorereplication.d.ts +108 -0
  35. package/dist_ts/requests/corestorereplication.js +2 -0
  36. package/dist_ts/requests/dcstorage.d.ts +204 -0
  37. package/dist_ts/requests/dcstorage.js +2 -0
  38. package/dist_ts/requests/gateway.d.ts +1 -1
  39. package/dist_ts/requests/gateway.js +2 -2
  40. package/dist_ts/requests/gatewaycertificatestore.d.ts +10 -0
  41. package/dist_ts/requests/gatewaycertificatestore.js +27 -10
  42. package/dist_ts/requests/gatewayconnector.d.ts +1 -1
  43. package/dist_ts/requests/gatewayconnector.js +2 -2
  44. package/dist_ts/requests/gatewayhealth.d.ts +65 -0
  45. package/dist_ts/requests/gatewayhealth.js +72 -0
  46. package/dist_ts/requests/gatewayremoteingress.d.ts +10 -2
  47. package/dist_ts/requests/gatewayremoteingress.js +7 -2
  48. package/dist_ts/requests/index.d.ts +5 -0
  49. package/dist_ts/requests/index.js +6 -1
  50. package/dist_ts/requests/mail.d.ts +1 -1
  51. package/dist_ts/requests/mail.js +2 -2
  52. package/dist_ts/requests/preparedimages.d.ts +24 -0
  53. package/dist_ts/requests/preparedimages.js +2 -0
  54. package/package.json +113 -1
  55. package/readme.md +120 -10
  56. package/ts/00_commitinfo_data.ts +1 -1
  57. package/ts/data/backup/index.ts +2 -0
  58. package/ts/data/controlledtakeover.ts +338 -0
  59. package/ts/data/coremail/index.ts +2 -0
  60. package/ts/data/corestorereplication.ts +223 -0
  61. package/ts/data/dcstorage.ts +505 -0
  62. package/ts/data/delegatedadmintoken.ts +9 -3
  63. package/ts/data/gateway.ts +18 -1
  64. package/ts/data/gatewayarearows.ts +76 -26
  65. package/ts/data/gatewayareas.ts +15 -3
  66. package/ts/data/gatewayareas.validation.ts +10 -4
  67. package/ts/data/index.ts +4 -0
  68. package/ts/data/preparedimages.ts +231 -0
  69. package/ts/index.ts +11 -2
  70. package/ts/requests/backup.ts +1 -1
  71. package/ts/requests/controlledtakeover.ts +108 -0
  72. package/ts/requests/corestore.ts +1 -1
  73. package/ts/requests/corestorereplication.ts +123 -0
  74. package/ts/requests/dcstorage.ts +208 -0
  75. package/ts/requests/gateway.ts +1 -1
  76. package/ts/requests/gatewaycertificatestore.ts +34 -9
  77. package/ts/requests/gatewayconnector.ts +1 -1
  78. package/ts/requests/gatewayhealth.ts +135 -0
  79. package/ts/requests/gatewayremoteingress.ts +15 -3
  80. package/ts/requests/index.ts +5 -0
  81. package/ts/requests/mail.ts +1 -1
  82. package/ts/requests/preparedimages.ts +39 -0
@@ -8,10 +8,12 @@
8
8
  * A row is addressed by area, member and id: a list member's row by its `id`, a singleton member
9
9
  * (`gatewayAreaSingletonMembers`) by `id: null`. Its write form (`IGatewayAreaRowWrites`) is its
10
10
  * table type (`gatewayareas.ts`) except that every secret-class member (`gatewayAreaSecretPaths`) is
11
- * a keep-or-set choice: a read answers every secret as `keep` (a sealed member with its version, a
11
+ * a keep-or-set choice, with an explicit promotion for the active edge secret. A read answers
12
+ * every secret as `keep` (a sealed member with its version, a
12
13
  * verifier without anything), so a row read and sent back unchanged writes nothing, and a write
13
14
  * states a new secret only as `set`. A sealed value's version is minted by the controller that
14
15
  * resolves the write (Linus ruling 121 Q9: by every write that sets a secret), never by the request.
16
+ * Promotion preserves the version of the staged secret it moves.
15
17
  * Nothing here carries a stored secret value: reads and answers name versions, never values.
16
18
  *
17
19
  * Both requests are for a human administrator who signed in within the last five minutes, with
@@ -84,6 +86,9 @@ export type TGatewaySealedValueWrite =
84
86
  /** A new value; the controller mints its version. */
85
87
  | { kind: 'set'; value: string };
86
88
 
89
+ /** Moves the observed staged version into the active slot and clears the staged slot. */
90
+ export type TGatewayEdgeSecretWrite = TGatewaySealedValueWrite | { kind: 'promoteStaged'; version: string };
91
+
87
92
  /** A verifier member in a row's write form; the secret it verifies never travels. */
88
93
  export type TGatewayVerifierWrite<TVerifier> =
89
94
  /**
@@ -152,11 +157,18 @@ export interface IGatewayCoreMailPeerRowWrite extends Omit<IGatewayCoreMailPeerR
152
157
  credentials: TGatewayVerifierWrite<IGatewayCoreMailCredentialVerifier[]>;
153
158
  }
154
159
 
155
- /** `IGatewayEdgeRow` with its tunnel secret as a keep-or-set choice. */
156
- export interface IGatewayEdgeRowWrite extends Omit<IGatewayEdgeRow, 'secret'> {
157
- secret: TGatewaySealedValueWrite;
160
+ /** `IGatewayEdgeRow` in write form. A `promoteStaged` active secret requires `stagedSecret: null`. */
161
+ export interface IGatewayEdgeRowWrite extends Omit<IGatewayEdgeRow, 'secret' | 'stagedSecret'> {
162
+ secret: TGatewayEdgeSecretWrite;
163
+ stagedSecret: TGatewaySealedValueWrite | null;
158
164
  }
159
165
 
166
+ /** The row write form for an edge that still uses the pre-rotation table shape. */
167
+ export type TGatewayLegacyEdgeRowWrite = Omit<IGatewayEdgeRowWrite, 'secret' | 'stagedSecret'> & {
168
+ secret: TGatewaySealedValueWrite;
169
+ stagedSecret?: never;
170
+ };
171
+
160
172
  /**
161
173
  * The write form of one row of every member, by area and member: a list member's row, or a
162
174
  * singleton's value. A member without secrets writes its table type unchanged.
@@ -196,7 +208,7 @@ export interface IGatewayAreaRowWrites {
196
208
  };
197
209
  edges: {
198
210
  hub: IGatewayEdgeHubSettings;
199
- edges: IGatewayEdgeRowWrite;
211
+ edges: IGatewayEdgeRowWrite | TGatewayLegacyEdgeRowWrite;
200
212
  };
201
213
  }
202
214
 
@@ -304,6 +316,10 @@ const parentOf = (rowArg: unknown, keysArg: readonly string[]): { parent: Record
304
316
  return isPlainRecord(current) && Object.hasOwn(current, key) ? { parent: current, key } : null;
305
317
  };
306
318
 
319
+ /** The one secret path that may be absent, in a pre-rotation edges row. */
320
+ const allowsLegacySecretOmission = (areaArg: TGatewayConfigArea, memberArg: string, pathArg: string): boolean =>
321
+ areaArg === 'edges' && memberArg === 'edges' && pathArg === 'stagedSecret';
322
+
307
323
  const failRowDigest = (reasonArg: string): never => {
308
324
  throw new Error(`Gateway area row digest input rejected: ${reasonArg}.`);
309
325
  };
@@ -316,8 +332,9 @@ const failRowDigest = (reasonArg: string): never => {
316
332
  * moves with every change of the row, a secret's included, while a reader who holds every other
317
333
  * input (the read answers the row and the versions) cannot test a guess at a sealed value against
318
334
  * it. Throws, naming no value, for an unknown area or member, an `id` that is not `null` exactly
319
- * for a singleton, and a row that is not strict JSON or lacks a sealed member or its version, which
320
- * a valid table never holds.
335
+ * for a singleton, and a row that is not strict JSON or lacks a required sealed member or its version.
336
+ * A promotion write form must be resolved before computing the stored row's token.
337
+ * Legacy edges rows have no `stagedSecret` member and retain their original digest input.
321
338
  */
322
339
  export const createGatewayAreaRowDigestInput = (inputArg: {
323
340
  area: TGatewayConfigArea;
@@ -330,8 +347,15 @@ export const createGatewayAreaRowDigestInput = (inputArg: {
330
347
  if ((id === null) !== isGatewayAreaSingletonMember(area, member)) failRowDigest(`${area} ${member} takes ${id === null ? 'a row id' : 'id null'}`);
331
348
  const row = (copyStrictJson(inputArg.row) ?? failRowDigest(`the ${area} ${member} row is not strict JSON`)).value;
332
349
  for (const secret of secretPathsOf(area, member)) {
350
+ const place = parentOf(row, splitPath(secret.path));
351
+ if (place !== null && readDataProperty(place.parent[place.key], 'kind')?.value === 'promoteStaged') {
352
+ failRowDigest(`the ${area} ${member} row's ${secret.path} is an unresolved promotion`);
353
+ }
333
354
  if (secret.secretClass !== 'sealed') continue;
334
- const place = parentOf(row, splitPath(secret.path)) ?? failRowDigest(`the ${area} ${member} row has no member ${secret.path}`);
355
+ if (place === null) {
356
+ if (allowsLegacySecretOmission(area, member, secret.path)) continue;
357
+ return failRowDigest(`the ${area} ${member} row has no member ${secret.path}`);
358
+ }
335
359
  const value = place.parent[place.key];
336
360
  if (value === null) continue;
337
361
  const version = isPlainRecord(value) ? value.version : undefined;
@@ -476,21 +500,34 @@ export type TGatewayAreaRowWriteReport =
476
500
  | { ok: true; written: IGatewayAreaRowWritten }
477
501
  | { ok: false; code: TGatewayAreaRowWriteRefusal; problems: string[] };
478
502
 
479
- /** One secret member of a write form as written: `null`, a keep or a set; `null` itself for a malformed form. */
503
+ /** One parsed secret write choice. `null` itself denotes a malformed form. */
480
504
  type TSecretWriteForm =
481
505
  | { form: 'null' }
482
506
  | { form: 'keep'; version: string | null }
507
+ | { form: 'promoteStaged'; version: string }
483
508
  | { form: 'set'; value: unknown };
484
509
 
485
- const readSecretWriteForm = (valueArg: unknown, secretClassArg: TGatewayAreaSecretClass): TSecretWriteForm | null => {
510
+ const permitsStagedPromotion = (
511
+ areaArg: TGatewayConfigArea, memberArg: string, pathArg: string, rowArg: unknown,
512
+ ): boolean => areaArg === 'edges' && memberArg === 'edges' && pathArg === 'secret'
513
+ && readDataProperty(rowArg, 'stagedSecret')?.value === null;
514
+
515
+ const readSecretWriteForm = (
516
+ valueArg: unknown, secretClassArg: TGatewayAreaSecretClass, permitsPromotionArg: boolean,
517
+ ): TSecretWriteForm | null => {
486
518
  if (valueArg === null) return { form: 'null' };
487
519
  if (secretClassArg === 'verifier') {
488
520
  if (readExactDataRecord(valueArg, ['kind'])?.kind === 'keep') return { form: 'keep', version: null };
489
521
  const set = readExactDataRecord(valueArg, ['kind', 'verifier']);
490
522
  return set?.kind === 'set' ? { form: 'set', value: set.verifier } : null;
491
523
  }
492
- const keep = readExactDataRecord(valueArg, ['kind', 'version']);
493
- if (keep?.kind === 'keep' && typeof keep.version === 'string') return { form: 'keep', version: keep.version };
524
+ const choice = readExactDataRecord(valueArg, ['kind', 'version']);
525
+ if (choice !== null && typeof choice.version === 'string') {
526
+ if (choice.kind === 'keep') return { form: 'keep', version: choice.version };
527
+ if (choice.kind === 'promoteStaged' && permitsPromotionArg) {
528
+ return { form: 'promoteStaged', version: choice.version };
529
+ }
530
+ }
494
531
  const set = readExactDataRecord(valueArg, ['kind', 'value']);
495
532
  return set?.kind === 'set' && typeof set.value === 'string' ? { form: 'set', value: set.value } : null;
496
533
  };
@@ -526,8 +563,9 @@ const rowWriteKeys = Object.freeze({
526
563
  * deleted) and a row id (`isGatewayAreaRowId`) for a list member, a `sha256:` `expectedDigest`
527
564
  * (`null` only for a put), and for a put a strict JSON row whose `id` is the address's (a list
528
565
  * member) and whose every secret member (`gatewayAreaSecretPaths`) is `null` or one of its
529
- * keep-or-set forms. A put of a `security` `apiTokens` row whose policy binds a gateway client
530
- * (`isGatewayClientBoundApiTokenPolicy`) is refused naming the row (Linus ruling 376
566
+ * keep-or-set forms. Only `edges.edges.secret` may use `promoteStaged`, with an explicit
567
+ * `stagedSecret: null`. A legacy edges row omits `stagedSecret`. A put of a `security` `apiTokens` row
568
+ * whose policy binds a gateway client (`isGatewayClientBoundApiTokenPolicy`) is refused naming the row (Linus ruling 376
531
569
  * item 6): the controller is the one author of the tables and compiles no gateway-client token, so
532
570
  * such a write would vanish at the next compile and a gateway from dcrouter 35 refuses it. The
533
571
  * content validator (`validateGatewayAreaContent`) keeps accepting the role, because it also judges
@@ -569,8 +607,11 @@ export const validateGatewayAreaRowWrite = (valueArg: unknown, pathArg = 'write'
569
607
  }
570
608
  for (const secret of secretPathsOf(area, member)) {
571
609
  const place = parentOf(row, splitPath(secret.path));
572
- if (place === null || readSecretWriteForm(place.parent[place.key], secret.secretClass) === null) {
573
- problems.push(`${pathArg} row ${secret.path} must be null or a ${secret.secretClass} keep-or-set form`);
610
+ if (place === null && allowsLegacySecretOmission(area, member, secret.path)) continue;
611
+ const permitsPromotion = permitsStagedPromotion(area, member, secret.path, row);
612
+ if (place === null || readSecretWriteForm(place.parent[place.key], secret.secretClass, permitsPromotion) === null) {
613
+ problems.push(`${pathArg} row ${secret.path} must be null or a ${secret.secretClass} keep-or-set form${
614
+ permitsPromotion ? ' or a staged promotion' : ''}`);
574
615
  }
575
616
  }
576
617
  return problems;
@@ -583,8 +624,8 @@ export const validateGatewayAreaRowWrite = (valueArg: unknown, pathArg = 'write'
583
624
  /**
584
625
  * A stored row (or singleton value) of a valid table in its write form, every secret as `keep`: a
585
626
  * sealed member as its version, a verifier as `{ kind: 'keep' }`, a `null` member as `null`. Throws
586
- * for a row that is not strict JSON or lacks a secret member's parent, which a valid table never
587
- * holds.
627
+ * for a row that is not strict JSON or lacks a required secret member. Legacy edges rows still
628
+ * omit `stagedSecret` in the projection.
588
629
  */
589
630
  export const projectGatewayAreaRow = <TArea extends TGatewayConfigArea, TMember extends TGatewayAreaMember<TArea>>(
590
631
  areaArg: TArea, memberArg: TMember, storedArg: unknown,
@@ -594,7 +635,10 @@ export const projectGatewayAreaRow = <TArea extends TGatewayConfigArea, TMember
594
635
  const row = copied.value;
595
636
  for (const secret of secretPathsOf(areaArg, memberArg)) {
596
637
  const place = parentOf(row, splitPath(secret.path));
597
- if (place === null) throw new Error(`The stored ${areaArg} ${memberArg} row has no member ${secret.path}.`);
638
+ if (place === null) {
639
+ if (allowsLegacySecretOmission(areaArg, memberArg, secret.path)) continue;
640
+ throw new Error(`The stored ${areaArg} ${memberArg} row has no member ${secret.path}.`);
641
+ }
598
642
  const value = place.parent[place.key];
599
643
  if (value === null) continue;
600
644
  if (secret.secretClass === 'verifier') {
@@ -610,8 +654,8 @@ export const projectGatewayAreaRow = <TArea extends TGatewayConfigArea, TMember
610
654
 
611
655
  /**
612
656
  * Why a row's write form cannot be resolved, by the secret's path: `invalid-write-form` for a
613
- * secret member that is not one of its keep-or-set forms (a write `validateGatewayAreaRowWrite`
614
- * refuses), or `kept-secret-unknown` for a `keep` the stored row does not hold there. Never a value.
657
+ * secret member whose write form `validateGatewayAreaRowWrite` refuses, or `kept-secret-unknown`
658
+ * when the stored row lacks the referenced keep or promotion source. Never a value.
615
659
  */
616
660
  export interface IGatewayAreaRowWriteFormRefusal {
617
661
  /** The secret's dotted path inside the row; `''` for the row as a whole. */
@@ -629,8 +673,11 @@ export type TGatewayAreaRowResolution =
629
673
  * none) into its stored form: a sealed `keep` becomes the stored `{ version, value }` at that path
630
674
  * when the stored row holds that version there, a verifier `keep` the stored verifier when the row
631
675
  * holds one; a sealed `set` becomes `{ version: mintVersionArg(), value }`, a verifier `set` the
632
- * stated verifier; `null` stays `null`. Every other member is copied as written; the area validator
633
- * judges the resolved row as part of its table. Judges the forms with the rule
676
+ * stated verifier; `null` stays `null`. A legacy write can omit `stagedSecret` only when the stored
677
+ * row also omits it or the write creates a row. `promoteStaged` moves the stored staged value and
678
+ * version to the active slot when the version matches, without minting a version. Every other
679
+ * member is copied as written. The area
680
+ * validator judges the resolved row as part of its table. Judges the forms with the rule
634
681
  * `validateGatewayAreaRowWrite` applies and never reads a value into a refusal. The minted
635
682
  * versions are answered ascending by path. `mintVersionArg` is the writer's
636
683
  * (`createGatewaySealedVersion`).
@@ -650,7 +697,10 @@ export const resolveGatewayAreaRowWrite = (inputArg: {
650
697
  for (const secret of secretPathsOf(inputArg.area, inputArg.member)) {
651
698
  const keys = splitPath(secret.path);
652
699
  const place = parentOf(row, keys);
653
- const form = place === null ? null : readSecretWriteForm(place.parent[place.key], secret.secretClass);
700
+ if (place === null && allowsLegacySecretOmission(inputArg.area, inputArg.member, secret.path)
701
+ && parentOf(inputArg.stored, keys) === null) continue;
702
+ const form = place === null ? null : readSecretWriteForm(place.parent[place.key], secret.secretClass,
703
+ permitsStagedPromotion(inputArg.area, inputArg.member, secret.path, row));
654
704
  if (place === null || form === null) {
655
705
  refusals.push({ path: secret.path, code: 'invalid-write-form' });
656
706
  continue;
@@ -666,8 +716,8 @@ export const resolveGatewayAreaRowWrite = (inputArg: {
666
716
  minted.push({ path: secret.path, version });
667
717
  continue;
668
718
  }
669
- const storedPlace = inputArg.stored === null ? null : parentOf(inputArg.stored, keys);
670
- const storedValue = storedPlace === null ? null : storedPlace.parent[storedPlace.key] ?? null;
719
+ const storedPlace = parentOf(inputArg.stored, form.form === 'promoteStaged' ? ['stagedSecret'] : keys);
720
+ const storedValue = storedPlace === null ? null : readDataProperty(storedPlace.parent, storedPlace.key)?.value ?? null;
671
721
  if (secret.secretClass === 'verifier') {
672
722
  if (storedValue === null) refusals.push({ path: secret.path, code: 'kept-secret-unknown' });
673
723
  else place.parent[place.key] = copyStrictJson(storedValue)?.value ?? null;
@@ -1078,8 +1078,14 @@ export interface IGatewayEdgeEgress {
1078
1078
  export interface IGatewayEdgeRow {
1079
1079
  id: string;
1080
1080
  name: string;
1081
- /** The edge's tunnel secret. */
1081
+ /** The edge's active tunnel secret. */
1082
1082
  secret: IGatewaySealedValue;
1083
+ /**
1084
+ * The staged tunnel secret, or `null` when idle. Cloudly stages, commits and aborts rotation
1085
+ * with one edges-table `replaceIntent` write each. Send this member only to a gateway that
1086
+ * advertises `remoteIngress.stagedSecretRotation: true`, even when the value is `null`.
1087
+ */
1088
+ stagedSecret: IGatewaySealedValue | null;
1083
1089
  /** A set of manually listed TCP ports; derived ports are computed on the gateway. */
1084
1090
  listenPorts: number[];
1085
1091
  /** A set of manually listed UDP ports (the gateway reads absent as empty). */
@@ -1099,6 +1105,9 @@ export interface IGatewayEdgeRow {
1099
1105
  mailHostname: string | null;
1100
1106
  }
1101
1107
 
1108
+ /** The exact edges row used before the gateway advertises staged secret rotation. */
1109
+ export type TGatewayLegacyEdgeRow = Omit<IGatewayEdgeRow, 'stagedSecret'> & { stagedSecret?: never };
1110
+
1102
1111
  /** The tunnel hub singleton, without its listener port and TLS files. */
1103
1112
  export interface IGatewayEdgeHubSettings {
1104
1113
  enabled: boolean;
@@ -1114,7 +1123,7 @@ export interface IGatewayEdgesArea {
1114
1123
  * that is off is `enabled: false`, with `hubDomain` and `performance` `null` when it has none.
1115
1124
  */
1116
1125
  hub: IGatewayEdgeHubSettings;
1117
- edges: IGatewayEdgeRow[];
1126
+ edges: (IGatewayEdgeRow | TGatewayLegacyEdgeRow)[];
1118
1127
  }
1119
1128
 
1120
1129
  // ---------------------------------------------------------------------------------------------
@@ -1210,7 +1219,10 @@ export const gatewayAreaSecretPaths: {
1210
1219
  coreMailPeers: Object.freeze([Object.freeze({ path: 'credentials', secretClass: 'verifier' as const })]),
1211
1220
  }),
1212
1221
  edges: Object.freeze({
1213
- edges: Object.freeze([Object.freeze({ path: 'secret', secretClass: 'sealed' as const })]),
1222
+ edges: Object.freeze([
1223
+ Object.freeze({ path: 'secret', secretClass: 'sealed' as const }),
1224
+ Object.freeze({ path: 'stagedSecret', secretClass: 'sealed' as const }),
1225
+ ]),
1214
1226
  }),
1215
1227
  });
1216
1228
 
@@ -2089,6 +2089,12 @@ const checkEgress = (scopeArg: IScope, valueArg: unknown): void => {
2089
2089
  'maxConcurrentStreams');
2090
2090
  };
2091
2091
 
2092
+ const edgeRowKeys = [
2093
+ 'id', 'name', 'secret', 'listenPorts', 'listenPortsUdp', 'enabled', 'autoDerivePorts', 'performance', 'egress',
2094
+ 'tags', 'publicIp', 'publicIpv6', 'mailHostname',
2095
+ ] as const;
2096
+ const stagedEdgeRowKeys = [...edgeRowKeys, 'stagedSecret'] as const;
2097
+
2092
2098
  const validateEdges = (scopeArg: IScope, contentArg: Record<string, unknown>): void => {
2093
2099
  // The hub is always stated (ruling 125, Q-b5): a hub that is off is `enabled: false`, never `null`.
2094
2100
  requiredSingleton(scopeArg, 'hub', contentArg.hub, (memberScopeArg, valueArg) => {
@@ -2103,15 +2109,15 @@ const validateEdges = (scopeArg: IScope, contentArg: Record<string, unknown>): v
2103
2109
  }
2104
2110
  });
2105
2111
  rowList(scopeArg, 'edges', contentArg.edges, contract.maximumRows.edges.edges, (rowScopeArg, rowArg) => {
2106
- const row = exact(rowScopeArg, rowArg, [
2107
- 'id', 'name', 'secret', 'listenPorts', 'listenPortsUdp', 'enabled', 'autoDerivePorts', 'performance', 'egress',
2108
- 'tags', 'publicIp', 'publicIpv6', 'mailHostname',
2109
- ], null);
2112
+ // Validate both exact wire forms. The controller chooses the form using the peer's capability.
2113
+ const hasStagedSecret = isPlainRecord(rowArg) && Object.hasOwn(rowArg, 'stagedSecret');
2114
+ const row = exact(rowScopeArg, rowArg, hasStagedSecret ? stagedEdgeRowKeys : edgeRowKeys, null);
2110
2115
  if (row === null) {
2111
2116
  return;
2112
2117
  }
2113
2118
  checkText(rowScopeArg, row.name, 'name');
2114
2119
  checkSealed(rowScopeArg, row.secret, 'secret');
2120
+ if (hasStagedSecret) checkNullableSealed(rowScopeArg, row.stagedSecret, 'stagedSecret');
2115
2121
  checkPortSet(rowScopeArg, row.listenPorts, 'listenPorts');
2116
2122
  checkPortSet(rowScopeArg, row.listenPortsUdp, 'listenPortsUdp');
2117
2123
  checkBoolean(rowScopeArg, row.enabled, 'enabled');
package/ts/data/index.ts CHANGED
@@ -8,9 +8,11 @@ export * from './clusteringressdesignation.js';
8
8
  export * from './clusterrelaycredential.js';
9
9
  export * from './config.js';
10
10
  export * from './controller.js';
11
+ export * from './controlledtakeover.js';
11
12
  export * from './corestore.js';
12
13
  export * from './corestorecontroltoken.js';
13
14
  export * from './corestorelegacyadoption.js';
15
+ export * from './corestorereplication.js';
14
16
  export * from './delegatedadmintoken.js';
15
17
  export * from './coremail.js';
16
18
  export * from './coremail.runtime.js';
@@ -68,6 +70,7 @@ export { runtimeNetworkProjectionRetirementContract, snapshotRuntimeNetworkProje
68
70
  export * from './networkprotection.js';
69
71
  export * from './networksigning.js';
70
72
  export * from './privatenetwork.js';
73
+ export * from './preparedimages.js';
71
74
  export * from './registry.js';
72
75
  export * from './releaseversion.js';
73
76
  export * from './runtimeassignment.js';
@@ -111,3 +114,4 @@ export * from './version.js';
111
114
  export * from './webpush.js';
112
115
  export * from './witness.js';
113
116
  export * from './workloadreplicaidentity.js';
117
+ export * from './dcstorage.js';
@@ -0,0 +1,231 @@
1
+ import { readDataElements, readExactDataRecord } from '../private/dataproperties.js';
2
+ import { isSha256Digest } from './immutableimage.js';
3
+ import type { IRuntimeSessionBinding } from './runtimesession.js';
4
+
5
+ export interface IPreparedImageEntry {
6
+ /** The digest-pinned registry reference. Its pin may name an index, distinct from the manifest. */
7
+ imageReference: string;
8
+ /** The config digest is Pallet's pull key and the list's sort key. */
9
+ imageConfigDigest: string;
10
+ manifestDigest: string;
11
+ }
12
+
13
+ /** The controller's whole desired list for one node, separate from assignment state. */
14
+ export interface IPreparedImageList {
15
+ /** Positive safe integer, kept monotone across controller takeovers. */
16
+ revision: number;
17
+ /** Canonical order is ascending by config digest, each digest appearing once. */
18
+ images: IPreparedImageEntry[];
19
+ }
20
+
21
+ export const preparedImageBounds = Object.freeze({
22
+ maximumImages: 64,
23
+ maximumRepositoryBytes: 509,
24
+ maximumRegistryUsernameBytes: 4096,
25
+ maximumRegistryPasswordBytes: 8192,
26
+ });
27
+
28
+ export type TPreparedImageAdmission = 'accepted' | 'replay' | 'historical';
29
+
30
+ export interface ISyncPreparedImagesRequest {
31
+ session: IRuntimeSessionBinding;
32
+ list: IPreparedImageList;
33
+ }
34
+
35
+ export interface ISyncPreparedImagesResponse {
36
+ status: TPreparedImageAdmission;
37
+ /** The list the node holds after admission. Admission does not establish image presence. */
38
+ list: IPreparedImageList;
39
+ }
40
+
41
+ export const preparedImageStates = ['present', 'pulling', 'failed'] as const;
42
+ export type TPreparedImageState = typeof preparedImageStates[number];
43
+
44
+ export interface IPreparedImageStatus {
45
+ imageConfigDigest: string;
46
+ state: TPreparedImageState;
47
+ }
48
+
49
+ export interface IPreparedImageReport {
50
+ /** Null denotes a node with no admitted list. Its images must then be empty. */
51
+ revision: number | null;
52
+ images: IPreparedImageStatus[];
53
+ }
54
+
55
+ export interface IReportPreparedImagesRequest {
56
+ session: IRuntimeSessionBinding;
57
+ report: IPreparedImageReport;
58
+ }
59
+
60
+ export interface IGetPreparedImagePullCredentialRequest {
61
+ session: IRuntimeSessionBinding;
62
+ revision: number;
63
+ image: IPreparedImageEntry;
64
+ }
65
+
66
+ /** Ephemeral, pull-only registry authorization. Exclude the envelope from logs and persistence. */
67
+ export interface IPreparedImagePullCredential {
68
+ username: string;
69
+ password: string;
70
+ /** Unix milliseconds. */
71
+ expiresAt: number;
72
+ }
73
+
74
+ export interface IGetPreparedImagePullCredentialResponse {
75
+ revision: number;
76
+ image: IPreparedImageEntry;
77
+ /** Null explicitly authorizes an anonymous attempt. A refusal is an RPC error. */
78
+ credential: IPreparedImagePullCredential | null;
79
+ }
80
+
81
+ export class PreparedImageContractError extends Error {
82
+ constructor(public readonly code: 'invalid' | 'conflict') {
83
+ super(`Prepared image contract rejected: ${code}.`);
84
+ }
85
+ }
86
+
87
+ const invalid = (): never => { throw new PreparedImageContractError('invalid'); };
88
+
89
+ const revisionOf = (value: unknown): number =>
90
+ typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : invalid();
91
+
92
+ const digestOf = (value: unknown): string =>
93
+ typeof value === 'string' && value.length === 71 && isSha256Digest(value) ? value : invalid();
94
+
95
+ const referenceOf = (value: unknown): string => {
96
+ if (typeof value !== 'string') return invalid();
97
+ const at = value.lastIndexOf('@');
98
+ if (at <= 0 || at > preparedImageBounds.maximumRepositoryBytes) return invalid();
99
+ const repository = value.slice(0, at);
100
+ // Pallet's native pull grammar, including the ability to pin an index.
101
+ if (/[^a-z0-9._/:-]/.test(repository) || !repository.includes('/')
102
+ || repository.startsWith('/') || repository.endsWith('/')
103
+ || repository.includes('//') || repository.includes('..')) return invalid();
104
+ digestOf(value.slice(at + 1));
105
+ return value;
106
+ };
107
+
108
+ const entryOf = (value: unknown): IPreparedImageEntry => {
109
+ const entry = readExactDataRecord(value, ['imageReference', 'imageConfigDigest', 'manifestDigest']);
110
+ if (!entry) return invalid();
111
+ return {
112
+ imageReference: referenceOf(entry.imageReference),
113
+ imageConfigDigest: digestOf(entry.imageConfigDigest),
114
+ manifestDigest: digestOf(entry.manifestDigest),
115
+ };
116
+ };
117
+
118
+ const compareDigest = (left: string, right: string): number => left < right ? -1 : left > right ? 1 : 0;
119
+
120
+ const requireCanonicalOrder = (rows: readonly { imageConfigDigest: string }[]): void => {
121
+ for (let index = 1; index < rows.length; index++) {
122
+ if (rows[index - 1]!.imageConfigDigest >= rows[index]!.imageConfigDigest) invalid();
123
+ }
124
+ };
125
+
126
+ const sameImage = (left: IPreparedImageEntry, right: IPreparedImageEntry): boolean =>
127
+ left.imageConfigDigest === right.imageConfigDigest && left.imageReference === right.imageReference
128
+ && left.manifestDigest === right.manifestDigest;
129
+
130
+ /** Capture and canonicalize a whole node list using Pallet's admission grammar. */
131
+ export const capturePreparedImageList = (value: unknown): IPreparedImageList => {
132
+ const list = readExactDataRecord(value, ['revision', 'images']);
133
+ const entries = list && readDataElements(list.images, preparedImageBounds.maximumImages);
134
+ if (!list || !entries) return invalid();
135
+ const revision = revisionOf(list.revision);
136
+ const images = entries.map(entryOf).sort((left, right) => compareDigest(left.imageConfigDigest, right.imageConfigDigest));
137
+ requireCanonicalOrder(images);
138
+ return { revision, images };
139
+ };
140
+
141
+ /** Judge revision order. The caller owns the authenticated transactional compare-and-replace. */
142
+ export const judgePreparedImageList = (
143
+ proposed: unknown, current: IPreparedImageList | null,
144
+ ): ISyncPreparedImagesResponse => {
145
+ const next = capturePreparedImageList(proposed);
146
+ if (current === null) return { status: 'accepted', list: next };
147
+ const previous = capturePreparedImageList(current);
148
+ if (next.revision > previous.revision) return { status: 'accepted', list: next };
149
+ if (next.revision < previous.revision) return { status: 'historical', list: previous };
150
+ if (next.images.length !== previous.images.length
151
+ || next.images.some((image, index) => !sameImage(image, previous.images[index]!))) {
152
+ throw new PreparedImageContractError('conflict');
153
+ }
154
+ return { status: 'replay', list: previous };
155
+ };
156
+
157
+ const reportOf = (value: unknown, fromPallet: boolean): IPreparedImageReport => {
158
+ const report = readExactDataRecord(value, ['revision', 'images']);
159
+ const entries = report && readDataElements(report.images, preparedImageBounds.maximumImages);
160
+ if (!report || !entries) return invalid();
161
+ const revision = report.revision === null ? null : revisionOf(report.revision);
162
+ if (revision === null && entries.length !== 0) return invalid();
163
+ const images = entries.map((value): IPreparedImageStatus => {
164
+ const entry = readExactDataRecord(value, fromPallet
165
+ ? ['imageConfigDigest', 'state', 'reason'] : ['imageConfigDigest', 'state']);
166
+ if (!entry) return invalid();
167
+ const state = fromPallet ? projectPalletState(entry.state)
168
+ : preparedImageStates.find((candidate) => candidate === entry.state);
169
+ if (!state) return invalid();
170
+ return { imageConfigDigest: digestOf(entry.imageConfigDigest), state };
171
+ });
172
+ requireCanonicalOrder(images);
173
+ return { revision, images };
174
+ };
175
+
176
+ const projectPalletState = (state: unknown): TPreparedImageState | undefined => {
177
+ switch (state) {
178
+ case 'present': return 'present';
179
+ case 'fetching': case 'queued': return 'pulling';
180
+ case 'refused': case 'unavailable': return 'failed';
181
+ }
182
+ };
183
+
184
+ /** Project Pallet's local preparation-pass output, dropping its internal reason entirely. */
185
+ export const projectPreparedImageReport = (value: unknown): IPreparedImageReport =>
186
+ reportOf(value, true);
187
+
188
+ /** Read a wire observation. Reasons and any other extra fields are refused. */
189
+ export const snapshotPreparedImageReport = (value: unknown): IPreparedImageReport =>
190
+ reportOf(value, false);
191
+
192
+ /** Match the whole pull target to the node's exact current list. Authenticate its session first. */
193
+ export const isPreparedImagePullAuthorizedByList = (
194
+ request: Pick<IGetPreparedImagePullCredentialRequest, 'revision' | 'image'>,
195
+ current: IPreparedImageList | null,
196
+ ): boolean => {
197
+ if (current === null) return false;
198
+ const list = capturePreparedImageList(current);
199
+ const image = entryOf(request.image);
200
+ return list.revision === revisionOf(request.revision) && list.images.some((entry) => sameImage(entry, image));
201
+ };
202
+
203
+ const encoder = new TextEncoder();
204
+ const credentialField = (value: unknown, minimum: number, maximum: number): string =>
205
+ typeof value === 'string' && value.length >= minimum && value.length <= maximum && !value.includes('\0')
206
+ && encoder.encode(value).byteLength <= maximum ? value : invalid();
207
+
208
+ /** Accept only a response for this exact request and only unexpired credentials. */
209
+ export const bindPreparedImagePullCredentialResponse = (
210
+ value: unknown, request: Pick<IGetPreparedImagePullCredentialRequest, 'revision' | 'image'>, now: number,
211
+ ): IGetPreparedImagePullCredentialResponse => {
212
+ const response = readExactDataRecord(value, ['revision', 'image', 'credential']);
213
+ if (!response) return invalid();
214
+ const revision = revisionOf(response.revision);
215
+ const image = entryOf(response.image);
216
+ if (revision !== revisionOf(request.revision) || !sameImage(image, entryOf(request.image))) return invalid();
217
+ if (response.credential === null) return { revision, image, credential: null };
218
+ const credential = readExactDataRecord(response.credential, ['username', 'password', 'expiresAt']);
219
+ if (!credential) return invalid();
220
+ const expiresAt = revisionOf(credential.expiresAt);
221
+ if (expiresAt <= revisionOf(now)) return invalid();
222
+ return {
223
+ revision,
224
+ image,
225
+ credential: {
226
+ username: credentialField(credential.username, 1, preparedImageBounds.maximumRegistryUsernameBytes),
227
+ password: credentialField(credential.password, 0, preparedImageBounds.maximumRegistryPasswordBytes),
228
+ expiresAt,
229
+ },
230
+ };
231
+ };
package/ts/index.ts CHANGED
@@ -3,7 +3,8 @@ import * as appstore from './appstore/index.js';
3
3
  import * as platform from './platform/index.js';
4
4
  import * as platformservice from './platformservice/index.js';
5
5
  import * as protocol from './protocol.js';
6
- import * as requests from './requests/index.js';
6
+
7
+ export * as requests from './requests/index.js';
7
8
 
8
9
  export {
9
10
  appstore,
@@ -11,5 +12,13 @@ export {
11
12
  platform,
12
13
  platformservice,
13
14
  protocol,
14
- requests
15
15
  }
16
+
17
+ /** Storage-node and pool TypedRequest contracts are also available at requests.dcstorage. */
18
+ export { dcstorage } from './requests/index.js';
19
+ /** Prepared-image TypedRequest contracts are also available at requests.preparedimages. */
20
+ export { preparedimages } from './requests/index.js';
21
+ /** Corestore replication TypedRequest contracts are also available at requests.corestorereplication. */
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';
@@ -1,4 +1,4 @@
1
- import * as plugins from '../plugins.js';
1
+ import type * as plugins from '../plugins.js';
2
2
  import type {
3
3
  IArchivePruneResult,
4
4
  IArchiveRetentionPolicy,