@camstack/server 1.2.778 → 1.2.780

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 (114) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/agent/main.js +5 -1
  3. package/dist/agent/stale-addon-gate.js +52 -15
  4. package/dist/api/addon-upload.js +41 -0
  5. package/dist/api/core/cap-providers.js +19 -29
  6. package/dist/api/core/integration-role.js +15 -2
  7. package/dist/api/tarball-manifest.js +10 -1
  8. package/dist/api/trpc/generated-cap-mounts.js +1 -9
  9. package/dist/api/trpc/generated-cap-routers.js +9 -88
  10. package/dist/core/addon/addon-package.service.js +24 -8
  11. package/dist/core/addon/addon-registry.service.js +61 -10
  12. package/dist/core/addon/hub-spawn-gate.js +92 -0
  13. package/dist/core/addon/integration-instances-provider.js +22 -0
  14. package/dist/core/agent/agent-registry.service.js +6 -2
  15. package/dist/core/agent/delivery-requirements.js +22 -6
  16. package/dist/core/updates/required-addon-update.js +188 -0
  17. package/dist/launcher.js +4 -0
  18. package/dist/manual-boot.js +27 -0
  19. package/dist/server-root/index.js +74 -3
  20. package/package.json +33 -11
  21. package/system/dist/addon-runner.js +179 -4
  22. package/system/dist/addon-runner.mjs +180 -5
  23. package/system/dist/{agent-https-DnEHxqTM.js → agent-https-A9wsxVGn.js} +1 -1
  24. package/system/dist/{agent-https-DjiLJBkD.mjs → agent-https-DuxDC67S.mjs} +1 -1
  25. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  26. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  27. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  28. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  29. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  30. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  31. package/system/dist/builtins/autotrack/index.js +1 -1
  32. package/system/dist/builtins/autotrack/index.mjs +1 -1
  33. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  34. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  35. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  36. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  37. package/system/dist/builtins/camera-grid/index.js +1 -1
  38. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  39. package/system/dist/builtins/composer/composer.addon.js +3 -3
  40. package/system/dist/builtins/composer/composer.addon.mjs +3 -3
  41. package/system/dist/builtins/console-logging/index.js +1 -1
  42. package/system/dist/builtins/console-logging/index.mjs +1 -1
  43. package/system/dist/builtins/core-blocks/core-blocks.addon.js +3 -3
  44. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +3 -3
  45. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  46. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  47. package/system/dist/builtins/device-manager/device-manager.addon.js +6 -3
  48. package/system/dist/builtins/device-manager/device-manager.addon.mjs +6 -3
  49. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  50. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  51. package/system/dist/builtins/keychain/index.js +4 -4
  52. package/system/dist/builtins/keychain/index.mjs +4 -4
  53. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  54. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  55. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  56. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  57. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  58. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  59. package/system/dist/builtins/loki-logging/index.js +1 -1
  60. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  61. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  62. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  63. package/system/dist/builtins/platform-probe/index.js +1 -1
  64. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  65. package/system/dist/builtins/record-entries/index.js +1 -1
  66. package/system/dist/builtins/record-entries/index.mjs +1 -1
  67. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  68. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  69. package/system/dist/builtins/snapshot/index.js +1 -1
  70. package/system/dist/builtins/snapshot/index.mjs +1 -1
  71. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  72. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  73. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  74. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  75. package/system/dist/builtins/sqlite-storage/migrations/installed-runner-resolver.d.ts +7 -0
  76. package/system/dist/builtins/sqlite-storage/migrations/migrations-provider.d.ts +10 -3
  77. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +38 -9
  78. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +38 -9
  79. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  80. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  81. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  82. package/system/dist/builtins/system-config/system-config.addon.mjs +3 -3
  83. package/system/dist/builtins/winston-logging/index.js +1 -1
  84. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  85. package/system/dist/{capture-engine-dY1enbrF.mjs → capture-engine-CEChNpAD.mjs} +1 -1
  86. package/system/dist/{capture-engine-DW3Tts4M.js → capture-engine-D6mXfLFQ.js} +1 -1
  87. package/system/dist/{composition-sources-Ckz1nky_.mjs → composition-sources-6XYW86Kw.mjs} +1 -1
  88. package/system/dist/{composition-sources-Y_vIrdLy.js → composition-sources-cVWKVph4.js} +1 -1
  89. package/system/dist/{constants-Bbu5TQF_.js → constants-B5Yg02ii.js} +1 -1
  90. package/system/dist/{constants-9sQvihXt.mjs → constants-DqwDEYfb.mjs} +1 -1
  91. package/system/dist/{device-ca-CbuTkPXx.js → device-ca-BVz14dRd.js} +1 -1
  92. package/system/dist/{device-ca-2dQqY2z0.mjs → device-ca-oY4Xqd7s.mjs} +1 -1
  93. package/system/dist/{dist-D3StiAs2.js → dist-B4wrqheM.js} +850 -635
  94. package/system/dist/{dist-CV4RPML4.mjs → dist-BX8nZeXV.mjs} +821 -636
  95. package/system/dist/file-host-worker.js +1 -1
  96. package/system/dist/file-host-worker.mjs +1 -1
  97. package/system/dist/{hub-mdns-ciao-BlxgXzRs.mjs → hub-mdns-ciao-BDPMfOgq.mjs} +2 -2
  98. package/system/dist/{hub-mdns-ciao-BJaeVvId.js → hub-mdns-ciao-CiMMA0rT.js} +2 -2
  99. package/system/dist/index.js +418 -16
  100. package/system/dist/index.mjs +413 -18
  101. package/system/dist/kernel/addon-installer.d.ts +44 -1
  102. package/system/dist/kernel/held-installs.d.ts +21 -0
  103. package/system/dist/kernel/index.d.ts +6 -0
  104. package/system/dist/kernel/moleculer/migration-api-facade.d.ts +73 -0
  105. package/system/dist/kernel/requires-registry.d.ts +31 -0
  106. package/system/dist/kernel/transport/acting-addon.d.ts +1 -1
  107. package/system/dist/{legacy-integration-rows-door-CUeUZHro.mjs → legacy-integration-rows-door-DDA3YOxL.mjs} +1 -1
  108. package/system/dist/{legacy-integration-rows-door-BqtcbHNX.js → legacy-integration-rows-door-YuWqHZW4.js} +1 -1
  109. package/system/dist/migrations/hub/__fixtures__/seed.d.ts +23 -0
  110. package/system/dist/{restore-archive-C4r-C6Hj.mjs → restore-archive-BrtpgNCt.mjs} +1 -1
  111. package/system/dist/{restore-archive-DM-QSOiY.js → restore-archive-Cn9OShm4.js} +1 -1
  112. package/system/dist/{wal-maintenance-1dP8IFlA.js → wal-maintenance-BTzu3s-6.js} +0 -0
  113. package/system/dist/{wal-maintenance-sPn0MLRB.mjs → wal-maintenance-jgyV9NbL.mjs} +0 -0
  114. package/system/package.json +1 -1
@@ -84,6 +84,7 @@ var require_dist = __commonJS({
84
84
  ELECTRON_APP_VERSION_ENV: /* @__PURE__ */ __name(() => ELECTRON_APP_VERSION_ENV, "ELECTRON_APP_VERSION_ENV"),
85
85
  HOST_EXTERNAL_SPECIFIERS: /* @__PURE__ */ __name(() => HOST_EXTERNAL_SPECIFIERS, "HOST_EXTERNAL_SPECIFIERS"),
86
86
  HUB_ROOT_SPEC: /* @__PURE__ */ __name(() => HUB_ROOT_SPEC2, "HUB_ROOT_SPEC"),
87
+ LAST_BOOTED_FILE: /* @__PURE__ */ __name(() => LAST_BOOTED_FILE, "LAST_BOOTED_FILE"),
87
88
  PENDING_ROOT_SWAP_FILE: /* @__PURE__ */ __name(() => PENDING_ROOT_SWAP_FILE, "PENDING_ROOT_SWAP_FILE"),
88
89
  REQUIRED_NATIVE_PACKAGES: /* @__PURE__ */ __name(() => REQUIRED_NATIVE_PACKAGES, "REQUIRED_NATIVE_PACKAGES"),
89
90
  RESTART_INTENT_FILE: /* @__PURE__ */ __name(() => RESTART_INTENT_FILE, "RESTART_INTENT_FILE"),
@@ -127,6 +128,7 @@ var require_dist = __commonJS({
127
128
  planBoot: /* @__PURE__ */ __name(() => planBoot, "planBoot"),
128
129
  readDesktopAppState: /* @__PURE__ */ __name(() => readDesktopAppState, "readDesktopAppState"),
129
130
  readDevUploadManifest: /* @__PURE__ */ __name(() => readDevUploadManifest, "readDevUploadManifest"),
131
+ readLastBooted: /* @__PURE__ */ __name(() => readLastBooted, "readLastBooted"),
130
132
  readPendingRootSwap: /* @__PURE__ */ __name(() => readPendingRootSwap, "readPendingRootSwap"),
131
133
  readRestartIntentMarker: /* @__PURE__ */ __name(() => readRestartIntentMarker, "readRestartIntentMarker"),
132
134
  readServerRootState: /* @__PURE__ */ __name(() => readServerRootState, "readServerRootState"),
@@ -1107,7 +1109,7 @@ var require_dist = __commonJS({
1107
1109
  try {
1108
1110
  const raw = JSON.parse(fs6.readFileSync(path6.join(rootPackageDir2(closureDir, spec), "package.json"), "utf-8"));
1109
1111
  if (typeof raw === "object" && raw !== null) {
1110
- const version = raw["version"];
1112
+ const version = Reflect.get(raw, "version");
1111
1113
  if (typeof version === "string") return version;
1112
1114
  }
1113
1115
  } catch {
@@ -1115,6 +1117,54 @@ var require_dist = __commonJS({
1115
1117
  return null;
1116
1118
  }
1117
1119
  __name(readClosureVersion2, "readClosureVersion2");
1120
+ var LAST_BOOTED_FILE = "last-booted.json";
1121
+ function readLastBooted(rootDir) {
1122
+ try {
1123
+ const raw = JSON.parse(fs6.readFileSync(path6.join(rootDir, LAST_BOOTED_FILE), "utf-8"));
1124
+ if (typeof raw === "object" && raw !== null) {
1125
+ const version = raw["version"];
1126
+ if (typeof version === "string") return version;
1127
+ }
1128
+ } catch {
1129
+ }
1130
+ return null;
1131
+ }
1132
+ __name(readLastBooted, "readLastBooted");
1133
+ function recordLastBooted(rootDir, version) {
1134
+ const previous = readLastBooted(rootDir);
1135
+ if (previous !== null && compareSemver(previous, version) >= 0) return;
1136
+ try {
1137
+ const target = path6.join(rootDir, LAST_BOOTED_FILE);
1138
+ const tmp = `${target}.tmp`;
1139
+ fs6.mkdirSync(rootDir, {
1140
+ recursive: true
1141
+ });
1142
+ fs6.writeFileSync(tmp, JSON.stringify({
1143
+ version
1144
+ }), "utf-8");
1145
+ fs6.renameSync(tmp, target);
1146
+ } catch (err) {
1147
+ console.warn(`[starter] could not record the booted version: ${String(err)}`);
1148
+ }
1149
+ }
1150
+ __name(recordLastBooted, "recordLastBooted");
1151
+ function readSeedVersion(seedEntry, spec) {
1152
+ let dir = path6.dirname(seedEntry);
1153
+ for (let i = 0; i < 5; i++) {
1154
+ try {
1155
+ const raw = JSON.parse(fs6.readFileSync(path6.join(dir, "package.json"), "utf-8"));
1156
+ if (typeof raw === "object" && raw !== null) {
1157
+ const name = Reflect.get(raw, "name");
1158
+ const version = Reflect.get(raw, "version");
1159
+ if (name === spec.packageName && typeof version === "string") return version;
1160
+ }
1161
+ } catch {
1162
+ }
1163
+ dir = path6.dirname(dir);
1164
+ }
1165
+ return null;
1166
+ }
1167
+ __name(readSeedVersion, "readSeedVersion");
1118
1168
  function dropEmptyTimeZone(env) {
1119
1169
  if (env["TZ"] === "") delete env["TZ"];
1120
1170
  }
@@ -1150,14 +1200,35 @@ var require_dist = __commonJS({
1150
1200
  if (invalid !== null && fs6.existsSync(activeRootDir)) {
1151
1201
  console.warn(`[starter] single copy invalid: ${invalid}`);
1152
1202
  }
1153
- const plan = planBoot(invalid === null);
1203
+ const activeVersion = invalid === null ? readClosureVersion2(activeRootDir, options.spec) : null;
1204
+ const outOfRange = invalid === null && (activeVersion === null || compareSemver(activeVersion, STARTER_HOSTS_SERVER_MIN) < 0);
1205
+ if (outOfRange) {
1206
+ console.warn(`[starter] single copy ${activeVersion ?? "with an unreadable version"} is below the ${STARTER_HOSTS_SERVER_MIN} this starter hosts \u2014 booting the baked seed; update the app or the container image`);
1207
+ }
1208
+ const plan = outOfRange ? {
1209
+ kind: "baked",
1210
+ reason: "the single copy is outside the range this starter hosts"
1211
+ } : planBoot(invalid === null);
1212
+ if (plan.kind === "baked") {
1213
+ const lastBooted = readLastBooted(rootDir);
1214
+ const seedVersion = readSeedVersion(options.seedEntry, options.spec);
1215
+ if (lastBooted !== null && (seedVersion === null || compareSemver(seedVersion, lastBooted) < 0)) {
1216
+ const copyState = !fs6.existsSync(activeRootDir) ? "absent" : invalid !== null ? `invalid (${invalid})` : activeVersion ?? "unreadable";
1217
+ const message = `[starter] REFUSING to boot the baked seed ${seedVersion ?? "(version unknown)"}: this data root last ran ${lastBooted} and the single copy on disk is ${copyState}. Restore the ${lastBooted} closure, or update the app / container image to ${lastBooted} or newer. ${options.envNames.killSwitch}=off boots the baked seed anyway.`;
1218
+ console.error(message);
1219
+ throw new Error(message);
1220
+ }
1221
+ }
1154
1222
  if (plan.kind === "current") {
1155
1223
  const version = readClosureVersion2(activeRootDir, options.spec);
1156
1224
  const entry = currentEntryPath(rootDir, options.spec);
1157
1225
  console.log(`[starter] booting ${options.spec.packageName}@${version ?? "?"} from ${activeRootDir}`);
1158
1226
  env[options.envNames.bootMode] = "data-root";
1159
1227
  env[options.envNames.activeRoot] = activeRootDir;
1160
- if (version !== null) env[options.envNames.activeVersion] = version;
1228
+ if (version !== null) {
1229
+ env[options.envNames.activeVersion] = version;
1230
+ recordLastBooted(rootDir, version);
1231
+ }
1161
1232
  registerResolver(activeRootDir);
1162
1233
  options.loadEntry(entry);
1163
1234
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/server",
3
- "version": "1.2.778",
3
+ "version": "1.2.780",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -66,11 +66,33 @@
66
66
  ],
67
67
  "requires": {
68
68
  "addons": {
69
- "@camstack/addon-admin-ui": ">=1.2.593",
70
- "@camstack/addon-agent-ui": ">=1.2.329",
71
- "@camstack/addon-post-analysis": ">=1.2.670",
72
- "@camstack/addon-provider-bosch": ">=0.1.38",
73
- "@camstack/addon-provider-esphome": ">=0.1.13"
69
+ "@camstack/addon-admin-ui": ">=1.2.595",
70
+ "@camstack/addon-agent-ui": ">=1.2.330",
71
+ "@camstack/addon-google-services": ">=0.2.39",
72
+ "@camstack/addon-import-alexa": ">=0.2.190",
73
+ "@camstack/addon-matter-broker": ">=0.2.160",
74
+ "@camstack/addon-mqtt-broker": ">=1.2.152",
75
+ "@camstack/addon-post-analysis": ">=1.2.671",
76
+ "@camstack/addon-provider-amcrest": ">=0.2.167",
77
+ "@camstack/addon-provider-bosch": ">=0.1.39",
78
+ "@camstack/addon-provider-dreame": ">=0.2.166",
79
+ "@camstack/addon-provider-dreo": ">=0.2.158",
80
+ "@camstack/addon-provider-enpal": ">=0.1.11",
81
+ "@camstack/addon-provider-esphome": ">=0.1.14",
82
+ "@camstack/addon-provider-gree": ">=0.2.153",
83
+ "@camstack/addon-provider-hikvision": ">=1.2.183",
84
+ "@camstack/addon-provider-homeassistant": ">=1.2.664",
85
+ "@camstack/addon-provider-mqtt-ha": ">=0.1.39",
86
+ "@camstack/addon-provider-petkit": ">=0.2.161",
87
+ "@camstack/addon-provider-rademacher": ">=0.2.160",
88
+ "@camstack/addon-provider-reolink": ">=1.2.230",
89
+ "@camstack/addon-provider-rtsp": ">=1.2.152",
90
+ "@camstack/addon-provider-tuya": ">=0.2.152",
91
+ "@camstack/addon-provider-unifi": ">=0.2.158",
92
+ "@camstack/addon-provider-unraid": ">=0.2.159",
93
+ "@camstack/addon-provider-velux": ">=0.2.160",
94
+ "@camstack/addon-provider-wyze": ">=0.2.165",
95
+ "@camstack/addon-smtp-nodemailer": ">=1.2.149"
74
96
  },
75
97
  "wrapper": {
76
98
  "desktop": ">=0.0.1",
@@ -79,19 +101,19 @@
79
101
  }
80
102
  },
81
103
  "dependencies": {
82
- "@camstack/addon-admin-ui": "1.2.593",
83
- "@camstack/addon-agent-ui": "1.2.329",
104
+ "@camstack/addon-admin-ui": "1.2.595",
105
+ "@camstack/addon-agent-ui": "1.2.330",
84
106
  "@camstack/addon-auth": "1.2.176",
85
107
  "@camstack/addon-benchmark": "1.2.311",
86
108
  "@camstack/addon-decoder-nodeav": "1.2.146",
87
109
  "@camstack/addon-notifiers": "1.2.628",
88
110
  "@camstack/addon-pipeline": "1.2.642",
89
111
  "@camstack/addon-pipeline-orchestrator": "1.2.662",
90
- "@camstack/addon-post-analysis": "1.2.670",
112
+ "@camstack/addon-post-analysis": "1.2.671",
91
113
  "@camstack/develop": "0.1.46",
92
114
  "@camstack/sdk": "1.2.155",
93
- "@camstack/types": "1.2.506",
94
- "@camstack/ui-library": "1.2.387",
115
+ "@camstack/types": "1.2.508",
116
+ "@camstack/ui-library": "1.2.388",
95
117
  "@fastify/compress": "^9.0.0",
96
118
  "@fastify/cookie": "^11.0.2",
97
119
  "@fastify/cors": "^11.2.0",
@@ -5486,6 +5486,172 @@ var CapabilityHandle = class {
5486
5486
  }
5487
5487
  };
5488
5488
  //#endregion
5489
+ //#region src/kernel/moleculer/migration-api-facade.ts
5490
+ var DEFAULT_QUERY_LIMIT = 100;
5491
+ function recordsKind(records, definition) {
5492
+ if (records === void 0) throw new Error("migration api: records are not available");
5493
+ const handle = records.kind(definition);
5494
+ return {
5495
+ get: ({ id }) => handle.get(id),
5496
+ getResolved: ({ id }) => handle.getResolved(id),
5497
+ put: ({ ifRev, ...row }) => handle.put(row, ifRev === void 0 ? void 0 : { ifRev }),
5498
+ putMany: ({ records: rows }) => handle.putMany(rows),
5499
+ patch: ({ id, partial, ifRev }) => handle.patch(id, partial, ifRev === void 0 ? void 0 : { ifRev }),
5500
+ delete: async ({ id }) => ({ deleted: await handle.delete(id) }),
5501
+ query: ({ limit, resolveSecrets, ...rest }) => handle.query({
5502
+ ...rest,
5503
+ limit: limit ?? DEFAULT_QUERY_LIMIT
5504
+ }, resolveSecrets === void 0 ? void 0 : { resolveSecrets }),
5505
+ deleteWhere: async (input) => ({ count: await handle.deleteWhere(input) })
5506
+ };
5507
+ }
5508
+ function requireSecrets(secrets) {
5509
+ if (secrets === void 0) throw new Error("migration api: the keychain is not available");
5510
+ return secrets;
5511
+ }
5512
+ function requireSettings(settings) {
5513
+ if (settings === void 0) throw new Error("migration api: settings are not available");
5514
+ return settings;
5515
+ }
5516
+ function createMigrationApi(backing) {
5517
+ const { legacy, ledger, logger } = backing;
5518
+ return {
5519
+ version: _camstack_types_addon.MIGRATION_API_VERSION,
5520
+ ledger: {
5521
+ declare: (input) => ledger.declareOwner(input),
5522
+ start: (input) => ledger.startMigration(input),
5523
+ finish: (input) => ledger.finishMigration(input)
5524
+ },
5525
+ legacyRows: {
5526
+ read: (input) => legacy.read(input),
5527
+ clear: (input) => legacy.clear(input),
5528
+ patch: (input) => legacy.patch(input),
5529
+ deleteKeys: (input) => legacy.deleteKeys({
5530
+ ...input,
5531
+ keys: [...input.keys]
5532
+ })
5533
+ },
5534
+ records: { kind: (definition) => recordsKind(backing.records, definition) },
5535
+ settings: {
5536
+ read: async () => ({ store: await requireSettings(backing.settings).readAddonStore() }),
5537
+ write: async ({ patch }) => {
5538
+ await requireSettings(backing.settings).writeAddonStore(patch);
5539
+ return {};
5540
+ },
5541
+ deleteKeys: async ({ keys }) => {
5542
+ const settings = requireSettings(backing.settings);
5543
+ const stored = await settings.readAddonStore();
5544
+ const removed = keys.filter((key) => key in stored);
5545
+ if (removed.length > 0) await settings.writeAddonStore(Object.fromEntries(removed.map((k) => [k, void 0])));
5546
+ return { removed };
5547
+ }
5548
+ },
5549
+ secrets: {
5550
+ resolve: async ({ refs }) => {
5551
+ const answers = await requireSecrets(backing.secrets).resolve(refs);
5552
+ const values = {};
5553
+ for (const ref of refs) {
5554
+ const answer = answers[ref];
5555
+ if (answer === void 0 || answer.kind === "missing") values[ref] = null;
5556
+ else if (answer.kind === "value") values[ref] = answer.value;
5557
+ else throw new Error(`migration api: a secret cannot be read (${answer.kind === "unavailable" ? answer.reason : answer.kind})`);
5558
+ }
5559
+ return { values };
5560
+ },
5561
+ put: async ({ ref, value }) => {
5562
+ await requireSecrets(backing.secrets).put(ref, value);
5563
+ return {};
5564
+ },
5565
+ delete: async ({ refs }) => ({ deleted: await requireSecrets(backing.secrets).delete(refs) })
5566
+ },
5567
+ integrations: {
5568
+ list: async () => ({ integrations: (await backing.listIntegrations()).map(toIntegration) }),
5569
+ get: async ({ id }) => {
5570
+ const found = (await backing.listIntegrations()).find((row) => row.id === id);
5571
+ return found === void 0 ? null : toIntegration(found);
5572
+ }
5573
+ },
5574
+ devices: {
5575
+ list: async ({ addonId, integrationId }) => ({ devices: (await backing.devices.list(addonId)).filter((d) => integrationId === void 0 || d.integrationId === integrationId).map((d) => ({ ...d })) }),
5576
+ get: async ({ deviceId }) => {
5577
+ const found = await backing.devices.get(deviceId);
5578
+ if (found === null) return null;
5579
+ return {
5580
+ id: deviceId,
5581
+ integrationId: found.integrationId ?? null,
5582
+ hasConfig: Object.keys(found.config ?? {}).length > 0
5583
+ };
5584
+ },
5585
+ setIntegrationId: async ({ deviceId, integrationId }) => {
5586
+ await backing.devices.setIntegrationId(deviceId, integrationId);
5587
+ return {};
5588
+ }
5589
+ },
5590
+ node: { localNodeId: async () => ({ nodeId: backing.nodeId }) },
5591
+ log: {
5592
+ info: async ({ message, meta, tags }) => {
5593
+ logger.info(message, {
5594
+ ...meta === void 0 ? {} : { meta },
5595
+ ...tags === void 0 ? {} : { tags }
5596
+ });
5597
+ return {};
5598
+ },
5599
+ warn: async ({ message, meta, tags }) => {
5600
+ logger.warn(message, {
5601
+ ...meta === void 0 ? {} : { meta },
5602
+ ...tags === void 0 ? {} : { tags }
5603
+ });
5604
+ return {};
5605
+ }
5606
+ }
5607
+ };
5608
+ }
5609
+ function toIntegration(row) {
5610
+ return {
5611
+ id: row.id,
5612
+ addonId: row.addonId,
5613
+ name: row.name,
5614
+ info: { ...row.info },
5615
+ ...row.originStableId === void 0 ? {} : { originStableId: row.originStableId }
5616
+ };
5617
+ }
5618
+ /** The facade over a context's `api` (the caller is stamped by the transport, never claimed here). */
5619
+ function createMigrationApiOverContext(deps) {
5620
+ const migrations = () => deps.api().migrations;
5621
+ return createMigrationApi({
5622
+ nodeId: deps.nodeId,
5623
+ logger: deps.logger,
5624
+ ledger: {
5625
+ declareOwner: (input) => migrations().declareOwner.mutate(input),
5626
+ startMigration: (input) => migrations().startMigration.mutate(input),
5627
+ finishMigration: (input) => migrations().finishMigration.mutate(input)
5628
+ },
5629
+ legacy: {
5630
+ read: (input) => migrations().readLegacyIntegrationRows.query(input),
5631
+ clear: (input) => migrations().clearLegacyIntegrationRows.mutate(input),
5632
+ patch: (input) => migrations().patchLegacyIntegrationRows.mutate(input),
5633
+ deleteKeys: (input) => migrations().deleteLegacyIntegrationRowKeys.mutate(input)
5634
+ },
5635
+ listIntegrations: () => deps.api().integrations.list.query(),
5636
+ devices: {
5637
+ list: (addonId) => deps.api().deviceManager.listAll.query({
5638
+ addonId,
5639
+ projection: "slim"
5640
+ }),
5641
+ get: (deviceId) => deps.api().deviceManager.getDevice.query({ deviceId }),
5642
+ setIntegrationId: async (deviceId, integrationId) => {
5643
+ await deps.api().deviceManager.setIntegrationId.mutate({
5644
+ deviceId,
5645
+ integrationId
5646
+ });
5647
+ }
5648
+ },
5649
+ records: deps.records,
5650
+ secrets: deps.secrets,
5651
+ settings: deps.settings
5652
+ });
5653
+ }
5654
+ //#endregion
5489
5655
  //#region src/kernel/moleculer/records-api-transport.ts
5490
5656
  function recordsTransportOf(api) {
5491
5657
  const r = api.records;
@@ -11040,6 +11206,12 @@ async function buildAddonContext(runtime, declaration, dataDir, options) {
11040
11206
  },
11041
11207
  eventBus: scopedEventBus
11042
11208
  });
11209
+ const records = (0, _camstack_types_addon.createRecordsAccess)({
11210
+ owner: addonId,
11211
+ transport: recordsTransportOf(api),
11212
+ secrets,
11213
+ logger: scopedLogger
11214
+ });
11043
11215
  return {
11044
11216
  id: addonId,
11045
11217
  logger: scopedLogger,
@@ -11054,11 +11226,14 @@ async function buildAddonContext(runtime, declaration, dataDir, options) {
11054
11226
  deps: new AddonDepsManager(addonDataDir, scopedLogger),
11055
11227
  settings: settingsView,
11056
11228
  secrets,
11057
- records: (0, _camstack_types_addon.createRecordsAccess)({
11058
- owner: addonId,
11059
- transport: recordsTransportOf(api),
11229
+ records,
11230
+ migrationApi: createMigrationApiOverContext({
11231
+ nodeId,
11232
+ logger: scopedLogger,
11233
+ api: () => api,
11234
+ records,
11060
11235
  secrets,
11061
- logger: scopedLogger
11236
+ settings: settingsView
11062
11237
  }),
11063
11238
  kernel: (() => {
11064
11239
  const streamProbe = runtime.mode === "broker" ? {
@@ -1,5 +1,5 @@
1
1
  import { register } from "node:module";
2
- import { BOOT_RECOVERY_BACKOFF_MS, CALLER_STAMPED_CAPABILITIES, DATAPLANE_SECRET_HEADER, DEVICE_CHILDREN_BATCH_MAX, DeviceType, DisposerChain, ErrorI18nPayloadSchema, EventCategory, PEER_BYTES_CHUNK_BYTES, PEER_BYTES_MAX_OUTSTANDING, PEER_BYTES_STALL_MS, PEER_BYTES_TICKET_TTL_MS, ReadinessRegistry, ReadinessTimeoutError, addonSliceHandleApi, asJsonObject, asString, collectZodSecretPaths, createDebugEmitter, createDeviceProxy, createEventBusSliceSource, createRecordsAccess, createSecretsAccess, describeCustomActions, deviceOpsCapability, emitReadiness, errMsg, expandCapMethods, findMigrationsBlocked, isCollectionArrayMethodName, isProviderOptionalMethodName, maskUrlCredentials, nodeIdOfScopedKey, normalizeAddonInitResult, readErrorI18n, readNodePin, resolveDeviceSettings, resolveSecretViewsIn, scopeKey, scrubKnownSecrets, withCapInputDefaults } from "@camstack/types/addon";
2
+ import { BOOT_RECOVERY_BACKOFF_MS, CALLER_STAMPED_CAPABILITIES, DATAPLANE_SECRET_HEADER, DEVICE_CHILDREN_BATCH_MAX, DeviceType, DisposerChain, ErrorI18nPayloadSchema, EventCategory, MIGRATION_API_VERSION, PEER_BYTES_CHUNK_BYTES, PEER_BYTES_MAX_OUTSTANDING, PEER_BYTES_STALL_MS, PEER_BYTES_TICKET_TTL_MS, ReadinessRegistry, ReadinessTimeoutError, addonSliceHandleApi, asJsonObject, asString, collectZodSecretPaths, createDebugEmitter, createDeviceProxy, createEventBusSliceSource, createRecordsAccess, createSecretsAccess, describeCustomActions, deviceOpsCapability, emitReadiness, errMsg, expandCapMethods, findMigrationsBlocked, isCollectionArrayMethodName, isProviderOptionalMethodName, maskUrlCredentials, nodeIdOfScopedKey, normalizeAddonInitResult, readErrorI18n, readNodePin, resolveDeviceSettings, resolveSecretViewsIn, scopeKey, scrubKnownSecrets, withCapInputDefaults } from "@camstack/types/addon";
3
3
  import * as fs$1 from "node:fs";
4
4
  import fs, { createReadStream, createWriteStream, existsSync, readFileSync, readdirSync } from "node:fs";
5
5
  import * as path from "node:path";
@@ -5431,6 +5431,172 @@ var CapabilityHandle = class {
5431
5431
  }
5432
5432
  };
5433
5433
  //#endregion
5434
+ //#region src/kernel/moleculer/migration-api-facade.ts
5435
+ var DEFAULT_QUERY_LIMIT = 100;
5436
+ function recordsKind(records, definition) {
5437
+ if (records === void 0) throw new Error("migration api: records are not available");
5438
+ const handle = records.kind(definition);
5439
+ return {
5440
+ get: ({ id }) => handle.get(id),
5441
+ getResolved: ({ id }) => handle.getResolved(id),
5442
+ put: ({ ifRev, ...row }) => handle.put(row, ifRev === void 0 ? void 0 : { ifRev }),
5443
+ putMany: ({ records: rows }) => handle.putMany(rows),
5444
+ patch: ({ id, partial, ifRev }) => handle.patch(id, partial, ifRev === void 0 ? void 0 : { ifRev }),
5445
+ delete: async ({ id }) => ({ deleted: await handle.delete(id) }),
5446
+ query: ({ limit, resolveSecrets, ...rest }) => handle.query({
5447
+ ...rest,
5448
+ limit: limit ?? DEFAULT_QUERY_LIMIT
5449
+ }, resolveSecrets === void 0 ? void 0 : { resolveSecrets }),
5450
+ deleteWhere: async (input) => ({ count: await handle.deleteWhere(input) })
5451
+ };
5452
+ }
5453
+ function requireSecrets(secrets) {
5454
+ if (secrets === void 0) throw new Error("migration api: the keychain is not available");
5455
+ return secrets;
5456
+ }
5457
+ function requireSettings(settings) {
5458
+ if (settings === void 0) throw new Error("migration api: settings are not available");
5459
+ return settings;
5460
+ }
5461
+ function createMigrationApi(backing) {
5462
+ const { legacy, ledger, logger } = backing;
5463
+ return {
5464
+ version: MIGRATION_API_VERSION,
5465
+ ledger: {
5466
+ declare: (input) => ledger.declareOwner(input),
5467
+ start: (input) => ledger.startMigration(input),
5468
+ finish: (input) => ledger.finishMigration(input)
5469
+ },
5470
+ legacyRows: {
5471
+ read: (input) => legacy.read(input),
5472
+ clear: (input) => legacy.clear(input),
5473
+ patch: (input) => legacy.patch(input),
5474
+ deleteKeys: (input) => legacy.deleteKeys({
5475
+ ...input,
5476
+ keys: [...input.keys]
5477
+ })
5478
+ },
5479
+ records: { kind: (definition) => recordsKind(backing.records, definition) },
5480
+ settings: {
5481
+ read: async () => ({ store: await requireSettings(backing.settings).readAddonStore() }),
5482
+ write: async ({ patch }) => {
5483
+ await requireSettings(backing.settings).writeAddonStore(patch);
5484
+ return {};
5485
+ },
5486
+ deleteKeys: async ({ keys }) => {
5487
+ const settings = requireSettings(backing.settings);
5488
+ const stored = await settings.readAddonStore();
5489
+ const removed = keys.filter((key) => key in stored);
5490
+ if (removed.length > 0) await settings.writeAddonStore(Object.fromEntries(removed.map((k) => [k, void 0])));
5491
+ return { removed };
5492
+ }
5493
+ },
5494
+ secrets: {
5495
+ resolve: async ({ refs }) => {
5496
+ const answers = await requireSecrets(backing.secrets).resolve(refs);
5497
+ const values = {};
5498
+ for (const ref of refs) {
5499
+ const answer = answers[ref];
5500
+ if (answer === void 0 || answer.kind === "missing") values[ref] = null;
5501
+ else if (answer.kind === "value") values[ref] = answer.value;
5502
+ else throw new Error(`migration api: a secret cannot be read (${answer.kind === "unavailable" ? answer.reason : answer.kind})`);
5503
+ }
5504
+ return { values };
5505
+ },
5506
+ put: async ({ ref, value }) => {
5507
+ await requireSecrets(backing.secrets).put(ref, value);
5508
+ return {};
5509
+ },
5510
+ delete: async ({ refs }) => ({ deleted: await requireSecrets(backing.secrets).delete(refs) })
5511
+ },
5512
+ integrations: {
5513
+ list: async () => ({ integrations: (await backing.listIntegrations()).map(toIntegration) }),
5514
+ get: async ({ id }) => {
5515
+ const found = (await backing.listIntegrations()).find((row) => row.id === id);
5516
+ return found === void 0 ? null : toIntegration(found);
5517
+ }
5518
+ },
5519
+ devices: {
5520
+ list: async ({ addonId, integrationId }) => ({ devices: (await backing.devices.list(addonId)).filter((d) => integrationId === void 0 || d.integrationId === integrationId).map((d) => ({ ...d })) }),
5521
+ get: async ({ deviceId }) => {
5522
+ const found = await backing.devices.get(deviceId);
5523
+ if (found === null) return null;
5524
+ return {
5525
+ id: deviceId,
5526
+ integrationId: found.integrationId ?? null,
5527
+ hasConfig: Object.keys(found.config ?? {}).length > 0
5528
+ };
5529
+ },
5530
+ setIntegrationId: async ({ deviceId, integrationId }) => {
5531
+ await backing.devices.setIntegrationId(deviceId, integrationId);
5532
+ return {};
5533
+ }
5534
+ },
5535
+ node: { localNodeId: async () => ({ nodeId: backing.nodeId }) },
5536
+ log: {
5537
+ info: async ({ message, meta, tags }) => {
5538
+ logger.info(message, {
5539
+ ...meta === void 0 ? {} : { meta },
5540
+ ...tags === void 0 ? {} : { tags }
5541
+ });
5542
+ return {};
5543
+ },
5544
+ warn: async ({ message, meta, tags }) => {
5545
+ logger.warn(message, {
5546
+ ...meta === void 0 ? {} : { meta },
5547
+ ...tags === void 0 ? {} : { tags }
5548
+ });
5549
+ return {};
5550
+ }
5551
+ }
5552
+ };
5553
+ }
5554
+ function toIntegration(row) {
5555
+ return {
5556
+ id: row.id,
5557
+ addonId: row.addonId,
5558
+ name: row.name,
5559
+ info: { ...row.info },
5560
+ ...row.originStableId === void 0 ? {} : { originStableId: row.originStableId }
5561
+ };
5562
+ }
5563
+ /** The facade over a context's `api` (the caller is stamped by the transport, never claimed here). */
5564
+ function createMigrationApiOverContext(deps) {
5565
+ const migrations = () => deps.api().migrations;
5566
+ return createMigrationApi({
5567
+ nodeId: deps.nodeId,
5568
+ logger: deps.logger,
5569
+ ledger: {
5570
+ declareOwner: (input) => migrations().declareOwner.mutate(input),
5571
+ startMigration: (input) => migrations().startMigration.mutate(input),
5572
+ finishMigration: (input) => migrations().finishMigration.mutate(input)
5573
+ },
5574
+ legacy: {
5575
+ read: (input) => migrations().readLegacyIntegrationRows.query(input),
5576
+ clear: (input) => migrations().clearLegacyIntegrationRows.mutate(input),
5577
+ patch: (input) => migrations().patchLegacyIntegrationRows.mutate(input),
5578
+ deleteKeys: (input) => migrations().deleteLegacyIntegrationRowKeys.mutate(input)
5579
+ },
5580
+ listIntegrations: () => deps.api().integrations.list.query(),
5581
+ devices: {
5582
+ list: (addonId) => deps.api().deviceManager.listAll.query({
5583
+ addonId,
5584
+ projection: "slim"
5585
+ }),
5586
+ get: (deviceId) => deps.api().deviceManager.getDevice.query({ deviceId }),
5587
+ setIntegrationId: async (deviceId, integrationId) => {
5588
+ await deps.api().deviceManager.setIntegrationId.mutate({
5589
+ deviceId,
5590
+ integrationId
5591
+ });
5592
+ }
5593
+ },
5594
+ records: deps.records,
5595
+ secrets: deps.secrets,
5596
+ settings: deps.settings
5597
+ });
5598
+ }
5599
+ //#endregion
5434
5600
  //#region src/kernel/moleculer/records-api-transport.ts
5435
5601
  function recordsTransportOf(api) {
5436
5602
  const r = api.records;
@@ -10985,6 +11151,12 @@ async function buildAddonContext(runtime, declaration, dataDir, options) {
10985
11151
  },
10986
11152
  eventBus: scopedEventBus
10987
11153
  });
11154
+ const records = createRecordsAccess({
11155
+ owner: addonId,
11156
+ transport: recordsTransportOf(api),
11157
+ secrets,
11158
+ logger: scopedLogger
11159
+ });
10988
11160
  return {
10989
11161
  id: addonId,
10990
11162
  logger: scopedLogger,
@@ -10999,11 +11171,14 @@ async function buildAddonContext(runtime, declaration, dataDir, options) {
10999
11171
  deps: new AddonDepsManager(addonDataDir, scopedLogger),
11000
11172
  settings: settingsView,
11001
11173
  secrets,
11002
- records: createRecordsAccess({
11003
- owner: addonId,
11004
- transport: recordsTransportOf(api),
11174
+ records,
11175
+ migrationApi: createMigrationApiOverContext({
11176
+ nodeId,
11177
+ logger: scopedLogger,
11178
+ api: () => api,
11179
+ records,
11005
11180
  secrets,
11006
- logger: scopedLogger
11181
+ settings: settingsView
11007
11182
  }),
11008
11183
  kernel: (() => {
11009
11184
  const streamProbe = runtime.mode === "broker" ? {
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require("./chunk-Cek0wNdY.js");
2
- const require_dist = require("./dist-D3StiAs2.js");
2
+ const require_dist = require("./dist-B4wrqheM.js");
3
3
  const require_x509_es = require("./x509.es-WtnRNyYS.js");
4
4
  let zod = require("zod");
5
5
  let node_crypto = require("node:crypto");
@@ -1,4 +1,4 @@
1
- import { bs as defineRecordKinds } from "./dist-CV4RPML4.mjs";
1
+ import { Ts as defineRecordKinds } from "./dist-BX8nZeXV.mjs";
2
2
  import { C as backdatedNotBefore, S as withUtcTimeEncoding, _ as NameConstraints, a as KeyUsageFlags, c as Pkcs10CertificateRequest, d as SubjectKeyIdentifierExtension, f as X509Certificate$1, g as GeneralSubtrees, h as GeneralSubtree, i as Extension, l as Pkcs10CertificateRequestGenerator, m as cryptoProvider, n as BasicConstraintsExtension, o as KeyUsagesExtension, p as X509CertificateGenerator, r as ExtendedKeyUsageExtension, s as PemConverter, t as AuthorityKeyIdentifierExtension, u as SubjectAlternativeNameExtension, v as GeneralName, x as AsnConvert } from "./x509.es-BRiJgOvu.mjs";
3
3
  import { z } from "zod";
4
4
  import { X509Certificate, createHash, createPrivateKey, randomBytes, webcrypto } from "node:crypto";
@@ -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-D3StiAs2.js");
6
+ const require_dist = require("../../dist-B4wrqheM.js");
7
7
  const require_settle_sources = require("../../settle-sources-Bhsy57y-.js");
8
8
  let node_crypto = require("node:crypto");
9
9
  let node_path = require("node:path");
@@ -1,4 +1,4 @@
1
- import { To as BaseAddon, cn as addonPagesCapability, dc as errMsg, fc as EventCategory } from "../../dist-CV4RPML4.mjs";
1
+ import { Ao as BaseAddon, _c as EventCategory, gc as errMsg, un as addonPagesCapability } from "../../dist-BX8nZeXV.mjs";
2
2
  import { t as settleSourcesWithTimeout } from "../../settle-sources-CDtNC8ub.mjs";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import * as path$1 from "node:path";
@@ -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-D3StiAs2.js");
6
+ const require_dist = require("../../dist-B4wrqheM.js");
7
7
  const require_settle_sources = require("../../settle-sources-Bhsy57y-.js");
8
8
  let node_crypto = require("node:crypto");
9
9
  let node_path = require("node:path");
@@ -1,4 +1,4 @@
1
- import { To as BaseAddon, dc as errMsg, fc as EventCategory, un as addonWidgetsCapability } from "../../dist-CV4RPML4.mjs";
1
+ import { Ao as BaseAddon, _c as EventCategory, fn as addonWidgetsCapability, gc as errMsg } from "../../dist-BX8nZeXV.mjs";
2
2
  import { t as settleSourcesWithTimeout } from "../../settle-sources-CDtNC8ub.mjs";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import * as path$1 from "node:path";
@@ -3,7 +3,7 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-D3StiAs2.js");
6
+ const require_dist = require("../../dist-B4wrqheM.js");
7
7
  const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
8
8
  //#region src/builtins/alerts/alert-episode-policy.ts
9
9
  /**