@camstack/server 1.2.943 → 1.2.945
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.
- package/CHANGELOG.md +26 -0
- package/closure-pins.json +350 -0
- package/dist/api/core/auth-sessions.procedures.js +18 -0
- package/dist/api/core/auth.router.js +19 -6
- package/dist/api/server-upload.js +17 -1
- package/dist/api/trpc/generated-cap-mounts.js +18 -1
- package/dist/api/trpc/generated-cap-routers.js +2662 -2542
- package/dist/auth/native-return.js +9 -3
- package/dist/auth/sso-routes.js +5 -1
- package/dist/core/addon/instance-lifecycle.js +4 -1
- package/dist/core/auth/handoff-code.service.js +35 -1
- package/dist/server-root/index.js +313 -70
- package/package.json +15 -11
- package/system/assets/apps-aggregator/icon.svg +5 -0
- package/system/dist/{action-index-B_cLRwXJ.js → action-index-Bcnb-jyg.js} +9 -1
- package/system/dist/{action-index-B1fgpQBt.mjs → action-index-DwPHO2nz.mjs} +9 -1
- package/system/dist/{addon-settings.cap-CZ4MC7ha.mjs → addon-settings.cap-CHpmuaQG.mjs} +1 -1
- package/system/dist/{addon-settings.cap-DrLdMFIe.js → addon-settings.cap-nZVHPo3X.js} +1 -1
- package/system/dist/{alert-episode-Be--PngO.mjs → alert-episode-D-1VUUkZ.mjs} +1 -1
- package/system/dist/{alert-episode-Bqktmt-i.js → alert-episode-DaQ3prSe.js} +1 -1
- package/system/dist/apps.cap-Bqb9NpYx.mjs +130 -0
- package/system/dist/apps.cap-CLjgnuUe.js +141 -0
- package/system/dist/{base-addon-CRsXtYFG.js → base-addon-BG7p06Hb.js} +136 -15
- package/system/dist/{base-addon-BcS6r1cT.mjs → base-addon-BcVoYZbC.mjs} +136 -15
- package/system/dist/{base-device-DAdWzDOl.js → base-device-DeSNiwZ4.js} +4 -4
- package/system/dist/{base-device-DJXF5eDN.mjs → base-device-w_MD0Bf4.mjs} +4 -4
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alerts.addon.js +3 -3
- package/system/dist/builtins/alerts/alerts.addon.mjs +3 -3
- package/system/dist/builtins/apps-aggregator/aggregate-apps.d.ts +24 -0
- package/system/dist/builtins/apps-aggregator/apps-aggregator.addon.d.ts +16 -0
- package/system/dist/builtins/apps-aggregator/apps-aggregator.addon.js +109 -0
- package/system/dist/builtins/apps-aggregator/apps-aggregator.addon.mjs +103 -0
- package/system/dist/builtins/apps-aggregator/index.d.ts +1 -0
- package/system/dist/builtins/apps-aggregator/index.js +8 -0
- package/system/dist/builtins/apps-aggregator/index.mjs +2 -0
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +3 -3
- package/system/dist/builtins/camera-grid/index.mjs +3 -3
- package/system/dist/builtins/composer/composer.addon.js +7 -7
- package/system/dist/builtins/composer/composer.addon.mjs +7 -7
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/actions-store.d.ts +2 -0
- package/system/dist/builtins/core-blocks/block-supervisor.d.ts +16 -4
- package/system/dist/builtins/core-blocks/core-block-store.d.ts +2 -0
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +1018 -323
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +986 -291
- package/system/dist/builtins/core-blocks/migrations/index.d.ts +5 -2
- package/system/dist/builtins/core-blocks/migrations/tag-ids.d.ts +42 -0
- package/system/dist/builtins/core-blocks/migrations/tags-as-records.d.ts +47 -0
- package/system/dist/builtins/core-blocks/record-kinds.d.ts +12 -1
- package/system/dist/builtins/core-blocks/runs-api.d.ts +3 -1
- package/system/dist/builtins/core-blocks/runs-ledger.d.ts +3 -1
- package/system/dist/builtins/core-blocks/scheduler/scheduler-store.d.ts +2 -0
- package/system/dist/builtins/core-blocks/tags-service.d.ts +52 -27
- package/system/dist/builtins/core-blocks/tags-wiring.d.ts +2 -0
- package/system/dist/builtins/core-notifier/core-notifier.addon.js +76 -67
- package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +76 -67
- package/system/dist/builtins/device-history/device-history.addon.js +4 -4
- package/system/dist/builtins/device-history/device-history.addon.mjs +4 -4
- package/system/dist/builtins/device-manager/device-manager.addon.js +1618 -755
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +1604 -741
- package/system/dist/builtins/device-manager/device-meta-actions.d.ts +13 -136
- package/system/dist/builtins/device-manager/device-meta-types.d.ts +5 -1
- package/system/dist/builtins/device-manager/device-provider-context.d.ts +9 -0
- package/system/dist/builtins/device-manager/device-row-store.d.ts +21 -4
- package/system/dist/builtins/device-manager/device-search.d.ts +6 -0
- package/system/dist/builtins/device-manager/location-alignment.d.ts +9 -2
- package/system/dist/builtins/device-manager/migrate-device.d.ts +7 -2
- package/system/dist/builtins/device-manager/migrate-hardware-state.d.ts +132 -1
- package/system/dist/builtins/device-manager/migrations/device-tag-ids.d.ts +25 -0
- package/system/dist/builtins/device-manager/migrations/index.d.ts +16 -0
- package/system/dist/builtins/device-manager/migrations/orphan-children.d.ts +33 -0
- package/system/dist/builtins/device-manager/migrations/ports.d.ts +17 -0
- package/system/dist/builtins/device-manager/migrations/rooms-as-records.d.ts +52 -0
- package/system/dist/builtins/device-manager/record-kinds.d.ts +3 -1
- package/system/dist/builtins/device-manager/removal-cleanup.d.ts +7 -0
- package/system/dist/builtins/device-manager/room-actions.d.ts +27 -0
- package/system/dist/builtins/device-manager/room-store.d.ts +19 -0
- package/system/dist/builtins/device-manager/tag-names.d.ts +32 -0
- package/system/dist/builtins/device-manager/wireable-enum-catalog.d.ts +18 -0
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +3 -3
- package/system/dist/builtins/keychain/index.mjs +3 -3
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +1 -1
- package/system/dist/builtins/local-network/local-network.addon.js +2 -2
- package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
- package/system/dist/builtins/loki-logging/index.js +2 -2
- package/system/dist/builtins/loki-logging/index.mjs +2 -2
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +1 -1
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/index.js +1 -1
- package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/migrations/migration-engine.d.ts +3 -1
- package/system/dist/builtins/sqlite-storage/migrations/migrations-provider.d.ts +1 -0
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +15 -10
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +15 -10
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +2 -2
- package/system/dist/builtins/system-config/system-config.addon.mjs +2 -2
- package/system/dist/builtins/winston-logging/index.js +2 -2
- package/system/dist/builtins/winston-logging/index.mjs +2 -2
- package/system/dist/{command-catalog-C29hVOOg.js → command-catalog-A_ONlLfF.js} +1 -1
- package/system/dist/{command-catalog-xAeqxbZk.mjs → command-catalog-CZDlLhxO.mjs} +1 -1
- package/system/dist/{composition-sources-Do5qM6EB.js → composition-sources-D1nPv7dJ.js} +1 -1
- package/system/dist/{composition-sources-C327LGFn.mjs → composition-sources-DubMf_ii.mjs} +1 -1
- package/system/dist/{core-blocks.cap-CdTGUKtr.js → core-blocks.cap-DEYCvF9J.js} +125 -373
- package/system/dist/{core-blocks.cap-DLkEfV5b.mjs → core-blocks.cap-sW5HLDlB.mjs} +109 -327
- package/system/dist/{device-manager.cap-DJs8izI6.js → device-manager.cap-B9qVf7ag.js} +163 -22
- package/system/dist/{device-manager.cap-eYrj1Ezp.mjs → device-manager.cap-CV4KGp3e.mjs} +134 -17
- package/system/dist/{error.cap-CU1FB6uE.mjs → error.cap-B8l7L8e4.mjs} +7 -1
- package/system/dist/{error.cap-BuKbL3Ac.js → error.cap-BqlvgBJd.js} +7 -1
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/index.js +8 -8
- package/system/dist/index.mjs +7 -7
- package/system/dist/{legacy-integration-rows-door-CdqYAj-o.js → legacy-integration-rows-door-BK8eoGlF.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-LSgpClpX.mjs → legacy-integration-rows-door-CwzC5XNk.mjs} +1 -1
- package/system/dist/{migration-DGAc6ywR.mjs → migration-BvbfW9g-.mjs} +6 -0
- package/system/dist/{migration-BOQlFZCN.js → migration-CHPdAdNh.js} +6 -0
- package/system/dist/{prefix-walk-Mtij0NNT.mjs → named-entity-store-Cq2oVrN5.mjs} +195 -89
- package/system/dist/{prefix-walk-BFnw8NBu.js → named-entity-store-O_hi1y_o.js} +244 -90
- package/system/dist/{notification-rules.cap-BUIuYPlQ.mjs → notification-rules.cap-ClvK6QT1.mjs} +10 -5
- package/system/dist/{notification-rules.cap-BJKUjizS.js → notification-rules.cap-uSLoe2pA.js} +10 -5
- package/system/dist/{notification-targets-DMW7xgR2.js → notification-targets-ChqpBbtR.js} +2 -2
- package/system/dist/{notification-targets-4bGYH5J7.mjs → notification-targets-DUA6-F2t.mjs} +2 -2
- package/system/dist/{device-row-store-CTocYKqC.mjs → record-kinds-BD2xv4Pd.mjs} +222 -93
- package/system/dist/{device-row-store-C0P2H18h.js → record-kinds-BV8Gcpsx.js} +246 -93
- package/system/dist/records/named-entity-store.d.ts +60 -0
- package/system/dist/{rename-composition-block-D9Uc1AF7.js → rename-composition-block-C60O0P16.js} +137 -33
- package/system/dist/{rename-composition-block-Cdh-dRmY.mjs → rename-composition-block-DcX3vkwS.mjs} +137 -33
- package/system/dist/{retention-source.cap-C6Hy0hlM.js → retention-source.cap-A-TMhU5O.js} +1 -1
- package/system/dist/{retention-source.cap-550kkyp5.mjs → retention-source.cap-Ct07pM30.mjs} +1 -1
- package/system/dist/{storage-admin.cap-Ci4QbL6P.mjs → storage-admin.cap-C54s9_B9.mjs} +8 -2
- package/system/dist/{storage-admin.cap-DqW1ol4j.js → storage-admin.cap-DSPHi7ut.js} +8 -2
- package/system/dist/{stream-catalog.cap-CjEQFknc.js → stream-catalog.cap-7WPsugOy.js} +1 -1
- package/system/dist/{stream-catalog.cap-DVniDdRD.mjs → stream-catalog.cap-CzwRDaqT.mjs} +1 -1
- package/system/dist/{tag-BxLazvVb.js → tag-BLraBqvp.js} +12 -0
- package/system/dist/{tag-uZBAq6ox.mjs → tag-DU8pm9Bi.mjs} +7 -1
- package/system/dist/time-window-B6UhCArd.js +679 -0
- package/system/dist/time-window-BnUBULgu.mjs +578 -0
- package/system/dist/{wal-maintenance-BgYiAy5b.js → wal-maintenance-CkPfVApC.js} +0 -0
- package/system/dist/{wal-maintenance-Bey5ChBb.mjs → wal-maintenance-u84_1sVl.mjs} +0 -0
- package/system/package.json +16 -1
- /package/system/dist/{constants-Ba3FTIHl.js → constants-Ba3FTIHl2.js} +0 -0
- /package/system/dist/{constants-DB4piTD5.mjs → constants-DB4piTD52.mjs} +0 -0
|
@@ -3,30 +3,31 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
5
|
const require_chunk = require("../../chunk-Cek0wNdY.js");
|
|
6
|
-
const require_stream_catalog_cap = require("../../stream-catalog.cap-
|
|
7
|
-
const require_base_addon = require("../../base-addon-
|
|
6
|
+
const require_stream_catalog_cap = require("../../stream-catalog.cap-7WPsugOy.js");
|
|
7
|
+
const require_base_addon = require("../../base-addon-BG7p06Hb.js");
|
|
8
8
|
const require_scoped_settings = require("../../scoped-settings-CylSSq_8.js");
|
|
9
|
-
const require_rename_composition_block = require("../../rename-composition-block-
|
|
9
|
+
const require_rename_composition_block = require("../../rename-composition-block-C60O0P16.js");
|
|
10
10
|
const require_camstack_error = require("../../camstack-error-DJ-TUAi1.js");
|
|
11
11
|
const require_capability_definition = require("../../capability-definition-BEVd01Xj.js");
|
|
12
12
|
const require_zod_secret = require("../../zod-secret-DS7mj1bk.js");
|
|
13
|
-
const require_device_manager_cap = require("../../device-manager.cap-
|
|
13
|
+
const require_device_manager_cap = require("../../device-manager.cap-B9qVf7ag.js");
|
|
14
14
|
const require_device_identifiers = require("../../device-identifiers-BQg9EQi1.js");
|
|
15
|
-
const
|
|
15
|
+
const require_record_kinds = require("../../record-kinds-BV8Gcpsx.js");
|
|
16
|
+
const require_migration = require("../../migration-CHPdAdNh.js");
|
|
17
|
+
const require_tag = require("../../tag-BLraBqvp.js");
|
|
16
18
|
const require_device_type = require("../../device-type-Cnc0NiSX.js");
|
|
17
19
|
const require_device_kind = require("../../device-kind-FMhJg8uC.js");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
20
|
+
const require_core_blocks_cap = require("../../core-blocks.cap-DEYCvF9J.js");
|
|
21
|
+
const require_action_index = require("../../action-index-Bcnb-jyg.js");
|
|
22
|
+
const require_addon_settings_cap = require("../../addon-settings.cap-nZVHPo3X.js");
|
|
21
23
|
require("../../compile-SpeAhaZ6.js");
|
|
22
24
|
const require_source_info = require("../../source-info-DtWf4k2j.js");
|
|
23
|
-
const
|
|
24
|
-
const require_command_catalog = require("../../command-catalog-
|
|
25
|
+
const require_named_entity_store = require("../../named-entity-store-O_hi1y_o.js");
|
|
26
|
+
const require_command_catalog = require("../../command-catalog-A_ONlLfF.js");
|
|
25
27
|
const require_read_all_rows$1 = require("../../read-all-rows-CVoO1ONM.js");
|
|
26
28
|
const require_log_redactor = require("../../log-redactor-BhIEMaG9.js");
|
|
27
29
|
const require_prefix_range = require("../../prefix-range-D_KueXbQ.js");
|
|
28
30
|
const require_retired_settings_keys = require("../../retired-settings-keys-C8nOOr5H.js");
|
|
29
|
-
const require_device_row_store = require("../../device-row-store-C0P2H18h.js");
|
|
30
31
|
const require_template_protocol = require("../../template-protocol-D5ogm1rj.js");
|
|
31
32
|
const require_dns_wire = require("../../dns-wire-B1BvF9Ao.js");
|
|
32
33
|
let zod = require("zod");
|
|
@@ -1253,6 +1254,27 @@ var METHOD_ACCESS_MAP = /* @__PURE__ */ Object.freeze({
|
|
|
1253
1254
|
access: "view",
|
|
1254
1255
|
role: "viewer"
|
|
1255
1256
|
},
|
|
1257
|
+
"apps.getNavBadges": {
|
|
1258
|
+
capName: "apps",
|
|
1259
|
+
capScope: "system",
|
|
1260
|
+
addonId: null,
|
|
1261
|
+
access: "view",
|
|
1262
|
+
role: "viewer"
|
|
1263
|
+
},
|
|
1264
|
+
"apps.listApps": {
|
|
1265
|
+
capName: "apps",
|
|
1266
|
+
capScope: "system",
|
|
1267
|
+
addonId: null,
|
|
1268
|
+
access: "view",
|
|
1269
|
+
role: "viewer"
|
|
1270
|
+
},
|
|
1271
|
+
"appSource.listApps": {
|
|
1272
|
+
capName: "app-source",
|
|
1273
|
+
capScope: "system",
|
|
1274
|
+
addonId: null,
|
|
1275
|
+
access: "view",
|
|
1276
|
+
role: "admin"
|
|
1277
|
+
},
|
|
1256
1278
|
"audioAnalysis.applyDeviceSettingsPatch": {
|
|
1257
1279
|
capName: "audio-analysis",
|
|
1258
1280
|
capScope: "device",
|
|
@@ -2947,6 +2969,13 @@ var METHOD_ACCESS_MAP = /* @__PURE__ */ Object.freeze({
|
|
|
2947
2969
|
access: "create",
|
|
2948
2970
|
role: "admin"
|
|
2949
2971
|
},
|
|
2972
|
+
"deviceManager.deleteRoom": {
|
|
2973
|
+
capName: "device-manager",
|
|
2974
|
+
capScope: "system",
|
|
2975
|
+
addonId: null,
|
|
2976
|
+
access: "delete",
|
|
2977
|
+
role: "admin"
|
|
2978
|
+
},
|
|
2950
2979
|
"deviceManager.disable": {
|
|
2951
2980
|
capName: "device-manager",
|
|
2952
2981
|
capScope: "system",
|
|
@@ -3003,6 +3032,13 @@ var METHOD_ACCESS_MAP = /* @__PURE__ */ Object.freeze({
|
|
|
3003
3032
|
access: "create",
|
|
3004
3033
|
role: "admin"
|
|
3005
3034
|
},
|
|
3035
|
+
"deviceManager.ensureRoom": {
|
|
3036
|
+
capName: "device-manager",
|
|
3037
|
+
capScope: "system",
|
|
3038
|
+
addonId: null,
|
|
3039
|
+
access: "create",
|
|
3040
|
+
role: "admin"
|
|
3041
|
+
},
|
|
3006
3042
|
"deviceManager.getAllBindings": {
|
|
3007
3043
|
capName: "device-manager",
|
|
3008
3044
|
capScope: "system",
|
|
@@ -3227,6 +3263,13 @@ var METHOD_ACCESS_MAP = /* @__PURE__ */ Object.freeze({
|
|
|
3227
3263
|
access: "view",
|
|
3228
3264
|
role: "admin"
|
|
3229
3265
|
},
|
|
3266
|
+
"deviceManager.listRooms": {
|
|
3267
|
+
capName: "device-manager",
|
|
3268
|
+
capScope: "system",
|
|
3269
|
+
addonId: null,
|
|
3270
|
+
access: "view",
|
|
3271
|
+
role: "viewer"
|
|
3272
|
+
},
|
|
3230
3273
|
"deviceManager.listSiteZones": {
|
|
3231
3274
|
capName: "device-manager",
|
|
3232
3275
|
capScope: "system",
|
|
@@ -3367,6 +3410,13 @@ var METHOD_ACCESS_MAP = /* @__PURE__ */ Object.freeze({
|
|
|
3367
3410
|
access: "view",
|
|
3368
3411
|
role: "admin"
|
|
3369
3412
|
},
|
|
3413
|
+
"deviceManager.repairMigrationSecrets": {
|
|
3414
|
+
capName: "device-manager",
|
|
3415
|
+
capScope: "system",
|
|
3416
|
+
addonId: null,
|
|
3417
|
+
access: "create",
|
|
3418
|
+
role: "admin"
|
|
3419
|
+
},
|
|
3370
3420
|
"deviceManager.reportDiscoveryObservations": {
|
|
3371
3421
|
capName: "device-manager",
|
|
3372
3422
|
capScope: "system",
|
|
@@ -3598,6 +3648,13 @@ var METHOD_ACCESS_MAP = /* @__PURE__ */ Object.freeze({
|
|
|
3598
3648
|
access: "create",
|
|
3599
3649
|
role: "admin"
|
|
3600
3650
|
},
|
|
3651
|
+
"deviceManager.updateRoom": {
|
|
3652
|
+
capName: "device-manager",
|
|
3653
|
+
capScope: "system",
|
|
3654
|
+
addonId: null,
|
|
3655
|
+
access: "create",
|
|
3656
|
+
role: "admin"
|
|
3657
|
+
},
|
|
3601
3658
|
"deviceOps.getConfigEntries": {
|
|
3602
3659
|
capName: "device-ops",
|
|
3603
3660
|
capScope: "device",
|
|
@@ -10444,6 +10501,20 @@ var METHOD_ACCESS_MAP = /* @__PURE__ */ Object.freeze({
|
|
|
10444
10501
|
access: "create",
|
|
10445
10502
|
role: "admin"
|
|
10446
10503
|
},
|
|
10504
|
+
"tags.deleteTag": {
|
|
10505
|
+
capName: "tags",
|
|
10506
|
+
capScope: "system",
|
|
10507
|
+
addonId: null,
|
|
10508
|
+
access: "delete",
|
|
10509
|
+
role: "admin"
|
|
10510
|
+
},
|
|
10511
|
+
"tags.ensureTag": {
|
|
10512
|
+
capName: "tags",
|
|
10513
|
+
capScope: "system",
|
|
10514
|
+
addonId: null,
|
|
10515
|
+
access: "create",
|
|
10516
|
+
role: "admin"
|
|
10517
|
+
},
|
|
10447
10518
|
"tags.list": {
|
|
10448
10519
|
capName: "tags",
|
|
10449
10520
|
capScope: "system",
|
|
@@ -10451,6 +10522,13 @@ var METHOD_ACCESS_MAP = /* @__PURE__ */ Object.freeze({
|
|
|
10451
10522
|
access: "view",
|
|
10452
10523
|
role: "admin"
|
|
10453
10524
|
},
|
|
10525
|
+
"tags.listTags": {
|
|
10526
|
+
capName: "tags",
|
|
10527
|
+
capScope: "system",
|
|
10528
|
+
addonId: null,
|
|
10529
|
+
access: "view",
|
|
10530
|
+
role: "admin"
|
|
10531
|
+
},
|
|
10454
10532
|
"tags.remove": {
|
|
10455
10533
|
capName: "tags",
|
|
10456
10534
|
capScope: "system",
|
|
@@ -10472,6 +10550,13 @@ var METHOD_ACCESS_MAP = /* @__PURE__ */ Object.freeze({
|
|
|
10472
10550
|
access: "create",
|
|
10473
10551
|
role: "admin"
|
|
10474
10552
|
},
|
|
10553
|
+
"tags.updateTag": {
|
|
10554
|
+
capName: "tags",
|
|
10555
|
+
capScope: "system",
|
|
10556
|
+
addonId: null,
|
|
10557
|
+
access: "create",
|
|
10558
|
+
role: "admin"
|
|
10559
|
+
},
|
|
10475
10560
|
"tamper.getStatus": {
|
|
10476
10561
|
capName: "tamper",
|
|
10477
10562
|
capScope: "device",
|
|
@@ -12519,97 +12604,622 @@ function resolveCommandHold(cap, method, args, current, option, shown = current)
|
|
|
12519
12604
|
};
|
|
12520
12605
|
}
|
|
12521
12606
|
//#endregion
|
|
12522
|
-
//#region src/builtins/device-manager/
|
|
12523
|
-
/**
|
|
12524
|
-
|
|
12525
|
-
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
|
|
12533
|
-
|
|
12534
|
-
|
|
12535
|
-
|
|
12536
|
-
|
|
12537
|
-
|
|
12607
|
+
//#region src/builtins/device-manager/migrations/device-tag-ids.ts
|
|
12608
|
+
/**
|
|
12609
|
+
* A device row gets the ids of its tags (D1089, the device-manager step of the tags
|
|
12610
|
+
* migration): `tagIds` is added beside the kept `tags` names, aligned by index, with each id
|
|
12611
|
+
* derived from the folded name (`tagIdFromKey`) so every owner of that name mints the same
|
|
12612
|
+
* one. The names stay for one release; the `tags` records are written later by the
|
|
12613
|
+
* core-blocks tags-as-records procedure, which `dependsOn` this step.
|
|
12614
|
+
*
|
|
12615
|
+
* ONE plan, one transaction. A row that already has `tagIds` is left alone (a rerun is
|
|
12616
|
+
* empty); a row whose names repeat one tag in two spellings is rewritten with both columns
|
|
12617
|
+
* de-duplicated, so the index alignment holds.
|
|
12618
|
+
*/
|
|
12619
|
+
var DEVICE_TAG_IDS_ID = "device-manager/2026-11-23-device-tag-ids";
|
|
12620
|
+
async function planDeviceTagIds(ports) {
|
|
12621
|
+
const rows = await ports.readDeviceTags();
|
|
12622
|
+
const edits = [];
|
|
12623
|
+
for (const row of rows) {
|
|
12624
|
+
if (row.hasTagIds) continue;
|
|
12625
|
+
const names = require_tag.normalizeTags(row.tags);
|
|
12626
|
+
if (names.length === 0) continue;
|
|
12627
|
+
const sameNames = names.length === row.tags.length;
|
|
12628
|
+
edits.push({
|
|
12629
|
+
op: "putRow",
|
|
12630
|
+
table: require_record_kinds.DEVICE_ROWS_COLLECTION,
|
|
12631
|
+
key: { deviceId: row.deviceId },
|
|
12632
|
+
row: {
|
|
12633
|
+
tagIds: names.map((name) => require_named_entity_store.tagIdFromKey(require_tag.tagKey(name))),
|
|
12634
|
+
...sameNames ? {} : { tags: names }
|
|
12635
|
+
},
|
|
12636
|
+
preconditionColumns: ["tagIds"],
|
|
12637
|
+
precondition: require_migration.preconditionOf({ tagIds: null })
|
|
12638
|
+
});
|
|
12639
|
+
}
|
|
12640
|
+
return { edits };
|
|
12641
|
+
}
|
|
12642
|
+
//#endregion
|
|
12643
|
+
//#region src/builtins/device-manager/migrations/orphan-children.ts
|
|
12644
|
+
/** The rows that name a parent no row answers to. */
|
|
12645
|
+
function orphansOf(rows) {
|
|
12646
|
+
const ids = new Set(rows.map((r) => r.id));
|
|
12647
|
+
return rows.filter((r) => r.parentDeviceId !== null && !ids.has(r.parentDeviceId));
|
|
12648
|
+
}
|
|
12649
|
+
/**
|
|
12650
|
+
* Destructive on one read is never enough (D49): a row is removed only when TWO
|
|
12651
|
+
* reads agree it is an orphan, and nothing is removed from a read that may have
|
|
12652
|
+
* been cut short at the row limit. The candidate ids are recorded in the summary
|
|
12653
|
+
* and the log BEFORE any removal.
|
|
12654
|
+
*/
|
|
12655
|
+
async function removeOrphanChildren(ports) {
|
|
12656
|
+
const first = await ports.listRows();
|
|
12657
|
+
if (first.length >= ports.rowLimit) throw new Error(`device-manager: ${first.length} rows read, the limit is ${ports.rowLimit} — the read may be truncated, nothing removed`);
|
|
12658
|
+
const candidates = orphansOf(first);
|
|
12659
|
+
if (candidates.length === 0) return {
|
|
12660
|
+
outcome: "already-done",
|
|
12661
|
+
summary: {
|
|
12662
|
+
candidates: [],
|
|
12663
|
+
removed: []
|
|
12664
|
+
}
|
|
12665
|
+
};
|
|
12666
|
+
const second = await ports.listRows();
|
|
12667
|
+
const stillOrphans = new Set(orphansOf(second).map((r) => r.id));
|
|
12668
|
+
const confirmed = candidates.filter((r) => stillOrphans.has(r.id));
|
|
12669
|
+
const candidateIds = candidates.map((r) => r.id);
|
|
12670
|
+
ports.summary({
|
|
12671
|
+
rows: first.length,
|
|
12672
|
+
candidateCount: candidateIds.length,
|
|
12673
|
+
candidates: candidateIds,
|
|
12674
|
+
confirmedCount: confirmed.length,
|
|
12675
|
+
confirmed: confirmed.map((r) => r.id)
|
|
12676
|
+
});
|
|
12677
|
+
const removed = [];
|
|
12678
|
+
for (const orphan of confirmed) {
|
|
12679
|
+
if (orphan.parentDeviceId === null) continue;
|
|
12680
|
+
ports.info("device-manager: removing an orphan child, its parent no longer exists", orphan.id, orphan.parentDeviceId);
|
|
12681
|
+
await ports.removeDevice(orphan.id);
|
|
12682
|
+
removed.push(orphan.id);
|
|
12538
12683
|
}
|
|
12539
12684
|
return {
|
|
12540
|
-
|
|
12541
|
-
|
|
12542
|
-
|
|
12543
|
-
|
|
12544
|
-
|
|
12545
|
-
processed,
|
|
12546
|
-
adopted,
|
|
12547
|
-
alreadyAdopted,
|
|
12548
|
-
failed,
|
|
12549
|
-
accessoriesCreated,
|
|
12550
|
-
currentChildNativeId: j.currentChildNativeId,
|
|
12551
|
-
results: j.results.map((r) => ({
|
|
12552
|
-
childNativeId: r.childNativeId,
|
|
12553
|
-
outcome: r.outcome,
|
|
12554
|
-
parentDeviceId: r.parentDeviceId,
|
|
12555
|
-
accessoryCount: r.accessoryCount,
|
|
12556
|
-
error: r.error
|
|
12557
|
-
})),
|
|
12558
|
-
startedAt: j.startedAt,
|
|
12559
|
-
finishedAt: j.finishedAt,
|
|
12560
|
-
error: j.error
|
|
12685
|
+
outcome: "done",
|
|
12686
|
+
summary: {
|
|
12687
|
+
candidates: candidateIds,
|
|
12688
|
+
removed
|
|
12689
|
+
}
|
|
12561
12690
|
};
|
|
12562
12691
|
}
|
|
12563
|
-
|
|
12564
|
-
|
|
12565
|
-
|
|
12566
|
-
|
|
12567
|
-
|
|
12568
|
-
|
|
12569
|
-
|
|
12570
|
-
|
|
12571
|
-
|
|
12692
|
+
//#endregion
|
|
12693
|
+
//#region src/builtins/device-manager/device-meta-types.ts
|
|
12694
|
+
/**
|
|
12695
|
+
* Decode the raw `ctx.settings.readAddonStore()` record into {@link AddonStore}.
|
|
12696
|
+
*
|
|
12697
|
+
* A field of the wrong shape reads as ABSENT rather than being trusted through
|
|
12698
|
+
* a cast: the store is JSON on disk and a hand-edit or a partial restore must
|
|
12699
|
+
* cost the caller its default, never a downstream `TypeError`.
|
|
12700
|
+
*/
|
|
12701
|
+
function decodeAddonStore(raw) {
|
|
12702
|
+
const nextDeviceId = raw["nextDeviceId"];
|
|
12703
|
+
const locations = raw["locations"];
|
|
12704
|
+
const roleDisplayDefaults = raw["roleDisplayDefaults"];
|
|
12705
|
+
const locationIcons = decodeLocationIcons(raw["locationIcons"]);
|
|
12706
|
+
const locationDescriptions = decodeLocationDescriptions(raw["locationDescriptions"]);
|
|
12707
|
+
const siteZones = decodeSiteZones(raw["siteZones"]);
|
|
12708
|
+
const locationZones = decodeStringMap(raw["locationZones"]);
|
|
12709
|
+
return {
|
|
12710
|
+
...typeof nextDeviceId === "number" && Number.isFinite(nextDeviceId) ? { nextDeviceId } : {},
|
|
12711
|
+
...Array.isArray(locations) ? { locations: locations.filter((l) => typeof l === "string") } : {},
|
|
12712
|
+
...isRoleDisplayDefaults(roleDisplayDefaults) ? { roleDisplayDefaults } : {},
|
|
12713
|
+
...locationIcons !== null ? { locationIcons } : {},
|
|
12714
|
+
...locationDescriptions !== null ? { locationDescriptions } : {},
|
|
12715
|
+
...siteZones !== null ? { siteZones } : {},
|
|
12716
|
+
...locationZones !== null ? { locationZones } : {}
|
|
12717
|
+
};
|
|
12718
|
+
}
|
|
12719
|
+
/**
|
|
12720
|
+
* Decode the `locationIcons` map, dropping every entry whose value is not a
|
|
12721
|
+
* member of the closed vocabulary.
|
|
12722
|
+
*
|
|
12723
|
+
* Dropping, not passing through: the icon's whole point is that both surfaces
|
|
12724
|
+
* can draw it, and an id from a hand-edit or a newer hub is exactly the value
|
|
12725
|
+
* that draws nothing. Absent reads as "no icon chosen", which every renderer
|
|
12726
|
+
* already degrades to the fallback pin. Returns `null` when the key itself is
|
|
12727
|
+
* absent or of the wrong shape, so the field stays OMITTED rather than being
|
|
12728
|
+
* written back as an empty object.
|
|
12729
|
+
*/
|
|
12730
|
+
function decodeLocationIcons(raw) {
|
|
12731
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
12732
|
+
const out = {};
|
|
12733
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
12734
|
+
const icon = require_tag.canonicalIconKey(value);
|
|
12735
|
+
if (icon === void 0) continue;
|
|
12736
|
+
out[key] = icon;
|
|
12572
12737
|
}
|
|
12573
|
-
|
|
12574
|
-
|
|
12575
|
-
|
|
12576
|
-
|
|
12738
|
+
return out;
|
|
12739
|
+
}
|
|
12740
|
+
/**
|
|
12741
|
+
* Decode the `locationDescriptions` map, dropping every entry that is not a
|
|
12742
|
+
* non-blank string.
|
|
12743
|
+
*
|
|
12744
|
+
* Same posture as the icons: a blank description and a missing one are the
|
|
12745
|
+
* same instruction to every reader, and storing the first would send an empty
|
|
12746
|
+
* line to a vision model. Over-long text is TRUNCATED rather than dropped —
|
|
12747
|
+
* losing the whole description because a hand-edit ran long is a worse answer
|
|
12748
|
+
* than losing its tail.
|
|
12749
|
+
*/
|
|
12750
|
+
function decodeLocationDescriptions(raw) {
|
|
12751
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
12752
|
+
const out = {};
|
|
12753
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
12754
|
+
if (typeof value !== "string") continue;
|
|
12755
|
+
const text = value.trim();
|
|
12756
|
+
if (text.length === 0) continue;
|
|
12757
|
+
out[key] = text.slice(0, 400);
|
|
12577
12758
|
}
|
|
12578
|
-
|
|
12579
|
-
|
|
12580
|
-
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
12590
|
-
|
|
12591
|
-
|
|
12592
|
-
|
|
12593
|
-
|
|
12594
|
-
|
|
12595
|
-
|
|
12596
|
-
|
|
12597
|
-
|
|
12759
|
+
return out;
|
|
12760
|
+
}
|
|
12761
|
+
/**
|
|
12762
|
+
* Decode the zone registry, dropping any entry without a usable label.
|
|
12763
|
+
*
|
|
12764
|
+
* A zone whose label did not survive a hand-edit cannot be shown or renamed —
|
|
12765
|
+
* it would be a row the operator can see the effects of and never name. An
|
|
12766
|
+
* icon outside the vocabulary is dropped on its own, leaving the zone: losing
|
|
12767
|
+
* a glyph is a smaller loss than losing the grouping.
|
|
12768
|
+
*/
|
|
12769
|
+
function decodeSiteZones(raw) {
|
|
12770
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
12771
|
+
const out = {};
|
|
12772
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
12773
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) continue;
|
|
12774
|
+
const rec = value;
|
|
12775
|
+
const label = typeof rec["label"] === "string" ? rec["label"].trim() : "";
|
|
12776
|
+
if (label.length === 0) continue;
|
|
12777
|
+
const icon = require_tag.canonicalIconKey(rec["icon"]);
|
|
12778
|
+
out[key] = icon === void 0 ? { label } : {
|
|
12779
|
+
label,
|
|
12780
|
+
icon
|
|
12598
12781
|
};
|
|
12599
|
-
this.jobs.set(job.jobId, job);
|
|
12600
|
-
this.prune(input.addonId, input.integrationId);
|
|
12601
|
-
this.deps.logger.info("adoption job started", {
|
|
12602
|
-
tags: { addonId: input.addonId },
|
|
12603
|
-
meta: {
|
|
12604
|
-
jobId: job.jobId,
|
|
12605
|
-
integrationId: input.integrationId,
|
|
12606
|
-
total: job.total
|
|
12607
|
-
}
|
|
12608
|
-
});
|
|
12609
|
-
job.done = this.run(job, provider, input);
|
|
12610
|
-
return { jobId: job.jobId };
|
|
12611
12782
|
}
|
|
12612
|
-
|
|
12783
|
+
return out;
|
|
12784
|
+
}
|
|
12785
|
+
/** Decode a plain `string → string` map, dropping anything else. */
|
|
12786
|
+
function decodeStringMap(raw) {
|
|
12787
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
12788
|
+
const out = {};
|
|
12789
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
12790
|
+
if (typeof value !== "string" || value.trim().length === 0) continue;
|
|
12791
|
+
out[key] = value;
|
|
12792
|
+
}
|
|
12793
|
+
return out;
|
|
12794
|
+
}
|
|
12795
|
+
function isRoleDisplayDefaults(value) {
|
|
12796
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
12797
|
+
}
|
|
12798
|
+
//#endregion
|
|
12799
|
+
//#region src/builtins/device-manager/migrations/rooms-as-records.ts
|
|
12800
|
+
/**
|
|
12801
|
+
* Rooms and site zones become records with an id (D1089, step 1 of the migration).
|
|
12802
|
+
*
|
|
12803
|
+
* Before: a room was a LABEL. The registry (`locations`), its icon and description maps
|
|
12804
|
+
* and the two zone maps (`siteZones`, `locationZones`) lived as keys of the addon store,
|
|
12805
|
+
* and a device carried the label in its `location` column.
|
|
12806
|
+
*
|
|
12807
|
+
* After: one `rooms` record per label and one `zones` record per site zone, with an id
|
|
12808
|
+
* derived from the folded name (`roomIdFromKey` / `zoneIdFromKey`, so a rerun and a
|
|
12809
|
+
* restored older snapshot reach the same ids); a device carries `locationId`; the maps and
|
|
12810
|
+
* the `location` column are gone.
|
|
12811
|
+
*
|
|
12812
|
+
* ONE plan, so ONE transaction with the ledger row: the records, the device rows and the
|
|
12813
|
+
* deleted keys land together or not at all. A rerun finds no legacy key and no device with
|
|
12814
|
+
* a `location`, and the plan is empty. A record that already exists is never rewritten (a
|
|
12815
|
+
* seed never overwrites): a room an operator edited after a partial restore keeps its edit.
|
|
12816
|
+
*
|
|
12817
|
+
* The display spelling is the registry's, else the one most devices use (the first
|
|
12818
|
+
* alphabetically on a tie), else the folded key a map entry carries.
|
|
12819
|
+
*/
|
|
12820
|
+
var DEVICE_MANAGER_ID = "device-manager";
|
|
12821
|
+
var ROOMS_AS_RECORDS_ID = "device-manager/2026-11-23-rooms-as-records";
|
|
12822
|
+
/** The canonical settings table: one row per key, id `<addonId>.<key>`. */
|
|
12823
|
+
var ADDON_SETTINGS_TABLE = "addon-settings";
|
|
12824
|
+
/** The addon-store keys this migration retires. */
|
|
12825
|
+
var LEGACY_ROOM_KEYS = [
|
|
12826
|
+
"locations",
|
|
12827
|
+
"locationIcons",
|
|
12828
|
+
"locationDescriptions",
|
|
12829
|
+
"siteZones",
|
|
12830
|
+
"locationZones"
|
|
12831
|
+
];
|
|
12832
|
+
var isPlainMap = (raw) => raw !== null && typeof raw === "object" && !Array.isArray(raw);
|
|
12833
|
+
/** The entries the decode drops or shortens, raw, before the keys are deleted. */
|
|
12834
|
+
function droppedLegacyEntries(stored) {
|
|
12835
|
+
const out = [];
|
|
12836
|
+
const icons = stored["locationIcons"];
|
|
12837
|
+
if (isPlainMap(icons)) {
|
|
12838
|
+
for (const [key, value] of Object.entries(icons)) if (require_tag.canonicalIconKey(value) === void 0) out.push({
|
|
12839
|
+
map: "locationIcons",
|
|
12840
|
+
key,
|
|
12841
|
+
reason: "icon not in the catalogue",
|
|
12842
|
+
value
|
|
12843
|
+
});
|
|
12844
|
+
}
|
|
12845
|
+
const descriptions = stored["locationDescriptions"];
|
|
12846
|
+
if (isPlainMap(descriptions)) {
|
|
12847
|
+
for (const [key, value] of Object.entries(descriptions)) if (typeof value !== "string" || value.trim().length === 0) out.push({
|
|
12848
|
+
map: "locationDescriptions",
|
|
12849
|
+
key,
|
|
12850
|
+
reason: "blank description",
|
|
12851
|
+
value
|
|
12852
|
+
});
|
|
12853
|
+
else if (value.trim().length > 400) out.push({
|
|
12854
|
+
map: "locationDescriptions",
|
|
12855
|
+
key,
|
|
12856
|
+
reason: "description truncated",
|
|
12857
|
+
value
|
|
12858
|
+
});
|
|
12859
|
+
}
|
|
12860
|
+
const zones = stored["siteZones"];
|
|
12861
|
+
if (isPlainMap(zones)) {
|
|
12862
|
+
for (const [key, value] of Object.entries(zones)) if ((isPlainMap(value) && typeof value["label"] === "string" ? value["label"].trim() : "").length === 0) out.push({
|
|
12863
|
+
map: "siteZones",
|
|
12864
|
+
key,
|
|
12865
|
+
reason: "zone without a label",
|
|
12866
|
+
value
|
|
12867
|
+
});
|
|
12868
|
+
else if (isPlainMap(value) && value["icon"] !== void 0 && require_tag.canonicalIconKey(value["icon"]) === void 0) out.push({
|
|
12869
|
+
map: "siteZones",
|
|
12870
|
+
key,
|
|
12871
|
+
reason: "zone icon not in the catalogue",
|
|
12872
|
+
value
|
|
12873
|
+
});
|
|
12874
|
+
}
|
|
12875
|
+
const membership = stored["locationZones"];
|
|
12876
|
+
if (isPlainMap(membership)) {
|
|
12877
|
+
for (const [key, value] of Object.entries(membership)) if (typeof value !== "string" || value.trim().length === 0) out.push({
|
|
12878
|
+
map: "locationZones",
|
|
12879
|
+
key,
|
|
12880
|
+
reason: "blank zone",
|
|
12881
|
+
value
|
|
12882
|
+
});
|
|
12883
|
+
else if (!isPlainMap(zones) || zones[value] === void 0) out.push({
|
|
12884
|
+
map: "locationZones",
|
|
12885
|
+
key,
|
|
12886
|
+
reason: "zone not in the registry",
|
|
12887
|
+
value
|
|
12888
|
+
});
|
|
12889
|
+
}
|
|
12890
|
+
return out;
|
|
12891
|
+
}
|
|
12892
|
+
/** A map keyed by the FOLDED room key: a legacy key that was never folded still matches. */
|
|
12893
|
+
function foldedBy(map) {
|
|
12894
|
+
const out = /* @__PURE__ */ new Map();
|
|
12895
|
+
for (const [key, value] of Object.entries(map ?? {})) {
|
|
12896
|
+
const folded = require_addon_settings_cap.locationIconKey(key);
|
|
12897
|
+
if (folded.length > 0 && !out.has(folded)) out.set(folded, value);
|
|
12898
|
+
}
|
|
12899
|
+
return out;
|
|
12900
|
+
}
|
|
12901
|
+
var settingsRowId = (key) => `${DEVICE_MANAGER_ID}.${key}`;
|
|
12902
|
+
function clip(name) {
|
|
12903
|
+
return name.trim().slice(0, 80);
|
|
12904
|
+
}
|
|
12905
|
+
/** The spelling to show for each folded room key: registry first, else the most used on devices. */
|
|
12906
|
+
function spellings(registry, devices) {
|
|
12907
|
+
const out = /* @__PURE__ */ new Map();
|
|
12908
|
+
for (const label of registry) {
|
|
12909
|
+
const key = require_addon_settings_cap.locationIconKey(label);
|
|
12910
|
+
if (key.length > 0 && !out.has(key)) out.set(key, clip(label));
|
|
12911
|
+
}
|
|
12912
|
+
const used = /* @__PURE__ */ new Map();
|
|
12913
|
+
for (const { location } of devices) {
|
|
12914
|
+
if (location === null) continue;
|
|
12915
|
+
const key = require_addon_settings_cap.locationIconKey(location);
|
|
12916
|
+
if (key.length === 0) continue;
|
|
12917
|
+
const counts = used.get(key) ?? /* @__PURE__ */ new Map();
|
|
12918
|
+
counts.set(location.trim(), (counts.get(location.trim()) ?? 0) + 1);
|
|
12919
|
+
used.set(key, counts);
|
|
12920
|
+
}
|
|
12921
|
+
for (const [key, counts] of used) {
|
|
12922
|
+
if (out.has(key)) continue;
|
|
12923
|
+
const best = [...counts.entries()].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0];
|
|
12924
|
+
if (best !== void 0) out.set(key, clip(best[0]));
|
|
12925
|
+
}
|
|
12926
|
+
return out;
|
|
12927
|
+
}
|
|
12928
|
+
async function planRoomsAsRecords(ports) {
|
|
12929
|
+
const stored = await ports.readStored(LEGACY_ROOM_KEYS);
|
|
12930
|
+
const store = decodeAddonStore(stored);
|
|
12931
|
+
const devices = await ports.readDeviceLocations();
|
|
12932
|
+
const existingRooms = await ports.readRoomIds();
|
|
12933
|
+
const existingZones = await ports.readZoneIds();
|
|
12934
|
+
const names = spellings(store.locations ?? [], devices);
|
|
12935
|
+
for (const key of [
|
|
12936
|
+
...Object.keys(store.locationIcons ?? {}),
|
|
12937
|
+
...Object.keys(store.locationDescriptions ?? {}),
|
|
12938
|
+
...Object.keys(store.locationZones ?? {})
|
|
12939
|
+
]) {
|
|
12940
|
+
const folded = require_addon_settings_cap.locationIconKey(key);
|
|
12941
|
+
if (folded.length > 0 && !names.has(folded)) names.set(folded, clip(key));
|
|
12942
|
+
}
|
|
12943
|
+
const zones = store.siteZones ?? {};
|
|
12944
|
+
const membership = foldedBy(store.locationZones);
|
|
12945
|
+
const iconsByRoom = foldedBy(store.locationIcons);
|
|
12946
|
+
const descriptionsByRoom = foldedBy(store.locationDescriptions);
|
|
12947
|
+
const dropped = droppedLegacyEntries(stored);
|
|
12948
|
+
if (dropped.length > 0) {
|
|
12949
|
+
const counts = {};
|
|
12950
|
+
for (const entry of dropped) counts[entry.map] = (counts[entry.map] ?? 0) + 1;
|
|
12951
|
+
ports.report?.("rooms migration: legacy entries not carried over", {
|
|
12952
|
+
counts,
|
|
12953
|
+
dropped
|
|
12954
|
+
});
|
|
12955
|
+
}
|
|
12956
|
+
const edits = [];
|
|
12957
|
+
for (const [zoneKey, zone] of Object.entries(zones)) {
|
|
12958
|
+
const id = require_named_entity_store.zoneIdFromKey(zoneKey);
|
|
12959
|
+
if (existingZones.has(id)) continue;
|
|
12960
|
+
const body = {
|
|
12961
|
+
name: clip(zone.label),
|
|
12962
|
+
...zone.icon === void 0 ? {} : { icon: zone.icon }
|
|
12963
|
+
};
|
|
12964
|
+
edits.push(require_record_kinds.recordUpsertEdit({
|
|
12965
|
+
owner: DEVICE_MANAGER_ID,
|
|
12966
|
+
kind: require_record_kinds.deviceManagerRecordKinds.zones,
|
|
12967
|
+
id,
|
|
12968
|
+
data: body,
|
|
12969
|
+
read: null
|
|
12970
|
+
}));
|
|
12971
|
+
}
|
|
12972
|
+
for (const [key, name] of names) {
|
|
12973
|
+
const id = require_named_entity_store.roomIdFromKey(key);
|
|
12974
|
+
if (existingRooms.has(id)) continue;
|
|
12975
|
+
const icon = iconsByRoom.get(key);
|
|
12976
|
+
const description = descriptionsByRoom.get(key);
|
|
12977
|
+
const zoneKey = membership.get(key);
|
|
12978
|
+
const zoneId = zoneKey !== void 0 && zones[zoneKey] !== void 0 ? require_named_entity_store.zoneIdFromKey(zoneKey) : void 0;
|
|
12979
|
+
const body = {
|
|
12980
|
+
name,
|
|
12981
|
+
...icon === void 0 ? {} : { icon },
|
|
12982
|
+
...description === void 0 ? {} : { description },
|
|
12983
|
+
...zoneId === void 0 ? {} : { zoneId }
|
|
12984
|
+
};
|
|
12985
|
+
edits.push(require_record_kinds.recordUpsertEdit({
|
|
12986
|
+
owner: DEVICE_MANAGER_ID,
|
|
12987
|
+
kind: require_record_kinds.deviceManagerRecordKinds.rooms,
|
|
12988
|
+
id,
|
|
12989
|
+
data: body,
|
|
12990
|
+
read: null
|
|
12991
|
+
}));
|
|
12992
|
+
}
|
|
12993
|
+
for (const device of devices) {
|
|
12994
|
+
if (device.location === null) continue;
|
|
12995
|
+
const folded = require_addon_settings_cap.locationIconKey(device.location);
|
|
12996
|
+
const locationId = device.locationId ?? (folded.length === 0 ? null : require_named_entity_store.roomIdFromKey(folded));
|
|
12997
|
+
edits.push({
|
|
12998
|
+
op: "putRow",
|
|
12999
|
+
table: require_record_kinds.DEVICE_ROWS_COLLECTION,
|
|
13000
|
+
key: { deviceId: device.deviceId },
|
|
13001
|
+
row: {
|
|
13002
|
+
locationId,
|
|
13003
|
+
location: null
|
|
13004
|
+
},
|
|
13005
|
+
preconditionColumns: ["location", "locationId"],
|
|
13006
|
+
precondition: require_migration.preconditionOf({
|
|
13007
|
+
location: device.location,
|
|
13008
|
+
locationId: device.locationId
|
|
13009
|
+
})
|
|
13010
|
+
});
|
|
13011
|
+
}
|
|
13012
|
+
const present = LEGACY_ROOM_KEYS.filter((key) => key in stored);
|
|
13013
|
+
if (present.length > 0) edits.push({
|
|
13014
|
+
op: "deleteKeys",
|
|
13015
|
+
scope: ADDON_SETTINGS_TABLE,
|
|
13016
|
+
keys: present.map(settingsRowId),
|
|
13017
|
+
precondition: require_migration.preconditionOf(Object.fromEntries(present.map((key) => [settingsRowId(key), {
|
|
13018
|
+
addonId: DEVICE_MANAGER_ID,
|
|
13019
|
+
key,
|
|
13020
|
+
value: stored[key]
|
|
13021
|
+
}])))
|
|
13022
|
+
});
|
|
13023
|
+
return { edits };
|
|
13024
|
+
}
|
|
13025
|
+
//#endregion
|
|
13026
|
+
//#region src/builtins/device-manager/migrations/index.ts
|
|
13027
|
+
var REMOVE_ORPHAN_CHILDREN_ID = "device-manager/2026-11-23-remove-orphan-children";
|
|
13028
|
+
/** Rooms, zones and tag ids: run BEFORE the first read resolves a name (D1089). */
|
|
13029
|
+
var ROOMS_AND_TAGS_MIGRATIONS = [{
|
|
13030
|
+
meta: {
|
|
13031
|
+
id: ROOMS_AS_RECORDS_ID,
|
|
13032
|
+
owner: DEVICE_MANAGER_ID,
|
|
13033
|
+
level: "addon-state",
|
|
13034
|
+
seq: 1,
|
|
13035
|
+
dependsOn: [],
|
|
13036
|
+
store: "settings",
|
|
13037
|
+
scope: "cluster",
|
|
13038
|
+
onFailure: "tolerate",
|
|
13039
|
+
bodyKind: "plan",
|
|
13040
|
+
description: "Rooms and site zones become records with an id: one record per label, a locationId on each device, and the label maps and the location column deleted, in one transaction",
|
|
13041
|
+
fixtureMark: "a device column and a room icon the migration does not know"
|
|
13042
|
+
},
|
|
13043
|
+
plan: (ports) => planRoomsAsRecords(ports)
|
|
13044
|
+
}, {
|
|
13045
|
+
meta: {
|
|
13046
|
+
id: DEVICE_TAG_IDS_ID,
|
|
13047
|
+
owner: DEVICE_MANAGER_ID,
|
|
13048
|
+
level: "addon-state",
|
|
13049
|
+
seq: 2,
|
|
13050
|
+
dependsOn: [],
|
|
13051
|
+
store: "settings",
|
|
13052
|
+
scope: "cluster",
|
|
13053
|
+
onFailure: "tolerate",
|
|
13054
|
+
bodyKind: "plan",
|
|
13055
|
+
description: "Add the ids of its tags to each device row beside the kept names, derived from the folded name",
|
|
13056
|
+
fixtureMark: "a device column the migration does not know"
|
|
13057
|
+
},
|
|
13058
|
+
plan: (ports) => planDeviceTagIds(ports)
|
|
13059
|
+
}];
|
|
13060
|
+
/** Accessory rows left behind by a removal that did not cascade: run once the fleet is up (D987). */
|
|
13061
|
+
var ORPHAN_CHILDREN_MIGRATIONS = [{
|
|
13062
|
+
meta: {
|
|
13063
|
+
id: REMOVE_ORPHAN_CHILDREN_ID,
|
|
13064
|
+
owner: DEVICE_MANAGER_ID,
|
|
13065
|
+
level: "addon-state",
|
|
13066
|
+
seq: 3,
|
|
13067
|
+
dependsOn: [],
|
|
13068
|
+
store: "settings",
|
|
13069
|
+
scope: "cluster",
|
|
13070
|
+
onFailure: "tolerate",
|
|
13071
|
+
bodyKind: "procedure",
|
|
13072
|
+
description: "Remove every device row whose parentDeviceId names no row, through the tombstoned removal, each one logged",
|
|
13073
|
+
fixtureMark: "a child of a live parent and a top-level row, both kept"
|
|
13074
|
+
},
|
|
13075
|
+
procedure: removeOrphanChildren
|
|
13076
|
+
}];
|
|
13077
|
+
[...ROOMS_AND_TAGS_MIGRATIONS, ...ORPHAN_CHILDREN_MIGRATIONS];
|
|
13078
|
+
//#endregion
|
|
13079
|
+
//#region src/builtins/device-manager/migrations/ports.ts
|
|
13080
|
+
var import_read_all_rows = require_read_all_rows$1.require_read_all_rows();
|
|
13081
|
+
var stringOrNull = (value) => typeof value === "string" ? value : null;
|
|
13082
|
+
function stringArray(value) {
|
|
13083
|
+
return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
|
|
13084
|
+
}
|
|
13085
|
+
function deviceManagerMigrationPorts(source) {
|
|
13086
|
+
return {
|
|
13087
|
+
readStored: async (keys) => {
|
|
13088
|
+
const found = {};
|
|
13089
|
+
for (const key of keys) {
|
|
13090
|
+
const answer = await source.readStoredKey(key);
|
|
13091
|
+
if (answer.kind === "unreadable") throw new Error(`${DEVICE_MANAGER_ID}: the setting ${key} cannot be read (${answer.reason})`);
|
|
13092
|
+
if (answer.kind === "present") found[key] = answer.value;
|
|
13093
|
+
}
|
|
13094
|
+
return found;
|
|
13095
|
+
},
|
|
13096
|
+
readDeviceLocations: async () => {
|
|
13097
|
+
return (await source.rows.readRawColumns([
|
|
13098
|
+
"deviceId",
|
|
13099
|
+
"location",
|
|
13100
|
+
"locationId"
|
|
13101
|
+
])).flatMap((row) => {
|
|
13102
|
+
const deviceId = row["deviceId"];
|
|
13103
|
+
if (typeof deviceId !== "number") return [];
|
|
13104
|
+
return [{
|
|
13105
|
+
deviceId,
|
|
13106
|
+
location: stringOrNull(row["location"]),
|
|
13107
|
+
locationId: stringOrNull(row["locationId"])
|
|
13108
|
+
}];
|
|
13109
|
+
});
|
|
13110
|
+
},
|
|
13111
|
+
readDeviceTags: async () => {
|
|
13112
|
+
return (await source.rows.readRawColumns([
|
|
13113
|
+
"deviceId",
|
|
13114
|
+
"tags",
|
|
13115
|
+
"tagIds"
|
|
13116
|
+
])).flatMap((row) => {
|
|
13117
|
+
const deviceId = row["deviceId"];
|
|
13118
|
+
if (typeof deviceId !== "number") return [];
|
|
13119
|
+
return [{
|
|
13120
|
+
deviceId,
|
|
13121
|
+
tags: stringArray(row["tags"]),
|
|
13122
|
+
hasTagIds: row["tagIds"] !== null && row["tagIds"] !== void 0
|
|
13123
|
+
}];
|
|
13124
|
+
});
|
|
13125
|
+
},
|
|
13126
|
+
readRoomIds: async () => new Set((await (0, import_read_all_rows.readAllRows)(source.rooms)).map((row) => row.id)),
|
|
13127
|
+
readZoneIds: async () => new Set((await (0, import_read_all_rows.readAllRows)(source.zones)).map((row) => row.id)),
|
|
13128
|
+
...source.report === void 0 ? {} : { report: source.report }
|
|
13129
|
+
};
|
|
13130
|
+
}
|
|
13131
|
+
//#endregion
|
|
13132
|
+
//#region src/builtins/device-manager/adoption-job-engine.ts
|
|
13133
|
+
/** How many finished jobs are kept per (addonId, integrationId). */
|
|
13134
|
+
var JOB_HISTORY = 20;
|
|
13135
|
+
function snapshot(j) {
|
|
13136
|
+
let adopted = 0;
|
|
13137
|
+
let alreadyAdopted = 0;
|
|
13138
|
+
let failed = 0;
|
|
13139
|
+
let processed = 0;
|
|
13140
|
+
let accessoriesCreated = 0;
|
|
13141
|
+
for (const r of j.results) {
|
|
13142
|
+
if (r.outcome === "cancelled") continue;
|
|
13143
|
+
processed += 1;
|
|
13144
|
+
accessoriesCreated += r.accessoryCount;
|
|
13145
|
+
if (r.outcome === "adopted") adopted += 1;
|
|
13146
|
+
else if (r.outcome === "already-adopted") alreadyAdopted += 1;
|
|
13147
|
+
else if (r.outcome === "failed") failed += 1;
|
|
13148
|
+
}
|
|
13149
|
+
return {
|
|
13150
|
+
jobId: j.jobId,
|
|
13151
|
+
addonId: j.addonId,
|
|
13152
|
+
integrationId: j.integrationId,
|
|
13153
|
+
state: j.state,
|
|
13154
|
+
total: j.total,
|
|
13155
|
+
processed,
|
|
13156
|
+
adopted,
|
|
13157
|
+
alreadyAdopted,
|
|
13158
|
+
failed,
|
|
13159
|
+
accessoriesCreated,
|
|
13160
|
+
currentChildNativeId: j.currentChildNativeId,
|
|
13161
|
+
results: j.results.map((r) => ({
|
|
13162
|
+
childNativeId: r.childNativeId,
|
|
13163
|
+
outcome: r.outcome,
|
|
13164
|
+
parentDeviceId: r.parentDeviceId,
|
|
13165
|
+
accessoryCount: r.accessoryCount,
|
|
13166
|
+
error: r.error
|
|
13167
|
+
})),
|
|
13168
|
+
startedAt: j.startedAt,
|
|
13169
|
+
finishedAt: j.finishedAt,
|
|
13170
|
+
error: j.error
|
|
13171
|
+
};
|
|
13172
|
+
}
|
|
13173
|
+
var AdoptionJobEngine = class {
|
|
13174
|
+
deps;
|
|
13175
|
+
jobs = /* @__PURE__ */ new Map();
|
|
13176
|
+
seq = 0;
|
|
13177
|
+
constructor(deps) {
|
|
13178
|
+
this.deps = deps;
|
|
13179
|
+
}
|
|
13180
|
+
now() {
|
|
13181
|
+
return this.deps.now?.() ?? Date.now();
|
|
13182
|
+
}
|
|
13183
|
+
newId() {
|
|
13184
|
+
if (this.deps.newId) return this.deps.newId();
|
|
13185
|
+
this.seq += 1;
|
|
13186
|
+
return `adopt-${Date.now().toString(36)}-${this.seq}`;
|
|
13187
|
+
}
|
|
13188
|
+
/**
|
|
13189
|
+
* Accept the batch and return immediately. The provider is resolved BEFORE
|
|
13190
|
+
* returning so an unroutable `addonId` is refused at the call the operator
|
|
13191
|
+
* made, not buried in a job they have to go looking for.
|
|
13192
|
+
*/
|
|
13193
|
+
async start(input) {
|
|
13194
|
+
const provider = await this.deps.resolveProvider(input.addonId);
|
|
13195
|
+
const job = {
|
|
13196
|
+
jobId: this.newId(),
|
|
13197
|
+
addonId: input.addonId,
|
|
13198
|
+
integrationId: input.integrationId,
|
|
13199
|
+
state: "running",
|
|
13200
|
+
total: input.childNativeIds.length,
|
|
13201
|
+
currentChildNativeId: null,
|
|
13202
|
+
results: [],
|
|
13203
|
+
startedAt: this.now(),
|
|
13204
|
+
finishedAt: null,
|
|
13205
|
+
error: null,
|
|
13206
|
+
cancelRequested: false,
|
|
13207
|
+
done: Promise.resolve()
|
|
13208
|
+
};
|
|
13209
|
+
this.jobs.set(job.jobId, job);
|
|
13210
|
+
this.prune(input.addonId, input.integrationId);
|
|
13211
|
+
this.deps.logger.info("adoption job started", {
|
|
13212
|
+
tags: { addonId: input.addonId },
|
|
13213
|
+
meta: {
|
|
13214
|
+
jobId: job.jobId,
|
|
13215
|
+
integrationId: input.integrationId,
|
|
13216
|
+
total: job.total
|
|
13217
|
+
}
|
|
13218
|
+
});
|
|
13219
|
+
job.done = this.run(job, provider, input);
|
|
13220
|
+
return { jobId: job.jobId };
|
|
13221
|
+
}
|
|
13222
|
+
get(jobId) {
|
|
12613
13223
|
const j = this.jobs.get(jobId);
|
|
12614
13224
|
return j ? snapshot(j) : null;
|
|
12615
13225
|
}
|
|
@@ -13494,6 +14104,104 @@ function sleep(ms) {
|
|
|
13494
14104
|
});
|
|
13495
14105
|
}
|
|
13496
14106
|
//#endregion
|
|
14107
|
+
//#region src/builtins/device-manager/wireable-enum-catalog.ts
|
|
14108
|
+
/**
|
|
14109
|
+
* Per-device value catalogs for wireable fields (`status.fieldEnums` on a cap).
|
|
14110
|
+
*
|
|
14111
|
+
* A status field such as `error.code` or `event-emitter.lastEvent.eventType` is a
|
|
14112
|
+
* plain string in the schema, but the device's integration DECLARES the closed set
|
|
14113
|
+
* of values at runtime (`error.listFaultTypes`, the event vocabulary). This module
|
|
14114
|
+
* asks the device's own provider and returns the values the editor offers as a
|
|
14115
|
+
* dropdown. A read that fails answers `null` — the caller leaves `enumValues`
|
|
14116
|
+
* absent (free text stays) and logs; it is never an empty list (D393, D315).
|
|
14117
|
+
*/
|
|
14118
|
+
var RecordSchema = zod.z.record(zod.z.string(), zod.z.unknown());
|
|
14119
|
+
function isProviderShape(value) {
|
|
14120
|
+
return typeof value === "object" && value !== null;
|
|
14121
|
+
}
|
|
14122
|
+
function listOf(answer, source) {
|
|
14123
|
+
const record = RecordSchema.safeParse(answer);
|
|
14124
|
+
if (!record.success) return null;
|
|
14125
|
+
const list = zod.z.array(RecordSchema).safeParse(record.data[source.listKey]);
|
|
14126
|
+
if (!list.success) return null;
|
|
14127
|
+
const values = [];
|
|
14128
|
+
for (const entry of list.data) {
|
|
14129
|
+
const value = entry[source.valueKey];
|
|
14130
|
+
if (typeof value !== "string") return null;
|
|
14131
|
+
if (!values.includes(value)) values.push(value);
|
|
14132
|
+
}
|
|
14133
|
+
return values;
|
|
14134
|
+
}
|
|
14135
|
+
async function readAnswer(provider, source, deviceId) {
|
|
14136
|
+
const fn = provider[source.from === "method" ? source.method : "getStatus"];
|
|
14137
|
+
if (typeof fn !== "function") return void 0;
|
|
14138
|
+
return await Reflect.apply(fn, provider, [{ deviceId }]);
|
|
14139
|
+
}
|
|
14140
|
+
var TIMED_OUT = Symbol("catalog-read-timed-out");
|
|
14141
|
+
async function raceBudget(work, budgetMs) {
|
|
14142
|
+
let timer;
|
|
14143
|
+
const deadline = new Promise((resolve) => {
|
|
14144
|
+
timer = setTimeout(() => resolve(TIMED_OUT), budgetMs);
|
|
14145
|
+
timer.unref?.();
|
|
14146
|
+
});
|
|
14147
|
+
try {
|
|
14148
|
+
return await Promise.race([work, deadline]);
|
|
14149
|
+
} finally {
|
|
14150
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
14151
|
+
}
|
|
14152
|
+
}
|
|
14153
|
+
/**
|
|
14154
|
+
* The device's declared values for one field, or `null` when there are none to
|
|
14155
|
+
* offer. A provider without the catalog, a cold (null) slice or an empty catalog
|
|
14156
|
+
* is a quiet absence; a thrown read, a timeout or a malformed answer is warned
|
|
14157
|
+
* with the device tag. Either way the field stays free text.
|
|
14158
|
+
*/
|
|
14159
|
+
async function readFieldCatalog(read) {
|
|
14160
|
+
const { registry, logger, capName, deviceId, path, source, budgetMs } = read;
|
|
14161
|
+
try {
|
|
14162
|
+
const provider = registry.getProviderForDevice(capName, deviceId);
|
|
14163
|
+
if (!isProviderShape(provider)) return null;
|
|
14164
|
+
const answer = await raceBudget(readAnswer(provider, source, deviceId), budgetMs);
|
|
14165
|
+
if (answer === TIMED_OUT) {
|
|
14166
|
+
logger.warn("wireable field catalog: read timed out, field stays free text", {
|
|
14167
|
+
tags: { deviceId },
|
|
14168
|
+
meta: {
|
|
14169
|
+
deviceId,
|
|
14170
|
+
capName,
|
|
14171
|
+
path,
|
|
14172
|
+
budgetMs
|
|
14173
|
+
}
|
|
14174
|
+
});
|
|
14175
|
+
return null;
|
|
14176
|
+
}
|
|
14177
|
+
if (answer === void 0 || answer === null) return null;
|
|
14178
|
+
const values = listOf(answer, source);
|
|
14179
|
+
if (values === null) {
|
|
14180
|
+
logger.warn("wireable field catalog: answer has an unexpected shape", {
|
|
14181
|
+
tags: { deviceId },
|
|
14182
|
+
meta: {
|
|
14183
|
+
deviceId,
|
|
14184
|
+
capName,
|
|
14185
|
+
path
|
|
14186
|
+
}
|
|
14187
|
+
});
|
|
14188
|
+
return null;
|
|
14189
|
+
}
|
|
14190
|
+
return values.length > 0 ? values : null;
|
|
14191
|
+
} catch (err) {
|
|
14192
|
+
logger.warn("wireable field catalog: read failed, field stays free text", {
|
|
14193
|
+
tags: { deviceId },
|
|
14194
|
+
meta: {
|
|
14195
|
+
deviceId,
|
|
14196
|
+
capName,
|
|
14197
|
+
path,
|
|
14198
|
+
error: err instanceof Error ? err.message : String(err)
|
|
14199
|
+
}
|
|
14200
|
+
});
|
|
14201
|
+
return null;
|
|
14202
|
+
}
|
|
14203
|
+
}
|
|
14204
|
+
//#endregion
|
|
13497
14205
|
//#region src/builtins/device-manager/device-aggregation-merge.ts
|
|
13498
14206
|
/**
|
|
13499
14207
|
* Pure aggregator-merge + field-tagging helpers for the device-manager
|
|
@@ -13663,11 +14371,11 @@ function mergeAggregates(parts) {
|
|
|
13663
14371
|
* per-row path (`connection.password`, `rows[].pin`) is not mapped onto a form
|
|
13664
14372
|
* field and keeps the driver's hydration.
|
|
13665
14373
|
*/
|
|
13666
|
-
function isRecord$
|
|
14374
|
+
function isRecord$4(value) {
|
|
13667
14375
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13668
14376
|
}
|
|
13669
14377
|
function isConfigFieldWithValue(field) {
|
|
13670
|
-
if (!isRecord$
|
|
14378
|
+
if (!isRecord$4(field)) return false;
|
|
13671
14379
|
return typeof field.type === "string" && typeof field.key === "string" && "value" in field;
|
|
13672
14380
|
}
|
|
13673
14381
|
/** The declared paths that name a top-level config key. */
|
|
@@ -13675,7 +14383,7 @@ function topLevelKeys(paths) {
|
|
|
13675
14383
|
return new Set(paths.filter((p) => p.length > 0 && !p.includes(".") && !p.includes("[")));
|
|
13676
14384
|
}
|
|
13677
14385
|
function viewField(field, stored, declared) {
|
|
13678
|
-
if (!isRecord$
|
|
14386
|
+
if (!isRecord$4(field)) return field;
|
|
13679
14387
|
const nested = field["fields"];
|
|
13680
14388
|
if (Array.isArray(nested)) return {
|
|
13681
14389
|
...field,
|
|
@@ -13684,7 +14392,7 @@ function viewField(field, stored, declared) {
|
|
|
13684
14392
|
const tabs = field["tabs"];
|
|
13685
14393
|
if (Array.isArray(tabs)) return {
|
|
13686
14394
|
...field,
|
|
13687
|
-
tabs: tabs.map((tab) => isRecord$
|
|
14395
|
+
tabs: tabs.map((tab) => isRecord$4(tab) && Array.isArray(tab["fields"]) ? {
|
|
13688
14396
|
...tab,
|
|
13689
14397
|
fields: tab["fields"].map((f) => viewField(f, stored, declared))
|
|
13690
14398
|
} : tab)
|
|
@@ -13793,7 +14501,7 @@ function isDeclaredCollectionCap(capName) {
|
|
|
13793
14501
|
function isDeclaredNonWrapperCap(capName) {
|
|
13794
14502
|
return DECLARED_NON_WRAPPER_CAPS.has(capName);
|
|
13795
14503
|
}
|
|
13796
|
-
function isRecord$
|
|
14504
|
+
function isRecord$3(value) {
|
|
13797
14505
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13798
14506
|
}
|
|
13799
14507
|
/** A persisted activation of a wrapper on a cap that has none (see module docblock). */
|
|
@@ -13836,12 +14544,12 @@ var StaleWrapperActivations = class {
|
|
|
13836
14544
|
if (this.checked) return;
|
|
13837
14545
|
this.checked = true;
|
|
13838
14546
|
const devices = store.deviceBindings;
|
|
13839
|
-
if (!isRecord$
|
|
14547
|
+
if (!isRecord$3(devices)) return;
|
|
13840
14548
|
for (const [deviceKey, perDevice] of Object.entries(devices)) {
|
|
13841
14549
|
const deviceId = Number(deviceKey);
|
|
13842
|
-
if (!Number.isInteger(deviceId) || !isRecord$
|
|
14550
|
+
if (!Number.isInteger(deviceId) || !isRecord$3(perDevice)) continue;
|
|
13843
14551
|
for (const [capName, row] of Object.entries(perDevice)) {
|
|
13844
|
-
const wrapperAddonId = isRecord$
|
|
14552
|
+
const wrapperAddonId = isRecord$3(row) ? row["wrapperAddonId"] : void 0;
|
|
13845
14553
|
if (typeof wrapperAddonId === "string" && isDeclaredNonWrapperCap(capName)) this.report(deviceId, capName, wrapperAddonId);
|
|
13846
14554
|
}
|
|
13847
14555
|
}
|
|
@@ -15494,6 +16202,7 @@ async function readDeviceConfigs(pctx, deviceIds) {
|
|
|
15494
16202
|
return pctx.settings.readDeviceStoreBatch(deviceIds);
|
|
15495
16203
|
}
|
|
15496
16204
|
async function listAll(pctx, input) {
|
|
16205
|
+
await pctx.freshTagNames();
|
|
15497
16206
|
const ownerFilter = Reflect.get(input, "addonId");
|
|
15498
16207
|
if (ownerFilter !== void 0 && (typeof ownerFilter !== "string" || ownerFilter.length === 0)) throw new Error(`deviceManager.listAll: addonId must be a non-empty string or be omitted — got ${JSON.stringify(ownerFilter)}. An owner filter that is present but empty is never widened to every device. On an addon context the id is \`ctx.id\`; there is no \`ctx.addonId\`.`);
|
|
15499
16208
|
const callerAddonId = pctx.metaStore.rows.censusArmed ? extractCallerAddonId(input) : void 0;
|
|
@@ -15581,6 +16290,7 @@ async function listAll(pctx, input) {
|
|
|
15581
16290
|
}
|
|
15582
16291
|
async function getDevice(pctx, input) {
|
|
15583
16292
|
const { deviceId } = input;
|
|
16293
|
+
await pctx.freshTagNames();
|
|
15584
16294
|
if (pctx.registry) {
|
|
15585
16295
|
const found = resolveDeviceById(pctx.registry, deviceId);
|
|
15586
16296
|
if (found) {
|
|
@@ -17175,6 +17885,36 @@ function wireableEntryForDef(capName, def) {
|
|
|
17175
17885
|
};
|
|
17176
17886
|
}
|
|
17177
17887
|
/**
|
|
17888
|
+
* Fill `enumValues` of the fields the cap declares a per-device catalog for
|
|
17889
|
+
* (`status.fieldEnums`) from the device's own provider. A failed or empty read
|
|
17890
|
+
* leaves the field untouched (free text), never an empty list.
|
|
17891
|
+
*/
|
|
17892
|
+
async function withDeclaredCatalogs(deps, registry, deviceId, entry, def) {
|
|
17893
|
+
const declared = def.status?.fieldEnums;
|
|
17894
|
+
if (!declared) return entry;
|
|
17895
|
+
const fields = await Promise.all(entry.fields.map(async (field) => {
|
|
17896
|
+
const source = declared[field.path];
|
|
17897
|
+
if (!source || field.item === true) return field;
|
|
17898
|
+
const values = await readFieldCatalog({
|
|
17899
|
+
registry,
|
|
17900
|
+
logger: deps.ctx.logger,
|
|
17901
|
+
capName: entry.cap,
|
|
17902
|
+
deviceId,
|
|
17903
|
+
path: field.path,
|
|
17904
|
+
source,
|
|
17905
|
+
budgetMs: CONTRIBUTION_BUDGET_MS
|
|
17906
|
+
});
|
|
17907
|
+
return values === null ? field : {
|
|
17908
|
+
...field,
|
|
17909
|
+
enumValues: values
|
|
17910
|
+
};
|
|
17911
|
+
}));
|
|
17912
|
+
return {
|
|
17913
|
+
...entry,
|
|
17914
|
+
fields
|
|
17915
|
+
};
|
|
17916
|
+
}
|
|
17917
|
+
/**
|
|
17178
17918
|
* Per-device wireable-field catalog — the domain status fields a device's
|
|
17179
17919
|
* bound caps expose, for the operator's cross-device wiring UI. Binding-driven:
|
|
17180
17920
|
* walks `getBindings(deviceId)`, skips wrapper caps (their status schemas are
|
|
@@ -17195,14 +17935,19 @@ async function getWireableFields(deps, input) {
|
|
|
17195
17935
|
const { entries } = await getBindings(deps.bindingsDeps, { deviceId });
|
|
17196
17936
|
const seen = /* @__PURE__ */ new Set();
|
|
17197
17937
|
const caps = [];
|
|
17938
|
+
const pending = [];
|
|
17198
17939
|
for (const entry of entries) {
|
|
17199
17940
|
if (seen.has(entry.capName)) continue;
|
|
17200
17941
|
seen.add(entry.capName);
|
|
17201
17942
|
const def = reg.getDefinition(entry.capName);
|
|
17202
17943
|
if (!def || def.kind === "wrapper") continue;
|
|
17203
17944
|
const wireable = wireableEntryForDef(entry.capName, def);
|
|
17204
|
-
if (wireable)
|
|
17945
|
+
if (wireable) pending.push({
|
|
17946
|
+
wireable,
|
|
17947
|
+
def
|
|
17948
|
+
});
|
|
17205
17949
|
}
|
|
17950
|
+
caps.push(...await Promise.all(pending.map(({ wireable, def }) => withDeclaredCatalogs(deps, reg, deviceId, wireable, def))));
|
|
17206
17951
|
if (input.includeSynthesizable === true) {
|
|
17207
17952
|
const deviceType = (await deps.bindingsDeps.rows.get(deviceId))?.meta.type;
|
|
17208
17953
|
if (deviceType !== void 0) for (const def of require_rename_composition_block.ALL_CAPABILITY_DEFINITIONS) {
|
|
@@ -17400,8 +18145,9 @@ async function searchDevices(deps, input) {
|
|
|
17400
18145
|
let compatibleTotal = 0;
|
|
17401
18146
|
let hiddenIncompatible = 0;
|
|
17402
18147
|
const filters = input.filters;
|
|
18148
|
+
const locationFilter = filters?.locations?.map((value) => deps.roomNameOf?.(value) ?? value);
|
|
17403
18149
|
for (const c of textPass) {
|
|
17404
|
-
const okLocation = matches(
|
|
18150
|
+
const okLocation = matches(locationFilter, c.device.location);
|
|
17405
18151
|
const okIntegration = matches(filters?.integrationIds, c.integrationId);
|
|
17406
18152
|
const okType = matches(filters?.types, c.device.type);
|
|
17407
18153
|
if (c.compatible) {
|
|
@@ -17734,7 +18480,7 @@ async function setWrapperActive(deps, input) {
|
|
|
17734
18480
|
}
|
|
17735
18481
|
});
|
|
17736
18482
|
}
|
|
17737
|
-
function isRecord$
|
|
18483
|
+
function isRecord$2(value) {
|
|
17738
18484
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
17739
18485
|
}
|
|
17740
18486
|
/** The key of this addon's store that holds every wrapper activation. */
|
|
@@ -17774,19 +18520,19 @@ async function readWrapperActivation(deps, query) {
|
|
|
17774
18520
|
error: "the store holds no deviceBindings row — an empty snapshot is not evidence of an unbind"
|
|
17775
18521
|
};
|
|
17776
18522
|
const deviceBindings = read.value;
|
|
17777
|
-
if (!isRecord$
|
|
18523
|
+
if (!isRecord$2(deviceBindings)) return {
|
|
17778
18524
|
kind: "failed",
|
|
17779
18525
|
error: "stored deviceBindings is not a map"
|
|
17780
18526
|
};
|
|
17781
18527
|
const perDevice = deviceBindings[String(query.deviceId)];
|
|
17782
18528
|
if (perDevice === void 0) return { kind: "missing" };
|
|
17783
|
-
if (!isRecord$
|
|
18529
|
+
if (!isRecord$2(perDevice)) return {
|
|
17784
18530
|
kind: "failed",
|
|
17785
18531
|
error: `stored bindings of device ${query.deviceId} are not a map`
|
|
17786
18532
|
};
|
|
17787
18533
|
const activation = perDevice[query.capName];
|
|
17788
18534
|
if (activation === void 0) return { kind: "missing" };
|
|
17789
|
-
if (!isRecord$
|
|
18535
|
+
if (!isRecord$2(activation)) return {
|
|
17790
18536
|
kind: "failed",
|
|
17791
18537
|
error: `stored "${query.capName}" activation is not a record`
|
|
17792
18538
|
};
|
|
@@ -18256,7 +19002,7 @@ function deviceIdOfSuffix(suffix) {
|
|
|
18256
19002
|
}
|
|
18257
19003
|
/** Every field row of one device scope, or a throw. */
|
|
18258
19004
|
async function readScope(door, addonId, deviceId) {
|
|
18259
|
-
return
|
|
19005
|
+
return require_named_entity_store.loadPrefixed(door, DEVICE_SETTINGS_COLLECTION, scopeOf(addonId, deviceId));
|
|
18260
19006
|
}
|
|
18261
19007
|
function createDeviceSettingsStore(door, addonId) {
|
|
18262
19008
|
return {
|
|
@@ -18280,7 +19026,7 @@ function createDeviceSettingsStore(door, addonId) {
|
|
|
18280
19026
|
if (deviceIds.length === 0) return out;
|
|
18281
19027
|
for (const id of deviceIds) out.set(id, {});
|
|
18282
19028
|
const wanted = new Set(deviceIds);
|
|
18283
|
-
const all = await
|
|
19029
|
+
const all = await require_named_entity_store.loadPrefixed(door, DEVICE_SETTINGS_COLLECTION, `${addonId}:`);
|
|
18284
19030
|
for (const [suffix, value] of Object.entries(all)) {
|
|
18285
19031
|
const id = deviceIdOfSuffix(suffix);
|
|
18286
19032
|
if (id === null || !wanted.has(id)) continue;
|
|
@@ -18290,7 +19036,7 @@ function createDeviceSettingsStore(door, addonId) {
|
|
|
18290
19036
|
return out;
|
|
18291
19037
|
},
|
|
18292
19038
|
async listIds() {
|
|
18293
|
-
const all = await
|
|
19039
|
+
const all = await require_named_entity_store.loadPrefixed(door, DEVICE_SETTINGS_COLLECTION, `${addonId}:`, () => null);
|
|
18294
19040
|
const ids = /* @__PURE__ */ new Set();
|
|
18295
19041
|
for (const suffix of Object.keys(all)) {
|
|
18296
19042
|
const id = deviceIdOfSuffix(suffix);
|
|
@@ -18917,7 +19663,7 @@ function nearestLocatedAncestor(byId, startParentId) {
|
|
|
18917
19663
|
visited.add(cursor);
|
|
18918
19664
|
const ancestor = byId.get(cursor);
|
|
18919
19665
|
if (!ancestor) return null;
|
|
18920
|
-
if (ancestor.
|
|
19666
|
+
if (ancestor.locationId !== void 0 && ancestor.locationId !== null) return ancestor;
|
|
18921
19667
|
cursor = ancestor.parentDeviceId;
|
|
18922
19668
|
}
|
|
18923
19669
|
return null;
|
|
@@ -18947,15 +19693,16 @@ function planNullLocationFills(rows) {
|
|
|
18947
19693
|
const byId = new Map(rows.map((r) => [r.id, r]));
|
|
18948
19694
|
const plan = [];
|
|
18949
19695
|
for (const row of rows) {
|
|
18950
|
-
if (row.
|
|
19696
|
+
if (row.locationId !== void 0 && row.locationId !== null) continue;
|
|
18951
19697
|
if (row.parentDeviceId === null) continue;
|
|
18952
19698
|
const hit = nearestLocatedAncestor(byId, row.parentDeviceId);
|
|
18953
19699
|
if (hit === null) continue;
|
|
18954
19700
|
if (hit.type !== require_device_type.DeviceType.Container) continue;
|
|
18955
|
-
if (hit.
|
|
19701
|
+
if (hit.locationId === void 0 || hit.locationId === null) continue;
|
|
18956
19702
|
plan.push({
|
|
18957
19703
|
id: row.id,
|
|
18958
19704
|
location: hit.location,
|
|
19705
|
+
locationId: hit.locationId,
|
|
18959
19706
|
ancestorId: hit.id
|
|
18960
19707
|
});
|
|
18961
19708
|
}
|
|
@@ -18980,8 +19727,15 @@ async function resolveInheritedLocation(rows, parentDeviceId) {
|
|
|
18980
19727
|
visited.add(cursor);
|
|
18981
19728
|
const ancestor = await rows.get(cursor);
|
|
18982
19729
|
if (ancestor === null) return null;
|
|
18983
|
-
|
|
18984
|
-
|
|
19730
|
+
const locationId = ancestor.meta.locationId ?? null;
|
|
19731
|
+
if (locationId !== null) {
|
|
19732
|
+
if (ancestor.meta.type !== require_device_type.DeviceType.Container) return null;
|
|
19733
|
+
return {
|
|
19734
|
+
locationId,
|
|
19735
|
+
location: ancestor.meta.location
|
|
19736
|
+
};
|
|
19737
|
+
}
|
|
19738
|
+
cursor = ancestor.meta.parentDeviceId;
|
|
18985
19739
|
}
|
|
18986
19740
|
return null;
|
|
18987
19741
|
}
|
|
@@ -19015,8 +19769,8 @@ async function runLocationBackfillAtBoot(pctx, bootRows) {
|
|
|
19015
19769
|
const plan = planNullLocationFills((await pctx.metaStore.rows.listAll()).map((r) => r.meta));
|
|
19016
19770
|
for (const fill of plan) try {
|
|
19017
19771
|
const current = await pctx.metaStore.rows.get(fill.id);
|
|
19018
|
-
if (current === null || current.meta.
|
|
19019
|
-
await pctx.metaStore.rows.patch(fill.id, {
|
|
19772
|
+
if (current === null || (current.meta.locationId ?? null) !== null) continue;
|
|
19773
|
+
await pctx.metaStore.rows.patch(fill.id, { locationId: fill.locationId });
|
|
19020
19774
|
patched.push(fill);
|
|
19021
19775
|
} catch (err) {
|
|
19022
19776
|
failed.push({
|
|
@@ -19225,12 +19979,13 @@ async function migrateDevice$1(deps, input) {
|
|
|
19225
19979
|
try {
|
|
19226
19980
|
await deps.swapIds(sourceId, targetId);
|
|
19227
19981
|
} catch (err) {
|
|
19228
|
-
if (err instanceof
|
|
19982
|
+
if (err instanceof require_record_kinds.MigrationRefusedError) return rollBackRefusal(deps, ids, prior, err);
|
|
19229
19983
|
alarmPartialMigration(deps, ids, "swapIds", err);
|
|
19230
19984
|
throw err;
|
|
19231
19985
|
}
|
|
19986
|
+
let secretScopes;
|
|
19232
19987
|
try {
|
|
19233
|
-
await deps.swapHardwareState(sourceId, targetId);
|
|
19988
|
+
secretScopes = await deps.swapHardwareState(sourceId, targetId);
|
|
19234
19989
|
} catch (err) {
|
|
19235
19990
|
alarmPartialMigration(deps, ids, "swapHardwareState", err);
|
|
19236
19991
|
throw err;
|
|
@@ -19256,7 +20011,8 @@ async function migrateDevice$1(deps, input) {
|
|
|
19256
20011
|
targetId,
|
|
19257
20012
|
switches: [...down, ...up],
|
|
19258
20013
|
sourceStillLive,
|
|
19259
|
-
swapped: true
|
|
20014
|
+
swapped: true,
|
|
20015
|
+
secretScopes
|
|
19260
20016
|
};
|
|
19261
20017
|
}
|
|
19262
20018
|
//#endregion
|
|
@@ -19293,6 +20049,15 @@ async function migrateDevice$1(deps, input) {
|
|
|
19293
20049
|
* stream-profile assignment (the live authority is the stream broker's own
|
|
19294
20050
|
* map — see `StreamsTab.tsx`, which stopped writing it), and either copy
|
|
19295
20051
|
* names stream ids of the wrong hardware after a swap.
|
|
20052
|
+
* - A secret marker inside the swapped config names the keychain scope of ONE
|
|
20053
|
+
* number (`secret://<owner>/device/<id>/<field>`; the ref is the AAD of the
|
|
20054
|
+
* ciphertext). Swapping the marker alone left each number pointing at the
|
|
20055
|
+
* other's scope, so removing either device purged the secret the other still
|
|
20056
|
+
* used (D1093, live 2026-11-23). The configs swap with their markers
|
|
20057
|
+
* unchanged (each still reads its value), then `repairCrossedSecretScopes`
|
|
20058
|
+
* brings every value under the number whose config holds it, through staged
|
|
20059
|
+
* copies, so a crash at any step is finished by a re-run of the repair.
|
|
20060
|
+
* - The location (room) is role state and stays on the number (`swapIds`).
|
|
19296
20061
|
* - The runtime-state blobs (`__device-state:<id>` — battery snapshot, sleep
|
|
19297
20062
|
* flag, feature probe) SWAP wholesale: every slice mirrors the box — never
|
|
19298
20063
|
* while either carries `$owned` (D663): the migration is refused first
|
|
@@ -19337,7 +20102,7 @@ var FieldClaimsBlockMigrationError = class extends Error {
|
|
|
19337
20102
|
* moved — so it is a {@link MigrationRefusedError}: both cameras' switches are
|
|
19338
20103
|
* restored, and the claim stays on the number it names.
|
|
19339
20104
|
*/
|
|
19340
|
-
var ClaimLandedDuringMigrationError = class extends
|
|
20105
|
+
var ClaimLandedDuringMigrationError = class extends require_record_kinds.MigrationRefusedError {
|
|
19341
20106
|
sourceId;
|
|
19342
20107
|
targetId;
|
|
19343
20108
|
blocked;
|
|
@@ -19418,11 +20183,21 @@ function splitConfig(config) {
|
|
|
19418
20183
|
* incident this module exists to prevent, and it must never be reported as a
|
|
19419
20184
|
* success.
|
|
19420
20185
|
*/
|
|
19421
|
-
async function swapHardwareState(settings, sourceId, targetId) {
|
|
20186
|
+
async function swapHardwareState(settings, sourceId, targetId, secrets) {
|
|
19422
20187
|
const sourceConfig = await settings.readDeviceStore(sourceId);
|
|
19423
20188
|
const targetConfig = await settings.readDeviceStore(targetId);
|
|
20189
|
+
const crossed = [{
|
|
20190
|
+
deviceId: sourceId,
|
|
20191
|
+
markers: crossedIn(sourceConfig, targetId)
|
|
20192
|
+
}, {
|
|
20193
|
+
deviceId: targetId,
|
|
20194
|
+
markers: crossedIn(targetConfig, sourceId)
|
|
20195
|
+
}].filter((c) => c.markers > 0);
|
|
20196
|
+
if (crossed.length > 0) throw new Error(new SecretScopesCrossedError(sourceId, targetId, crossed).message);
|
|
19424
20197
|
const source = splitConfig(sourceConfig);
|
|
19425
20198
|
const target = splitConfig(targetConfig);
|
|
20199
|
+
const marked = hasDeviceMarkers(source.hardware, sourceId, targetId) || hasDeviceMarkers(target.hardware, sourceId, targetId);
|
|
20200
|
+
if (secrets === void 0 && marked) throw new Error(`keychain door unavailable - devices ${sourceId} and ${targetId} hold keychain secrets and the migration cannot move them; nothing was changed`);
|
|
19426
20201
|
await settings.clearDeviceStore(sourceId);
|
|
19427
20202
|
await settings.writeDeviceStore(sourceId, {
|
|
19428
20203
|
...target.hardware,
|
|
@@ -19437,14 +20212,216 @@ async function swapHardwareState(settings, sourceId, targetId) {
|
|
|
19437
20212
|
const targetRuntimeState = await settings.readDeviceRuntimeState(targetId);
|
|
19438
20213
|
await settings.writeDeviceRuntimeState(sourceId, targetRuntimeState);
|
|
19439
20214
|
await settings.writeDeviceRuntimeState(targetId, sourceRuntimeState);
|
|
20215
|
+
let secretScopes = {
|
|
20216
|
+
exchanged: false,
|
|
20217
|
+
markersRepointed: 0,
|
|
20218
|
+
refsAtSource: [],
|
|
20219
|
+
refsAtTarget: []
|
|
20220
|
+
};
|
|
20221
|
+
if (marked) try {
|
|
20222
|
+
const repaired = await repairCrossedSecretScopes(settings, secrets, sourceId, targetId, true);
|
|
20223
|
+
secretScopes = {
|
|
20224
|
+
exchanged: repaired.outcome === "repaired",
|
|
20225
|
+
markersRepointed: repaired.markersRepointedAtA + repaired.markersRepointedAtB,
|
|
20226
|
+
refsAtSource: repaired.refsNowAtA,
|
|
20227
|
+
refsAtTarget: repaired.refsNowAtB
|
|
20228
|
+
};
|
|
20229
|
+
} catch (err) {
|
|
20230
|
+
throw new Error(`migration: configs swapped but the secrets are not yet under their own numbers (${err instanceof Error ? err.message : String(err)}); every marker still reads its value - run deviceManager.repairMigrationSecrets { deviceA: ${sourceId}, deviceB: ${targetId}, apply: true }`, { cause: err });
|
|
20231
|
+
}
|
|
19440
20232
|
return {
|
|
19441
20233
|
runtimeStateNowAtSource: targetRuntimeState,
|
|
19442
20234
|
runtimeStateNowAtTarget: sourceRuntimeState,
|
|
19443
20235
|
hardwareKeysToSource: Object.keys(target.hardware).toSorted(),
|
|
19444
20236
|
hardwareKeysToTarget: Object.keys(source.hardware).toSorted(),
|
|
19445
20237
|
roleKeysKeptAtSource: Object.keys(source.role).toSorted(),
|
|
19446
|
-
roleKeysKeptAtTarget: Object.keys(target.role).toSorted()
|
|
20238
|
+
roleKeysKeptAtTarget: Object.keys(target.role).toSorted(),
|
|
20239
|
+
secretScopes
|
|
20240
|
+
};
|
|
20241
|
+
}
|
|
20242
|
+
/** The suffix of the staging copy a repair keeps while a value changes scope. */
|
|
20243
|
+
var REPAIR_STAGING_SUFFIX = "~repair";
|
|
20244
|
+
function refWithin(parts, deviceId, fieldPath) {
|
|
20245
|
+
return require_scoped_settings.buildSecretRef({
|
|
20246
|
+
...parts,
|
|
20247
|
+
scope: {
|
|
20248
|
+
kind: "device",
|
|
20249
|
+
deviceId
|
|
20250
|
+
},
|
|
20251
|
+
fieldPath
|
|
20252
|
+
});
|
|
20253
|
+
}
|
|
20254
|
+
/**
|
|
20255
|
+
* The markers of `config` (the config of `ownId`) the repair must move: those
|
|
20256
|
+
* naming `otherId`'s scope, and the staging copies of an interrupted run.
|
|
20257
|
+
*/
|
|
20258
|
+
function repairMarkers(config, ownId, otherId) {
|
|
20259
|
+
const found = [];
|
|
20260
|
+
for (const current of collectMarkerRefs(config)) {
|
|
20261
|
+
const parts = require_scoped_settings.parseSecretRef(current);
|
|
20262
|
+
if (parts === null || parts.scope.kind !== "device") continue;
|
|
20263
|
+
const staged = parts.fieldPath.endsWith(REPAIR_STAGING_SUFFIX);
|
|
20264
|
+
if (!(parts.scope.deviceId === otherId || staged && parts.scope.deviceId === ownId)) continue;
|
|
20265
|
+
const fieldPath = staged ? parts.fieldPath.slice(0, -7) : parts.fieldPath;
|
|
20266
|
+
found.push({
|
|
20267
|
+
current,
|
|
20268
|
+
staging: staged ? current : refWithin(parts, ownId, `${fieldPath}${REPAIR_STAGING_SUFFIX}`),
|
|
20269
|
+
dest: refWithin(parts, ownId, fieldPath),
|
|
20270
|
+
owner: parts.owner,
|
|
20271
|
+
staged
|
|
20272
|
+
});
|
|
20273
|
+
}
|
|
20274
|
+
return found;
|
|
20275
|
+
}
|
|
20276
|
+
/**
|
|
20277
|
+
* Repair a pair a migration left with CROSSED secrets (it ran before the
|
|
20278
|
+
* secrets followed the config): a number's config carries markers naming the
|
|
20279
|
+
* OTHER number's keychain scope, so removing either device would purge the
|
|
20280
|
+
* secret the other still reads. Each such marker's value is brought under the
|
|
20281
|
+
* number whose config holds it.
|
|
20282
|
+
*
|
|
20283
|
+
* The configs ARE the state machine, so a crash at any step is re-run to the
|
|
20284
|
+
* right end state — never a double exchange, never a value lost:
|
|
20285
|
+
* 1. stage: copy each value to a staging ref in its own number's scope
|
|
20286
|
+
* (idempotent puts; the originals are untouched);
|
|
20287
|
+
* 2. point both configs at the staging refs — from here every marker reads a
|
|
20288
|
+
* value that is not about to be overwritten;
|
|
20289
|
+
* 3. put each value at its end ref (idempotent: the source is the staging ref);
|
|
20290
|
+
* 4. point both configs at the end refs;
|
|
20291
|
+
* 5. delete the staging refs and any original no config names any more.
|
|
20292
|
+
* A re-run reads each marker's CURRENT ref, so a marker already at a staging
|
|
20293
|
+
* or end ref continues from there. One-sided pairs and a pair where only some
|
|
20294
|
+
* fields are crossed work the same way, field by field.
|
|
20295
|
+
*
|
|
20296
|
+
* Idempotent: a pair with no marker to move is left alone. `apply: false` is
|
|
20297
|
+
* the dry run: counts only. A missing keychain door with markers to move THROWS.
|
|
20298
|
+
*/
|
|
20299
|
+
async function repairCrossedSecretScopes(settings, secrets, deviceA, deviceB, apply) {
|
|
20300
|
+
const configA = await settings.readDeviceStore(deviceA);
|
|
20301
|
+
const configB = await settings.readDeviceStore(deviceB);
|
|
20302
|
+
const markersA = repairMarkers(configA, deviceA, deviceB);
|
|
20303
|
+
const markersB = repairMarkers(configB, deviceB, deviceA);
|
|
20304
|
+
const counts = {
|
|
20305
|
+
markersRepointedAtA: markersA.length,
|
|
20306
|
+
markersRepointedAtB: markersB.length
|
|
20307
|
+
};
|
|
20308
|
+
if (markersA.length === 0 && markersB.length === 0) return {
|
|
20309
|
+
outcome: "nothing-to-repair",
|
|
20310
|
+
...counts,
|
|
20311
|
+
refsNowAtA: [],
|
|
20312
|
+
refsNowAtB: []
|
|
20313
|
+
};
|
|
20314
|
+
if (secrets === void 0) throw new Error(`repairMigrationSecrets: no keychain door on this node — devices ${deviceA} and ${deviceB} hold markers that must move; nothing was changed`);
|
|
20315
|
+
if (!apply) return {
|
|
20316
|
+
outcome: "would-repair",
|
|
20317
|
+
...counts,
|
|
20318
|
+
refsNowAtA: [],
|
|
20319
|
+
refsNowAtB: []
|
|
20320
|
+
};
|
|
20321
|
+
const all = [...markersA, ...markersB];
|
|
20322
|
+
const valueOf = async (owner, ref) => {
|
|
20323
|
+
const answer = (await secrets.forOwner(owner).resolve([ref]))[ref];
|
|
20324
|
+
if (answer?.kind === "value") return answer.value;
|
|
20325
|
+
throw new Error(`repairMigrationSecrets: ${ref} cannot be read (${answer?.kind ?? "no answer"}); nothing was changed`);
|
|
20326
|
+
};
|
|
20327
|
+
const rewritten = (pick) => {
|
|
20328
|
+
const mapOf = (markers) => {
|
|
20329
|
+
const byCurrent = new Map(markers.map((m) => [m.current, pick(m)]));
|
|
20330
|
+
return (ref) => byCurrent.get(ref);
|
|
20331
|
+
};
|
|
20332
|
+
return [rewriteMarkerRefs(configA, mapOf(markersA)), rewriteMarkerRefs(configB, mapOf(markersB))];
|
|
19447
20333
|
};
|
|
20334
|
+
const writeBoth = async (pick) => {
|
|
20335
|
+
const [nextA, nextB] = rewritten(pick);
|
|
20336
|
+
await settings.writeDeviceStore(deviceA, nextA);
|
|
20337
|
+
await settings.writeDeviceStore(deviceB, nextB);
|
|
20338
|
+
};
|
|
20339
|
+
for (const m of all) if (!m.staged) await secrets.forOwner(m.owner).put(m.staging, await valueOf(m.owner, m.current));
|
|
20340
|
+
await writeBoth((m) => m.staging);
|
|
20341
|
+
for (const m of all) await secrets.forOwner(m.owner).put(m.dest, await valueOf(m.owner, m.staging));
|
|
20342
|
+
await writeBoth((m) => m.dest);
|
|
20343
|
+
const finalRefs = new Set(rewritten((m) => m.dest).flatMap(collectMarkerRefs));
|
|
20344
|
+
for (const m of all) {
|
|
20345
|
+
const stale = [m.staging, ...m.staged || finalRefs.has(m.current) ? [] : [m.current]];
|
|
20346
|
+
await secrets.forOwner(m.owner).delete(stale);
|
|
20347
|
+
}
|
|
20348
|
+
for (const ref of finalRefs) {
|
|
20349
|
+
const parts = require_scoped_settings.parseSecretRef(ref);
|
|
20350
|
+
if (parts === null || parts.scope.kind !== "device") continue;
|
|
20351
|
+
const strays = [deviceA, deviceB].map((id) => refWithin(parts, id, `${parts.fieldPath.replace(/~repair$/, "")}${REPAIR_STAGING_SUFFIX}`)).filter((stray) => !finalRefs.has(stray));
|
|
20352
|
+
await secrets.forOwner(parts.owner).delete(strays);
|
|
20353
|
+
}
|
|
20354
|
+
return {
|
|
20355
|
+
outcome: "repaired",
|
|
20356
|
+
...counts,
|
|
20357
|
+
refsNowAtA: markersA.map((m) => m.dest),
|
|
20358
|
+
refsNowAtB: markersB.map((m) => m.dest)
|
|
20359
|
+
};
|
|
20360
|
+
}
|
|
20361
|
+
/**
|
|
20362
|
+
* The refusal of a migration over a pair whose configs hold markers naming the
|
|
20363
|
+
* OTHER number's keychain scope (an earlier migration crossed them): swapping
|
|
20364
|
+
* again would mix the passwords. Nothing moved; run the repair first.
|
|
20365
|
+
*/
|
|
20366
|
+
var SecretScopesCrossedError = class extends require_record_kinds.MigrationRefusedError {
|
|
20367
|
+
sourceId;
|
|
20368
|
+
targetId;
|
|
20369
|
+
crossed;
|
|
20370
|
+
constructor(sourceId, targetId, crossed) {
|
|
20371
|
+
super(`secret-scopes-crossed: migration ${sourceId} → ${targetId} refused: ${crossed.map((c) => `device ${c.deviceId} holds ${c.markers} secret marker(s) naming the other number's keychain scope`).join("; ")} — run deviceManager.repairMigrationSecrets first (nothing moved)`);
|
|
20372
|
+
this.sourceId = sourceId;
|
|
20373
|
+
this.targetId = targetId;
|
|
20374
|
+
this.crossed = crossed;
|
|
20375
|
+
this.name = "SecretScopesCrossedError";
|
|
20376
|
+
}
|
|
20377
|
+
};
|
|
20378
|
+
/** True when `config` holds a marker in the keychain scope of device `a` or `b`. */
|
|
20379
|
+
function hasDeviceMarkers(config, a, b) {
|
|
20380
|
+
return collectMarkerRefs(config).some((ref) => {
|
|
20381
|
+
const parts = require_scoped_settings.parseSecretRef(ref);
|
|
20382
|
+
return parts !== null && parts.scope.kind === "device" && (parts.scope.deviceId === a || parts.scope.deviceId === b);
|
|
20383
|
+
});
|
|
20384
|
+
}
|
|
20385
|
+
function crossedIn(config, otherId) {
|
|
20386
|
+
return collectMarkerRefs(config).filter((ref) => {
|
|
20387
|
+
const parts = require_scoped_settings.parseSecretRef(ref);
|
|
20388
|
+
return parts !== null && parts.scope.kind === "device" && parts.scope.deviceId === otherId;
|
|
20389
|
+
}).length;
|
|
20390
|
+
}
|
|
20391
|
+
/**
|
|
20392
|
+
* Refuse a migration when either config already names the other number's
|
|
20393
|
+
* keychain scope. Read from the stored configs (D49: an unreadable config
|
|
20394
|
+
* throws, never reads as "not crossed").
|
|
20395
|
+
*/
|
|
20396
|
+
async function assertNoCrossedSecretScopes(settings, sourceId, targetId) {
|
|
20397
|
+
const crossed = [{
|
|
20398
|
+
deviceId: sourceId,
|
|
20399
|
+
markers: crossedIn(await settings.readDeviceStore(sourceId), targetId)
|
|
20400
|
+
}, {
|
|
20401
|
+
deviceId: targetId,
|
|
20402
|
+
markers: crossedIn(await settings.readDeviceStore(targetId), sourceId)
|
|
20403
|
+
}].filter((c) => c.markers > 0);
|
|
20404
|
+
if (crossed.length > 0) throw new SecretScopesCrossedError(sourceId, targetId, crossed);
|
|
20405
|
+
}
|
|
20406
|
+
/** Every secret marker's ref in a config, at any depth. */
|
|
20407
|
+
function collectMarkerRefs(value) {
|
|
20408
|
+
if (Array.isArray(value)) return value.flatMap(collectMarkerRefs);
|
|
20409
|
+
if (require_scoped_settings.isSecretMarker(value)) return [value.$secret];
|
|
20410
|
+
if (isRecord$1(value)) return Object.values(value).flatMap(collectMarkerRefs);
|
|
20411
|
+
return [];
|
|
20412
|
+
}
|
|
20413
|
+
/** A copy of `value` whose markers name `map(ref)` where it answers (others untouched). */
|
|
20414
|
+
function rewriteMarkerRefs(value, map) {
|
|
20415
|
+
const walk = (node) => {
|
|
20416
|
+
if (Array.isArray(node)) return node.map(walk);
|
|
20417
|
+
if (require_scoped_settings.isSecretMarker(node)) return require_scoped_settings.makeSecretMarker(map(node.$secret) ?? node.$secret);
|
|
20418
|
+
if (isRecord$1(node)) return Object.fromEntries(Object.entries(node).map(([k, v]) => [k, walk(v)]));
|
|
20419
|
+
return node;
|
|
20420
|
+
};
|
|
20421
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, walk(v)]));
|
|
20422
|
+
}
|
|
20423
|
+
function isRecord$1(value) {
|
|
20424
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19448
20425
|
}
|
|
19449
20426
|
//#endregion
|
|
19450
20427
|
//#region src/builtins/device-manager/migrate-reload.ts
|
|
@@ -19493,6 +20470,274 @@ async function reloadMigratedDevices(pctx, targets) {
|
|
|
19493
20470
|
}));
|
|
19494
20471
|
}
|
|
19495
20472
|
//#endregion
|
|
20473
|
+
//#region src/builtins/device-manager/room-actions.ts
|
|
20474
|
+
/**
|
|
20475
|
+
* Rooms and site zones as records with an id (D1089).
|
|
20476
|
+
*
|
|
20477
|
+
* The entity methods (`ensureRoom`, `listRooms`, `updateRoom`, `deleteRoom`) are
|
|
20478
|
+
* the model: a rename, a new icon or a new description is ONE write to ONE
|
|
20479
|
+
* `rooms` record, and no device is rewritten (a device meta carries only
|
|
20480
|
+
* `locationId`; its `location` name is derived at read). A delete clears the
|
|
20481
|
+
* references in one operation.
|
|
20482
|
+
*
|
|
20483
|
+
* Everything else here — `listLocations`, `addLocation`, `removeLocation`,
|
|
20484
|
+
* `renameLocation`, the icon / description maps, the site-zone methods and
|
|
20485
|
+
* `setLocationZone` — is a thin SHIM over those, answering the same shapes as
|
|
20486
|
+
* before so the admin UI and the viewer keep working until they move to the ids.
|
|
20487
|
+
* A shim is removed once nothing calls it (D1089).
|
|
20488
|
+
*/
|
|
20489
|
+
/** Room record → the wire shape. */
|
|
20490
|
+
function toRoom(entity) {
|
|
20491
|
+
return entity;
|
|
20492
|
+
}
|
|
20493
|
+
function requireName(name, code, what) {
|
|
20494
|
+
const trimmed = name.trim();
|
|
20495
|
+
if (trimmed.length === 0) throw require_camstack_error.userError(code, void 0, `[device-manager] ${what}: name must be non-empty`);
|
|
20496
|
+
return trimmed;
|
|
20497
|
+
}
|
|
20498
|
+
/** Drop a field when the patch says `null`, keep it when absent, set it otherwise. */
|
|
20499
|
+
function applied(patch, current) {
|
|
20500
|
+
if (patch === void 0) return current;
|
|
20501
|
+
if (patch === null) return void 0;
|
|
20502
|
+
return patch;
|
|
20503
|
+
}
|
|
20504
|
+
function emitLocationChanged(pctx, deviceId, value) {
|
|
20505
|
+
pctx.host.ctx.eventBus.emit({
|
|
20506
|
+
id: (0, node_crypto.randomUUID)(),
|
|
20507
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
20508
|
+
source: {
|
|
20509
|
+
type: "device",
|
|
20510
|
+
id: deviceId
|
|
20511
|
+
},
|
|
20512
|
+
category: require_base_addon.EventCategory.DeviceMetaChanged,
|
|
20513
|
+
data: {
|
|
20514
|
+
deviceId,
|
|
20515
|
+
field: "location",
|
|
20516
|
+
value
|
|
20517
|
+
}
|
|
20518
|
+
});
|
|
20519
|
+
}
|
|
20520
|
+
/** The ids of every device whose room is `roomId`. */
|
|
20521
|
+
async function devicesInRoom(pctx, roomId) {
|
|
20522
|
+
return (await pctx.metaStore.rows.listAll()).filter((row) => row.meta.locationId === roomId).map((row) => row.meta.id);
|
|
20523
|
+
}
|
|
20524
|
+
async function ensureRoom(pctx, input) {
|
|
20525
|
+
const name = requireName(input.name, "system.location-name-required", "ensureRoom");
|
|
20526
|
+
return toRoom(await pctx.rooms.rooms.ensure(name, {}));
|
|
20527
|
+
}
|
|
20528
|
+
async function listRooms(pctx) {
|
|
20529
|
+
return pctx.rooms.rooms.list().map(toRoom);
|
|
20530
|
+
}
|
|
20531
|
+
async function updateRoom(pctx, input) {
|
|
20532
|
+
const { id, patch } = input;
|
|
20533
|
+
const before = pctx.rooms.rooms.get(id);
|
|
20534
|
+
let updated;
|
|
20535
|
+
try {
|
|
20536
|
+
updated = await pctx.rooms.rooms.update(id, (current) => {
|
|
20537
|
+
return {
|
|
20538
|
+
name: patch.name ?? current.name,
|
|
20539
|
+
icon: applied(patch.icon, current.icon),
|
|
20540
|
+
description: applied(patch.description, current.description),
|
|
20541
|
+
zoneId: applied(patch.zoneId, current.zoneId),
|
|
20542
|
+
colour: applied(patch.colour, current.colour),
|
|
20543
|
+
order: applied(patch.order, current.order)
|
|
20544
|
+
};
|
|
20545
|
+
});
|
|
20546
|
+
} catch (err) {
|
|
20547
|
+
if (err instanceof require_named_entity_store.EntityNotFoundError) throw require_camstack_error.userError("system.room-not-found", void 0, `[device-manager] room not found: ${id}`);
|
|
20548
|
+
if (err instanceof require_named_entity_store.EntityNameTakenError) throw require_camstack_error.userError("system.room-name-taken", void 0, `[device-manager] ${err.message}`);
|
|
20549
|
+
throw err;
|
|
20550
|
+
}
|
|
20551
|
+
if (before !== null && before.name !== updated.name) for (const deviceId of await devicesInRoom(pctx, id)) emitLocationChanged(pctx, deviceId, updated.name);
|
|
20552
|
+
return toRoom(updated);
|
|
20553
|
+
}
|
|
20554
|
+
async function deleteRoom(pctx, input) {
|
|
20555
|
+
if (!await pctx.rooms.rooms.delete(input.id)) return { cleared: 0 };
|
|
20556
|
+
const cleared = await pctx.metaStore.withMetaWriteLock(async () => {
|
|
20557
|
+
const out = [];
|
|
20558
|
+
for (const row of await pctx.metaStore.rows.listAll()) {
|
|
20559
|
+
if (row.meta.locationId !== input.id) continue;
|
|
20560
|
+
await pctx.metaStore.rows.patch(row.meta.id, { locationId: null });
|
|
20561
|
+
out.push(row.meta.id);
|
|
20562
|
+
}
|
|
20563
|
+
return out;
|
|
20564
|
+
});
|
|
20565
|
+
for (const deviceId of cleared) emitLocationChanged(pctx, deviceId, null);
|
|
20566
|
+
return { cleared: cleared.length };
|
|
20567
|
+
}
|
|
20568
|
+
/**
|
|
20569
|
+
* The id a write names: `locationId` wins, else `location` (text) is resolved
|
|
20570
|
+
* through `ensureRoom`. `undefined` = the caller named neither, `null` = clear.
|
|
20571
|
+
*/
|
|
20572
|
+
async function resolveRoomId(pctx, input) {
|
|
20573
|
+
if (input.locationId !== void 0) {
|
|
20574
|
+
if (input.locationId !== null && pctx.rooms.rooms.get(input.locationId) === null) throw require_camstack_error.userError("system.room-not-found", void 0, `[device-manager] room not found: ${input.locationId}`);
|
|
20575
|
+
return input.locationId;
|
|
20576
|
+
}
|
|
20577
|
+
if (input.location === void 0) return void 0;
|
|
20578
|
+
if (input.location === null || input.location.trim().length === 0) return null;
|
|
20579
|
+
return (await pctx.rooms.rooms.ensure(input.location.trim(), {})).id;
|
|
20580
|
+
}
|
|
20581
|
+
async function listLocations(pctx) {
|
|
20582
|
+
return pctx.rooms.rooms.list().map((room) => room.name).toSorted((a, b) => a.localeCompare(b, void 0, { sensitivity: "base" }));
|
|
20583
|
+
}
|
|
20584
|
+
async function addLocation(pctx, input) {
|
|
20585
|
+
const name = requireName(input.name, "system.location-name-required", "addLocation");
|
|
20586
|
+
await pctx.rooms.rooms.ensure(name, {});
|
|
20587
|
+
}
|
|
20588
|
+
async function removeLocation(pctx, input) {
|
|
20589
|
+
const room = pctx.rooms.rooms.findByName(input.name);
|
|
20590
|
+
if (room === null) return;
|
|
20591
|
+
if (input.cascade === true) {
|
|
20592
|
+
await deleteRoom(pctx, { id: room.id });
|
|
20593
|
+
return;
|
|
20594
|
+
}
|
|
20595
|
+
if ((await devicesInRoom(pctx, room.id)).length > 0) {
|
|
20596
|
+
await updateRoom(pctx, {
|
|
20597
|
+
id: room.id,
|
|
20598
|
+
patch: {
|
|
20599
|
+
icon: null,
|
|
20600
|
+
description: null,
|
|
20601
|
+
zoneId: null
|
|
20602
|
+
}
|
|
20603
|
+
});
|
|
20604
|
+
return;
|
|
20605
|
+
}
|
|
20606
|
+
await pctx.rooms.rooms.delete(room.id);
|
|
20607
|
+
}
|
|
20608
|
+
async function renameLocation(pctx, input) {
|
|
20609
|
+
const from = requireName(input.from, "system.location-name-required", "renameLocation");
|
|
20610
|
+
const to = requireName(input.to, "system.location-name-required", "renameLocation");
|
|
20611
|
+
const source = pctx.rooms.rooms.findByName(from);
|
|
20612
|
+
if (source === null) return { moved: 0 };
|
|
20613
|
+
const target = pctx.rooms.rooms.findByName(to);
|
|
20614
|
+
if (target === null || target.id === source.id) {
|
|
20615
|
+
await updateRoom(pctx, {
|
|
20616
|
+
id: source.id,
|
|
20617
|
+
patch: { name: to }
|
|
20618
|
+
});
|
|
20619
|
+
return { moved: (await devicesInRoom(pctx, source.id)).length };
|
|
20620
|
+
}
|
|
20621
|
+
const moved = await pctx.metaStore.withMetaWriteLock(async () => {
|
|
20622
|
+
const out = [];
|
|
20623
|
+
for (const row of await pctx.metaStore.rows.listAll()) {
|
|
20624
|
+
if (row.meta.locationId !== source.id) continue;
|
|
20625
|
+
await pctx.metaStore.rows.patch(row.meta.id, { locationId: target.id });
|
|
20626
|
+
out.push(row.meta.id);
|
|
20627
|
+
}
|
|
20628
|
+
return out;
|
|
20629
|
+
});
|
|
20630
|
+
await pctx.rooms.rooms.delete(source.id);
|
|
20631
|
+
for (const deviceId of moved) emitLocationChanged(pctx, deviceId, target.name);
|
|
20632
|
+
return { moved: moved.length };
|
|
20633
|
+
}
|
|
20634
|
+
async function listLocationIcons(pctx) {
|
|
20635
|
+
return pctx.rooms.rooms.list().flatMap((room) => room.icon === void 0 ? [] : [{
|
|
20636
|
+
locationKey: require_named_entity_store.entityNameKey(room.name),
|
|
20637
|
+
icon: room.icon
|
|
20638
|
+
}]).toSorted((a, b) => a.locationKey.localeCompare(b.locationKey));
|
|
20639
|
+
}
|
|
20640
|
+
async function setLocationIcon(pctx, input) {
|
|
20641
|
+
const name = requireName(input.location, "system.location-required", "setLocationIcon");
|
|
20642
|
+
const existing = pctx.rooms.rooms.findByName(name);
|
|
20643
|
+
if (existing === null && input.icon === null) return;
|
|
20644
|
+
const room = existing ?? await pctx.rooms.rooms.ensure(name, {});
|
|
20645
|
+
const icon = input.icon;
|
|
20646
|
+
await updateRoom(pctx, {
|
|
20647
|
+
id: room.id,
|
|
20648
|
+
patch: { icon }
|
|
20649
|
+
});
|
|
20650
|
+
}
|
|
20651
|
+
async function listLocationDescriptions(pctx) {
|
|
20652
|
+
return pctx.rooms.rooms.list().flatMap((room) => room.description === void 0 ? [] : [{
|
|
20653
|
+
locationKey: require_named_entity_store.entityNameKey(room.name),
|
|
20654
|
+
description: room.description
|
|
20655
|
+
}]).toSorted((a, b) => a.locationKey.localeCompare(b.locationKey));
|
|
20656
|
+
}
|
|
20657
|
+
async function setLocationDescription(pctx, input) {
|
|
20658
|
+
const name = requireName(input.location, "system.location-required", "setLocationDescription");
|
|
20659
|
+
const text = input.description === null ? "" : input.description.trim();
|
|
20660
|
+
const existing = pctx.rooms.rooms.findByName(name);
|
|
20661
|
+
if (existing === null && text.length === 0) return;
|
|
20662
|
+
await updateRoom(pctx, {
|
|
20663
|
+
id: (existing ?? await pctx.rooms.rooms.ensure(name, {})).id,
|
|
20664
|
+
patch: { description: text.length === 0 ? null : text }
|
|
20665
|
+
});
|
|
20666
|
+
}
|
|
20667
|
+
function zoneFolded(zone) {
|
|
20668
|
+
return require_named_entity_store.entityNameKey(zone.name);
|
|
20669
|
+
}
|
|
20670
|
+
async function listSiteZones(pctx) {
|
|
20671
|
+
const rooms = pctx.rooms.rooms.list();
|
|
20672
|
+
return pctx.rooms.zones.list().map((zone) => ({
|
|
20673
|
+
zoneKey: zoneFolded(zone),
|
|
20674
|
+
label: zone.name,
|
|
20675
|
+
icon: zone.icon ?? null,
|
|
20676
|
+
locationKeys: rooms.filter((room) => room.zoneId === zone.id).map((room) => require_named_entity_store.entityNameKey(room.name)).toSorted((a, b) => a.localeCompare(b))
|
|
20677
|
+
})).toSorted((a, b) => a.zoneKey.localeCompare(b.zoneKey));
|
|
20678
|
+
}
|
|
20679
|
+
async function setSiteZone(pctx, input) {
|
|
20680
|
+
const label = requireName(input.name, "system.site-zone-name-required", "setSiteZone");
|
|
20681
|
+
const zone = await pctx.rooms.zones.ensure(label, {});
|
|
20682
|
+
await pctx.rooms.zones.update(zone.id, (current) => {
|
|
20683
|
+
const next = { name: label };
|
|
20684
|
+
const icon = input.icon === void 0 ? current.icon : input.icon === null ? void 0 : input.icon;
|
|
20685
|
+
if (icon !== void 0) next.icon = icon;
|
|
20686
|
+
return next;
|
|
20687
|
+
});
|
|
20688
|
+
}
|
|
20689
|
+
/** Clear `zoneId` on every room that names `zoneId`; one record write per room. */
|
|
20690
|
+
async function detachRooms(pctx, zoneId, to) {
|
|
20691
|
+
for (const room of pctx.rooms.rooms.list()) {
|
|
20692
|
+
if (room.zoneId !== zoneId) continue;
|
|
20693
|
+
await updateRoom(pctx, {
|
|
20694
|
+
id: room.id,
|
|
20695
|
+
patch: { zoneId: to }
|
|
20696
|
+
});
|
|
20697
|
+
}
|
|
20698
|
+
}
|
|
20699
|
+
async function removeSiteZone(pctx, input) {
|
|
20700
|
+
const zone = pctx.rooms.zones.findByName(input.name);
|
|
20701
|
+
if (zone === null) return;
|
|
20702
|
+
await detachRooms(pctx, zone.id, null);
|
|
20703
|
+
await pctx.rooms.zones.delete(zone.id);
|
|
20704
|
+
}
|
|
20705
|
+
async function renameSiteZone(pctx, input) {
|
|
20706
|
+
const to = requireName(input.to, "system.site-zone-name-required", "renameSiteZone");
|
|
20707
|
+
const source = pctx.rooms.zones.findByName(input.from);
|
|
20708
|
+
if (source === null) return;
|
|
20709
|
+
const target = pctx.rooms.zones.findByName(to);
|
|
20710
|
+
if (target === null || target.id === source.id) {
|
|
20711
|
+
await pctx.rooms.zones.update(source.id, (current) => ({
|
|
20712
|
+
...current,
|
|
20713
|
+
name: to
|
|
20714
|
+
}));
|
|
20715
|
+
return;
|
|
20716
|
+
}
|
|
20717
|
+
await detachRooms(pctx, source.id, target.id);
|
|
20718
|
+
await pctx.rooms.zones.delete(source.id);
|
|
20719
|
+
}
|
|
20720
|
+
async function setLocationZone(pctx, input) {
|
|
20721
|
+
const name = requireName(input.location, "system.location-required", "setLocationZone");
|
|
20722
|
+
if (input.zone === null) {
|
|
20723
|
+
const existing = pctx.rooms.rooms.findByName(name);
|
|
20724
|
+
if (existing === null || existing.zoneId === void 0) return;
|
|
20725
|
+
await updateRoom(pctx, {
|
|
20726
|
+
id: existing.id,
|
|
20727
|
+
patch: { zoneId: null }
|
|
20728
|
+
});
|
|
20729
|
+
return;
|
|
20730
|
+
}
|
|
20731
|
+
const zoneName = requireName(input.zone, "system.site-zone-name-required", "setLocationZone");
|
|
20732
|
+
const zone = await pctx.rooms.zones.ensure(zoneName, {});
|
|
20733
|
+
const room = await pctx.rooms.rooms.ensure(name, {});
|
|
20734
|
+
if (room.zoneId === zone.id) return;
|
|
20735
|
+
await updateRoom(pctx, {
|
|
20736
|
+
id: room.id,
|
|
20737
|
+
patch: { zoneId: zone.id }
|
|
20738
|
+
});
|
|
20739
|
+
}
|
|
20740
|
+
//#endregion
|
|
19496
20741
|
//#region src/builtins/device-manager/device-meta-actions.ts
|
|
19497
20742
|
/**
|
|
19498
20743
|
* Device meta-mutation + persistence actions for the device-manager addon —
|
|
@@ -19568,6 +20813,7 @@ async function allocateDeviceId(pctx, input) {
|
|
|
19568
20813
|
type: "generic",
|
|
19569
20814
|
name: stableId,
|
|
19570
20815
|
location: null,
|
|
20816
|
+
locationId: null,
|
|
19571
20817
|
disabled: false,
|
|
19572
20818
|
parentDeviceId: null,
|
|
19573
20819
|
id
|
|
@@ -19662,7 +20908,16 @@ async function migrateDevice(pctx, input) {
|
|
|
19662
20908
|
assertNoFieldClaims: async (a, b) => {
|
|
19663
20909
|
try {
|
|
19664
20910
|
await assertNoFieldClaims(pctx.settings, a, b);
|
|
20911
|
+
await assertNoCrossedSecretScopes(pctx.settings, a, b);
|
|
19665
20912
|
} catch (err) {
|
|
20913
|
+
if (err instanceof SecretScopesCrossedError) for (const c of err.crossed) ctx.logger.warn("migrateDevice refused: secret scopes crossed", {
|
|
20914
|
+
tags: { deviceId: c.deviceId },
|
|
20915
|
+
meta: {
|
|
20916
|
+
sourceId: a,
|
|
20917
|
+
targetId: b,
|
|
20918
|
+
markers: c.markers
|
|
20919
|
+
}
|
|
20920
|
+
});
|
|
19666
20921
|
if (err instanceof FieldClaimsBlockMigrationError) for (const blocked of err.blocked) ctx.logger.warn("migrateDevice refused: fields claimed by a customization", {
|
|
19667
20922
|
tags: { deviceId: blocked.deviceId },
|
|
19668
20923
|
meta: {
|
|
@@ -19675,7 +20930,8 @@ async function migrateDevice(pctx, input) {
|
|
|
19675
20930
|
}
|
|
19676
20931
|
},
|
|
19677
20932
|
swapHardwareState: async (a, b) => {
|
|
19678
|
-
const
|
|
20933
|
+
const forOwner = pctx.host.ctx.secrets?.forOwner;
|
|
20934
|
+
const swapped = await swapHardwareState(pctx.settings, a, b, forOwner === void 0 || forOwner === null ? void 0 : { forOwner });
|
|
19679
20935
|
pctx.host.seedMirror(a, pctx.host.withResetSessionProbe(swapped.runtimeStateNowAtSource), "replace");
|
|
19680
20936
|
pctx.host.seedMirror(b, pctx.host.withResetSessionProbe(swapped.runtimeStateNowAtTarget), "replace");
|
|
19681
20937
|
ctx.logger.info("migration: hardware-scoped device state swapped", {
|
|
@@ -19686,9 +20942,11 @@ async function migrateDevice(pctx, input) {
|
|
|
19686
20942
|
hardwareKeysToSource: swapped.hardwareKeysToSource,
|
|
19687
20943
|
hardwareKeysToTarget: swapped.hardwareKeysToTarget,
|
|
19688
20944
|
roleKeysKeptAtSource: swapped.roleKeysKeptAtSource,
|
|
19689
|
-
roleKeysKeptAtTarget: swapped.roleKeysKeptAtTarget
|
|
20945
|
+
roleKeysKeptAtTarget: swapped.roleKeysKeptAtTarget,
|
|
20946
|
+
secretScopes: swapped.secretScopes
|
|
19690
20947
|
}
|
|
19691
20948
|
});
|
|
20949
|
+
return swapped.secretScopes;
|
|
19692
20950
|
},
|
|
19693
20951
|
forgetStreamState: async (deviceId) => {
|
|
19694
20952
|
await ctx.api.streamBroker.forgetDeviceHardware.mutate({ deviceId });
|
|
@@ -19772,10 +21030,10 @@ async function registerDevice(pctx, input) {
|
|
|
19772
21030
|
deviceType: type,
|
|
19773
21031
|
features: settledFeatures
|
|
19774
21032
|
});
|
|
19775
|
-
const
|
|
21033
|
+
const priorLocationId = existingMeta?.locationId ?? null;
|
|
19776
21034
|
const resolvedParentId = parentDeviceId ?? null;
|
|
19777
21035
|
const parentChanged = existingMeta !== void 0 && (existingMeta.parentDeviceId ?? null) !== resolvedParentId;
|
|
19778
|
-
const inherited =
|
|
21036
|
+
const inherited = priorLocationId === null && resolvedParentId !== null && (isFirst || parentChanged) ? await resolveInheritedLocation(pctx.metaStore.rows, resolvedParentId) : null;
|
|
19779
21037
|
await pctx.metaStore.rows.upsertRegistration({
|
|
19780
21038
|
deviceId: id,
|
|
19781
21039
|
addonId,
|
|
@@ -19783,7 +21041,7 @@ async function registerDevice(pctx, input) {
|
|
|
19783
21041
|
type,
|
|
19784
21042
|
name: resolvedName,
|
|
19785
21043
|
userNamed: wasUserNamed,
|
|
19786
|
-
|
|
21044
|
+
locationId: priorLocationId ?? inherited?.locationId ?? null,
|
|
19787
21045
|
disabled: existingMeta?.disabled ?? false,
|
|
19788
21046
|
parentDeviceId: resolvedParentId,
|
|
19789
21047
|
registered: true,
|
|
@@ -19799,7 +21057,7 @@ async function registerDevice(pctx, input) {
|
|
|
19799
21057
|
if (inherited !== null) for (const descendant of await collectDescendants(pctx.metaStore, id)) {
|
|
19800
21058
|
if (descendant.location !== null) continue;
|
|
19801
21059
|
try {
|
|
19802
|
-
await pctx.metaStore.rows.patch(descendant.id, {
|
|
21060
|
+
await pctx.metaStore.rows.patch(descendant.id, { locationId: inherited.locationId });
|
|
19803
21061
|
descendantsFilled.push(descendant.id);
|
|
19804
21062
|
} catch (err) {
|
|
19805
21063
|
descendantsFailed.push({
|
|
@@ -19813,7 +21071,7 @@ async function registerDevice(pctx, input) {
|
|
|
19813
21071
|
storedFeatures: settledFeatures,
|
|
19814
21072
|
exportFingerprint: fingerprint,
|
|
19815
21073
|
fingerprintChanged: existingMeta?.exportFingerprint !== fingerprint,
|
|
19816
|
-
inheritedLocation: inherited,
|
|
21074
|
+
inheritedLocation: inherited?.location ?? null,
|
|
19817
21075
|
inheritedDescendantIds: descendantsFilled,
|
|
19818
21076
|
inheritFailed: descendantsFailed,
|
|
19819
21077
|
filledRole: roleToFill
|
|
@@ -20079,8 +21337,38 @@ function removalSteps(pctx, deviceId, providerAddonId, deletedAt) {
|
|
|
20079
21337
|
})
|
|
20080
21338
|
];
|
|
20081
21339
|
}
|
|
21340
|
+
/**
|
|
21341
|
+
* The rows that belong to `deviceId` and cannot outlive it: its accessory
|
|
21342
|
+
* children (`parentDeviceId === id`). A row that merely LINKS to it
|
|
21343
|
+
* (`linkDeviceId`: an operator-picked link, or an entity of another integration
|
|
21344
|
+
* adopted under its own container) is a device of its own and stays.
|
|
21345
|
+
*/
|
|
21346
|
+
async function ownedRowIds(pctx, deviceId) {
|
|
21347
|
+
return (await pctx.metaStore.rows.listByParent(deviceId)).map((row) => row.meta.id).filter((id) => id !== deviceId);
|
|
21348
|
+
}
|
|
21349
|
+
/**
|
|
21350
|
+
* Removing a device removes what it owns (an accessory child never outlives its
|
|
21351
|
+
* parent: a Reolink siren row survived its camera with a dangling
|
|
21352
|
+
* `parentDeviceId`). Each child goes through the same tombstoned removal, so
|
|
21353
|
+
* its data stores, its removal hooks and its identity fence are the parent's.
|
|
21354
|
+
*/
|
|
20082
21355
|
async function removeDevice(pctx, input) {
|
|
20083
|
-
|
|
21356
|
+
await removeDeviceTree(pctx, input.deviceId, /* @__PURE__ */ new Set());
|
|
21357
|
+
}
|
|
21358
|
+
async function removeDeviceTree(pctx, deviceId, seen) {
|
|
21359
|
+
if (seen.has(deviceId)) return;
|
|
21360
|
+
seen.add(deviceId);
|
|
21361
|
+
const ownedIds = await ownedRowIds(pctx, deviceId);
|
|
21362
|
+
await removeOneDevice(pctx, deviceId);
|
|
21363
|
+
for (const childId of ownedIds) {
|
|
21364
|
+
pctx.host.ctx.logger.info("removed device: cascading to an owned child", {
|
|
21365
|
+
tags: { deviceId: childId },
|
|
21366
|
+
meta: { parentDeviceId: deviceId }
|
|
21367
|
+
});
|
|
21368
|
+
await removeDeviceTree(pctx, childId, seen);
|
|
21369
|
+
}
|
|
21370
|
+
}
|
|
21371
|
+
async function removeOneDevice(pctx, deviceId) {
|
|
20084
21372
|
const persisted = await pctx.metaStore.resolvePersistedById(deviceId);
|
|
20085
21373
|
if (!persisted) return;
|
|
20086
21374
|
const { addonId, stableId, meta: persistedMeta } = persisted;
|
|
@@ -20347,15 +21635,18 @@ async function collectDescendants(metaStore, rootId) {
|
|
|
20347
21635
|
* consumers (the linked-devices picker, which suggests by location) see exactly what landed.
|
|
20348
21636
|
*/
|
|
20349
21637
|
async function setLocation(pctx, input) {
|
|
20350
|
-
const { deviceId
|
|
21638
|
+
const { deviceId } = input;
|
|
21639
|
+
const locationId = await resolveRoomId(pctx, input);
|
|
21640
|
+
if (locationId === void 0) throw new Error("[device-manager] setLocation: name `location` or `locationId`");
|
|
21641
|
+
const location = pctx.rooms.nameOf(locationId);
|
|
20351
21642
|
const cascaded = [];
|
|
20352
21643
|
const failed = [];
|
|
20353
21644
|
await pctx.metaStore.withMetaWriteLock(async () => {
|
|
20354
21645
|
if (!await pctx.metaStore.resolvePersistedById(deviceId)) throw new Error(`[device-manager] setLocation: unknown device id=${deviceId}`);
|
|
20355
|
-
await pctx.metaStore.rows.patch(deviceId, {
|
|
21646
|
+
await pctx.metaStore.rows.patch(deviceId, { locationId });
|
|
20356
21647
|
const descendants = await collectDescendants(pctx.metaStore, deviceId);
|
|
20357
21648
|
for (const descendant of descendants) try {
|
|
20358
|
-
await pctx.metaStore.rows.patch(descendant.id, {
|
|
21649
|
+
await pctx.metaStore.rows.patch(descendant.id, { locationId });
|
|
20359
21650
|
cascaded.push(descendant.id);
|
|
20360
21651
|
} catch (err) {
|
|
20361
21652
|
failed.push({
|
|
@@ -20409,10 +21700,24 @@ async function setLocation(pctx, input) {
|
|
|
20409
21700
|
}
|
|
20410
21701
|
});
|
|
20411
21702
|
}
|
|
20412
|
-
/** The
|
|
20413
|
-
function
|
|
20414
|
-
|
|
20415
|
-
return
|
|
21703
|
+
/** The current names of tag ids; an id with no tag record is left out, never shown raw. */
|
|
21704
|
+
function tagNamesOf(pctx, ids) {
|
|
21705
|
+
if (ids === null) return null;
|
|
21706
|
+
return ids.flatMap((id) => {
|
|
21707
|
+
const name = pctx.tagNameOf(id);
|
|
21708
|
+
return name === null ? [] : [name];
|
|
21709
|
+
});
|
|
21710
|
+
}
|
|
21711
|
+
/**
|
|
21712
|
+
* The tag ids a write names: `tagIds` wins, else `tags` (text) is resolved through
|
|
21713
|
+
* `ensureTag` (D1089, accepted for one release). `[]` stays `[]`: the operator cleared
|
|
21714
|
+
* them, and `null` would let the kept names of an older row read back as tags again.
|
|
21715
|
+
*/
|
|
21716
|
+
async function resolveTagIds(pctx, input) {
|
|
21717
|
+
if (input.tagIds !== void 0) return [...new Set(input.tagIds)];
|
|
21718
|
+
const names = require_tag.normalizeTags(input.tags ?? []);
|
|
21719
|
+
if (names.length === 0) return [];
|
|
21720
|
+
return [...new Set(await pctx.ensureTagIds(names))];
|
|
20416
21721
|
}
|
|
20417
21722
|
/**
|
|
20418
21723
|
* Replace the operator tags of one device (D1054). Normalised on write; `[]`
|
|
@@ -20421,10 +21726,11 @@ function storedTags(tags) {
|
|
|
20421
21726
|
*/
|
|
20422
21727
|
async function setTags(pctx, input) {
|
|
20423
21728
|
const { deviceId } = input;
|
|
20424
|
-
const
|
|
21729
|
+
const tagIds = await resolveTagIds(pctx, input);
|
|
21730
|
+
const tags = tagNamesOf(pctx, tagIds);
|
|
20425
21731
|
await pctx.metaStore.withMetaWriteLock(async () => {
|
|
20426
21732
|
if (!await pctx.metaStore.resolvePersistedById(deviceId)) throw new Error(`[device-manager] setTags: unknown device id=${deviceId}`);
|
|
20427
|
-
await pctx.metaStore.rows.patch(deviceId, {
|
|
21733
|
+
await pctx.metaStore.rows.patch(deviceId, { tagIds });
|
|
20428
21734
|
});
|
|
20429
21735
|
pctx.host.ctx.eventBus.emit({
|
|
20430
21736
|
id: (0, node_crypto.randomUUID)(),
|
|
@@ -20716,12 +22022,14 @@ async function setRoleDisplayDefaults(pctx, input) {
|
|
|
20716
22022
|
*/
|
|
20717
22023
|
async function applyInitialMeta(pctx, input) {
|
|
20718
22024
|
const { deviceId, name, location, tags, type, integrationId, linkDeviceId, role } = input;
|
|
22025
|
+
const locationId = location === void 0 && input.locationId === void 0 ? void 0 : await resolveRoomId(pctx, input);
|
|
22026
|
+
const tagIds = tags === void 0 && input.tagIds === void 0 ? void 0 : await resolveTagIds(pctx, input);
|
|
20719
22027
|
await pctx.metaStore.withMetaWriteLock(async () => {
|
|
20720
22028
|
if (!await pctx.metaStore.resolvePersistedById(deviceId)) throw new Error(`[device-manager] applyInitialMeta: unknown device id=${deviceId}`);
|
|
20721
22029
|
await pctx.metaStore.rows.patch(deviceId, {
|
|
20722
22030
|
...name !== void 0 ? { name } : {},
|
|
20723
|
-
...
|
|
20724
|
-
...
|
|
22031
|
+
...locationId !== void 0 ? { locationId } : {},
|
|
22032
|
+
...tagIds !== void 0 ? { tagIds } : {},
|
|
20725
22033
|
...type !== void 0 ? { type } : {},
|
|
20726
22034
|
...integrationId !== void 0 ? { integrationId } : {},
|
|
20727
22035
|
...linkDeviceId !== void 0 ? { linkDeviceId } : {},
|
|
@@ -20745,8 +22053,8 @@ async function applyInitialMeta(pctx, input) {
|
|
|
20745
22053
|
});
|
|
20746
22054
|
};
|
|
20747
22055
|
if (name !== void 0) emitMetaChanged("name", name);
|
|
20748
|
-
if (
|
|
20749
|
-
if (
|
|
22056
|
+
if (locationId !== void 0) emitMetaChanged("location", pctx.rooms.nameOf(locationId));
|
|
22057
|
+
if (tagIds !== void 0) emitMetaChanged("tags", tagNamesOf(pctx, tagIds) ?? []);
|
|
20750
22058
|
if (type !== void 0) emitMetaChanged("type", type);
|
|
20751
22059
|
if (integrationId !== void 0) emitMetaChanged("integrationId", integrationId);
|
|
20752
22060
|
if (linkDeviceId !== void 0) emitMetaChanged("linkDeviceId", linkDeviceId);
|
|
@@ -20858,480 +22166,109 @@ async function loadRuntimeState(pctx, input) {
|
|
|
20858
22166
|
return splitRuntimeBlob(pctx.host.seedMirrorFromRow(deviceId, data, pctx.settings)).native;
|
|
20859
22167
|
}
|
|
20860
22168
|
/**
|
|
20861
|
-
*
|
|
20862
|
-
*
|
|
20863
|
-
*
|
|
20864
|
-
*
|
|
20865
|
-
*
|
|
20866
|
-
*/
|
|
20867
|
-
async function listLocations(pctx) {
|
|
20868
|
-
const locations = (await pctx.metaStore.readStore()).locations ?? [];
|
|
20869
|
-
const seen = /* @__PURE__ */ new Map();
|
|
20870
|
-
const consider = (raw) => {
|
|
20871
|
-
if (typeof raw !== "string") return;
|
|
20872
|
-
const trimmed = raw.trim();
|
|
20873
|
-
if (trimmed.length === 0) return;
|
|
20874
|
-
const key = trimmed.toLowerCase();
|
|
20875
|
-
if (!seen.has(key)) seen.set(key, trimmed);
|
|
20876
|
-
};
|
|
20877
|
-
for (const label of locations) consider(label);
|
|
20878
|
-
for (const row of await pctx.metaStore.rows.listAll()) consider(row.meta.location);
|
|
20879
|
-
return [...seen.values()].toSorted((a, b) => a.localeCompare(b, void 0, { sensitivity: "base" }));
|
|
20880
|
-
}
|
|
20881
|
-
/**
|
|
20882
|
-
* Add a label to the curated location registry. Idempotent:
|
|
20883
|
-
* existing entries (case-insensitive match) are silently kept.
|
|
20884
|
-
* Empty / whitespace-only inputs throw — operators must supply a
|
|
20885
|
-
* meaningful label.
|
|
20886
|
-
*/
|
|
20887
|
-
async function addLocation(pctx, input) {
|
|
20888
|
-
const trimmed = input.name.trim();
|
|
20889
|
-
if (trimmed.length === 0) throw require_camstack_error.userError("system.location-name-required", void 0, "[device-manager] addLocation: name must be non-empty");
|
|
20890
|
-
await pctx.bindingsDeps.withAddonStoreWriteLock(async () => {
|
|
20891
|
-
const current = (await pctx.metaStore.readStore()).locations ?? [];
|
|
20892
|
-
if (current.some((l) => l.toLowerCase() === trimmed.toLowerCase())) return;
|
|
20893
|
-
await pctx.settings.writeAddonStore({ locations: [...current, trimmed] });
|
|
20894
|
-
});
|
|
20895
|
-
}
|
|
20896
|
-
/**
|
|
20897
|
-
* Every location that carries an icon, as `(locationKey, icon)` pairs.
|
|
20898
|
-
*
|
|
20899
|
-
* ADDITIVE beside `listLocations`, which still answers `string[]` — the
|
|
20900
|
-
* autocomplete, the HA adoption import and the recorder all read a list of
|
|
20901
|
-
* LABELS and a shape change there would break every one of them. A surface
|
|
20902
|
-
* that wants icons asks for them and joins on `locationIconKey`.
|
|
20903
|
-
*
|
|
20904
|
-
* Returns only what was actually stored. A location with no assignment is
|
|
20905
|
-
* ABSENT, never `map-pin`: the fallback belongs to the renderer
|
|
20906
|
-
* (`resolveIconKey`), and folding it in here would make "the operator
|
|
20907
|
-
* picked the pin" indistinguishable from "the operator picked nothing" —
|
|
20908
|
-
* which is the difference an icon picker has to draw.
|
|
20909
|
-
*/
|
|
20910
|
-
async function listLocationIcons(pctx) {
|
|
20911
|
-
const icons = (await pctx.metaStore.readStore()).locationIcons ?? {};
|
|
20912
|
-
return Object.entries(icons).map(([locationKey, icon]) => ({
|
|
20913
|
-
locationKey,
|
|
20914
|
-
icon
|
|
20915
|
-
})).toSorted((a, b) => a.locationKey.localeCompare(b.locationKey));
|
|
20916
|
-
}
|
|
20917
|
-
/**
|
|
20918
|
-
* Set (or clear) the icon of a location label.
|
|
20919
|
-
*
|
|
20920
|
-
* Keyed on `locationIconKey` — trimmed + lower-cased, the equality the
|
|
20921
|
-
* registry matches on everywhere — so a case-only rename keeps the icon and
|
|
20922
|
-
* two spellings of one room can never carry two different icons.
|
|
20923
|
-
*
|
|
20924
|
-
* The label need NOT be registered: `setLocation` accepts a free-form string
|
|
20925
|
-
* and `listLocations` folds in whatever devices carry, so requiring
|
|
20926
|
-
* registration here would leave exactly the ad-hoc rooms unable to have an
|
|
20927
|
-
* icon. An empty label throws — there is no room to name.
|
|
20928
|
-
*
|
|
20929
|
-
* Same read-modify-write and same lock as `addLocation`: the map is one key of
|
|
20930
|
-
* the addon store, and `writeAddonStore` re-inserts the whole key range, so an
|
|
20931
|
-
* unordered write carries a stale copy of every other key.
|
|
22169
|
+
* `deviceManager.repairMigrationSecrets` — the live repair for a pair a
|
|
22170
|
+
* migration left with crossed keychain scopes (see `repairCrossedSecretScopes`).
|
|
22171
|
+
* Under the meta write lock the migration itself ran under: a config write
|
|
22172
|
+
* racing it would read the half this repair is moving. The running devices
|
|
22173
|
+
* keep their loaded config until the next reload.
|
|
20932
22174
|
*/
|
|
20933
|
-
async function
|
|
20934
|
-
const
|
|
20935
|
-
|
|
20936
|
-
const
|
|
20937
|
-
await pctx.
|
|
20938
|
-
|
|
20939
|
-
|
|
20940
|
-
|
|
20941
|
-
|
|
20942
|
-
|
|
20943
|
-
|
|
20944
|
-
|
|
20945
|
-
if (icons[key] === input.icon) return;
|
|
20946
|
-
await pctx.settings.writeAddonStore({ locationIcons: {
|
|
20947
|
-
...icons,
|
|
20948
|
-
[key]: input.icon
|
|
20949
|
-
} });
|
|
20950
|
-
});
|
|
20951
|
-
}
|
|
20952
|
-
/**
|
|
20953
|
-
* Every location that carries a description, sorted by key.
|
|
20954
|
-
*
|
|
20955
|
-
* Only what was WRITTEN — a location with no description is absent, and the
|
|
20956
|
-
* digest then tells the model the location name alone, exactly as it did
|
|
20957
|
-
* before descriptions existed.
|
|
20958
|
-
*/
|
|
20959
|
-
async function listLocationDescriptions(pctx) {
|
|
20960
|
-
const descriptions = (await pctx.metaStore.readStore()).locationDescriptions ?? {};
|
|
20961
|
-
return Object.entries(descriptions).map(([locationKey, description]) => ({
|
|
20962
|
-
locationKey,
|
|
20963
|
-
description
|
|
20964
|
-
})).toSorted((a, b) => a.locationKey.localeCompare(b.locationKey));
|
|
20965
|
-
}
|
|
20966
|
-
/**
|
|
20967
|
-
* Set (or clear) a location's description.
|
|
20968
|
-
*
|
|
20969
|
-
* A BLANK description clears, exactly as `null` does: an empty line handed to
|
|
20970
|
-
* a vision model costs attention and says nothing, so the two must not be
|
|
20971
|
-
* different states. The label is folded with `locationIconKey` — the same key
|
|
20972
|
-
* the icon uses, which is the whole point of this living here.
|
|
20973
|
-
*
|
|
20974
|
-
* Same read-modify-write and same lock as `setLocationIcon`; `writeAddonStore`
|
|
20975
|
-
* re-inserts the whole key range, so an unordered write carries a stale copy
|
|
20976
|
-
* of every other key.
|
|
20977
|
-
*/
|
|
20978
|
-
async function setLocationDescription(pctx, input) {
|
|
20979
|
-
const trimmed = input.location.trim();
|
|
20980
|
-
if (trimmed.length === 0) throw new Error("[device-manager] setLocationDescription: location must be non-empty");
|
|
20981
|
-
const key = require_addon_settings_cap.locationIconKey(trimmed);
|
|
20982
|
-
const text = input.description === null ? "" : input.description.trim();
|
|
20983
|
-
await pctx.bindingsDeps.withAddonStoreWriteLock(async () => {
|
|
20984
|
-
const descriptions = (await pctx.metaStore.readStore()).locationDescriptions ?? {};
|
|
20985
|
-
if (text.length === 0) {
|
|
20986
|
-
if (!(key in descriptions)) return;
|
|
20987
|
-
const { [key]: _cleared, ...kept } = descriptions;
|
|
20988
|
-
await pctx.settings.writeAddonStore({ locationDescriptions: kept });
|
|
20989
|
-
return;
|
|
22175
|
+
async function repairMigrationSecrets(pctx, input) {
|
|
22176
|
+
const { deviceA, deviceB, apply } = input;
|
|
22177
|
+
const ctx = pctx.host.ctx;
|
|
22178
|
+
const forOwner = ctx.secrets?.forOwner ?? null;
|
|
22179
|
+
const report = await pctx.metaStore.withMetaWriteLock(() => repairCrossedSecretScopes(pctx.settings, forOwner === null ? void 0 : { forOwner }, deviceA, deviceB, apply));
|
|
22180
|
+
for (const deviceId of [deviceA, deviceB]) ctx.logger.info("repairMigrationSecrets", {
|
|
22181
|
+
tags: { deviceId },
|
|
22182
|
+
meta: {
|
|
22183
|
+
deviceA,
|
|
22184
|
+
deviceB,
|
|
22185
|
+
apply,
|
|
22186
|
+
outcome: report.outcome
|
|
20990
22187
|
}
|
|
20991
|
-
if (descriptions[key] === text) return;
|
|
20992
|
-
await pctx.settings.writeAddonStore({ locationDescriptions: {
|
|
20993
|
-
...descriptions,
|
|
20994
|
-
[key]: text
|
|
20995
|
-
} });
|
|
20996
|
-
});
|
|
20997
|
-
}
|
|
20998
|
-
/**
|
|
20999
|
-
* Every site zone, with its rooms, sorted by key.
|
|
21000
|
-
*
|
|
21001
|
-
* Membership is inverted HERE rather than stored both ways: the store keeps
|
|
21002
|
-
* `location → zone`, which is what makes "one zone per room" structural, and a
|
|
21003
|
-
* second copy keyed the other way is a second thing that can disagree with the
|
|
21004
|
-
* first.
|
|
21005
|
-
*/
|
|
21006
|
-
async function listSiteZones(pctx) {
|
|
21007
|
-
const store = await pctx.metaStore.readStore();
|
|
21008
|
-
const zones = store.siteZones ?? {};
|
|
21009
|
-
const membership = store.locationZones ?? {};
|
|
21010
|
-
const rooms = /* @__PURE__ */ new Map();
|
|
21011
|
-
for (const [locationKey, zoneKey] of Object.entries(membership)) {
|
|
21012
|
-
const list = rooms.get(zoneKey);
|
|
21013
|
-
if (list === void 0) rooms.set(zoneKey, [locationKey]);
|
|
21014
|
-
else list.push(locationKey);
|
|
21015
|
-
}
|
|
21016
|
-
return Object.entries(zones).map(([zoneKey, record]) => ({
|
|
21017
|
-
zoneKey,
|
|
21018
|
-
label: record.label,
|
|
21019
|
-
icon: record.icon ?? null,
|
|
21020
|
-
locationKeys: (rooms.get(zoneKey) ?? []).toSorted((a, b) => a.localeCompare(b))
|
|
21021
|
-
})).toSorted((a, b) => a.zoneKey.localeCompare(b.zoneKey));
|
|
21022
|
-
}
|
|
21023
|
-
/**
|
|
21024
|
-
* Create a zone, or set the icon of one that already exists.
|
|
21025
|
-
*
|
|
21026
|
-
* `icon: null` clears the icon and KEEPS the zone. Conflating the two would
|
|
21027
|
-
* make a mis-click on "no icon" delete every room's membership — the icon is a
|
|
21028
|
-
* decoration and the grouping is the data.
|
|
21029
|
-
*
|
|
21030
|
-
* `icon` OMITTED leaves whatever icon is there: creating a zone from a screen
|
|
21031
|
-
* with no picker must not silently clear the glyph a previous screen set.
|
|
21032
|
-
*/
|
|
21033
|
-
async function setSiteZone(pctx, input) {
|
|
21034
|
-
const label = input.name.trim();
|
|
21035
|
-
if (label.length === 0) throw require_camstack_error.userError("system.site-zone-name-required", void 0, "[device-manager] setSiteZone: name must be non-empty");
|
|
21036
|
-
const key = require_device_manager_cap.siteZoneKey(label);
|
|
21037
|
-
await pctx.bindingsDeps.withAddonStoreWriteLock(async () => {
|
|
21038
|
-
const zones = (await pctx.metaStore.readStore()).siteZones ?? {};
|
|
21039
|
-
const existing = zones[key];
|
|
21040
|
-
const icon = input.icon === void 0 ? existing?.icon : input.icon === null ? void 0 : input.icon;
|
|
21041
|
-
const next = icon === void 0 ? { label } : {
|
|
21042
|
-
label,
|
|
21043
|
-
icon
|
|
21044
|
-
};
|
|
21045
|
-
if (existing?.label === next.label && existing.icon === next.icon) return;
|
|
21046
|
-
await pctx.settings.writeAddonStore({ siteZones: {
|
|
21047
|
-
...zones,
|
|
21048
|
-
[key]: next
|
|
21049
|
-
} });
|
|
21050
|
-
});
|
|
21051
|
-
}
|
|
21052
|
-
/**
|
|
21053
|
-
* Delete a zone. Its LOCATIONS survive, unattached.
|
|
21054
|
-
*
|
|
21055
|
-
* Deleting a grouping must never delete what was grouped — the rooms exist
|
|
21056
|
-
* independently and the devices in them were never touched to begin with.
|
|
21057
|
-
*/
|
|
21058
|
-
async function removeSiteZone(pctx, input) {
|
|
21059
|
-
const key = require_device_manager_cap.siteZoneKey(input.name);
|
|
21060
|
-
await pctx.bindingsDeps.withAddonStoreWriteLock(async () => {
|
|
21061
|
-
const store = await pctx.metaStore.readStore();
|
|
21062
|
-
const zones = store.siteZones ?? {};
|
|
21063
|
-
const membership = store.locationZones ?? {};
|
|
21064
|
-
const hadZone = key in zones;
|
|
21065
|
-
const orphaned = Object.entries(membership).filter(([, zoneKey]) => zoneKey === key);
|
|
21066
|
-
if (!hadZone && orphaned.length === 0) return;
|
|
21067
|
-
const { [key]: _dropped, ...keptZones } = zones;
|
|
21068
|
-
const keptMembership = Object.fromEntries(Object.entries(membership).filter(([, zoneKey]) => zoneKey !== key));
|
|
21069
|
-
await pctx.settings.writeAddonStore({
|
|
21070
|
-
...hadZone ? { siteZones: keptZones } : {},
|
|
21071
|
-
...orphaned.length > 0 ? { locationZones: keptMembership } : {}
|
|
21072
|
-
});
|
|
21073
|
-
});
|
|
21074
|
-
}
|
|
21075
|
-
/**
|
|
21076
|
-
* Rename a zone, carrying its icon AND every room in it.
|
|
21077
|
-
*
|
|
21078
|
-
* It exists so that renaming is not delete-then-recreate, which drops both.
|
|
21079
|
-
* A rename onto an existing zone MERGES: the target keeps its own icon and the
|
|
21080
|
-
* rooms are unioned, the same rule `renameLocation` follows.
|
|
21081
|
-
*/
|
|
21082
|
-
async function renameSiteZone(pctx, input) {
|
|
21083
|
-
const toLabel = input.to.trim();
|
|
21084
|
-
if (toLabel.length === 0) throw new Error("[device-manager] renameSiteZone: target name must be non-empty");
|
|
21085
|
-
const fromKey = require_device_manager_cap.siteZoneKey(input.from);
|
|
21086
|
-
const toKey = require_device_manager_cap.siteZoneKey(toLabel);
|
|
21087
|
-
await pctx.bindingsDeps.withAddonStoreWriteLock(async () => {
|
|
21088
|
-
const store = await pctx.metaStore.readStore();
|
|
21089
|
-
const zones = store.siteZones ?? {};
|
|
21090
|
-
const moved = zones[fromKey];
|
|
21091
|
-
if (moved === void 0) return;
|
|
21092
|
-
const { [fromKey]: _dropped, ...rest } = zones;
|
|
21093
|
-
const target = rest[toKey];
|
|
21094
|
-
const nextZones = {
|
|
21095
|
-
...rest,
|
|
21096
|
-
[toKey]: target ?? (moved.icon === void 0 ? { label: toLabel } : {
|
|
21097
|
-
label: toLabel,
|
|
21098
|
-
icon: moved.icon
|
|
21099
|
-
})
|
|
21100
|
-
};
|
|
21101
|
-
const membership = store.locationZones ?? {};
|
|
21102
|
-
const nextMembership = Object.fromEntries(Object.entries(membership).map(([locationKey, zoneKey]) => [locationKey, zoneKey === fromKey ? toKey : zoneKey]));
|
|
21103
|
-
await pctx.settings.writeAddonStore({
|
|
21104
|
-
siteZones: nextZones,
|
|
21105
|
-
locationZones: nextMembership
|
|
21106
|
-
});
|
|
21107
22188
|
});
|
|
22189
|
+
return report;
|
|
21108
22190
|
}
|
|
22191
|
+
//#endregion
|
|
22192
|
+
//#region src/builtins/device-manager/room-store.ts
|
|
21109
22193
|
/**
|
|
21110
|
-
*
|
|
22194
|
+
* The rooms and site zones of the property, as records with an id (D1089).
|
|
21111
22195
|
*
|
|
21112
|
-
*
|
|
21113
|
-
*
|
|
21114
|
-
*
|
|
21115
|
-
*
|
|
22196
|
+
* `rooms` and `zones` are record kinds the device manager owns; a device meta
|
|
22197
|
+
* carries `locationId`, a room carries `zoneId`. The store keeps both in memory
|
|
22198
|
+
* once read — a device read resolves a room name through {@link RoomStore.nameOf}
|
|
22199
|
+
* without a query, and an unknown id reads as unset.
|
|
21116
22200
|
*/
|
|
21117
|
-
|
|
21118
|
-
|
|
21119
|
-
|
|
21120
|
-
|
|
21121
|
-
|
|
21122
|
-
|
|
21123
|
-
|
|
21124
|
-
|
|
21125
|
-
|
|
21126
|
-
|
|
21127
|
-
|
|
21128
|
-
|
|
21129
|
-
|
|
21130
|
-
|
|
21131
|
-
|
|
21132
|
-
|
|
21133
|
-
|
|
21134
|
-
|
|
21135
|
-
|
|
21136
|
-
|
|
21137
|
-
|
|
21138
|
-
|
|
21139
|
-
|
|
21140
|
-
|
|
21141
|
-
|
|
21142
|
-
|
|
21143
|
-
|
|
22201
|
+
var RoomStore = class RoomStore {
|
|
22202
|
+
rooms;
|
|
22203
|
+
zones;
|
|
22204
|
+
constructor(rooms, zones) {
|
|
22205
|
+
this.rooms = rooms;
|
|
22206
|
+
this.zones = zones;
|
|
22207
|
+
}
|
|
22208
|
+
static of(records) {
|
|
22209
|
+
return new RoomStore(new require_named_entity_store.NamedEntityStore("room", records.kind(require_record_kinds.deviceManagerRecordKinds.rooms), (body) => require_device_manager_cap.RoomBodySchema.parse(body)), new require_named_entity_store.NamedEntityStore("zone", records.kind(require_record_kinds.deviceManagerRecordKinds.zones), (body) => require_device_manager_cap.ZoneBodySchema.parse(body)));
|
|
22210
|
+
}
|
|
22211
|
+
async load() {
|
|
22212
|
+
await this.rooms.load();
|
|
22213
|
+
await this.zones.load();
|
|
22214
|
+
}
|
|
22215
|
+
/** The current name of room `id`; `null` when unset or unknown. */
|
|
22216
|
+
nameOf(id) {
|
|
22217
|
+
return this.rooms.nameOf(id);
|
|
22218
|
+
}
|
|
22219
|
+
};
|
|
22220
|
+
var TagNames = class {
|
|
22221
|
+
source;
|
|
22222
|
+
logger;
|
|
22223
|
+
now;
|
|
22224
|
+
names = /* @__PURE__ */ new Map();
|
|
22225
|
+
refreshedAt = 0;
|
|
22226
|
+
inFlight = null;
|
|
22227
|
+
constructor(source, logger, now = Date.now) {
|
|
22228
|
+
this.source = source;
|
|
22229
|
+
this.logger = logger;
|
|
22230
|
+
this.now = now;
|
|
22231
|
+
}
|
|
22232
|
+
nameOf(id) {
|
|
22233
|
+
return this.names.get(id) ?? null;
|
|
22234
|
+
}
|
|
22235
|
+
/** Revalidate when older than the window. A failed read keeps the last answer. */
|
|
22236
|
+
async fresh() {
|
|
22237
|
+
if (this.source === null) return;
|
|
22238
|
+
if (this.now() - this.refreshedAt < 5e3) return;
|
|
22239
|
+
await this.refresh();
|
|
22240
|
+
}
|
|
22241
|
+
async refresh() {
|
|
22242
|
+
const source = this.source;
|
|
22243
|
+
if (source === null) return;
|
|
22244
|
+
if (this.inFlight !== null) return this.inFlight;
|
|
22245
|
+
const run = (async () => {
|
|
22246
|
+
try {
|
|
22247
|
+
const tags = await source.list();
|
|
22248
|
+
this.names = new Map(tags.map((tag) => [tag.id, tag.name]));
|
|
22249
|
+
this.refreshedAt = this.now();
|
|
22250
|
+
} catch (err) {
|
|
22251
|
+
this.logger.warn("tag names not refreshed — keeping the last answer", { meta: { error: require_scoped_settings.errMsg(err) } });
|
|
22252
|
+
} finally {
|
|
22253
|
+
this.inFlight = null;
|
|
21144
22254
|
}
|
|
21145
|
-
});
|
|
21146
|
-
|
|
21147
|
-
|
|
21148
|
-
|
|
21149
|
-
|
|
21150
|
-
|
|
21151
|
-
|
|
21152
|
-
|
|
21153
|
-
|
|
21154
|
-
|
|
21155
|
-
|
|
21156
|
-
|
|
21157
|
-
return toKey in rest ? rest : {
|
|
21158
|
-
...rest,
|
|
21159
|
-
[toKey]: moved
|
|
21160
|
-
};
|
|
21161
|
-
}
|
|
21162
|
-
/**
|
|
21163
|
-
* Move a location's description from one key to another, for `renameLocation`.
|
|
21164
|
-
*
|
|
21165
|
-
* Identical rule to {@link renameLocationIcon}, deliberately: a merge keeps the
|
|
21166
|
-
* TARGET's description, because renaming "Sala" into "Hall" moves devices
|
|
21167
|
-
* into Hall and does not re-describe it. Split from the icon mover only
|
|
21168
|
-
* because the value types differ; if one ever changes, the other must.
|
|
21169
|
-
*/
|
|
21170
|
-
function renameLocationDescription(descriptions, fromKey, toKey) {
|
|
21171
|
-
const moved = descriptions[fromKey];
|
|
21172
|
-
if (moved === void 0) return null;
|
|
21173
|
-
if (fromKey === toKey) return null;
|
|
21174
|
-
const { [fromKey]: _dropped, ...rest } = descriptions;
|
|
21175
|
-
return toKey in rest ? rest : {
|
|
21176
|
-
...rest,
|
|
21177
|
-
[toKey]: moved
|
|
21178
|
-
};
|
|
21179
|
-
}
|
|
21180
|
-
/**
|
|
21181
|
-
* Move a location's icon from one key to another, for `renameLocation`.
|
|
21182
|
-
*
|
|
21183
|
-
* Returns `null` when NOTHING changes, so the caller can leave the key out of
|
|
21184
|
-
* its `writeAddonStore` patch instead of re-writing an identical map.
|
|
21185
|
-
*
|
|
21186
|
-
* A rename onto a room that already has an icon is a MERGE, and the surviving
|
|
21187
|
-
* room keeps its own: the operator renaming "Sala" into "Hall" is moving
|
|
21188
|
-
* devices into Hall, not restyling it. The source key is dropped either way.
|
|
21189
|
-
* Pure — builds a new record, mutates nothing.
|
|
21190
|
-
*/
|
|
21191
|
-
function renameLocationIcon(icons, fromKey, toKey) {
|
|
21192
|
-
const moved = icons[fromKey];
|
|
21193
|
-
if (moved === void 0) return null;
|
|
21194
|
-
if (fromKey === toKey) return null;
|
|
21195
|
-
const { [fromKey]: _dropped, ...rest } = icons;
|
|
21196
|
-
return toKey in rest ? rest : {
|
|
21197
|
-
...rest,
|
|
21198
|
-
[toKey]: moved
|
|
21199
|
-
};
|
|
21200
|
-
}
|
|
21201
|
-
/**
|
|
21202
|
-
* Remove a label from the curated registry. Match is
|
|
21203
|
-
* case-insensitive. Devices that still reference this label keep
|
|
21204
|
-
* their `meta.location` value (the registry is a suggestion
|
|
21205
|
-
* list, not a foreign key) — pass `cascade: true` to also clear
|
|
21206
|
-
* `setLocation` on every device that referenced this exact
|
|
21207
|
-
* label. Cascade only matches case-insensitively + trimmed, same
|
|
21208
|
-
* as the registry equality check.
|
|
21209
|
-
*/
|
|
21210
|
-
/**
|
|
21211
|
-
* Rename a room in ONE server operation: the registry label in place, then
|
|
21212
|
-
* every device that carried it.
|
|
21213
|
-
*
|
|
21214
|
-
* The lock order is the one `removeLocation` documents and must not be
|
|
21215
|
-
* "simplified": the registry edit takes the addon-store lock and RELEASES it
|
|
21216
|
-
* before the cascade takes the meta lock. Holding both, in that order, is the
|
|
21217
|
-
* reverse of `allocateNextDeviceId`'s meta ⊃ addon-store nesting — the pair
|
|
21218
|
-
* that deadlocks.
|
|
21219
|
-
*
|
|
21220
|
-
* Validation happens BEFORE either lock. A rename that throws halfway is the
|
|
21221
|
-
* exact failure this function exists to remove, so an empty target must be
|
|
21222
|
-
* refused while nothing has been written yet.
|
|
21223
|
-
*/
|
|
21224
|
-
async function renameLocation(pctx, input) {
|
|
21225
|
-
const from = input.from.trim();
|
|
21226
|
-
const to = input.to.trim();
|
|
21227
|
-
if (from.length === 0) throw new Error("[device-manager] renameLocation: `from` must be non-empty");
|
|
21228
|
-
if (to.length === 0) throw new Error("[device-manager] renameLocation: `to` must be non-empty");
|
|
21229
|
-
const fromKey = from.toLowerCase();
|
|
21230
|
-
const toKey = to.toLowerCase();
|
|
21231
|
-
await pctx.bindingsDeps.withAddonStoreWriteLock(async () => {
|
|
21232
|
-
const store = await pctx.metaStore.readStore();
|
|
21233
|
-
const current = store.locations ?? [];
|
|
21234
|
-
const registered = current.some((l) => l.trim().toLowerCase() === fromKey);
|
|
21235
|
-
const movedIcons = renameLocationIcon(store.locationIcons ?? {}, fromKey, toKey);
|
|
21236
|
-
const movedDescriptions = renameLocationDescription(store.locationDescriptions ?? {}, fromKey, toKey);
|
|
21237
|
-
const movedZones = renameLocationZone(store.locationZones ?? {}, fromKey, toKey);
|
|
21238
|
-
if (!registered && movedIcons === null && movedDescriptions === null && movedZones === null) return;
|
|
21239
|
-
const kept = current.filter((l) => {
|
|
21240
|
-
const key = l.trim().toLowerCase();
|
|
21241
|
-
return key !== fromKey && key !== toKey;
|
|
21242
|
-
});
|
|
21243
|
-
await pctx.settings.writeAddonStore({
|
|
21244
|
-
...registered ? { locations: [...kept, to] } : {},
|
|
21245
|
-
...movedIcons !== null ? { locationIcons: movedIcons } : {},
|
|
21246
|
-
...movedDescriptions !== null ? { locationDescriptions: movedDescriptions } : {},
|
|
21247
|
-
...movedZones !== null ? { locationZones: movedZones } : {}
|
|
21248
|
-
});
|
|
21249
|
-
});
|
|
21250
|
-
const moved = await pctx.metaStore.withMetaWriteLock(async () => {
|
|
21251
|
-
const out = [];
|
|
21252
|
-
for (const row of await pctx.metaStore.rows.listAll()) {
|
|
21253
|
-
const location = row.meta.location;
|
|
21254
|
-
if (typeof location !== "string") continue;
|
|
21255
|
-
if (location.trim().toLowerCase() !== fromKey) continue;
|
|
21256
|
-
await pctx.metaStore.rows.patch(row.meta.id, { location: to });
|
|
21257
|
-
out.push(row.meta.id);
|
|
21258
|
-
}
|
|
21259
|
-
return out;
|
|
21260
|
-
});
|
|
21261
|
-
for (const deviceId of moved) pctx.host.ctx.eventBus.emit({
|
|
21262
|
-
id: (0, node_crypto.randomUUID)(),
|
|
21263
|
-
timestamp: /* @__PURE__ */ new Date(),
|
|
21264
|
-
source: {
|
|
21265
|
-
type: "device",
|
|
21266
|
-
id: deviceId
|
|
21267
|
-
},
|
|
21268
|
-
category: require_base_addon.EventCategory.DeviceMetaChanged,
|
|
21269
|
-
data: {
|
|
21270
|
-
deviceId,
|
|
21271
|
-
field: "location",
|
|
21272
|
-
value: to
|
|
21273
|
-
}
|
|
21274
|
-
});
|
|
21275
|
-
pctx.host.ctx.logger.info("renameLocation: room renamed", { meta: {
|
|
21276
|
-
from,
|
|
21277
|
-
to,
|
|
21278
|
-
moved: moved.length
|
|
21279
|
-
} });
|
|
21280
|
-
return { moved: moved.length };
|
|
21281
|
-
}
|
|
21282
|
-
async function removeLocation(pctx, input) {
|
|
21283
|
-
const trimmed = input.name.trim();
|
|
21284
|
-
if (trimmed.length === 0) return;
|
|
21285
|
-
await pctx.bindingsDeps.withAddonStoreWriteLock(async () => {
|
|
21286
|
-
const store = await pctx.metaStore.readStore();
|
|
21287
|
-
const current = store.locations ?? [];
|
|
21288
|
-
const key = require_addon_settings_cap.locationIconKey(trimmed);
|
|
21289
|
-
const remaining = current.filter((l) => l.toLowerCase() !== key);
|
|
21290
|
-
const droppedLabel = remaining.length !== current.length;
|
|
21291
|
-
const icons = store.locationIcons ?? {};
|
|
21292
|
-
const droppedIcon = key in icons;
|
|
21293
|
-
const descriptions = store.locationDescriptions ?? {};
|
|
21294
|
-
const droppedDescription = key in descriptions;
|
|
21295
|
-
const membership = store.locationZones ?? {};
|
|
21296
|
-
const droppedZone = key in membership;
|
|
21297
|
-
if (!droppedLabel && !droppedIcon && !droppedDescription && !droppedZone) return;
|
|
21298
|
-
const { [key]: _removedIcon, ...keptIcons } = icons;
|
|
21299
|
-
const { [key]: _removedDescription, ...keptDescriptions } = descriptions;
|
|
21300
|
-
const { [key]: _removedZone, ...keptMembership } = membership;
|
|
21301
|
-
await pctx.settings.writeAddonStore({
|
|
21302
|
-
...droppedLabel ? { locations: remaining } : {},
|
|
21303
|
-
...droppedIcon ? { locationIcons: keptIcons } : {},
|
|
21304
|
-
...droppedDescription ? { locationDescriptions: keptDescriptions } : {},
|
|
21305
|
-
...droppedZone ? { locationZones: keptMembership } : {}
|
|
21306
|
-
});
|
|
21307
|
-
});
|
|
21308
|
-
if (input.cascade !== true) return;
|
|
21309
|
-
const cleared = await pctx.metaStore.withMetaWriteLock(async () => {
|
|
21310
|
-
const out = [];
|
|
21311
|
-
for (const row of await pctx.metaStore.rows.listAll()) {
|
|
21312
|
-
const location = row.meta.location;
|
|
21313
|
-
if (typeof location !== "string") continue;
|
|
21314
|
-
if (location.trim().toLowerCase() !== trimmed.toLowerCase()) continue;
|
|
21315
|
-
await pctx.metaStore.rows.patch(row.meta.id, { location: null });
|
|
21316
|
-
out.push(row.meta.id);
|
|
21317
|
-
}
|
|
21318
|
-
return out;
|
|
21319
|
-
});
|
|
21320
|
-
for (const deviceId of cleared) pctx.host.ctx.eventBus.emit({
|
|
21321
|
-
id: (0, node_crypto.randomUUID)(),
|
|
21322
|
-
timestamp: /* @__PURE__ */ new Date(),
|
|
21323
|
-
source: {
|
|
21324
|
-
type: "device",
|
|
21325
|
-
id: deviceId
|
|
21326
|
-
},
|
|
21327
|
-
category: require_base_addon.EventCategory.DeviceMetaChanged,
|
|
21328
|
-
data: {
|
|
21329
|
-
deviceId,
|
|
21330
|
-
field: "location",
|
|
21331
|
-
value: null
|
|
22255
|
+
})();
|
|
22256
|
+
this.inFlight = run;
|
|
22257
|
+
return run;
|
|
22258
|
+
}
|
|
22259
|
+
/** Resolve text names to ids through `ensureTag`; a name no tag cap can mint is left out. */
|
|
22260
|
+
async ensureIds(names) {
|
|
22261
|
+
const source = this.source;
|
|
22262
|
+
if (source === null) return [];
|
|
22263
|
+
const ids = [];
|
|
22264
|
+
for (const name of names) {
|
|
22265
|
+
const tag = await source.ensure(name);
|
|
22266
|
+
ids.push(tag.id);
|
|
21332
22267
|
}
|
|
21333
|
-
|
|
21334
|
-
|
|
22268
|
+
await this.refresh();
|
|
22269
|
+
return ids;
|
|
22270
|
+
}
|
|
22271
|
+
};
|
|
21335
22272
|
//#endregion
|
|
21336
22273
|
//#region src/builtins/device-manager/device-identifiers-action.ts
|
|
21337
22274
|
/**
|
|
@@ -21781,7 +22718,6 @@ var IdentityLinkReconciler = class {
|
|
|
21781
22718
|
};
|
|
21782
22719
|
//#endregion
|
|
21783
22720
|
//#region src/builtins/device-manager/identity-links-store.ts
|
|
21784
|
-
var import_read_all_rows = require_read_all_rows$1.require_read_all_rows();
|
|
21785
22721
|
var IdentityLinksStore = class IdentityLinksStore {
|
|
21786
22722
|
kind;
|
|
21787
22723
|
links = null;
|
|
@@ -21789,7 +22725,7 @@ var IdentityLinksStore = class IdentityLinksStore {
|
|
|
21789
22725
|
this.kind = kind;
|
|
21790
22726
|
}
|
|
21791
22727
|
static of(records) {
|
|
21792
|
-
return new IdentityLinksStore(records.kind(
|
|
22728
|
+
return new IdentityLinksStore(records.kind(require_record_kinds.deviceManagerRecordKinds["identity-links"]));
|
|
21793
22729
|
}
|
|
21794
22730
|
async load() {
|
|
21795
22731
|
const rows = await (0, import_read_all_rows.readAllRows)(this.kind);
|
|
@@ -22325,7 +23261,7 @@ var DeviceTemplateHost = class {
|
|
|
22325
23261
|
}
|
|
22326
23262
|
}
|
|
22327
23263
|
const entries = [...rows.values()];
|
|
22328
|
-
const mirror = new
|
|
23264
|
+
const mirror = new require_named_entity_store.ConditionMirror(templateMirrorSources(entries));
|
|
22329
23265
|
const report = await mirror.refresh({
|
|
22330
23266
|
fetchSlice: (deviceId, cap) => this.deps.fetchSlice(deviceId, cap),
|
|
22331
23267
|
fetchStableIds: async () => /* @__PURE__ */ new Map()
|
|
@@ -22865,130 +23801,6 @@ var DeviceTemplateActions = class {
|
|
|
22865
23801
|
}
|
|
22866
23802
|
};
|
|
22867
23803
|
//#endregion
|
|
22868
|
-
//#region src/builtins/device-manager/device-meta-types.ts
|
|
22869
|
-
/**
|
|
22870
|
-
* Decode the raw `ctx.settings.readAddonStore()` record into {@link AddonStore}.
|
|
22871
|
-
*
|
|
22872
|
-
* A field of the wrong shape reads as ABSENT rather than being trusted through
|
|
22873
|
-
* a cast: the store is JSON on disk and a hand-edit or a partial restore must
|
|
22874
|
-
* cost the caller its default, never a downstream `TypeError`.
|
|
22875
|
-
*/
|
|
22876
|
-
function decodeAddonStore(raw) {
|
|
22877
|
-
const nextDeviceId = raw["nextDeviceId"];
|
|
22878
|
-
const locations = raw["locations"];
|
|
22879
|
-
const roleDisplayDefaults = raw["roleDisplayDefaults"];
|
|
22880
|
-
const locationIcons = decodeLocationIcons(raw["locationIcons"]);
|
|
22881
|
-
const locationDescriptions = decodeLocationDescriptions(raw["locationDescriptions"]);
|
|
22882
|
-
const siteZones = decodeSiteZones(raw["siteZones"]);
|
|
22883
|
-
const locationZones = decodeStringMap(raw["locationZones"]);
|
|
22884
|
-
return {
|
|
22885
|
-
...typeof nextDeviceId === "number" && Number.isFinite(nextDeviceId) ? { nextDeviceId } : {},
|
|
22886
|
-
...Array.isArray(locations) ? { locations: locations.filter((l) => typeof l === "string") } : {},
|
|
22887
|
-
...isRoleDisplayDefaults(roleDisplayDefaults) ? { roleDisplayDefaults } : {},
|
|
22888
|
-
...locationIcons !== null ? { locationIcons } : {},
|
|
22889
|
-
...locationDescriptions !== null ? { locationDescriptions } : {},
|
|
22890
|
-
...siteZones !== null ? { siteZones } : {},
|
|
22891
|
-
...locationZones !== null ? { locationZones } : {}
|
|
22892
|
-
};
|
|
22893
|
-
}
|
|
22894
|
-
/**
|
|
22895
|
-
* Decode the `locationIcons` map, dropping every entry whose value is not a
|
|
22896
|
-
* member of the closed vocabulary.
|
|
22897
|
-
*
|
|
22898
|
-
* Dropping, not passing through: the icon's whole point is that both surfaces
|
|
22899
|
-
* can draw it, and an id from a hand-edit or a newer hub is exactly the value
|
|
22900
|
-
* that draws nothing. Absent reads as "no icon chosen", which every renderer
|
|
22901
|
-
* already degrades to the fallback pin. Returns `null` when the key itself is
|
|
22902
|
-
* absent or of the wrong shape, so the field stays OMITTED rather than being
|
|
22903
|
-
* written back as an empty object.
|
|
22904
|
-
*/
|
|
22905
|
-
function decodeLocationIcons(raw) {
|
|
22906
|
-
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
22907
|
-
const out = {};
|
|
22908
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
22909
|
-
const icon = require_tag.canonicalIconKey(value);
|
|
22910
|
-
if (icon === void 0) continue;
|
|
22911
|
-
out[key] = icon;
|
|
22912
|
-
}
|
|
22913
|
-
return out;
|
|
22914
|
-
}
|
|
22915
|
-
/**
|
|
22916
|
-
* Decode the `locationDescriptions` map, dropping every entry that is not a
|
|
22917
|
-
* non-blank string.
|
|
22918
|
-
*
|
|
22919
|
-
* Same posture as the icons: a blank description and a missing one are the
|
|
22920
|
-
* same instruction to every reader, and storing the first would send an empty
|
|
22921
|
-
* line to a vision model. Over-long text is TRUNCATED rather than dropped —
|
|
22922
|
-
* losing the whole description because a hand-edit ran long is a worse answer
|
|
22923
|
-
* than losing its tail.
|
|
22924
|
-
*/
|
|
22925
|
-
function decodeLocationDescriptions(raw) {
|
|
22926
|
-
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
22927
|
-
const out = {};
|
|
22928
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
22929
|
-
if (typeof value !== "string") continue;
|
|
22930
|
-
const text = value.trim();
|
|
22931
|
-
if (text.length === 0) continue;
|
|
22932
|
-
out[key] = text.slice(0, 400);
|
|
22933
|
-
}
|
|
22934
|
-
return out;
|
|
22935
|
-
}
|
|
22936
|
-
/**
|
|
22937
|
-
* Decode the zone registry, dropping any entry without a usable label.
|
|
22938
|
-
*
|
|
22939
|
-
* A zone whose label did not survive a hand-edit cannot be shown or renamed —
|
|
22940
|
-
* it would be a row the operator can see the effects of and never name. An
|
|
22941
|
-
* icon outside the vocabulary is dropped on its own, leaving the zone: losing
|
|
22942
|
-
* a glyph is a smaller loss than losing the grouping.
|
|
22943
|
-
*/
|
|
22944
|
-
function decodeSiteZones(raw) {
|
|
22945
|
-
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
22946
|
-
const out = {};
|
|
22947
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
22948
|
-
if (value === null || typeof value !== "object" || Array.isArray(value)) continue;
|
|
22949
|
-
const rec = value;
|
|
22950
|
-
const label = typeof rec["label"] === "string" ? rec["label"].trim() : "";
|
|
22951
|
-
if (label.length === 0) continue;
|
|
22952
|
-
const icon = require_tag.canonicalIconKey(rec["icon"]);
|
|
22953
|
-
out[key] = icon === void 0 ? { label } : {
|
|
22954
|
-
label,
|
|
22955
|
-
icon
|
|
22956
|
-
};
|
|
22957
|
-
}
|
|
22958
|
-
return out;
|
|
22959
|
-
}
|
|
22960
|
-
/** Decode a plain `string → string` map, dropping anything else. */
|
|
22961
|
-
function decodeStringMap(raw) {
|
|
22962
|
-
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
22963
|
-
const out = {};
|
|
22964
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
22965
|
-
if (typeof value !== "string" || value.trim().length === 0) continue;
|
|
22966
|
-
out[key] = value;
|
|
22967
|
-
}
|
|
22968
|
-
return out;
|
|
22969
|
-
}
|
|
22970
|
-
function isRoleDisplayDefaults(value) {
|
|
22971
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
22972
|
-
}
|
|
22973
|
-
//#endregion
|
|
22974
|
-
//#region src/builtins/device-manager/write-lock.ts
|
|
22975
|
-
function createWriteLock() {
|
|
22976
|
-
let chain = Promise.resolve();
|
|
22977
|
-
return async (fn) => {
|
|
22978
|
-
const previous = chain;
|
|
22979
|
-
let release = () => {};
|
|
22980
|
-
chain = new Promise((resolve) => {
|
|
22981
|
-
release = resolve;
|
|
22982
|
-
});
|
|
22983
|
-
try {
|
|
22984
|
-
await previous.catch(() => {});
|
|
22985
|
-
return await fn();
|
|
22986
|
-
} finally {
|
|
22987
|
-
release();
|
|
22988
|
-
}
|
|
22989
|
-
};
|
|
22990
|
-
}
|
|
22991
|
-
//#endregion
|
|
22992
23804
|
//#region src/builtins/device-manager/device-meta-store.ts
|
|
22993
23805
|
var DeviceMetaStore = class {
|
|
22994
23806
|
settings;
|
|
@@ -23001,7 +23813,7 @@ var DeviceMetaStore = class {
|
|
|
23001
23813
|
* ownership without awaiting. Kept in sync with every register/remove and
|
|
23002
23814
|
* warmed from persistence on boot. */
|
|
23003
23815
|
idToAddonId = /* @__PURE__ */ new Map();
|
|
23004
|
-
constructor(settings, registry, rows, withAddonStoreWriteLock = createWriteLock()) {
|
|
23816
|
+
constructor(settings, registry, rows, withAddonStoreWriteLock = require_named_entity_store.createWriteLock()) {
|
|
23005
23817
|
this.settings = settings;
|
|
23006
23818
|
this.registry = registry;
|
|
23007
23819
|
this.rows = rows;
|
|
@@ -23036,7 +23848,7 @@ var DeviceMetaStore = class {
|
|
|
23036
23848
|
this.inFlightRead = read;
|
|
23037
23849
|
return read;
|
|
23038
23850
|
};
|
|
23039
|
-
withMetaWriteLock = createWriteLock();
|
|
23851
|
+
withMetaWriteLock = require_named_entity_store.createWriteLock();
|
|
23040
23852
|
/** The whole persisted row for one device, or `null`. */
|
|
23041
23853
|
getRow = async (deviceId) => this.rows.get(deviceId);
|
|
23042
23854
|
/**
|
|
@@ -23118,7 +23930,7 @@ var DeviceTombstoneStore = class DeviceTombstoneStore {
|
|
|
23118
23930
|
}
|
|
23119
23931
|
static of(records, logger) {
|
|
23120
23932
|
return new DeviceTombstoneStore({
|
|
23121
|
-
kind: records.kind(
|
|
23933
|
+
kind: records.kind(require_record_kinds.deviceManagerRecordKinds.tombstones),
|
|
23122
23934
|
logger
|
|
23123
23935
|
});
|
|
23124
23936
|
}
|
|
@@ -23281,7 +24093,7 @@ var DiscoveryProposalStore = class DiscoveryProposalStore {
|
|
|
23281
24093
|
this.now = now;
|
|
23282
24094
|
}
|
|
23283
24095
|
static of(records, now) {
|
|
23284
|
-
return new DiscoveryProposalStore(records.kind(
|
|
24096
|
+
return new DiscoveryProposalStore(records.kind(require_record_kinds.deviceManagerRecordKinds["discovery-proposals"]), now);
|
|
23285
24097
|
}
|
|
23286
24098
|
/** Record what a provider classified. Returns how many proposals are NEW. */
|
|
23287
24099
|
async observe(addonId, candidates) {
|
|
@@ -23731,7 +24543,7 @@ function errorMessage$3(err) {
|
|
|
23731
24543
|
* moved yet, so it is a {@link MigrationRefusedError}: the migration refuses
|
|
23732
24544
|
* and restores both cameras' switches.
|
|
23733
24545
|
*/
|
|
23734
|
-
var RuntimeStateDrainError = class extends
|
|
24546
|
+
var RuntimeStateDrainError = class extends require_record_kinds.MigrationRefusedError {
|
|
23735
24547
|
deviceId;
|
|
23736
24548
|
constructor(deviceId, reason, options) {
|
|
23737
24549
|
super(`migration refused: the runtime state of device ${deviceId} could not be drained before the swap (${reason}) — nothing moved; retry the migration`, options);
|
|
@@ -26705,16 +27517,20 @@ var REMOVAL_RETRY_DELAYS_MS = [
|
|
|
26705
27517
|
12e4,
|
|
26706
27518
|
6e5
|
|
26707
27519
|
];
|
|
26708
|
-
async function attempt(steps) {
|
|
27520
|
+
async function attempt(steps, concurrent) {
|
|
26709
27521
|
const counts = {};
|
|
26710
27522
|
const failed = [];
|
|
26711
27523
|
const errors = {};
|
|
26712
|
-
|
|
26713
|
-
|
|
26714
|
-
|
|
26715
|
-
|
|
26716
|
-
|
|
26717
|
-
|
|
27524
|
+
const runOne = async (step) => {
|
|
27525
|
+
try {
|
|
27526
|
+
counts[step.store] = await step.run();
|
|
27527
|
+
} catch (err) {
|
|
27528
|
+
failed.push(step);
|
|
27529
|
+
errors[step.store] = require_scoped_settings.errMsg(err);
|
|
27530
|
+
}
|
|
27531
|
+
};
|
|
27532
|
+
if (concurrent) await Promise.all(steps.map(runOne));
|
|
27533
|
+
else for (const step of steps) await runOne(step);
|
|
26718
27534
|
return {
|
|
26719
27535
|
counts,
|
|
26720
27536
|
failed,
|
|
@@ -26723,6 +27539,7 @@ async function attempt(steps) {
|
|
|
26723
27539
|
}
|
|
26724
27540
|
function createRemovalCleanup(opts) {
|
|
26725
27541
|
const label = opts.label ?? "device removal cleanup";
|
|
27542
|
+
const concurrent = opts.concurrent ?? false;
|
|
26726
27543
|
const delays = opts.retryDelaysMs ?? REMOVAL_RETRY_DELAYS_MS;
|
|
26727
27544
|
const setTimer = opts.setTimer ?? ((fn, ms) => setTimeout(fn, ms));
|
|
26728
27545
|
const clearTimer = opts.clearTimer ?? ((handle) => clearTimeout(handle));
|
|
@@ -26749,7 +27566,7 @@ function createRemovalCleanup(opts) {
|
|
|
26749
27566
|
pending.add(handle);
|
|
26750
27567
|
};
|
|
26751
27568
|
const retry = async (deviceId, steps, retryIndex) => {
|
|
26752
|
-
const result = await attempt(steps);
|
|
27569
|
+
const result = await attempt(steps, concurrent);
|
|
26753
27570
|
opts.logger.info(`${label} retried`, {
|
|
26754
27571
|
tags: { deviceId },
|
|
26755
27572
|
meta: {
|
|
@@ -26762,7 +27579,7 @@ function createRemovalCleanup(opts) {
|
|
|
26762
27579
|
};
|
|
26763
27580
|
return {
|
|
26764
27581
|
async run(deviceId, steps) {
|
|
26765
|
-
const result = await attempt(steps);
|
|
27582
|
+
const result = await attempt(steps, concurrent);
|
|
26766
27583
|
const failedStores = result.failed.map((s) => s.store);
|
|
26767
27584
|
const meta = {
|
|
26768
27585
|
counts: result.counts,
|
|
@@ -27095,7 +27912,7 @@ var DeviceManagerAddon = class extends require_base_addon.BaseAddon {
|
|
|
27095
27912
|
* bindings purge reach the store through `BindingsDeps` — and two locks over
|
|
27096
27913
|
* one key range is the same defect one level up. Handed to both.
|
|
27097
27914
|
*/
|
|
27098
|
-
addonStoreWriteLock = createWriteLock();
|
|
27915
|
+
addonStoreWriteLock = require_named_entity_store.createWriteLock();
|
|
27099
27916
|
/** Stored activations of RETIRED wrappers, said once per process (task 17 review M1). */
|
|
27100
27917
|
staleWrapperActivationsImpl = null;
|
|
27101
27918
|
get staleWrapperActivations() {
|
|
@@ -27174,6 +27991,7 @@ var DeviceManagerAddon = class extends require_base_addon.BaseAddon {
|
|
|
27174
27991
|
return /* @__PURE__ */ new Map();
|
|
27175
27992
|
}
|
|
27176
27993
|
},
|
|
27994
|
+
roomNameOf: (value) => pctx.rooms.nameOf(value),
|
|
27177
27995
|
logger: this.ctx.logger
|
|
27178
27996
|
}, input);
|
|
27179
27997
|
}
|
|
@@ -27226,12 +28044,30 @@ var DeviceManagerAddon = class extends require_base_addon.BaseAddon {
|
|
|
27226
28044
|
const settingsStoreApi = this.ctx.api?.settingsStore;
|
|
27227
28045
|
if (!settingsStoreApi) throw new Error("[device-manager] settings-store API not available — refusing to serve a fleet it cannot persist");
|
|
27228
28046
|
const identityIndex = new DeviceIdentityIndex();
|
|
27229
|
-
const deviceRows = new
|
|
28047
|
+
const deviceRows = new require_record_kinds.DeviceRowStore(require_record_kinds.deviceRowBackendOf(settingsStoreApi), this.ctx.logger.child("rows"), void 0, identityIndex);
|
|
27230
28048
|
await deviceRows.declare();
|
|
27231
28049
|
this.deviceRows = deviceRows;
|
|
27232
28050
|
const records = this.ctx.records;
|
|
27233
28051
|
if (records === void 0) throw new Error("[device-manager] ctx.records is required on the hub");
|
|
27234
|
-
await records.declare(
|
|
28052
|
+
await records.declare(require_record_kinds.deviceManagerRecordKinds);
|
|
28053
|
+
await this.runMigrations(require_base_addon.defineAddonMigrations(ROOMS_AND_TAGS_MIGRATIONS, deviceManagerMigrationPorts({
|
|
28054
|
+
readStoredKey: (key) => this.readStoredGlobalKey(key),
|
|
28055
|
+
rows: deviceRows,
|
|
28056
|
+
rooms: records.kind(require_record_kinds.deviceManagerRecordKinds.rooms),
|
|
28057
|
+
zones: records.kind(require_record_kinds.deviceManagerRecordKinds.zones),
|
|
28058
|
+
report: (message, meta) => this.ctx.logger.info(message, { meta })
|
|
28059
|
+
})));
|
|
28060
|
+
const rooms = RoomStore.of(records);
|
|
28061
|
+
await rooms.load();
|
|
28062
|
+
const tagApi = this.ctx.api?.tags;
|
|
28063
|
+
const tagNames = new TagNames(tagApi === void 0 ? null : {
|
|
28064
|
+
list: () => tagApi.listTags.query({}),
|
|
28065
|
+
ensure: (name) => tagApi.ensureTag.mutate({ name })
|
|
28066
|
+
}, this.ctx.logger.child("tag-names"));
|
|
28067
|
+
deviceRows.setDerivedNames({
|
|
28068
|
+
room: (id) => rooms.nameOf(id),
|
|
28069
|
+
tag: (id) => tagNames.nameOf(id)
|
|
28070
|
+
});
|
|
27235
28071
|
const tombstones = DeviceTombstoneStore.of(records, this.ctx.logger.child("tombstones"));
|
|
27236
28072
|
const identityLinksStore = IdentityLinksStore.of(records);
|
|
27237
28073
|
await identityLinksStore.load();
|
|
@@ -27336,6 +28172,10 @@ var DeviceManagerAddon = class extends require_base_addon.BaseAddon {
|
|
|
27336
28172
|
const templates = this.makeTemplateActions();
|
|
27337
28173
|
const pctx = {
|
|
27338
28174
|
host: this.providerHost,
|
|
28175
|
+
rooms,
|
|
28176
|
+
freshTagNames: () => tagNames.fresh(),
|
|
28177
|
+
tagNameOf: (id) => tagNames.nameOf(id),
|
|
28178
|
+
ensureTagIds: (names) => tagNames.ensureIds(names),
|
|
27339
28179
|
metaStore,
|
|
27340
28180
|
settings,
|
|
27341
28181
|
registry,
|
|
@@ -27381,11 +28221,29 @@ var DeviceManagerAddon = class extends require_base_addon.BaseAddon {
|
|
|
27381
28221
|
} catch (err) {
|
|
27382
28222
|
this.ctx.logger.warn("linked-devices manual backfill failed — auto links are NOT materialised", { meta: { error: require_scoped_settings.errMsg(err) } });
|
|
27383
28223
|
}
|
|
28224
|
+
try {
|
|
28225
|
+
await this.runMigrations(require_base_addon.defineAddonMigrations(ORPHAN_CHILDREN_MIGRATIONS, {
|
|
28226
|
+
listRows: async () => (await deviceRows.listAll()).map((row) => ({
|
|
28227
|
+
id: row.meta.id,
|
|
28228
|
+
parentDeviceId: row.meta.parentDeviceId
|
|
28229
|
+
})),
|
|
28230
|
+
rowLimit: require_record_kinds.DEVICE_ROWS_FLEET_LIMIT,
|
|
28231
|
+
removeDevice: (deviceId) => removeDevice(pctx, { deviceId }),
|
|
28232
|
+
summary: (counts) => this.ctx.logger.info("device-manager: orphan children found", { meta: counts }),
|
|
28233
|
+
info: (message, deviceId, parentDeviceId) => this.ctx.logger.info(message, {
|
|
28234
|
+
tags: { deviceId },
|
|
28235
|
+
meta: { parentDeviceId }
|
|
28236
|
+
})
|
|
28237
|
+
}));
|
|
28238
|
+
} catch (err) {
|
|
28239
|
+
this.ctx.logger.warn("orphan-children migration failed — rows stay as they are", { meta: { error: require_scoped_settings.errMsg(err) } });
|
|
28240
|
+
}
|
|
27384
28241
|
const provider = {
|
|
27385
28242
|
resolveDeviceOwnerSync: (deviceId) => resolveDeviceOwnerSync(pctx, deviceId),
|
|
27386
28243
|
resolveNativeCapOwnerSync: (capName, deviceId) => resolveNativeCapOwnerSync(pctx, capName, deviceId),
|
|
27387
28244
|
allocateDeviceId: (input) => allocateDeviceId(pctx, input),
|
|
27388
28245
|
migrateDevice: (input) => migrateDevice(pctx, input),
|
|
28246
|
+
repairMigrationSecrets: (input) => repairMigrationSecrets(pctx, input),
|
|
27389
28247
|
registerDevice: (input) => registerDevice(pctx, input),
|
|
27390
28248
|
removeDevice: (input) => removeDevice(pctx, input),
|
|
27391
28249
|
listDeletedSince: ({ sinceMs }) => tombstones.listSince(sinceMs),
|
|
@@ -27431,6 +28289,10 @@ var DeviceManagerAddon = class extends require_base_addon.BaseAddon {
|
|
|
27431
28289
|
setMetadata: (input) => setMetadata(pctx, input),
|
|
27432
28290
|
setDisabled: (input) => setDisabled(pctx, input),
|
|
27433
28291
|
loadRuntimeState: (input) => loadRuntimeState(pctx, input),
|
|
28292
|
+
ensureRoom: (input) => ensureRoom(pctx, input),
|
|
28293
|
+
listRooms: () => listRooms(pctx),
|
|
28294
|
+
updateRoom: (input) => updateRoom(pctx, input),
|
|
28295
|
+
deleteRoom: (input) => deleteRoom(pctx, input),
|
|
27434
28296
|
listLocations: () => listLocations(pctx),
|
|
27435
28297
|
addLocation: (input) => addLocation(pctx, input),
|
|
27436
28298
|
removeLocation: (input) => removeLocation(pctx, input),
|
|
@@ -27650,7 +28512,8 @@ var DeviceManagerAddon = class extends require_base_addon.BaseAddon {
|
|
|
27650
28512
|
get removalHooksCleanup() {
|
|
27651
28513
|
if (this.removalHooksCleanupImpl === null) this.removalHooksCleanupImpl = createRemovalCleanup({
|
|
27652
28514
|
logger: this.ctx.logger,
|
|
27653
|
-
label: "device removal hooks"
|
|
28515
|
+
label: "device removal hooks",
|
|
28516
|
+
concurrent: true
|
|
27654
28517
|
});
|
|
27655
28518
|
return this.removalHooksCleanupImpl;
|
|
27656
28519
|
}
|