@camstack/server 1.2.779 → 1.2.781

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 +22 -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/cap-router-runtime.js +18 -9
  9. package/dist/api/trpc/generated-cap-mounts.js +1 -9
  10. package/dist/api/trpc/generated-cap-routers.js +9 -88
  11. package/dist/core/addon/addon-package.service.js +24 -8
  12. package/dist/core/addon/addon-registry.service.js +61 -10
  13. package/dist/core/addon/hub-spawn-gate.js +92 -0
  14. package/dist/core/addon/integration-instances-provider.js +22 -0
  15. package/dist/core/agent/agent-registry.service.js +6 -2
  16. package/dist/core/agent/delivery-requirements.js +22 -6
  17. package/dist/core/updates/required-addon-update.js +188 -0
  18. package/dist/launcher.js +4 -0
  19. package/dist/manual-boot.js +27 -0
  20. package/dist/server-root/index.js +74 -3
  21. package/package.json +7 -11
  22. package/system/dist/addon-runner.js +188 -5
  23. package/system/dist/addon-runner.mjs +189 -6
  24. package/system/dist/{agent-https-swBZI1iJ.js → agent-https-A9wsxVGn.js} +1 -1
  25. package/system/dist/{agent-https-BrINLeNj.mjs → agent-https-DuxDC67S.mjs} +1 -1
  26. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  27. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  28. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  29. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  30. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  31. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  32. package/system/dist/builtins/autotrack/index.js +1 -1
  33. package/system/dist/builtins/autotrack/index.mjs +1 -1
  34. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  35. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  36. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  37. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  38. package/system/dist/builtins/camera-grid/index.js +1 -1
  39. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  40. package/system/dist/builtins/composer/composer.addon.js +3 -3
  41. package/system/dist/builtins/composer/composer.addon.mjs +3 -3
  42. package/system/dist/builtins/console-logging/index.js +1 -1
  43. package/system/dist/builtins/console-logging/index.mjs +1 -1
  44. package/system/dist/builtins/core-blocks/core-blocks.addon.js +3 -3
  45. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +3 -3
  46. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  47. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  48. package/system/dist/builtins/device-manager/device-manager.addon.js +1 -1
  49. package/system/dist/builtins/device-manager/device-manager.addon.mjs +1 -1
  50. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  51. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  52. package/system/dist/builtins/keychain/index.js +4 -4
  53. package/system/dist/builtins/keychain/index.mjs +4 -4
  54. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  55. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  56. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  57. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  58. package/system/dist/builtins/local-network/local-network.addon.js +2 -2
  59. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  60. package/system/dist/builtins/loki-logging/index.js +1 -1
  61. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  62. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  63. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  64. package/system/dist/builtins/platform-probe/index.js +1 -1
  65. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  66. package/system/dist/builtins/record-entries/index.js +1 -1
  67. package/system/dist/builtins/record-entries/index.mjs +1 -1
  68. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  69. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  70. package/system/dist/builtins/snapshot/index.js +1 -1
  71. package/system/dist/builtins/snapshot/index.mjs +1 -1
  72. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  73. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  74. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  75. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  76. package/system/dist/builtins/sqlite-storage/migrations/migrations-provider.d.ts +5 -1
  77. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +12 -4
  78. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +12 -4
  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 +284 -284
  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-D_ImDrdj.mjs → capture-engine-CEChNpAD.mjs} +1 -1
  86. package/system/dist/{capture-engine-BXV6UiHl.js → capture-engine-D6mXfLFQ.js} +1 -1
  87. package/system/dist/{composition-sources-BjktkDte.mjs → composition-sources-6XYW86Kw.mjs} +1 -1
  88. package/system/dist/{composition-sources-DjTxqryW.js → composition-sources-cVWKVph4.js} +1 -1
  89. package/system/dist/{constants-CGXiM2LV.js → constants-B5Yg02ii.js} +1 -1
  90. package/system/dist/{constants-C68806R6.mjs → constants-DqwDEYfb.mjs} +1 -1
  91. package/system/dist/{device-ca-D_q1MiQ3.js → device-ca-BVz14dRd.js} +1 -1
  92. package/system/dist/{device-ca-CFRagVlE.mjs → device-ca-oY4Xqd7s.mjs} +1 -1
  93. package/system/dist/{dist-C9Ms2Ul9.js → dist-B4wrqheM.js} +833 -631
  94. package/system/dist/{dist-BzpjKSec.mjs → dist-BX8nZeXV.mjs} +804 -632
  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-CFsSp0tc.mjs → hub-mdns-ciao-BDPMfOgq.mjs} +2 -2
  98. package/system/dist/{hub-mdns-ciao-C87S9O_n.js → hub-mdns-ciao-CiMMA0rT.js} +2 -2
  99. package/system/dist/index.js +441 -31
  100. package/system/dist/index.mjs +436 -33
  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/moleculer/trpc-links.d.ts +8 -0
  106. package/system/dist/kernel/requires-registry.d.ts +31 -0
  107. package/system/dist/{legacy-integration-rows-door-CI-AaB-M.mjs → legacy-integration-rows-door-DDA3YOxL.mjs} +1 -1
  108. package/system/dist/{legacy-integration-rows-door-C_aaT1DH.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-D3K33hws.mjs → restore-archive-BrtpgNCt.mjs} +82 -82
  111. package/system/dist/{restore-archive-BC8OECG8.js → restore-archive-Cn9OShm4.js} +1 -1
  112. package/system/dist/{wal-maintenance-Bf9m0JZr.js → wal-maintenance-BTzu3s-6.js} +0 -0
  113. package/system/dist/{wal-maintenance-CMjTxyAC.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.779",
3
+ "version": "1.2.781",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -65,11 +65,7 @@
65
65
  "@camstack/addon-agent-ui"
66
66
  ],
67
67
  "requires": {
68
- "addons": {
69
- "@camstack/addon-admin-ui": ">=1.2.594",
70
- "@camstack/addon-provider-homeassistant": ">=1.2.663",
71
- "@camstack/addon-provider-reolink": ">=1.2.229"
72
- },
68
+ "addons": {},
73
69
  "wrapper": {
74
70
  "desktop": ">=0.0.1",
75
71
  "image": ">=0.0.1"
@@ -77,19 +73,19 @@
77
73
  }
78
74
  },
79
75
  "dependencies": {
80
- "@camstack/addon-admin-ui": "1.2.594",
81
- "@camstack/addon-agent-ui": "1.2.329",
76
+ "@camstack/addon-admin-ui": "1.2.595",
77
+ "@camstack/addon-agent-ui": "1.2.330",
82
78
  "@camstack/addon-auth": "1.2.176",
83
79
  "@camstack/addon-benchmark": "1.2.311",
84
80
  "@camstack/addon-decoder-nodeav": "1.2.146",
85
81
  "@camstack/addon-notifiers": "1.2.628",
86
82
  "@camstack/addon-pipeline": "1.2.642",
87
83
  "@camstack/addon-pipeline-orchestrator": "1.2.662",
88
- "@camstack/addon-post-analysis": "1.2.670",
84
+ "@camstack/addon-post-analysis": "1.2.671",
89
85
  "@camstack/develop": "0.1.46",
90
86
  "@camstack/sdk": "1.2.155",
91
- "@camstack/types": "1.2.507",
92
- "@camstack/ui-library": "1.2.387",
87
+ "@camstack/types": "1.2.508",
88
+ "@camstack/ui-library": "1.2.388",
93
89
  "@fastify/compress": "^9.0.0",
94
90
  "@fastify/cookie": "^11.0.2",
95
91
  "@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;
@@ -7713,7 +7879,12 @@ function localProviderLink(resolver, observerOpts) {
7713
7879
  const pinnedNodeId = (0, _camstack_types_addon.readNodePin)(op.context);
7714
7880
  if (pinnedNodeId !== void 0 && pinnedNodeId !== localBase) return next(opWithDefaults);
7715
7881
  }
7716
- const provider = resolver.getByName(parsed.capName);
7882
+ let provider;
7883
+ const pinnedAddonId = liftRoutingHints(op.input).addonId;
7884
+ if (pinnedAddonId !== void 0 && resolver.getByAddonId !== void 0 && Object.hasOwn(_camstack_types_addon.COLLECTION_ARRAY_METHODS, parsed.capName)) {
7885
+ provider = resolver.getByAddonId(parsed.capName, pinnedAddonId);
7886
+ if (!provider) return next(opWithDefaults);
7887
+ } else provider = resolver.getByName(parsed.capName);
7717
7888
  if (!provider || typeof provider !== "object") return next(opWithDefaults);
7718
7889
  const fn = Reflect.get(provider, parsed.method);
7719
7890
  if (typeof fn !== "function") return next(opWithDefaults);
@@ -10842,6 +11013,9 @@ async function buildAddonContext(runtime, declaration, dataDir, options) {
10842
11013
  const regs = getRegistries(nodeId);
10843
11014
  const workerResolver = {
10844
11015
  localNodeId: nodeId,
11016
+ getByAddonId(capabilityName, pinnedAddonId) {
11017
+ return regs.byAddonId.get(capabilityName)?.get(pinnedAddonId) ?? null;
11018
+ },
10845
11019
  getByName(capabilityName) {
10846
11020
  const preferred = regs.preferred.get(capabilityName);
10847
11021
  if (preferred) {
@@ -11040,6 +11214,12 @@ async function buildAddonContext(runtime, declaration, dataDir, options) {
11040
11214
  },
11041
11215
  eventBus: scopedEventBus
11042
11216
  });
11217
+ const records = (0, _camstack_types_addon.createRecordsAccess)({
11218
+ owner: addonId,
11219
+ transport: recordsTransportOf(api),
11220
+ secrets,
11221
+ logger: scopedLogger
11222
+ });
11043
11223
  return {
11044
11224
  id: addonId,
11045
11225
  logger: scopedLogger,
@@ -11054,11 +11234,14 @@ async function buildAddonContext(runtime, declaration, dataDir, options) {
11054
11234
  deps: new AddonDepsManager(addonDataDir, scopedLogger),
11055
11235
  settings: settingsView,
11056
11236
  secrets,
11057
- records: (0, _camstack_types_addon.createRecordsAccess)({
11058
- owner: addonId,
11059
- transport: recordsTransportOf(api),
11237
+ records,
11238
+ migrationApi: createMigrationApiOverContext({
11239
+ nodeId,
11240
+ logger: scopedLogger,
11241
+ api: () => api,
11242
+ records,
11060
11243
  secrets,
11061
- logger: scopedLogger
11244
+ settings: settingsView
11062
11245
  }),
11063
11246
  kernel: (() => {
11064
11247
  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, COLLECTION_ARRAY_METHODS, 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;
@@ -7658,7 +7824,12 @@ function localProviderLink(resolver, observerOpts) {
7658
7824
  const pinnedNodeId = readNodePin(op.context);
7659
7825
  if (pinnedNodeId !== void 0 && pinnedNodeId !== localBase) return next(opWithDefaults);
7660
7826
  }
7661
- const provider = resolver.getByName(parsed.capName);
7827
+ let provider;
7828
+ const pinnedAddonId = liftRoutingHints(op.input).addonId;
7829
+ if (pinnedAddonId !== void 0 && resolver.getByAddonId !== void 0 && Object.hasOwn(COLLECTION_ARRAY_METHODS, parsed.capName)) {
7830
+ provider = resolver.getByAddonId(parsed.capName, pinnedAddonId);
7831
+ if (!provider) return next(opWithDefaults);
7832
+ } else provider = resolver.getByName(parsed.capName);
7662
7833
  if (!provider || typeof provider !== "object") return next(opWithDefaults);
7663
7834
  const fn = Reflect.get(provider, parsed.method);
7664
7835
  if (typeof fn !== "function") return next(opWithDefaults);
@@ -10787,6 +10958,9 @@ async function buildAddonContext(runtime, declaration, dataDir, options) {
10787
10958
  const regs = getRegistries(nodeId);
10788
10959
  const workerResolver = {
10789
10960
  localNodeId: nodeId,
10961
+ getByAddonId(capabilityName, pinnedAddonId) {
10962
+ return regs.byAddonId.get(capabilityName)?.get(pinnedAddonId) ?? null;
10963
+ },
10790
10964
  getByName(capabilityName) {
10791
10965
  const preferred = regs.preferred.get(capabilityName);
10792
10966
  if (preferred) {
@@ -10985,6 +11159,12 @@ async function buildAddonContext(runtime, declaration, dataDir, options) {
10985
11159
  },
10986
11160
  eventBus: scopedEventBus
10987
11161
  });
11162
+ const records = createRecordsAccess({
11163
+ owner: addonId,
11164
+ transport: recordsTransportOf(api),
11165
+ secrets,
11166
+ logger: scopedLogger
11167
+ });
10988
11168
  return {
10989
11169
  id: addonId,
10990
11170
  logger: scopedLogger,
@@ -10999,11 +11179,14 @@ async function buildAddonContext(runtime, declaration, dataDir, options) {
10999
11179
  deps: new AddonDepsManager(addonDataDir, scopedLogger),
11000
11180
  settings: settingsView,
11001
11181
  secrets,
11002
- records: createRecordsAccess({
11003
- owner: addonId,
11004
- transport: recordsTransportOf(api),
11182
+ records,
11183
+ migrationApi: createMigrationApiOverContext({
11184
+ nodeId,
11185
+ logger: scopedLogger,
11186
+ api: () => api,
11187
+ records,
11005
11188
  secrets,
11006
- logger: scopedLogger
11189
+ settings: settingsView
11007
11190
  }),
11008
11191
  kernel: (() => {
11009
11192
  const streamProbe = runtime.mode === "broker" ? {
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require("./chunk-Cek0wNdY.js");
2
- const require_dist = require("./dist-C9Ms2Ul9.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-BzpjKSec.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-C9Ms2Ul9.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-BzpjKSec.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-C9Ms2Ul9.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");