@camstack/server 1.2.788 → 1.2.790

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 (127) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/agent/agent-child-manifest.js +39 -0
  3. package/dist/agent/agent-hub-registration.js +11 -1
  4. package/dist/agent/forward-to-hub.js +43 -0
  5. package/dist/agent/main.js +31 -81
  6. package/dist/agent/stale-addon-gate.js +70 -34
  7. package/dist/api/trpc/generated-cap-mounts.js +1 -6
  8. package/dist/api/trpc/generated-cap-routers.js +1221 -1417
  9. package/dist/core/addon/addon-registry.service.js +25 -33
  10. package/dist/core/addon/boot-health-snapshot.js +0 -28
  11. package/dist/core/addon/{hub-spawn-gate.js → hub-addon-support.js} +12 -35
  12. package/dist/core/moleculer/moleculer.service.js +2 -13
  13. package/dist/core/moleculer/runner-hosted-on-node.js +23 -0
  14. package/dist/core/updates/required-addon-update.js +1 -1
  15. package/package.json +23 -58
  16. package/system/dist/addon-utils.mjs +1 -1
  17. package/system/dist/{agent-https-jJDe-XNl.js → agent-https-BmXXKQAA.js} +1 -1
  18. package/system/dist/{agent-https-szf2FU49.mjs → agent-https-ByceQLwr.mjs} +1 -1
  19. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  20. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +4 -4
  21. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  22. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +5 -5
  23. package/system/dist/builtins/alerts/alerts.addon.d.ts +8 -0
  24. package/system/dist/builtins/alerts/alerts.addon.js +72 -1
  25. package/system/dist/builtins/alerts/alerts.addon.mjs +74 -3
  26. package/system/dist/builtins/autotrack/index.js +1 -1
  27. package/system/dist/builtins/autotrack/index.mjs +1 -1
  28. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  29. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +5 -5
  30. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  31. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  32. package/system/dist/builtins/camera-grid/index.js +1 -1
  33. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  34. package/system/dist/builtins/composer/composer.addon.js +3 -3
  35. package/system/dist/builtins/composer/composer.addon.mjs +3 -3
  36. package/system/dist/builtins/console-logging/index.js +1 -1
  37. package/system/dist/builtins/console-logging/index.mjs +1 -1
  38. package/system/dist/builtins/core-blocks/core-blocks.addon.js +11 -5
  39. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +11 -5
  40. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  41. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  42. package/system/dist/builtins/device-manager/device-manager.addon.js +1 -1
  43. package/system/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
  44. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  45. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  46. package/system/dist/builtins/keychain/index.js +4 -4
  47. package/system/dist/builtins/keychain/index.mjs +4 -4
  48. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  49. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  50. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  51. package/system/dist/builtins/local-auth/local-auth.addon.mjs +5 -5
  52. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  53. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  54. package/system/dist/builtins/loki-logging/index.js +1 -1
  55. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  56. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  57. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +10 -10
  58. package/system/dist/builtins/platform-probe/index.js +1 -1
  59. package/system/dist/builtins/platform-probe/index.mjs +10 -10
  60. package/system/dist/builtins/record-entries/index.js +1 -1
  61. package/system/dist/builtins/record-entries/index.mjs +1 -1
  62. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  63. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  64. package/system/dist/builtins/snapshot/index.js +1 -1
  65. package/system/dist/builtins/snapshot/index.mjs +1 -1
  66. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  67. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +20 -20
  68. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  69. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  70. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  71. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  72. package/system/dist/builtins/storage-orchestrator/access-guards.d.ts +1 -1
  73. package/system/dist/builtins/storage-orchestrator/custom-actions.d.ts +11 -0
  74. package/system/dist/builtins/storage-orchestrator/index.d.ts +1 -0
  75. package/system/dist/builtins/storage-orchestrator/index.js +2 -0
  76. package/system/dist/builtins/storage-orchestrator/index.mjs +2 -2
  77. package/system/dist/builtins/storage-orchestrator/location-instances.d.ts +72 -0
  78. package/system/dist/builtins/storage-orchestrator/location-repoint-move.d.ts +1 -1
  79. package/system/dist/builtins/storage-orchestrator/location-secret-refs.d.ts +26 -0
  80. package/system/dist/builtins/storage-orchestrator/location-store.d.ts +28 -2
  81. package/system/dist/builtins/storage-orchestrator/migrations/index.d.ts +9 -2
  82. package/system/dist/builtins/storage-orchestrator/migrations/legacy-location-secret-refs.d.ts +13 -0
  83. package/system/dist/builtins/storage-orchestrator/migrations/location-secret-ports.d.ts +15 -0
  84. package/system/dist/builtins/storage-orchestrator/migrations/location-secrets-to-record.d.ts +57 -0
  85. package/system/dist/builtins/storage-orchestrator/provider-discovery.d.ts +10 -13
  86. package/system/dist/builtins/storage-orchestrator/record-kinds.d.ts +6 -0
  87. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.d.ts +39 -8
  88. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +954 -131
  89. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +954 -132
  90. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.service.d.ts +8 -0
  91. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  92. package/system/dist/builtins/system-config/system-config.addon.mjs +115 -115
  93. package/system/dist/builtins/winston-logging/index.js +112 -3
  94. package/system/dist/builtins/winston-logging/index.mjs +112 -3
  95. package/system/dist/builtins/winston-logging/migrations/index.d.ts +8 -0
  96. package/system/dist/builtins/winston-logging/migrations/node-fields.d.ts +43 -0
  97. package/system/dist/builtins/winston-logging/winston-logging.addon.d.ts +10 -2
  98. package/system/dist/{capture-engine-DNHgjQot.js → capture-engine-BHj1fNYC.js} +1 -1
  99. package/system/dist/{capture-engine-BsKY_3xa.mjs → capture-engine-D9n4KDaN.mjs} +1 -1
  100. package/system/dist/{composition-sources-BgO0GQYW.js → composition-sources-BGgIuuvd.js} +1 -1
  101. package/system/dist/{composition-sources-BRdGsbVT.mjs → composition-sources-wI4qWTz2.mjs} +1 -1
  102. package/system/dist/{constants-CQeMrR4f.mjs → constants-DHqkxbYk.mjs} +1 -1
  103. package/system/dist/{constants-C3jGKQSQ.js → constants-DNdriMRD.js} +1 -1
  104. package/system/dist/{coral-accelerators-BW3OcrLD.mjs → coral-accelerators-DBlgWB8k.mjs} +6 -6
  105. package/system/dist/{custom-action-registry-N7flBDwT.mjs → custom-action-registry-B9zFBNVa.mjs} +37 -37
  106. package/system/dist/{device-ca-D3y6wGmn.js → device-ca-C2RzT1VT.js} +1 -1
  107. package/system/dist/{device-ca-ByVi5eUC.mjs → device-ca-gr5eE3h5.mjs} +1 -1
  108. package/system/dist/{dist-BsQA6-0i.mjs → dist-BUoL5bbr.mjs} +116 -418
  109. package/system/dist/{dist-BRI-Mwx0.js → dist-DV0V3JiE.js} +133 -417
  110. package/system/dist/file-host-worker.js +1 -1
  111. package/system/dist/file-host-worker.mjs +1 -1
  112. package/system/dist/{hub-mdns-ciao-Ry_Jpljx.js → hub-mdns-ciao-Be5PGXW6.js} +2 -2
  113. package/system/dist/{hub-mdns-ciao-8dJTW2LI.mjs → hub-mdns-ciao-DoSb8dwB.mjs} +2 -2
  114. package/system/dist/index.js +151 -53
  115. package/system/dist/index.mjs +362 -266
  116. package/system/dist/kernel/addon-health-monitor.d.ts +0 -21
  117. package/system/dist/kernel/index.d.ts +2 -0
  118. package/system/dist/kernel/transport/runner-of-addon.d.ts +2 -0
  119. package/system/dist/kernel/unsupported-addon-tracker.d.ts +74 -0
  120. package/system/dist/{legacy-integration-rows-door-D5BdSNla.js → legacy-integration-rows-door-D5s8oM7e.js} +1 -1
  121. package/system/dist/{legacy-integration-rows-door-CjXTbmvH.mjs → legacy-integration-rows-door-DRC0xn6k.mjs} +1 -1
  122. package/system/dist/migrations/hub/2026-11-06-addon-settings-bare-rows.d.ts +3 -0
  123. package/system/dist/{restore-archive-Co2lk3OU.mjs → restore-archive-DH3P9j-V.mjs} +94 -94
  124. package/system/dist/{restore-archive-GoWJMdHy.js → restore-archive-Dh4gfCRY.js} +1 -1
  125. package/system/dist/{wal-maintenance-DRnV6QYu.mjs → wal-maintenance-BWfH3Lov.mjs} +0 -0
  126. package/system/dist/{wal-maintenance-C1Haue74.js → wal-maintenance-DgN_WD5T.js} +0 -0
  127. package/system/package.json +4 -1
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  const require_chunk = require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-BRI-Mwx0.js");
6
+ const require_dist = require("../../dist-DV0V3JiE.js");
7
7
  const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
8
8
  let zod = require("zod");
9
9
  let node_crypto = require("node:crypto");
@@ -12,6 +12,39 @@ let node_path = require("node:path");
12
12
  node_path = require_chunk.__toESM(node_path);
13
13
  let node_fs_promises = require("node:fs/promises");
14
14
  node_fs_promises = require_chunk.__toESM(node_fs_promises);
15
+ //#region src/builtins/storage-orchestrator/location-secret-refs.ts
16
+ /**
17
+ * Where a storage location's credentials live (planning#440 step 6, D879, D987).
18
+ *
19
+ * A credential is a keychain value bound to the location's OWN record: the body's `secrets` map
20
+ * (`secrets{password}`) is what the records door stores, so deleting the row deletes the value and
21
+ * one location's credential is never another's. Before this, the credential was filed under
22
+ * `row/storage_locations/<id>` and the row's `config` held the marker; those refs are the LEGACY
23
+ * ones the migration `storage-orchestrator/2026-11-07-location-secrets-to-record` moves.
24
+ *
25
+ * The in-memory location still carries a marker per credential in `config` (the orchestrator
26
+ * resolves it through `ctx.secrets` when a provider needs the value); the marker built here is the
27
+ * one the records door itself wrote, so both ends agree without a read.
28
+ */
29
+ /** The addon id the records door and the keychain both file this owner's values under. */
30
+ var STORAGE_RECORD_OWNER = "storage-orchestrator";
31
+ /** The record kind the locations live in (`record-kinds.ts`). */
32
+ var LOCATIONS_RECORD_KIND = "locations";
33
+ /** The body field that holds the credentials, by config key. */
34
+ var LOCATION_SECRETS_FIELD = "secrets";
35
+ /** The ref the records door files the credential `key` of location `id` under. */
36
+ function locationSecretRef(id, key) {
37
+ return require_dist.recordSecretRef(STORAGE_RECORD_OWNER, LOCATIONS_RECORD_KIND, id, `${LOCATION_SECRETS_FIELD}{${encodeURIComponent(key)}}`);
38
+ }
39
+ /** The marker the location carries in memory for a credential kept in its record. */
40
+ function locationSecretMarker(id, key) {
41
+ return require_dist.makeSecretMarker(locationSecretRef(id, key));
42
+ }
43
+ /** Is `value` the marker of the credential `key` of location `id` kept in its own record? */
44
+ function isOwnLocationMarker(id, key, value) {
45
+ return require_dist.isSecretMarker(value) && value.$secret === locationSecretRef(id, key);
46
+ }
47
+ //#endregion
15
48
  //#region src/builtins/storage-orchestrator/record-kinds.ts
16
49
  var import_read_all_rows = require_read_all_rows$1.require_read_all_rows();
17
50
  var StorageLocationBodySchema = zod.z.object({
@@ -25,7 +58,8 @@ var StorageLocationBodySchema = zod.z.object({
25
58
  nodeId: zod.z.string().optional(),
26
59
  enabled: zod.z.boolean().optional(),
27
60
  mode: require_dist.StorageLocationModeSchema.optional(),
28
- isDefault: zod.z.boolean().optional()
61
+ isDefault: zod.z.boolean().optional(),
62
+ secrets: zod.z.record(zod.z.string(), zod.z.string().meta({ secret: true })).optional()
29
63
  });
30
64
  var StorageSeedMarkerBodySchema = zod.z.object({ seededAt: zod.z.number() });
31
65
  var StorageDrainStateBodySchema = zod.z.object({
@@ -78,11 +112,43 @@ _storageOrchestratorRecordKinds["drain-state"];
78
112
  //#endregion
79
113
  //#region src/builtins/storage-orchestrator/location-store.ts
80
114
  /**
81
- * The keychain scope collection a storage location's secret fields are filed
82
- * under (`row/storage_locations/<id>`). The table it was named for is gone; the
83
- * string stays because existing secret markers point at it.
115
+ * Credentials a save carries, by config key, until the store writes the row: a value sets the
116
+ * credential, `null` removes it. The service persists without waiting (`upsert` is fire and
117
+ * forget), so the plaintext cannot ride on the location itself; it is staged here, one shot per
118
+ * location id, and `SqliteLocationStore.upsert` hands it to the records door with the row.
84
119
  */
85
- var STORAGE_LOCATIONS_SECRET_SCOPE = "storage_locations";
120
+ var LocationSecretStaging = class {
121
+ staged = /* @__PURE__ */ new Map();
122
+ waiting = /* @__PURE__ */ new Map();
123
+ settledBy = /* @__PURE__ */ new Map();
124
+ stage(id, secrets) {
125
+ if (Object.keys(secrets).length === 0) return;
126
+ this.staged.set(id, secrets);
127
+ this.settledBy.set(id, new Promise((resolve) => {
128
+ this.waiting.set(id, resolve);
129
+ }));
130
+ }
131
+ /** The staged credentials of `id`, once; a save that was refused discards them instead. */
132
+ take(id) {
133
+ const secrets = this.staged.get(id) ?? {};
134
+ this.staged.delete(id);
135
+ return secrets;
136
+ }
137
+ /** The row of `id` is written (or the write failed): whoever waits for the credential may go on. */
138
+ written(id) {
139
+ this.waiting.get(id)?.();
140
+ this.waiting.delete(id);
141
+ this.settledBy.delete(id);
142
+ }
143
+ discard(id) {
144
+ this.staged.delete(id);
145
+ this.written(id);
146
+ }
147
+ /** Resolves when the staged credentials of `id` are written; at once when none are staged. */
148
+ settled(id) {
149
+ return this.settledBy.get(id) ?? Promise.resolve();
150
+ }
151
+ };
86
152
  /**
87
153
  * `ILocationStore` on the storage-orchestrator's own record kinds (`locations`
88
154
  * and `seed-markers`).
@@ -90,9 +156,11 @@ var STORAGE_LOCATIONS_SECRET_SCOPE = "storage_locations";
90
156
  var SqliteLocationStore = class {
91
157
  locationsKind;
92
158
  seedMarkersKind;
93
- constructor(locationsKind, seedMarkersKind) {
159
+ staging;
160
+ constructor(locationsKind, seedMarkersKind, staging = new LocationSecretStaging()) {
94
161
  this.locationsKind = locationsKind;
95
162
  this.seedMarkersKind = seedMarkersKind;
163
+ this.staging = staging;
96
164
  }
97
165
  static seedMarkersOf(records) {
98
166
  return records.kind(storageOrchestratorRecordKinds["seed-markers"]);
@@ -123,22 +191,40 @@ var SqliteLocationStore = class {
123
191
  return out;
124
192
  }
125
193
  async upsert(loc) {
126
- const data = storageOrchestratorRecordKinds.locations.schema.parse(locationToBody(loc));
127
- await this.locationsKind.put({
128
- id: loc.id,
129
- data
130
- });
194
+ const staged = this.staging.take(loc.id);
195
+ try {
196
+ const data = storageOrchestratorRecordKinds.locations.schema.parse(locationToBody(loc, staged));
197
+ await this.locationsKind.put({
198
+ id: loc.id,
199
+ data
200
+ });
201
+ } finally {
202
+ this.staging.written(loc.id);
203
+ }
131
204
  }
132
205
  async delete(id) {
133
206
  await this.locationsKind.delete(id);
134
207
  }
135
208
  };
136
- function locationToBody(loc) {
209
+ /**
210
+ * The body a location is stored as. A credential the location keeps in its own record (the marker
211
+ * of `location-secret-refs.ts`) leaves `config` for `secrets`, where the records door keeps the
212
+ * value and the redaction token means "keep what is stored"; `staged` sets or removes one. Any
213
+ * other marker (a legacy ref the migration has not moved yet) stays in `config` untouched.
214
+ */
215
+ function locationToBody(loc, staged = {}) {
216
+ const config = {};
217
+ const secrets = {};
218
+ for (const [key, value] of Object.entries(loc.config)) if (isOwnLocationMarker(loc.id, key, value)) secrets[key] = require_dist.REDACTED_SECRET;
219
+ else config[key] = value;
220
+ for (const [key, value] of Object.entries(staged)) if (value === null) delete secrets[key];
221
+ else secrets[key] = value;
137
222
  return {
138
223
  type: loc.type,
139
224
  displayName: loc.displayName,
140
225
  providerId: loc.providerId,
141
- config: { ...loc.config },
226
+ config,
227
+ ...Object.keys(secrets).length > 0 ? { secrets } : {},
142
228
  isSystem: loc.isSystem,
143
229
  createdAt: loc.createdAt,
144
230
  updatedAt: loc.updatedAt,
@@ -155,7 +241,10 @@ function bodyToPersistedLocation(id, body) {
155
241
  type: parsedType.data,
156
242
  displayName: body.displayName,
157
243
  providerId: body.providerId,
158
- config: { ...body.config },
244
+ config: {
245
+ ...body.config,
246
+ ...Object.fromEntries(Object.keys(body.secrets ?? {}).map((key) => [key, locationSecretMarker(id, key)]))
247
+ },
159
248
  ...body.nodeId !== void 0 ? { nodeId: body.nodeId } : {},
160
249
  ...body.enabled !== void 0 ? { enabled: body.enabled } : {},
161
250
  ...body.mode !== void 0 ? { mode: body.mode } : {},
@@ -238,7 +327,7 @@ var StorageMigrationCoordinator = class {
238
327
  if (target.type !== storageClass) throw new Error(`Storage location "${targetId}" is type "${target.type}", expected "${storageClass}"`);
239
328
  if (source.id === target.id) throw new Error(namedSourceId ? `Source and destination are the same location ("${targetId}")` : `Storage location "${targetId}" is already the only write target for "${storageClass}"`);
240
329
  const freezeSource = !writeSet.some((loc) => loc.id === source.id);
241
- if (!MOVER_CLASSES.includes(storageClass)) throw new Error(`No mover owns "${storageClass}" — the migration can move its write set but cannot move its bytes. Move it by hand, then enable the destination (and disable the source) with upsertLocation.`);
330
+ if (!MOVER_CLASSES.includes(storageClass)) throw new Error(`No mover owns "${storageClass}" — the migration can move its write set but cannot move its bytes. Move it by hand, then enable the destination (and disable the source) from the Storage page.`);
242
331
  moves.push({
243
332
  storageClass,
244
333
  fromLocationId: source.id,
@@ -1021,11 +1110,121 @@ function buildStorageLocationRegistry(perAddon) {
1021
1110
  }
1022
1111
  };
1023
1112
  }
1024
- /** The `storage-orchestrator` catalogue (D987): offered to the engine once the seed state is known. */
1113
+ //#endregion
1114
+ //#region src/builtins/storage-orchestrator/migrations/legacy-location-secret-refs.ts
1115
+ /**
1116
+ * The keychain refs a storage location's credentials were filed under BEFORE they moved into the
1117
+ * location's own record (`row/storage_locations/<id>`). Only the migration
1118
+ * `storage-orchestrator/2026-11-07-location-secrets-to-record` reads this shape.
1119
+ */
1120
+ /** The keychain collection of the legacy per-row refs (the table it was named for is gone). */
1121
+ var LEGACY_LOCATION_SECRET_COLLECTION = "storage_locations";
1122
+ /** The ref a credential of `id` was filed under before the move to the record. */
1123
+ function legacyLocationSecretRef(id, key) {
1124
+ return require_dist.buildSecretRef({
1125
+ owner: STORAGE_RECORD_OWNER,
1126
+ scope: {
1127
+ kind: "row",
1128
+ collection: LEGACY_LOCATION_SECRET_COLLECTION,
1129
+ rowId: id
1130
+ },
1131
+ fieldPath: key
1132
+ });
1133
+ }
1134
+ /**
1135
+ * Is `value` a marker the migration has to move: a keychain marker of THIS location's legacy
1136
+ * collection. Anything else (a record-bound marker, someone else's ref) is left alone.
1137
+ */
1138
+ function isLegacyLocationMarker(id, value) {
1139
+ if (!require_dist.isSecretMarker(value)) return false;
1140
+ const parts = require_dist.parseSecretRef(value.$secret);
1141
+ if (parts === null || parts.scope.kind !== "row") return false;
1142
+ return parts.scope.collection === LEGACY_LOCATION_SECRET_COLLECTION && parts.scope.rowId === id;
1143
+ }
1144
+ //#endregion
1145
+ //#region src/builtins/storage-orchestrator/migrations/location-secrets-to-record.ts
1146
+ function sameSecrets(back, expected) {
1147
+ const entries = (value) => JSON.stringify(Object.entries(value).toSorted(([a], [b]) => a < b ? -1 : 1));
1148
+ return entries(back) === entries(expected);
1149
+ }
1150
+ /**
1151
+ * Release the legacy values a row already moved off of. Fail-safe in both directions: a keychain
1152
+ * that cannot answer, or a record credential that does not resolve, releases nothing here (the
1153
+ * next boot looks again); nothing is ever released on a guess.
1154
+ */
1155
+ async function sweepStrandedLegacy(ports, all) {
1156
+ const candidates = all.filter((row) => Object.keys(row.legacy).length === 0 && row.recorded.length > 0);
1157
+ if (candidates.length === 0) return 0;
1158
+ const refOf = (row, key) => legacyLocationSecretRef(row.id, key);
1159
+ const answers = await ports.resolveLegacy(candidates.flatMap((row) => row.recorded.map((key) => refOf(row, key))));
1160
+ const stranded = [];
1161
+ for (const row of candidates) {
1162
+ const present = row.recorded.filter((key) => answers.get(refOf(row, key))?.kind === "value");
1163
+ if (present.length === 0) continue;
1164
+ const moved = await ports.readMoved(row.id).catch(() => null);
1165
+ for (const key of present) if ((moved?.secrets[key] ?? "") !== "") stranded.push(refOf(row, key));
1166
+ }
1167
+ if (stranded.length > 0) await ports.releaseLegacy(stranded);
1168
+ return stranded.length;
1169
+ }
1170
+ async function moveLocationSecretsToRecords(ports) {
1171
+ const all = await ports.readLegacy();
1172
+ const released = await sweepStrandedLegacy(ports, all);
1173
+ const rows = all.filter((row) => Object.keys(row.legacy).length > 0);
1174
+ if (rows.length === 0) return released > 0 ? {
1175
+ outcome: "done",
1176
+ summary: {
1177
+ locations: 0,
1178
+ credentials: 0,
1179
+ released
1180
+ }
1181
+ } : {
1182
+ outcome: "already-done",
1183
+ summary: { reason: "no-legacy-secrets" }
1184
+ };
1185
+ const refs = [...new Set(rows.flatMap((row) => Object.values(row.legacy).map((m) => m.$secret)))];
1186
+ const answers = await ports.resolveLegacy(refs);
1187
+ const lost = [];
1188
+ for (const row of rows) for (const [key, marker] of Object.entries(row.legacy)) if (answers.get(marker.$secret)?.kind !== "value") lost.push(`${row.id}.${key}`);
1189
+ if (lost.length > 0) throw new Error(`storage-orchestrator: ${lost.length} location credential(s) cannot be read from the keychain (${lost.join(", ")}); nothing was moved`);
1190
+ let moved = 0;
1191
+ let credentials = 0;
1192
+ try {
1193
+ for (const row of rows) {
1194
+ const expected = {};
1195
+ for (const [key, marker] of Object.entries(row.legacy)) {
1196
+ const answer = answers.get(marker.$secret);
1197
+ if (answer?.kind === "value") expected[key] = answer.value;
1198
+ }
1199
+ await ports.moveToRecord(row.id, expected);
1200
+ const back = await ports.readMoved(row.id);
1201
+ const staleKeys = back === null ? [] : back.configKeys.filter((key) => key in expected);
1202
+ if (back === null || !sameSecrets(back.secrets, expected) || staleKeys.length > 0) throw new Error(`storage-orchestrator: location '${row.id}' did not read back as moved; its legacy credentials were kept`);
1203
+ await ports.releaseLegacy(Object.values(row.legacy).map((marker) => marker.$secret));
1204
+ moved += 1;
1205
+ credentials += Object.keys(expected).length;
1206
+ }
1207
+ } finally {
1208
+ if (moved > 0) await ports.refreshLocations();
1209
+ }
1210
+ return {
1211
+ outcome: "done",
1212
+ summary: {
1213
+ locations: moved,
1214
+ credentials
1215
+ }
1216
+ };
1217
+ }
1218
+ //#endregion
1219
+ //#region src/builtins/storage-orchestrator/migrations/index.ts
1220
+ var STORAGE_ORCHESTRATOR_ID = "storage-orchestrator";
1221
+ var RESEED_PRUNED_DEFAULTS_ID = "storage-orchestrator/2026-11-04-reseed-pruned-defaults";
1222
+ var LOCATION_SECRETS_TO_RECORD_ID = "storage-orchestrator/2026-11-07-location-secrets-to-record";
1223
+ /** The `storage-orchestrator` catalogue (D987), declared whole every time and run by id. */
1025
1224
  var ADDON_MIGRATIONS = [{
1026
1225
  meta: {
1027
- id: "storage-orchestrator/2026-11-04-reseed-pruned-defaults",
1028
- owner: "storage-orchestrator",
1226
+ id: RESEED_PRUNED_DEFAULTS_ID,
1227
+ owner: STORAGE_ORCHESTRATOR_ID,
1029
1228
  level: "addon-state",
1030
1229
  seq: 1,
1031
1230
  dependsOn: [],
@@ -1043,8 +1242,76 @@ var ADDON_MIGRATIONS = [{
1043
1242
  summary: { types: [...types] }
1044
1243
  };
1045
1244
  }
1245
+ }, {
1246
+ meta: {
1247
+ id: LOCATION_SECRETS_TO_RECORD_ID,
1248
+ owner: STORAGE_ORCHESTRATOR_ID,
1249
+ level: "addon-state",
1250
+ seq: 2,
1251
+ dependsOn: [],
1252
+ store: "settings",
1253
+ scope: "cluster",
1254
+ onFailure: "block-owner",
1255
+ bodyKind: "procedure",
1256
+ description: "Move each storage location's credentials from the per-row keychain refs into the location's own record",
1257
+ fixtureMark: "a location row that carries no credential (a drain row, recordings:default), which the move must not touch"
1258
+ },
1259
+ procedure: moveLocationSecretsToRecords
1046
1260
  }];
1047
1261
  //#endregion
1262
+ //#region src/builtins/storage-orchestrator/migrations/location-secret-ports.ts
1263
+ function locationSecretPortsOver(deps) {
1264
+ const { locations, secrets } = deps;
1265
+ return {
1266
+ async readLegacy() {
1267
+ return (await (0, import_read_all_rows.readAllRows)(locations)).map((row) => {
1268
+ const legacy = {};
1269
+ for (const [key, value] of Object.entries(row.data.config)) if (isLegacyLocationMarker(row.id, value)) legacy[key] = value;
1270
+ return {
1271
+ id: row.id,
1272
+ legacy,
1273
+ recorded: Object.keys(row.data.secrets ?? {})
1274
+ };
1275
+ });
1276
+ },
1277
+ async resolveLegacy(refs) {
1278
+ const answer = await secrets.resolve(refs);
1279
+ const out = /* @__PURE__ */ new Map();
1280
+ for (const ref of refs) {
1281
+ const entry = answer[ref];
1282
+ if (entry?.kind === "value") out.set(ref, {
1283
+ kind: "value",
1284
+ value: entry.value
1285
+ });
1286
+ else out.set(ref, { kind: entry?.kind === "missing" ? "missing" : "unavailable" });
1287
+ }
1288
+ return out;
1289
+ },
1290
+ async moveToRecord(id, moved) {
1291
+ const removed = {};
1292
+ for (const key of Object.keys(moved)) removed[key] = null;
1293
+ await locations.patch(id, {
1294
+ secrets: moved,
1295
+ config: removed
1296
+ });
1297
+ },
1298
+ async readMoved(id) {
1299
+ const row = await locations.getResolved(id);
1300
+ if (row === null) return null;
1301
+ return {
1302
+ secrets: row.data.secrets ?? {},
1303
+ configKeys: Object.keys(row.data.config)
1304
+ };
1305
+ },
1306
+ async releaseLegacy(refs) {
1307
+ await secrets.delete(refs);
1308
+ },
1309
+ async refreshLocations() {
1310
+ await deps.refreshLocations();
1311
+ }
1312
+ };
1313
+ }
1314
+ //#endregion
1048
1315
  //#region src/builtins/storage-orchestrator/location-occupancy.ts
1049
1316
  /**
1050
1317
  * Delete-time occupancy of a location's on-disk root.
@@ -2058,6 +2325,465 @@ function restoreRedactedSecrets(incoming, stored, secretKeys) {
2058
2325
  return touched ? out : incoming;
2059
2326
  }
2060
2327
  //#endregion
2328
+ //#region src/builtins/storage-orchestrator/custom-actions.ts
2329
+ /**
2330
+ * The forced delete of a storage location (D49). `deleteInstance` keeps the occupancy refusal;
2331
+ * this is the separate, explicit action for a location the check could not read (a removed disk,
2332
+ * another node, a remote provider). The caller states it after a second confirmation.
2333
+ */
2334
+ var forceDeleteLocationInput = zod.z.object({ id: zod.z.string().min(1) });
2335
+ var storageOrchestratorActions = require_dist.defineCustomActions({ forceDeleteLocation: require_dist.customAction(forceDeleteLocationInput, zod.z.object({ ok: zod.z.literal(true) }), {
2336
+ kind: "mutation",
2337
+ auth: "admin"
2338
+ }) });
2339
+ //#endregion
2340
+ //#region src/builtins/storage-orchestrator/location-instances.ts
2341
+ /**
2342
+ * The storage locations as `integration-instances` (planning#440 step 6, D985, D986): one
2343
+ * instance per location, one KIND per declared location type (`recordings`, `backups`, ...).
2344
+ * The form is the provider select, the provider's own fields and the location's state; the
2345
+ * credentials the provider declares go to the keychain bound to the location's record
2346
+ * (`location-secret-refs.ts`, D879).
2347
+ *
2348
+ * A location keeps ONE typed state (`mode`, D385) and only `storage-location-mode.ts` reads it.
2349
+ * The row switch maps to it: on is `active`; off is `readonly` (the write switch, D383), and a
2350
+ * location that is already `drain` or `disabled` stays as it is. Delete keeps the occupancy
2351
+ * refusal; the forced delete is NOT a flag here, it is the separate `forceDeleteLocation`
2352
+ * action (D49: destructive, confirmed by a second read).
2353
+ *
2354
+ * The edit form is the provider's schema as it is. The create form offers every provider, so
2355
+ * each provider's fields are namespaced `<providerId>.<key>` and shown for that provider; a
2356
+ * `notEquals` / `notIn` condition on a select is rewritten to the options it leaves, because the
2357
+ * selector of another provider is unset and an unset value would satisfy a negation.
2358
+ */
2359
+ var STORAGE_INSTANCE_KIND = "storage-location";
2360
+ var STORAGE_FUNCTION_CAP = "storage";
2361
+ /** The generic widget id the admin UI maps to its path browser. */
2362
+ var STORAGE_PATH_WIDGET = "storage/path-browser";
2363
+ var PROVIDER_FIELD = "providerId";
2364
+ var MODE_FIELD = "mode";
2365
+ var NODE_FIELD = "nodeId";
2366
+ var MIN_FREE_FIELD = "minFreePercent";
2367
+ var MAX_USED_FIELD = "maxUsedGb";
2368
+ /** Config keys the framework owns; a provider never declares them. */
2369
+ var FRAMEWORK_NUMBER_KEYS = [MIN_FREE_FIELD, MAX_USED_FIELD];
2370
+ /** The legacy mirror of the mode; it is derived and never part of a form. */
2371
+ var LEGACY_READ_ONLY = "readOnly";
2372
+ var LOCATION_ID_SLUG = /^[a-z0-9-]+$/;
2373
+ function isRecord(value) {
2374
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2375
+ }
2376
+ function isConfigField(value) {
2377
+ return isRecord(value) && typeof value["key"] === "string" && typeof value["label"] === "string" && typeof value["type"] === "string";
2378
+ }
2379
+ function isConfigSection(value) {
2380
+ return isRecord(value) && typeof value["id"] === "string" && typeof value["title"] === "string" && Array.isArray(value["fields"]) && value["fields"].every(isConfigField);
2381
+ }
2382
+ /** The sections a provider's `configSchema` carries; anything else is no form. */
2383
+ function providerSections(schema) {
2384
+ if (!isRecord(schema)) return [];
2385
+ const sections = schema["sections"];
2386
+ return Array.isArray(sections) ? sections.filter(isConfigSection) : [];
2387
+ }
2388
+ function isStorageMode(value) {
2389
+ return require_dist.STORAGE_LOCATION_MODES.some((mode) => mode === value);
2390
+ }
2391
+ function namespaced(providerId, key) {
2392
+ return `${providerId}.${key}`;
2393
+ }
2394
+ function conditionOf(field) {
2395
+ return "showWhen" in field ? field.showWhen : void 0;
2396
+ }
2397
+ /** The field under a new key and a new condition (a field type without one ignores it). */
2398
+ function placed(field, key, showWhen) {
2399
+ return Object.assign({}, field, {
2400
+ key,
2401
+ showWhen
2402
+ });
2403
+ }
2404
+ /** A provider's field as the create form shows it: its own key space, shown for that provider. */
2405
+ function namespacedField(providerId, field, siblings) {
2406
+ const key = namespaced(providerId, field.key);
2407
+ if (field.type === "object-array") return {
2408
+ ...field,
2409
+ key
2410
+ };
2411
+ const own = conditionOf(field);
2412
+ if (own === void 0) return placed(field, key, {
2413
+ field: PROVIDER_FIELD,
2414
+ equals: providerId
2415
+ });
2416
+ const sibling = siblings.find((f) => f.key === own.field);
2417
+ let showWhen = {
2418
+ ...own,
2419
+ field: namespaced(providerId, own.field)
2420
+ };
2421
+ if (sibling?.type === "select") {
2422
+ const values = sibling.options.map((option) => option.value);
2423
+ if (own.notEquals !== void 0) {
2424
+ const excluded = own.notEquals;
2425
+ const { notEquals: _dropped, ...rest } = showWhen;
2426
+ showWhen = {
2427
+ ...rest,
2428
+ in: values.filter((value) => value !== excluded)
2429
+ };
2430
+ } else if (own.notIn !== void 0) {
2431
+ const excluded = own.notIn;
2432
+ const { notIn: _dropped, ...rest } = showWhen;
2433
+ showWhen = {
2434
+ ...rest,
2435
+ in: values.filter((value) => !excluded.includes(value))
2436
+ };
2437
+ }
2438
+ }
2439
+ return placed(field, key, showWhen);
2440
+ }
2441
+ function createProviderSections(providers) {
2442
+ return providers.flatMap((provider) => providerSections(provider.configSchema).map((section) => {
2443
+ const all = providerSections(provider.configSchema).flatMap((s) => s.fields);
2444
+ return {
2445
+ ...section,
2446
+ id: `${provider.providerId}:${section.id}`,
2447
+ fields: section.fields.map((field) => namespacedField(provider.providerId, field, all))
2448
+ };
2449
+ }));
2450
+ }
2451
+ /**
2452
+ * Where the location lives. On an existing location its state (`mode`) is not a form field: the
2453
+ * admin page changes it through its own control, which knows the last-writable guard and confirms
2454
+ * `disabled`. A new location asks only whether it takes writes or is only read (`withState`).
2455
+ */
2456
+ function stateSection(nodeLocalIds, withState = false) {
2457
+ const fields = [];
2458
+ if (withState) fields.push({
2459
+ type: "select",
2460
+ key: MODE_FIELD,
2461
+ label: "State",
2462
+ default: "active",
2463
+ options: [{
2464
+ value: "active",
2465
+ label: "Active"
2466
+ }, {
2467
+ value: "readonly",
2468
+ label: "Read-only"
2469
+ }]
2470
+ });
2471
+ if (nodeLocalIds === null || nodeLocalIds.length > 0) fields.push({
2472
+ type: "text",
2473
+ key: NODE_FIELD,
2474
+ label: "Node",
2475
+ description: "The node whose disk this location is. Empty means the hub.",
2476
+ ...nodeLocalIds === null ? {} : { showWhen: {
2477
+ field: PROVIDER_FIELD,
2478
+ in: [...nodeLocalIds]
2479
+ } }
2480
+ });
2481
+ return {
2482
+ id: "state",
2483
+ title: withState ? "Placement" : "Node",
2484
+ columns: 1,
2485
+ fields
2486
+ };
2487
+ }
2488
+ function protectionSection() {
2489
+ return {
2490
+ id: "protection",
2491
+ title: "Disk protection",
2492
+ columns: 2,
2493
+ fields: [{
2494
+ type: "number",
2495
+ key: MIN_FREE_FIELD,
2496
+ label: "Keep free (%)",
2497
+ min: 0,
2498
+ max: 100
2499
+ }, {
2500
+ type: "number",
2501
+ key: MAX_USED_FIELD,
2502
+ label: "Use at most (GB)",
2503
+ min: 0
2504
+ }]
2505
+ };
2506
+ }
2507
+ function stateOf(location) {
2508
+ return require_dist.resolveLocationMode(location);
2509
+ }
2510
+ /** A form value that names a credential KEPT: left out, empty, the redaction token or the view. */
2511
+ function keepsSecret(value) {
2512
+ return value === void 0 || value === "" || value === "__camstack_redacted__" || require_dist.isSecretFieldView(value) || require_dist.isSecretMarker(value);
2513
+ }
2514
+ function numberOrNull(value) {
2515
+ if (value === void 0) return void 0;
2516
+ if (value === null || value === "") return null;
2517
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
2518
+ }
2519
+ var StorageLocationInstances = class {
2520
+ deps;
2521
+ constructor(deps) {
2522
+ this.deps = deps;
2523
+ }
2524
+ kinds() {
2525
+ return this.deps.declarations().map((declaration) => ({
2526
+ id: declaration.id,
2527
+ label: declaration.displayName,
2528
+ functionCap: STORAGE_FUNCTION_CAP,
2529
+ role: "services",
2530
+ canTest: true,
2531
+ widgets: [{
2532
+ id: STORAGE_PATH_WIDGET,
2533
+ placement: "connection"
2534
+ }]
2535
+ }));
2536
+ }
2537
+ viewOf(location) {
2538
+ const mode = stateOf(location);
2539
+ const secretKeys = this.deps.secretKeys(location.providerId, location.config);
2540
+ const formValues = {
2541
+ [PROVIDER_FIELD]: location.providerId,
2542
+ [MODE_FIELD]: mode
2543
+ };
2544
+ if (location.nodeId !== void 0) formValues[NODE_FIELD] = location.nodeId;
2545
+ for (const [key, value] of Object.entries(location.config)) {
2546
+ if (key === LEGACY_READ_ONLY) continue;
2547
+ if (secretKeys.has(key)) {
2548
+ const view = require_dist.toSecretFieldView(value);
2549
+ if (view !== null) formValues[key] = view;
2550
+ } else formValues[key] = value;
2551
+ }
2552
+ return {
2553
+ id: location.id,
2554
+ name: location.displayName,
2555
+ configured: true,
2556
+ enabled: require_dist.switchStateOfMode(mode),
2557
+ kind: location.type,
2558
+ formValues,
2559
+ status: {
2560
+ state: require_dist.switchStateOfMode(mode) ? "ok" : "off",
2561
+ label: mode
2562
+ }
2563
+ };
2564
+ }
2565
+ describe = async () => ({
2566
+ role: "services",
2567
+ instanceMode: "multiple",
2568
+ kind: STORAGE_INSTANCE_KIND,
2569
+ canTest: true,
2570
+ mintsId: true,
2571
+ kinds: [...this.kinds()]
2572
+ });
2573
+ instanceFormSchema = async ({ id }) => {
2574
+ const providers = await this.deps.providers();
2575
+ if (id === null) {
2576
+ const nodeLocal = providers.filter((p) => p.nodeLocal).map((p) => p.providerId);
2577
+ return { sections: [
2578
+ {
2579
+ id: "provider",
2580
+ title: "Provider",
2581
+ columns: 1,
2582
+ fields: [{
2583
+ type: "select",
2584
+ key: PROVIDER_FIELD,
2585
+ label: "Provider",
2586
+ required: true,
2587
+ options: providers.map((p) => ({
2588
+ value: p.providerId,
2589
+ label: p.displayName
2590
+ }))
2591
+ }]
2592
+ },
2593
+ ...createProviderSections(providers),
2594
+ stateSection(nodeLocal, true),
2595
+ protectionSection()
2596
+ ] };
2597
+ }
2598
+ const location = this.deps.locations().find((l) => l.id === id);
2599
+ if (location === void 0) throw new Error(`storage location '${id}' not found`);
2600
+ const provider = providers.find((p) => p.providerId === location.providerId);
2601
+ return { sections: [
2602
+ stateSection(provider?.nodeLocal === true ? [location.providerId] : []),
2603
+ ...provider === void 0 ? [] : providerSections(provider.configSchema),
2604
+ protectionSection()
2605
+ ] };
2606
+ };
2607
+ listInstances = async () => this.deps.locations().map((location) => this.viewOf(location));
2608
+ getInstance = async ({ id }) => {
2609
+ const location = this.deps.locations().find((l) => l.id === id);
2610
+ return location === void 0 ? null : this.viewOf(location);
2611
+ };
2612
+ /**
2613
+ * The config and credentials a form `values` object means for a provider: its own namespaced
2614
+ * keys (create form) or plain keys (edit form), the framework numbers, nothing of another
2615
+ * provider. `base` is the stored config; a credential kept stays as stored.
2616
+ */
2617
+ configFrom(providerId, values, base) {
2618
+ const config = { ...base };
2619
+ const clear = [];
2620
+ const prefix = `${providerId}.`;
2621
+ const secretKeys = this.deps.secretKeys(providerId, base);
2622
+ const named = [];
2623
+ for (const [raw, value] of Object.entries(values)) {
2624
+ if (raw === PROVIDER_FIELD || raw === MODE_FIELD || raw === NODE_FIELD) continue;
2625
+ if (raw.startsWith(prefix)) named.push([raw.slice(prefix.length), value]);
2626
+ else if (!raw.includes(".")) named.push([raw, value]);
2627
+ }
2628
+ for (const [key, value] of named) {
2629
+ if (value === void 0) continue;
2630
+ if (FRAMEWORK_NUMBER_KEYS.includes(key)) {
2631
+ const number = numberOrNull(value);
2632
+ if (number === null) delete config[key];
2633
+ else if (number !== void 0) config[key] = number;
2634
+ continue;
2635
+ }
2636
+ if (secretKeys.has(key)) {
2637
+ if (require_dist.isSecretClear(value)) clear.push(key);
2638
+ else if (keepsSecret(value)) continue;
2639
+ else if (typeof value === "string") config[key] = value;
2640
+ continue;
2641
+ }
2642
+ if (value === null || value === "") delete config[key];
2643
+ else config[key] = value;
2644
+ }
2645
+ return {
2646
+ config,
2647
+ clear
2648
+ };
2649
+ }
2650
+ async mintId(kind, name) {
2651
+ const taken = new Set(this.deps.locations().map((l) => l.id));
2652
+ const slug = name.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
2653
+ const base = `${kind}:${slug.length > 0 ? slug : "default"}`;
2654
+ if (!taken.has(base)) return base;
2655
+ for (let n = 2;; n += 1) {
2656
+ const candidate = `${base}-${n}`;
2657
+ if (!taken.has(candidate)) return candidate;
2658
+ }
2659
+ }
2660
+ createInstance = async ({ id, name, kind, values }) => {
2661
+ const form = values ?? {};
2662
+ const declared = this.deps.declarations();
2663
+ const type = kind ?? (declared.length === 1 ? declared[0]?.id : void 0);
2664
+ if (type === void 0) throw new Error("pick the kind of location first");
2665
+ if (!declared.some((d) => d.id === type)) throw new Error(`unknown location kind '${type}'`);
2666
+ const providerId = form[PROVIDER_FIELD];
2667
+ if (typeof providerId !== "string" || providerId === "") throw new Error("pick a provider");
2668
+ const minted = id ?? await this.mintId(type, name);
2669
+ const slug = minted.slice(type.length + 1);
2670
+ if (!minted.startsWith(`${type}:`) || !LOCATION_ID_SLUG.test(slug)) throw new Error(`id must be '${type}:<slug>' (lowercase letters, digits and hyphens)`);
2671
+ if (this.deps.locations().some((l) => l.id === minted)) throw new Error(`storage location '${minted}' already exists`);
2672
+ const { config, clear } = this.configFrom(providerId, form, {});
2673
+ const mode = form[MODE_FIELD];
2674
+ const node = form[NODE_FIELD];
2675
+ await this.deps.save({
2676
+ id: minted,
2677
+ type,
2678
+ displayName: name,
2679
+ providerId,
2680
+ config,
2681
+ isSystem: false,
2682
+ ...typeof node === "string" && node !== "" ? { nodeId: node } : {},
2683
+ ...isStorageMode(mode) ? { mode } : {}
2684
+ }, clear);
2685
+ return { id: minted };
2686
+ };
2687
+ /** The whole location again, from the stored row, with `patch` on top (the save REPLACES). */
2688
+ rebuilt(stored, patch) {
2689
+ const nodeId = patch.nodeId ?? stored.nodeId;
2690
+ return {
2691
+ id: stored.id,
2692
+ type: stored.type,
2693
+ displayName: patch.displayName ?? stored.displayName,
2694
+ providerId: stored.providerId,
2695
+ config: patch.config ?? stored.config,
2696
+ isSystem: stored.isSystem,
2697
+ ...nodeId !== void 0 ? { nodeId } : {},
2698
+ ...patch.mode !== void 0 ? { mode: patch.mode } : {}
2699
+ };
2700
+ }
2701
+ updateInstance = async ({ id, name, values }) => {
2702
+ const stored = this.deps.locations().find((l) => l.id === id);
2703
+ if (stored === void 0) throw new Error(`storage location '${id}' not found`);
2704
+ const { config, clear } = this.configFrom(stored.providerId, values, stored.config);
2705
+ const mode = values[MODE_FIELD];
2706
+ const node = values[NODE_FIELD];
2707
+ await this.deps.save(this.rebuilt(stored, {
2708
+ ...name !== void 0 ? { displayName: name } : {},
2709
+ config,
2710
+ ...isStorageMode(mode) ? { mode } : {},
2711
+ ...typeof node === "string" && node !== "" ? { nodeId: node } : {}
2712
+ }), clear);
2713
+ return { ok: true };
2714
+ };
2715
+ setInstanceEnabled = async ({ id, enabled }) => {
2716
+ const stored = this.deps.locations().find((l) => l.id === id);
2717
+ if (stored === void 0) throw new Error(`storage location '${id}' not found`);
2718
+ const move = require_dist.modeForSwitch(enabled, stateOf(stored));
2719
+ if (move.kind === "refuse") throw new Error(`storage location '${id}': ${move.reason}`);
2720
+ if (move.kind === "set") await this.deps.save(this.rebuilt(stored, { mode: move.mode }), []);
2721
+ return { ok: true };
2722
+ };
2723
+ /** The occupancy refusal stays; the forced delete is the separate action. */
2724
+ deleteInstance = async ({ id }) => {
2725
+ await this.deps.remove(id);
2726
+ return { ok: true };
2727
+ };
2728
+ testInstance = async ({ id, values }) => {
2729
+ const stored = id === null ? void 0 : this.deps.locations().find((l) => l.id === id);
2730
+ if (id !== null && stored === void 0) return {
2731
+ success: false,
2732
+ status: "inconclusive",
2733
+ error: `storage location '${id}' not found`
2734
+ };
2735
+ const formProvider = values[PROVIDER_FIELD];
2736
+ const providerId = stored?.providerId ?? (typeof formProvider === "string" ? formProvider : "");
2737
+ if (providerId === "") return {
2738
+ success: false,
2739
+ status: "inconclusive",
2740
+ error: "Pick a provider first"
2741
+ };
2742
+ const { config } = this.configFrom(providerId, values, stored?.config ?? {});
2743
+ const started = Date.now();
2744
+ const limit = this.deps.testTimeoutMs ?? 2e4;
2745
+ let timer;
2746
+ const timedOut = new Promise((resolve) => {
2747
+ timer = setTimeout(() => resolve({
2748
+ success: false,
2749
+ status: "inconclusive",
2750
+ error: `The provider did not answer within ${Math.round(limit / 1e3)} s`
2751
+ }), limit);
2752
+ });
2753
+ const probe = this.deps.probe(providerId, config).then((result) => result.ok ? {
2754
+ success: true,
2755
+ status: "validated",
2756
+ latencyMs: Date.now() - started
2757
+ } : {
2758
+ success: false,
2759
+ status: "rejected",
2760
+ error: result.error ?? "The provider refused this configuration"
2761
+ }).catch((err) => ({
2762
+ success: false,
2763
+ status: "inconclusive",
2764
+ error: err instanceof Error ? err.message : String(err)
2765
+ }));
2766
+ try {
2767
+ return await Promise.race([probe, timedOut]);
2768
+ } finally {
2769
+ if (timer !== void 0) clearTimeout(timer);
2770
+ }
2771
+ };
2772
+ toProvider() {
2773
+ return {
2774
+ describe: this.describe,
2775
+ instanceFormSchema: this.instanceFormSchema,
2776
+ listInstances: this.listInstances,
2777
+ getInstance: this.getInstance,
2778
+ createInstance: this.createInstance,
2779
+ updateInstance: this.updateInstance,
2780
+ setInstanceEnabled: this.setInstanceEnabled,
2781
+ deleteInstance: this.deleteInstance,
2782
+ testInstance: this.testInstance
2783
+ };
2784
+ }
2785
+ };
2786
+ //#endregion
2061
2787
  //#region src/builtins/storage-orchestrator/provider-discovery.ts
2062
2788
  async function collectProviderInfos(providers, onError) {
2063
2789
  const out = [];
@@ -3189,6 +3915,30 @@ var StorageOrchestratorService = class {
3189
3915
  } : { added };
3190
3916
  }
3191
3917
  /**
3918
+ * Re-read the `config` of every location the store holds and replace the in-memory one where it
3919
+ * differs. The credential migration moves a location's secrets into its record, which changes
3920
+ * the markers its config carries; the in-memory copy would otherwise keep pointing at keychain
3921
+ * values the migration released. Only `config` is taken: the rest of a location is what this
3922
+ * process already decided. Returns the ids refreshed.
3923
+ */
3924
+ async refreshConfigsFromStore() {
3925
+ const store = this.locationStore;
3926
+ if (store === null) return [];
3927
+ const rows = await store.loadAll();
3928
+ const refreshed = [];
3929
+ for (const row of rows) {
3930
+ const live = this.locations.get(row.id);
3931
+ if (live === void 0) continue;
3932
+ if (JSON.stringify(live.config) === JSON.stringify(row.config)) continue;
3933
+ this.locations.set(row.id, {
3934
+ ...live,
3935
+ config: row.config
3936
+ });
3937
+ refreshed.push(row.id);
3938
+ }
3939
+ return refreshed;
3940
+ }
3941
+ /**
3192
3942
  * Re-create the default of a type whose seed marker survived the loss of every
3193
3943
  * row (the 2026-11-01 prune: it deleted the rows and, until D1006, left the
3194
3944
  * marker). That state cannot be an operator action — the service refuses to
@@ -3885,6 +4635,8 @@ var STORAGE_OCCUPANCY_CAP_NAME = "storage-occupancy";
3885
4635
  * before `nodeId` existed.
3886
4636
  */
3887
4637
  var HUB_NODE_ID = "hub";
4638
+ /** How long a save waits for its credential to reach the record before it answers anyway. */
4639
+ var SECRET_PERSIST_WAIT_MS = 5e3;
3888
4640
  /** How often the pressure manager re-evaluates free space per location. */
3889
4641
  var PRESSURE_SWEEP_INTERVAL_MS = 6e4;
3890
4642
  /**
@@ -3947,6 +4699,8 @@ var StorageOrchestratorAddon = class extends require_dist.BaseAddon {
3947
4699
  * is readable through a provider the orchestrator can otherwise use.
3948
4700
  */
3949
4701
  secretKeysByProvider = /* @__PURE__ */ new Map();
4702
+ /** Credentials of a save on their way to the location's record (`LocationSecretStaging`). */
4703
+ secretStaging = new LocationSecretStaging();
3950
4704
  /**
3951
4705
  * Disposers run on `onShutdown` — currently the eventBus subscription
3952
4706
  * for `capability:provider-registered` events used by the lazy seed
@@ -3998,67 +4752,6 @@ var StorageOrchestratorAddon = class extends require_dist.BaseAddon {
3998
4752
  },
3999
4753
  listLocationDeclarations: async () => service.listDeclarations(),
4000
4754
  listDrainProgress: async () => this.drainProgress(),
4001
- upsertLocation: async (input) => {
4002
- const stored = service.getLocationById(input.id);
4003
- const config = restoreRedactedSecrets(input.config, stored?.config, this.secretKeysFor(input.providerId, stored?.config ?? {}));
4004
- const keychained = await this.keepSecretsInKeychain(input.id, input.providerId, config, stored?.config ?? {});
4005
- const next = keychained === input.config ? input : {
4006
- ...input,
4007
- config: keychained
4008
- };
4009
- const saved = await this.upsertCarryingData(stored, next, () => service.upsertLocation(next));
4010
- this.announceLocationsChanged(saved.id, saved.type, "upsert");
4011
- return this.redacted(saved);
4012
- },
4013
- deleteLocation: async ({ id, force }) => {
4014
- const doomed = service.getLocationById(id);
4015
- await service.deleteLocation(id, { force: force === true });
4016
- this.announceLocationsChanged(id, doomed?.type ?? "", "delete");
4017
- },
4018
- testLocation: async ({ id }) => {
4019
- const loc = service.getLocationById(id);
4020
- if (!loc) return {
4021
- ok: false,
4022
- error: `Location "${id}" not found`
4023
- };
4024
- try {
4025
- const p = await service.getProviderFor(loc);
4026
- const live = await this.withResolvedSecrets(loc);
4027
- return p.testLocation({ config: live.config });
4028
- } catch (err) {
4029
- return {
4030
- ok: false,
4031
- error: err instanceof Error ? err.message : String(err)
4032
- };
4033
- }
4034
- },
4035
- listProviders: async () => {
4036
- return collectProviderInfos(getProviders(), (_provider, err, index) => {
4037
- this.ctx.logger.warn("storage-orchestrator: getProviderInfo failed", { meta: {
4038
- providerIndex: index,
4039
- error: err instanceof Error ? err.message : String(err)
4040
- } });
4041
- });
4042
- },
4043
- testConfig: async ({ providerId, locationId, config }) => {
4044
- const stored = locationId === void 0 ? void 0 : service.getLocationById(locationId);
4045
- const base = stored?.providerId === providerId ? stored.config : void 0;
4046
- const resolved = restoreRedactedSecrets(config, base, this.secretKeysFor(providerId, base ?? {}));
4047
- const providers = getProviders();
4048
- for (const p of providers) try {
4049
- if ((await p.getProviderInfo()).providerId !== providerId) continue;
4050
- return p.testLocation({ config: resolved });
4051
- } catch (err) {
4052
- return {
4053
- ok: false,
4054
- error: err instanceof Error ? err.message : String(err)
4055
- };
4056
- }
4057
- return {
4058
- ok: false,
4059
- error: `No storage-provider registered for providerId "${providerId}"`
4060
- };
4061
- },
4062
4755
  resolve: async ({ location, relativePath }) => {
4063
4756
  const loc = await this.withResolvedSecrets(service.resolveRef(location));
4064
4757
  this.refuseRemoteResolve(loc);
@@ -4350,20 +5043,65 @@ var StorageOrchestratorAddon = class extends require_dist.BaseAddon {
4350
5043
  this.recordLocationHistory();
4351
5044
  }, PRESSURE_SWEEP_INTERVAL_MS);
4352
5045
  this.ctx.logger.info("Storage orchestrator initialized");
4353
- return [
4354
- {
4355
- capability: require_dist.storageCapability,
4356
- provider
4357
- },
4358
- {
4359
- capability: require_dist.storageMigrationCapability,
4360
- provider: migrationProvider
5046
+ const instances = this.locationsKind === null ? null : new StorageLocationInstances({
5047
+ locations: () => service.listLocations(),
5048
+ declarations: () => service.listDeclarations(),
5049
+ providers: () => collectProviderInfos(getProviders(), (_provider, err, index) => {
5050
+ this.ctx.logger.warn("storage-orchestrator: getProviderInfo failed", { meta: {
5051
+ providerIndex: index,
5052
+ error: err instanceof Error ? err.message : String(err)
5053
+ } });
5054
+ }),
5055
+ save: async (input, clear) => this.redacted(await this.saveLocation(input, clear)),
5056
+ remove: (id) => this.removeLocation(id, false),
5057
+ probe: async (providerId, config) => {
5058
+ const live = await this.resolvedConfig(`probe:${providerId}`, config);
5059
+ const match = (await Promise.all(getProviders().map(async (p) => ({
5060
+ p,
5061
+ info: await p.getProviderInfo()
5062
+ })))).find((entry) => entry.info.providerId === providerId);
5063
+ if (match === void 0) return {
5064
+ ok: false,
5065
+ error: `No storage-provider registered for providerId "${providerId}"`
5066
+ };
5067
+ return match.p.testLocation({ config: live });
4361
5068
  },
4362
- {
4363
- capability: require_dist.settingsStoreCapability,
4364
- provider: createDataStoreDispatch(getEngines, () => this.hubSettingsForward())
4365
- }
4366
- ];
5069
+ secretKeys: (providerId, config) => this.secretKeysFor(providerId, config)
5070
+ });
5071
+ return {
5072
+ providers: [
5073
+ {
5074
+ capability: require_dist.storageCapability,
5075
+ provider
5076
+ },
5077
+ {
5078
+ capability: require_dist.storageMigrationCapability,
5079
+ provider: migrationProvider
5080
+ },
5081
+ {
5082
+ capability: require_dist.settingsStoreCapability,
5083
+ provider: createDataStoreDispatch(getEngines, () => this.hubSettingsForward())
5084
+ },
5085
+ ...instances === null ? [] : [{
5086
+ capability: require_dist.integrationInstancesCapability,
5087
+ provider: instances.toProvider()
5088
+ }]
5089
+ ],
5090
+ customActions: storageOrchestratorActions,
5091
+ actionHandlers: { forceDeleteLocation: async (input) => {
5092
+ const { id } = forceDeleteLocationInput.parse(input);
5093
+ await this.removeLocation(id, true);
5094
+ return { ok: true };
5095
+ } }
5096
+ };
5097
+ }
5098
+ /** Delete a location; the occupancy refusal stands unless `force` was stated. */
5099
+ async removeLocation(id, force) {
5100
+ const service = this.service;
5101
+ if (service === null) throw new Error("storage-orchestrator is not initialised");
5102
+ const doomed = service.getLocationById(id);
5103
+ await service.deleteLocation(id, { force });
5104
+ this.announceLocationsChanged(id, doomed?.type ?? "", "delete");
4367
5105
  }
4368
5106
  /**
4369
5107
  * The remote behind the data door on a node that owns no engine.
@@ -4435,7 +5173,7 @@ var StorageOrchestratorAddon = class extends require_dist.BaseAddon {
4435
5173
  return null;
4436
5174
  }
4437
5175
  if (this.locationsKind === null || this.seedMarkersKind === null) return null;
4438
- return new SqliteLocationStore(this.locationsKind, this.seedMarkersKind);
5176
+ return new SqliteLocationStore(this.locationsKind, this.seedMarkersKind, this.secretStaging);
4439
5177
  }
4440
5178
  /**
4441
5179
  * Late-wire the persistence store once a `data-store-provider` engine
@@ -4745,55 +5483,99 @@ var StorageOrchestratorAddon = class extends require_dist.BaseAddon {
4745
5483
  * ref; the provider then fails its own connection, by name.
4746
5484
  */
4747
5485
  async withResolvedSecrets(location) {
5486
+ const config = await this.resolvedConfig(location.id, location.config);
5487
+ return config === location.config ? location : {
5488
+ ...location,
5489
+ config
5490
+ };
5491
+ }
5492
+ /** `config` with every keychain marker resolved; the same object when it holds none. */
5493
+ async resolvedConfig(locationId, config) {
4748
5494
  const secrets = this.ctx.secrets;
4749
- if (secrets === void 0) return location;
4750
- const { value, unresolved } = await require_dist.resolveSecretMarkers(location.config, secrets);
5495
+ if (secrets === void 0) return config;
5496
+ const { value, unresolved } = await require_dist.resolveSecretMarkers(config, secrets);
4751
5497
  if (unresolved.length > 0) this.ctx.logger.error("storage location secret unavailable", { meta: {
4752
- locationId: location.id,
5498
+ locationId,
4753
5499
  secrets: unresolved.map((u) => ({
4754
5500
  ref: u.ref,
4755
5501
  reason: u.reason
4756
5502
  }))
4757
5503
  } });
4758
- return value === location.config ? location : {
4759
- ...location,
4760
- config: value
5504
+ return value;
5505
+ }
5506
+ /**
5507
+ * Save one location the way every door does (the legacy `upsertLocation` and the instance
5508
+ * provider): the sentinel travelling back in means "keep the stored secret", the provider's
5509
+ * declared credentials are staged for the location's own record (D787, never the row's
5510
+ * `config`), a SINGLETON that changes root carries its bytes, and the change is announced.
5511
+ * Returns the saved location with its markers; the callers redact it.
5512
+ */
5513
+ async saveLocation(input, clearSecrets = []) {
5514
+ const service = this.service;
5515
+ if (service === null) throw new Error("storage-orchestrator is not initialised");
5516
+ const stored = service.getLocationById(input.id);
5517
+ const restored = restoreRedactedSecrets(input.config, stored?.config, this.secretKeysFor(input.providerId, stored?.config ?? {}));
5518
+ const prepared = this.prepareLocationSecrets(input.id, input.providerId, restored, stored?.config ?? {}, clearSecrets);
5519
+ const next = prepared.config === input.config ? input : {
5520
+ ...input,
5521
+ config: prepared.config
4761
5522
  };
5523
+ this.secretStaging.stage(input.id, prepared.staged);
5524
+ try {
5525
+ const saved = await this.upsertCarryingData(stored, next, () => service.upsertLocation(next));
5526
+ await this.persistedWithin(input.id);
5527
+ this.announceLocationsChanged(saved.id, saved.type, "upsert");
5528
+ return saved;
5529
+ } catch (err) {
5530
+ this.secretStaging.discard(input.id);
5531
+ throw err;
5532
+ }
5533
+ }
5534
+ /** The record write of a save that staged a credential is awaited, bounded: a hung store must not hang the save. */
5535
+ async persistedWithin(id) {
5536
+ let timer;
5537
+ const bound = new Promise((resolve) => {
5538
+ timer = setTimeout(resolve, SECRET_PERSIST_WAIT_MS);
5539
+ });
5540
+ try {
5541
+ await Promise.race([this.secretStaging.settled(id), bound]);
5542
+ } finally {
5543
+ if (timer !== void 0) clearTimeout(timer);
5544
+ }
4762
5545
  }
4763
5546
  /**
4764
- * Strip the provider's DECLARED secrets (its form schema, by type) out of a
4765
- * location config into the keychain, under `row/storage_locations/<id>`.
4766
- * A provider that has not registered declares nothing: only keys that
4767
- * already hold a marker are handled then — a new plaintext is never guessed
4768
- * at, it stays as sent until the provider is back and the location is saved.
5547
+ * Split the credentials of an incoming config from the rest (D787). A declared secret key with a
5548
+ * new value is STAGED (the records door stores it with the row) and the location carries the
5549
+ * marker of its own record; a key that is absent, empty or already a marker keeps what is stored;
5550
+ * `clear` removes it. A provider that has not registered declares nothing: a new plaintext is
5551
+ * never guessed at, it stays as sent until the provider is back and the location is saved.
4769
5552
  */
4770
- async keepSecretsInKeychain(locationId, providerId, config, stored) {
4771
- const secrets = this.ctx.secrets;
4772
- if (secrets === void 0) return config;
5553
+ prepareLocationSecrets(locationId, providerId, config, stored, clear) {
5554
+ if (this.ctx.secrets === void 0) return {
5555
+ config,
5556
+ staged: {}
5557
+ };
4773
5558
  const declared = this.declaredSecretKeys(providerId) ?? /* @__PURE__ */ new Set();
4774
- const markerKeys = Object.entries(stored).filter(([, v]) => require_dist.isSecretMarker(v)).map(([k]) => k);
4775
- const tree = require_dist.secretTreeFromPaths([...new Set([...declared, ...markerKeys])]);
4776
- if (tree.size === 0) return config;
4777
- const result = await require_dist.transformSecretWrite({
4778
- tree,
4779
- secrets,
4780
- patch: { ...config },
4781
- stored: { ...stored },
4782
- scope: {
4783
- kind: "row",
4784
- collection: STORAGE_LOCATIONS_SECRET_SCOPE,
4785
- rowId: locationId
5559
+ const out = { ...config };
5560
+ const staged = {};
5561
+ for (const key of new Set([...declared, ...clear])) {
5562
+ if (clear.includes(key)) {
5563
+ delete out[key];
5564
+ staged[key] = null;
5565
+ continue;
4786
5566
  }
4787
- });
4788
- const merged = { ...result.patch };
4789
- for (const key of tree.keys()) if (!(key in merged) && key in stored) merged[key] = stored[key];
4790
- result.afterWrite().then(({ orphaned }) => {
4791
- if (orphaned.length > 0) this.ctx.logger.warn("storage location: dropped keychain refs could not be deleted", { meta: {
4792
- locationId,
4793
- refs: [...orphaned]
4794
- } });
4795
- });
4796
- return merged;
5567
+ const value = out[key];
5568
+ if (typeof value === "string" && value.length > 0) {
5569
+ staged[key] = value;
5570
+ out[key] = locationSecretMarker(locationId, key);
5571
+ } else if (value === void 0 || value === "") if (require_dist.isSecretMarker(stored[key])) out[key] = stored[key];
5572
+ else delete out[key];
5573
+ }
5574
+ for (const [key, value] of Object.entries(stored)) if (require_dist.isSecretMarker(value) && !(key in out) && !clear.includes(key)) out[key] = value;
5575
+ return {
5576
+ config: Object.keys(staged).length > 0 || Object.keys(out).length !== Object.keys(config).length || Object.entries(out).some(([key, value]) => config[key] !== value) ? out : config,
5577
+ staged
5578
+ };
4797
5579
  }
4798
5580
  redacted(location) {
4799
5581
  return redactLocation(location, this.secretKeysFor(location.providerId, location.config));
@@ -5022,6 +5804,7 @@ var StorageOrchestratorAddon = class extends require_dist.BaseAddon {
5022
5804
  */
5023
5805
  async seedFromDeclarations() {
5024
5806
  if (!this.service) return;
5807
+ await this.moveLocationSecrets();
5025
5808
  await this.refreshNodeLocalCache();
5026
5809
  const declarers = this.ctx.kernel.listStorageLocationDeclarers?.();
5027
5810
  const perAddon = declarers !== void 0 ? declarers.filter((d) => d.loaded).map((d) => d.declarations) : this.ctx.kernel.listStorageLocationDeclarations?.() ?? [];
@@ -5059,7 +5842,7 @@ var StorageOrchestratorAddon = class extends require_dist.BaseAddon {
5059
5842
  if (!this.seedAnswered || !service.locationsAuthoritative()) return;
5060
5843
  this.reseedRepairRunning = true;
5061
5844
  try {
5062
- await this.runMigrations(require_dist.defineAddonMigrations(ADDON_MIGRATIONS, { reseed: () => service.reseedPrunedDefaults(seedInput) }));
5845
+ await this.runMigrations(require_dist.defineAddonMigrations(ADDON_MIGRATIONS, this.cataloguePorts(service, seedInput)), { only: [RESEED_PRUNED_DEFAULTS_ID] });
5063
5846
  this.reseedRepairDone = true;
5064
5847
  } catch (err) {
5065
5848
  this.ctx.logger.warn("storage-orchestrator: the pruned-default repair did not run", { meta: { error: err instanceof Error ? err.message : String(err) } });
@@ -5068,6 +5851,45 @@ var StorageOrchestratorAddon = class extends require_dist.BaseAddon {
5068
5851
  }
5069
5852
  }
5070
5853
  /**
5854
+ * Every port of the catalogue, bound once. The reseed port only answers inside the seed pass
5855
+ * (it needs the declarations); the credential ports need the hub's records and keychain, so
5856
+ * a node without them runs neither step.
5857
+ */
5858
+ cataloguePorts(service, seedInput) {
5859
+ const locations = this.locationsKind;
5860
+ const secrets = this.ctx.secrets;
5861
+ if (locations === null || secrets === void 0) throw new Error("storage-orchestrator: the credential move needs the records and the keychain");
5862
+ return {
5863
+ reseed: () => seedInput === null ? [] : service.reseedPrunedDefaults(seedInput),
5864
+ ...locationSecretPortsOver({
5865
+ locations,
5866
+ secrets,
5867
+ refreshLocations: () => service.refreshConfigsFromStore()
5868
+ })
5869
+ };
5870
+ }
5871
+ secretsMoveDone = false;
5872
+ secretsMoveRunning = false;
5873
+ /**
5874
+ * D987: move the credentials of every location from the per-row keychain refs into the
5875
+ * location's own record. Runs once the persisted rows are loaded; a refusal (keychain locked,
5876
+ * a value gone) leaves every row as it was and the next seed pass asks again.
5877
+ */
5878
+ async moveLocationSecrets() {
5879
+ const service = this.service;
5880
+ if (!service || this.secretsMoveDone || this.secretsMoveRunning) return;
5881
+ if (!service.hasStore() || this.locationsKind === null || this.ctx.secrets === void 0) return;
5882
+ this.secretsMoveRunning = true;
5883
+ try {
5884
+ await this.runMigrations(require_dist.defineAddonMigrations(ADDON_MIGRATIONS, this.cataloguePorts(service, null)), { only: [LOCATION_SECRETS_TO_RECORD_ID] });
5885
+ this.secretsMoveDone = true;
5886
+ } catch (err) {
5887
+ this.ctx.logger.error("storage-orchestrator: the location credentials were NOT moved to their records; they stay where they were", { meta: { error: err instanceof Error ? err.message : String(err) } });
5888
+ } finally {
5889
+ this.secretsMoveRunning = false;
5890
+ }
5891
+ }
5892
+ /**
5071
5893
  * Alert when a declared type has nowhere to write. Runs after every seed pass
5072
5894
  * and every change to the set of locations; a no-op until a pass has an
5073
5895
  * answered state AND the kernel could list its declarers (D315).
@@ -5145,5 +5967,6 @@ exports.default = StorageOrchestratorAddon;
5145
5967
  exports.StorageOrchestratorService = StorageOrchestratorService;
5146
5968
  exports.buildStorageLocationRegistry = buildStorageLocationRegistry;
5147
5969
  exports.createHubCapForwardService = createHubCapForwardService;
5970
+ exports.storageOrchestratorActions = storageOrchestratorActions;
5148
5971
  exports.storageOrchestratorRecordKinds = storageOrchestratorRecordKinds;
5149
5972
  exports.stripForwardedCaller = stripForwardedCaller;