@camstack/addon-provider-unifi 0.2.151 → 0.2.152

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 CHANGED
@@ -7,11 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.152] - 2026-11-01
11
+
12
+ ### Changed
13
+
14
+ - Declares the minimum CamStack server it needs; the Addons page shows a held update as requires server >= X
15
+ - Integration reconcile no longer removes devices when the integration list or settings read fails or is empty; devices are removed only on an explicit Deleted/Disabled event
16
+
10
17
  ## [0.2.151] - 2026-11-01
11
18
 
12
19
  ### Changed
13
20
 
14
21
  - UniFi is now added as an integration: the controller connection and credentials are the integration's settings, and the controller appears as a Gateway beside its infra devices and clients instead of a Hub.
22
+ - Declares the minimum CamStack server it needs; the Addons page shows a held update as requires server >= X
15
23
 
16
24
  ## [0.2.150] - 2026-10-28
17
25
 
package/dist/addon.js CHANGED
@@ -5831,7 +5831,7 @@ var ZodIssueCode = {
5831
5831
  var ZodFirstPartyTypeKind;
5832
5832
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5833
5833
  //#endregion
5834
- //#region ../types/dist/sleep-BHS4ImRX.mjs
5834
+ //#region ../types/dist/sleep-CSYuxssh.mjs
5835
5835
  /**
5836
5836
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5837
5837
  * window to float samples (D455).
@@ -9114,7 +9114,7 @@ var ProfileRtspEntrySchema = object({
9114
9114
  /**
9115
9115
  * The model weight formats a catalog entry can ship. Schema-free on purpose:
9116
9116
  * `types/models.ts` builds Zod schemas from it, but a runner-closure consumer
9117
- * (the model downloader in `@camstack/system`) needs only the list and must
9117
+ * (the model downloader in `@camstack/server/system`) needs only the list and must
9118
9118
  * reach it through `@camstack/types/addon` without building the cap schema
9119
9119
  * graph (D28).
9120
9120
  */
@@ -12489,6 +12489,71 @@ var EventOwnerTypeSchema = _enum(EVENT_OWNER_TYPES);
12489
12489
  var MediaPresenceOwnerKindSchema = _enum([...EVENT_OWNER_TYPES, "track"]);
12490
12490
  new Set(EVENT_OWNER_TYPES);
12491
12491
  /**
12492
+ * What a published package needs from the rest of the install (D989).
12493
+ *
12494
+ * One published framework package (`@camstack/server`) carries the kernel, the
12495
+ * builtins and the capability contracts, so "which addon runs on which
12496
+ * framework" is a question of version, and the answer is DECLARED by the
12497
+ * package that knows it:
12498
+ *
12499
+ * - an addon says the oldest server it runs on (`requires.server: ">=X"`);
12500
+ * - the server says the oldest addon it works with
12501
+ * (`requires.addons: { "@camstack/addon-x": ">=Y" }`) and the oldest shell
12502
+ * around it (`requires.wrapper: { desktop, image }`);
12503
+ * - a wrapper (the desktop app, the container starter) says which server
12504
+ * range it can host, and reports its own kind and version.
12505
+ *
12506
+ * The publish workflow STAMPS these after the version bump
12507
+ * (`scripts/ci/stamp-requires.mjs`); nobody types a number by hand.
12508
+ *
12509
+ * A requirement that cannot be checked is NOT met: a shell that reports no
12510
+ * version counts as below the minimum, and an unreadable running version is
12511
+ * named in the result (a failed read is never a pass).
12512
+ */
12513
+ /** `>=MAJOR.MINOR.PATCH[-prerelease]` — the only range shape a requirement uses. */
12514
+ var MinVersionSchema = string().regex(/^>=\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/, "a minimum is written \">=X.Y.Z\"");
12515
+ object({
12516
+ /** The oldest `@camstack/server` this package runs on. */
12517
+ server: MinVersionSchema.optional(),
12518
+ /** The oldest installed version of each named addon package. */
12519
+ addons: record(string(), MinVersionSchema).optional(),
12520
+ /** The oldest shell around the server, per shell kind. */
12521
+ wrapper: object({
12522
+ desktop: MinVersionSchema.optional(),
12523
+ image: MinVersionSchema.optional()
12524
+ }).optional()
12525
+ });
12526
+ /** One unmet requirement; each names the versions on both sides. */
12527
+ var UnmetRequirementSchema = discriminatedUnion("kind", [
12528
+ object({
12529
+ kind: literal("server-too-old"),
12530
+ required: string(),
12531
+ /** `null` — the running server version could not be read. */
12532
+ running: string().nullable()
12533
+ }),
12534
+ object({
12535
+ kind: literal("addon-too-old"),
12536
+ packageName: string(),
12537
+ required: string(),
12538
+ /** `null` — the addon is not installed (or its version is unreadable). */
12539
+ running: string().nullable()
12540
+ }),
12541
+ object({
12542
+ kind: literal("wrapper-too-old"),
12543
+ wrapper: _enum(["desktop", "image"]),
12544
+ required: string(),
12545
+ /** `null` — the wrapper reported no version. */
12546
+ running: string().nullable()
12547
+ })
12548
+ ]);
12549
+ var RequiredAddonUpdateSchema = object({
12550
+ packageName: string(),
12551
+ /** The minimum the target server declares. */
12552
+ required: string(),
12553
+ /** What this node has; `null` when the addon is not installed. */
12554
+ installed: string().nullable()
12555
+ });
12556
+ /**
12492
12557
  * Which integration instance a settings form is for. An addon that serves several instances
12493
12558
  * (`instanceMode: multiple`) can show a different form per instance — an NVR integration
12494
12559
  * needs its connection, the default integration needs the addon's own sections.
@@ -42904,7 +42969,7 @@ method(object({}), array(TargetKindSchema)), method(object({}), array(TargetSche
42904
42969
  * rebuilds without manual reload.
42905
42970
  *
42906
42971
  * The hub-local builtin `addon-pages-aggregator` (see
42907
- * `@camstack/system/builtins/addon-pages-aggregator`) registers the
42972
+ * `@camstack/server/system/builtins/addon-pages-aggregator`) registers the
42908
42973
  * provider. Splitting the public aggregator from the raw collection
42909
42974
  * keeps both ends in codegen — there's no hand-written
42910
42975
  * `addon-pages.router.ts` wrapper anymore.
@@ -43204,7 +43269,7 @@ method(_void(), array(WidgetMetadataSchema).readonly(), { auth: "admin" });
43204
43269
  * manual reload — same scheme used by `addon-pages`.
43205
43270
  *
43206
43271
  * The hub-local builtin `addon-widgets-aggregator` (see
43207
- * `@camstack/system/builtins/addon-widgets-aggregator`) registers the
43272
+ * `@camstack/server/system/builtins/addon-widgets-aggregator`) registers the
43208
43273
  * provider. Splitting the public aggregator from the raw collection
43209
43274
  * keeps both ends in codegen — there's no hand-written wrapper.
43210
43275
  */
@@ -61404,7 +61469,18 @@ var ServerUpdateActionResultSchema = object({
61404
61469
  * store (D877), present when the pre-flight refused the update
61405
61470
  * (`reason: 'addon-would-refuse'`). Optional for version skew.
61406
61471
  */
61407
- blockers: array(UpdateBlockerSchema).optional()
61472
+ blockers: array(UpdateBlockerSchema).optional(),
61473
+ /**
61474
+ * The minimums the target server declares and this node does not meet
61475
+ * (D989), present when the update was refused with
61476
+ * `reason: 'requirements-unmet'`. Each names the versions on both sides.
61477
+ */
61478
+ unmet: array(UnmetRequirementSchema).optional(),
61479
+ /**
61480
+ * The addons this node has below the minimum the staged server declares —
61481
+ * the ones to update WITH the server. Present on an accepted update.
61482
+ */
61483
+ requiredAddonUpdates: array(RequiredAddonUpdateSchema).optional()
61408
61484
  });
61409
61485
  var LaunchOverridesSchema = object({
61410
61486
  /** The persisted heap ceiling in MB, or `null` when none is set. */
@@ -63948,7 +64024,9 @@ var PackageUpdateSchema = object({
63948
64024
  latestVersion: string(),
63949
64025
  category: _enum(["addon", "core"]),
63950
64026
  requiresRestart: boolean(),
63951
- isSystem: boolean()
64027
+ isSystem: boolean(),
64028
+ /** Held: what the newer version needs and this node does not meet (D989). */
64029
+ blockedBy: array(UnmetRequirementSchema).readonly().optional()
63952
64030
  });
63953
64031
  var PackageVersionInfoSchema = object({
63954
64032
  version: string(),
@@ -69248,7 +69326,7 @@ var lawnMowerControlCapability = {
69248
69326
  * clients — they reverse-connect to the hub. Exposing their interfaces
69249
69327
  * via the same surface would leak internal topology with no upside.
69250
69328
  *
69251
- * Implementation in `@camstack/system/builtins/local-network/`.
69329
+ * Implementation in `@camstack/server/system/builtins/local-network/`.
69252
69330
  */
69253
69331
  /** Coarse classification derived from the interface name + IP range. */
69254
69332
  var InterfaceKindEnum = _enum([
@@ -71136,7 +71214,7 @@ onStatusChanged: { data: object({
71136
71214
  * jitter, and observed/peak bandwidth per device + per client.
71137
71215
  *
71138
71216
  * Implementation lives in the server's `NetworkQualityService` (thin
71139
- * wrapper over the shared `NetworkQualityTracker` from `@camstack/system`).
71217
+ * wrapper over the shared `NetworkQualityTracker` from `@camstack/server/system`).
71140
71218
  * The provider is registered from `trpc.router.ts` against the existing
71141
71219
  * service instance — no addon owns this state.
71142
71220
  *
@@ -73287,7 +73365,7 @@ var ptzAutotrackCapability = {
73287
73365
  * - **Native**: the camera's own firmware autotrack, registered per device by
73288
73366
  * the driver when the probe says it exists (Reolink: yes; Hikvision:
73289
73367
  * model-dependent).
73290
- * - **Wrapper**: the emulated implementation (`@camstack/system`'s `autotrack` builtin),
73368
+ * - **Wrapper**: the emulated implementation (`@camstack/server/system`'s `autotrack` builtin),
73291
73369
  * which follows a subject with `ptz.move` pulses driven by the detection
73292
73370
  * pipeline. `defaultActive: false` — the operator binds it per camera in
73293
73371
  * the bindings UI.
@@ -95915,6 +95993,60 @@ async function reconcileInfraFeatures(input) {
95915
95993
  return changed;
95916
95994
  }
95917
95995
  //#endregion
95996
+ //#region src/unifi-reconciler.ts
95997
+ /**
95998
+ * Keeps one live client per enabled integration. Devices are removed ONLY on an explicit
95999
+ * lifecycle event naming the integration (D49): a list that failed, an empty list or an
96000
+ * unreadable connection changes nothing about devices and is logged, never read as "gone".
96001
+ */
96002
+ var UnifiReconciler = class {
96003
+ #deps;
96004
+ constructor(deps) {
96005
+ this.#deps = deps;
96006
+ }
96007
+ /** Upsert a client per usable enabled integration; drop the CLIENT (never devices) of one the list answered is gone. */
96008
+ async reconcile() {
96009
+ const { logger, clients } = this.#deps;
96010
+ let all;
96011
+ try {
96012
+ all = await this.#deps.listIntegrations();
96013
+ } catch (err) {
96014
+ logger.warn("Unifi integration reconcile skipped — the integration list did not answer", { meta: { error: errMsg(err) } });
96015
+ return;
96016
+ }
96017
+ const enabled = all.filter((i) => i.addonId === this.#deps.addonId && i.enabled);
96018
+ for (const integration of enabled) try {
96019
+ if (!await this.#deps.applySettings(integration)) logger.warn("Unifi integration has no usable connection — left as it is", { meta: { integrationId: integration.id } });
96020
+ } catch (err) {
96021
+ logger.warn("Unifi reconcile failed for integration — left as it is", { meta: {
96022
+ integrationId: integration.id,
96023
+ error: errMsg(err)
96024
+ } });
96025
+ }
96026
+ const enabledIds = new Set(enabled.map((i) => i.id));
96027
+ for (const id of clients.list()) if (!enabledIds.has(id)) await clients.remove(id);
96028
+ }
96029
+ /** An explicit lifecycle event: only `deleted` / `disabled` of a named integration remove devices. */
96030
+ async onLifecycle(kind, integrationId) {
96031
+ await this.reconcile();
96032
+ if (kind === "enabled" || integrationId === null) return;
96033
+ try {
96034
+ const removed = await this.#deps.removeDevices(integrationId);
96035
+ this.#deps.logger.info("Unifi integration devices removed", { meta: {
96036
+ integrationId,
96037
+ kind,
96038
+ removed
96039
+ } });
96040
+ } catch (err) {
96041
+ this.#deps.logger.warn("Unifi integration device removal failed", { meta: {
96042
+ integrationId,
96043
+ kind,
96044
+ error: errMsg(err)
96045
+ } });
96046
+ }
96047
+ }
96048
+ };
96049
+ //#endregion
95918
96050
  //#region src/unifi-integration-device-cascade.ts
95919
96051
  /**
95920
96052
  * Remove every top-level device (Gateway, infra Container, client Presence) of an integration that
@@ -95992,6 +96124,7 @@ var UnifiProviderAddon = class extends BaseDeviceProvider {
95992
96124
  [DeviceType.Sensor]: UnifiFeatureDevice,
95993
96125
  [DeviceType.Presence]: UnifiFeatureDevice
95994
96126
  };
96127
+ integrationReconciler = null;
95995
96128
  clients = null;
95996
96129
  constructor() {
95997
96130
  super({});
@@ -96017,6 +96150,7 @@ var UnifiProviderAddon = class extends BaseDeviceProvider {
96017
96150
  this.ctx.logger.warn("UniFi shutdown error", { meta: { error: errMsg(err) } });
96018
96151
  }
96019
96152
  this.clients = null;
96153
+ this.integrationReconciler = null;
96020
96154
  unifiControllers.clear();
96021
96155
  await super.onShutdown();
96022
96156
  }
@@ -96033,51 +96167,47 @@ var UnifiProviderAddon = class extends BaseDeviceProvider {
96033
96167
  return unifiStableId(integrationId, childNativeId);
96034
96168
  }
96035
96169
  /**
96036
- * Rebuild the clients from the live integration list: upsert one per enabled integration
96037
- * with a host, drop the ones that vanished and cascade-remove their devices. Idempotent;
96038
- * runs at boot and on every integration lifecycle event.
96170
+ * Upsert one client per enabled integration and drop the client of one the list ANSWERED is
96171
+ * gone. Never removes a device (D49): that follows only an explicit lifecycle event.
96172
+ * Idempotent; runs at boot and on every integration lifecycle event.
96039
96173
  */
96040
- async reconcileIntegrations() {
96041
- const reg = this.requireClients();
96042
- try {
96043
- const mine = (await this.ctx.api.integrations.list.query()).filter((i) => i.addonId === this.ctx.id && i.enabled);
96044
- const surviving = /* @__PURE__ */ new Set();
96045
- for (const integration of mine) try {
96174
+ reconciler() {
96175
+ this.integrationReconciler ??= new UnifiReconciler({
96176
+ addonId: this.ctx.id,
96177
+ logger: this.ctx.logger,
96178
+ clients: this.requireClients(),
96179
+ listIntegrations: () => this.ctx.api.integrations.list.query(),
96180
+ applySettings: async (integration) => {
96181
+ const reg = this.requireClients();
96046
96182
  const read = connectionFromSettings(await this.ctx.api.integrations.getSettings.query({ id: integration.id }));
96047
- if (read === null) {
96048
- this.ctx.logger.warn("UniFi integration has no controller host — skipping", { meta: { integrationId: integration.id } });
96049
- continue;
96050
- }
96183
+ if (read === null) return false;
96051
96184
  await reg.upsert(integration.id, integration.name, read.connection, read.credentialsLocked);
96052
- surviving.add(integration.id);
96053
- } catch (err) {
96054
- this.ctx.logger.warn("UniFi reconcile failed for integration", { meta: {
96055
- integrationId: integration.id,
96056
- error: errMsg(err)
96057
- } });
96058
- }
96059
- const vanished = reg.list().filter((id) => !surviving.has(id));
96060
- await reg.retain(surviving);
96061
- for (const integrationId of vanished) await this.cascadeRemoveDevicesForIntegration(integrationId);
96062
- } catch (err) {
96063
- this.ctx.logger.warn("UniFi integration reconcile failed", { meta: { error: errMsg(err) } });
96064
- }
96185
+ return true;
96186
+ },
96187
+ removeDevices: (integrationId) => this.cascadeRemoveDevicesForIntegration(integrationId)
96188
+ });
96189
+ return this.integrationReconciler;
96190
+ }
96191
+ async reconcileIntegrations() {
96192
+ await this.reconciler().reconcile();
96065
96193
  }
96194
+ /** Lifecycle events: only an explicit Deleted/Disabled naming an integration removes devices. */
96066
96195
  subscribeIntegrationLifecycle() {
96067
- const handler = (event) => {
96196
+ const on = (kind) => (event) => {
96068
96197
  const addonId = event.data["addonId"];
96069
96198
  if (typeof addonId === "string" && addonId !== this.ctx.id) return;
96070
- this.reconcileIntegrations();
96199
+ const integrationId = event.data["integrationId"];
96200
+ this.reconciler().onLifecycle(kind, typeof integrationId === "string" ? integrationId : null);
96071
96201
  };
96072
- this.ctx.eventBus.subscribe({ category: EventCategory.IntegrationEnabled }, handler);
96073
- this.ctx.eventBus.subscribe({ category: EventCategory.IntegrationDisabled }, handler);
96074
- this.ctx.eventBus.subscribe({ category: EventCategory.IntegrationDeleted }, handler);
96202
+ this.ctx.eventBus.subscribe({ category: EventCategory.IntegrationEnabled }, on("enabled"));
96203
+ this.ctx.eventBus.subscribe({ category: EventCategory.IntegrationDisabled }, on("disabled"));
96204
+ this.ctx.eventBus.subscribe({ category: EventCategory.IntegrationDeleted }, on("deleted"));
96075
96205
  }
96076
96206
  async cascadeRemoveDevicesForIntegration(integrationId) {
96077
96207
  const reg = this.ctx.kernel.deviceRegistry;
96078
96208
  const devices = this.ctx.kernel.devices;
96079
- if (!reg || !devices) return;
96080
- await cascadeRemoveDevicesForIntegration({
96209
+ if (!reg || !devices) return 0;
96210
+ return await cascadeRemoveDevicesForIntegration({
96081
96211
  reg,
96082
96212
  devices,
96083
96213
  addonId: this.addonId,
package/dist/addon.mjs CHANGED
@@ -5830,7 +5830,7 @@ var ZodIssueCode = {
5830
5830
  var ZodFirstPartyTypeKind;
5831
5831
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5832
5832
  //#endregion
5833
- //#region ../types/dist/sleep-BHS4ImRX.mjs
5833
+ //#region ../types/dist/sleep-CSYuxssh.mjs
5834
5834
  /**
5835
5835
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5836
5836
  * window to float samples (D455).
@@ -9113,7 +9113,7 @@ var ProfileRtspEntrySchema = object({
9113
9113
  /**
9114
9114
  * The model weight formats a catalog entry can ship. Schema-free on purpose:
9115
9115
  * `types/models.ts` builds Zod schemas from it, but a runner-closure consumer
9116
- * (the model downloader in `@camstack/system`) needs only the list and must
9116
+ * (the model downloader in `@camstack/server/system`) needs only the list and must
9117
9117
  * reach it through `@camstack/types/addon` without building the cap schema
9118
9118
  * graph (D28).
9119
9119
  */
@@ -12488,6 +12488,71 @@ var EventOwnerTypeSchema = _enum(EVENT_OWNER_TYPES);
12488
12488
  var MediaPresenceOwnerKindSchema = _enum([...EVENT_OWNER_TYPES, "track"]);
12489
12489
  new Set(EVENT_OWNER_TYPES);
12490
12490
  /**
12491
+ * What a published package needs from the rest of the install (D989).
12492
+ *
12493
+ * One published framework package (`@camstack/server`) carries the kernel, the
12494
+ * builtins and the capability contracts, so "which addon runs on which
12495
+ * framework" is a question of version, and the answer is DECLARED by the
12496
+ * package that knows it:
12497
+ *
12498
+ * - an addon says the oldest server it runs on (`requires.server: ">=X"`);
12499
+ * - the server says the oldest addon it works with
12500
+ * (`requires.addons: { "@camstack/addon-x": ">=Y" }`) and the oldest shell
12501
+ * around it (`requires.wrapper: { desktop, image }`);
12502
+ * - a wrapper (the desktop app, the container starter) says which server
12503
+ * range it can host, and reports its own kind and version.
12504
+ *
12505
+ * The publish workflow STAMPS these after the version bump
12506
+ * (`scripts/ci/stamp-requires.mjs`); nobody types a number by hand.
12507
+ *
12508
+ * A requirement that cannot be checked is NOT met: a shell that reports no
12509
+ * version counts as below the minimum, and an unreadable running version is
12510
+ * named in the result (a failed read is never a pass).
12511
+ */
12512
+ /** `>=MAJOR.MINOR.PATCH[-prerelease]` — the only range shape a requirement uses. */
12513
+ var MinVersionSchema = string().regex(/^>=\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/, "a minimum is written \">=X.Y.Z\"");
12514
+ object({
12515
+ /** The oldest `@camstack/server` this package runs on. */
12516
+ server: MinVersionSchema.optional(),
12517
+ /** The oldest installed version of each named addon package. */
12518
+ addons: record(string(), MinVersionSchema).optional(),
12519
+ /** The oldest shell around the server, per shell kind. */
12520
+ wrapper: object({
12521
+ desktop: MinVersionSchema.optional(),
12522
+ image: MinVersionSchema.optional()
12523
+ }).optional()
12524
+ });
12525
+ /** One unmet requirement; each names the versions on both sides. */
12526
+ var UnmetRequirementSchema = discriminatedUnion("kind", [
12527
+ object({
12528
+ kind: literal("server-too-old"),
12529
+ required: string(),
12530
+ /** `null` — the running server version could not be read. */
12531
+ running: string().nullable()
12532
+ }),
12533
+ object({
12534
+ kind: literal("addon-too-old"),
12535
+ packageName: string(),
12536
+ required: string(),
12537
+ /** `null` — the addon is not installed (or its version is unreadable). */
12538
+ running: string().nullable()
12539
+ }),
12540
+ object({
12541
+ kind: literal("wrapper-too-old"),
12542
+ wrapper: _enum(["desktop", "image"]),
12543
+ required: string(),
12544
+ /** `null` — the wrapper reported no version. */
12545
+ running: string().nullable()
12546
+ })
12547
+ ]);
12548
+ var RequiredAddonUpdateSchema = object({
12549
+ packageName: string(),
12550
+ /** The minimum the target server declares. */
12551
+ required: string(),
12552
+ /** What this node has; `null` when the addon is not installed. */
12553
+ installed: string().nullable()
12554
+ });
12555
+ /**
12491
12556
  * Which integration instance a settings form is for. An addon that serves several instances
12492
12557
  * (`instanceMode: multiple`) can show a different form per instance — an NVR integration
12493
12558
  * needs its connection, the default integration needs the addon's own sections.
@@ -42903,7 +42968,7 @@ method(object({}), array(TargetKindSchema)), method(object({}), array(TargetSche
42903
42968
  * rebuilds without manual reload.
42904
42969
  *
42905
42970
  * The hub-local builtin `addon-pages-aggregator` (see
42906
- * `@camstack/system/builtins/addon-pages-aggregator`) registers the
42971
+ * `@camstack/server/system/builtins/addon-pages-aggregator`) registers the
42907
42972
  * provider. Splitting the public aggregator from the raw collection
42908
42973
  * keeps both ends in codegen — there's no hand-written
42909
42974
  * `addon-pages.router.ts` wrapper anymore.
@@ -43203,7 +43268,7 @@ method(_void(), array(WidgetMetadataSchema).readonly(), { auth: "admin" });
43203
43268
  * manual reload — same scheme used by `addon-pages`.
43204
43269
  *
43205
43270
  * The hub-local builtin `addon-widgets-aggregator` (see
43206
- * `@camstack/system/builtins/addon-widgets-aggregator`) registers the
43271
+ * `@camstack/server/system/builtins/addon-widgets-aggregator`) registers the
43207
43272
  * provider. Splitting the public aggregator from the raw collection
43208
43273
  * keeps both ends in codegen — there's no hand-written wrapper.
43209
43274
  */
@@ -61403,7 +61468,18 @@ var ServerUpdateActionResultSchema = object({
61403
61468
  * store (D877), present when the pre-flight refused the update
61404
61469
  * (`reason: 'addon-would-refuse'`). Optional for version skew.
61405
61470
  */
61406
- blockers: array(UpdateBlockerSchema).optional()
61471
+ blockers: array(UpdateBlockerSchema).optional(),
61472
+ /**
61473
+ * The minimums the target server declares and this node does not meet
61474
+ * (D989), present when the update was refused with
61475
+ * `reason: 'requirements-unmet'`. Each names the versions on both sides.
61476
+ */
61477
+ unmet: array(UnmetRequirementSchema).optional(),
61478
+ /**
61479
+ * The addons this node has below the minimum the staged server declares —
61480
+ * the ones to update WITH the server. Present on an accepted update.
61481
+ */
61482
+ requiredAddonUpdates: array(RequiredAddonUpdateSchema).optional()
61407
61483
  });
61408
61484
  var LaunchOverridesSchema = object({
61409
61485
  /** The persisted heap ceiling in MB, or `null` when none is set. */
@@ -63947,7 +64023,9 @@ var PackageUpdateSchema = object({
63947
64023
  latestVersion: string(),
63948
64024
  category: _enum(["addon", "core"]),
63949
64025
  requiresRestart: boolean(),
63950
- isSystem: boolean()
64026
+ isSystem: boolean(),
64027
+ /** Held: what the newer version needs and this node does not meet (D989). */
64028
+ blockedBy: array(UnmetRequirementSchema).readonly().optional()
63951
64029
  });
63952
64030
  var PackageVersionInfoSchema = object({
63953
64031
  version: string(),
@@ -69247,7 +69325,7 @@ var lawnMowerControlCapability = {
69247
69325
  * clients — they reverse-connect to the hub. Exposing their interfaces
69248
69326
  * via the same surface would leak internal topology with no upside.
69249
69327
  *
69250
- * Implementation in `@camstack/system/builtins/local-network/`.
69328
+ * Implementation in `@camstack/server/system/builtins/local-network/`.
69251
69329
  */
69252
69330
  /** Coarse classification derived from the interface name + IP range. */
69253
69331
  var InterfaceKindEnum = _enum([
@@ -71135,7 +71213,7 @@ onStatusChanged: { data: object({
71135
71213
  * jitter, and observed/peak bandwidth per device + per client.
71136
71214
  *
71137
71215
  * Implementation lives in the server's `NetworkQualityService` (thin
71138
- * wrapper over the shared `NetworkQualityTracker` from `@camstack/system`).
71216
+ * wrapper over the shared `NetworkQualityTracker` from `@camstack/server/system`).
71139
71217
  * The provider is registered from `trpc.router.ts` against the existing
71140
71218
  * service instance — no addon owns this state.
71141
71219
  *
@@ -73286,7 +73364,7 @@ var ptzAutotrackCapability = {
73286
73364
  * - **Native**: the camera's own firmware autotrack, registered per device by
73287
73365
  * the driver when the probe says it exists (Reolink: yes; Hikvision:
73288
73366
  * model-dependent).
73289
- * - **Wrapper**: the emulated implementation (`@camstack/system`'s `autotrack` builtin),
73367
+ * - **Wrapper**: the emulated implementation (`@camstack/server/system`'s `autotrack` builtin),
73290
73368
  * which follows a subject with `ptz.move` pulses driven by the detection
73291
73369
  * pipeline. `defaultActive: false` — the operator binds it per camera in
73292
73370
  * the bindings UI.
@@ -95914,6 +95992,60 @@ async function reconcileInfraFeatures(input) {
95914
95992
  return changed;
95915
95993
  }
95916
95994
  //#endregion
95995
+ //#region src/unifi-reconciler.ts
95996
+ /**
95997
+ * Keeps one live client per enabled integration. Devices are removed ONLY on an explicit
95998
+ * lifecycle event naming the integration (D49): a list that failed, an empty list or an
95999
+ * unreadable connection changes nothing about devices and is logged, never read as "gone".
96000
+ */
96001
+ var UnifiReconciler = class {
96002
+ #deps;
96003
+ constructor(deps) {
96004
+ this.#deps = deps;
96005
+ }
96006
+ /** Upsert a client per usable enabled integration; drop the CLIENT (never devices) of one the list answered is gone. */
96007
+ async reconcile() {
96008
+ const { logger, clients } = this.#deps;
96009
+ let all;
96010
+ try {
96011
+ all = await this.#deps.listIntegrations();
96012
+ } catch (err) {
96013
+ logger.warn("Unifi integration reconcile skipped — the integration list did not answer", { meta: { error: errMsg(err) } });
96014
+ return;
96015
+ }
96016
+ const enabled = all.filter((i) => i.addonId === this.#deps.addonId && i.enabled);
96017
+ for (const integration of enabled) try {
96018
+ if (!await this.#deps.applySettings(integration)) logger.warn("Unifi integration has no usable connection — left as it is", { meta: { integrationId: integration.id } });
96019
+ } catch (err) {
96020
+ logger.warn("Unifi reconcile failed for integration — left as it is", { meta: {
96021
+ integrationId: integration.id,
96022
+ error: errMsg(err)
96023
+ } });
96024
+ }
96025
+ const enabledIds = new Set(enabled.map((i) => i.id));
96026
+ for (const id of clients.list()) if (!enabledIds.has(id)) await clients.remove(id);
96027
+ }
96028
+ /** An explicit lifecycle event: only `deleted` / `disabled` of a named integration remove devices. */
96029
+ async onLifecycle(kind, integrationId) {
96030
+ await this.reconcile();
96031
+ if (kind === "enabled" || integrationId === null) return;
96032
+ try {
96033
+ const removed = await this.#deps.removeDevices(integrationId);
96034
+ this.#deps.logger.info("Unifi integration devices removed", { meta: {
96035
+ integrationId,
96036
+ kind,
96037
+ removed
96038
+ } });
96039
+ } catch (err) {
96040
+ this.#deps.logger.warn("Unifi integration device removal failed", { meta: {
96041
+ integrationId,
96042
+ kind,
96043
+ error: errMsg(err)
96044
+ } });
96045
+ }
96046
+ }
96047
+ };
96048
+ //#endregion
95917
96049
  //#region src/unifi-integration-device-cascade.ts
95918
96050
  /**
95919
96051
  * Remove every top-level device (Gateway, infra Container, client Presence) of an integration that
@@ -95991,6 +96123,7 @@ var UnifiProviderAddon = class extends BaseDeviceProvider {
95991
96123
  [DeviceType.Sensor]: UnifiFeatureDevice,
95992
96124
  [DeviceType.Presence]: UnifiFeatureDevice
95993
96125
  };
96126
+ integrationReconciler = null;
95994
96127
  clients = null;
95995
96128
  constructor() {
95996
96129
  super({});
@@ -96016,6 +96149,7 @@ var UnifiProviderAddon = class extends BaseDeviceProvider {
96016
96149
  this.ctx.logger.warn("UniFi shutdown error", { meta: { error: errMsg(err) } });
96017
96150
  }
96018
96151
  this.clients = null;
96152
+ this.integrationReconciler = null;
96019
96153
  unifiControllers.clear();
96020
96154
  await super.onShutdown();
96021
96155
  }
@@ -96032,51 +96166,47 @@ var UnifiProviderAddon = class extends BaseDeviceProvider {
96032
96166
  return unifiStableId(integrationId, childNativeId);
96033
96167
  }
96034
96168
  /**
96035
- * Rebuild the clients from the live integration list: upsert one per enabled integration
96036
- * with a host, drop the ones that vanished and cascade-remove their devices. Idempotent;
96037
- * runs at boot and on every integration lifecycle event.
96169
+ * Upsert one client per enabled integration and drop the client of one the list ANSWERED is
96170
+ * gone. Never removes a device (D49): that follows only an explicit lifecycle event.
96171
+ * Idempotent; runs at boot and on every integration lifecycle event.
96038
96172
  */
96039
- async reconcileIntegrations() {
96040
- const reg = this.requireClients();
96041
- try {
96042
- const mine = (await this.ctx.api.integrations.list.query()).filter((i) => i.addonId === this.ctx.id && i.enabled);
96043
- const surviving = /* @__PURE__ */ new Set();
96044
- for (const integration of mine) try {
96173
+ reconciler() {
96174
+ this.integrationReconciler ??= new UnifiReconciler({
96175
+ addonId: this.ctx.id,
96176
+ logger: this.ctx.logger,
96177
+ clients: this.requireClients(),
96178
+ listIntegrations: () => this.ctx.api.integrations.list.query(),
96179
+ applySettings: async (integration) => {
96180
+ const reg = this.requireClients();
96045
96181
  const read = connectionFromSettings(await this.ctx.api.integrations.getSettings.query({ id: integration.id }));
96046
- if (read === null) {
96047
- this.ctx.logger.warn("UniFi integration has no controller host — skipping", { meta: { integrationId: integration.id } });
96048
- continue;
96049
- }
96182
+ if (read === null) return false;
96050
96183
  await reg.upsert(integration.id, integration.name, read.connection, read.credentialsLocked);
96051
- surviving.add(integration.id);
96052
- } catch (err) {
96053
- this.ctx.logger.warn("UniFi reconcile failed for integration", { meta: {
96054
- integrationId: integration.id,
96055
- error: errMsg(err)
96056
- } });
96057
- }
96058
- const vanished = reg.list().filter((id) => !surviving.has(id));
96059
- await reg.retain(surviving);
96060
- for (const integrationId of vanished) await this.cascadeRemoveDevicesForIntegration(integrationId);
96061
- } catch (err) {
96062
- this.ctx.logger.warn("UniFi integration reconcile failed", { meta: { error: errMsg(err) } });
96063
- }
96184
+ return true;
96185
+ },
96186
+ removeDevices: (integrationId) => this.cascadeRemoveDevicesForIntegration(integrationId)
96187
+ });
96188
+ return this.integrationReconciler;
96189
+ }
96190
+ async reconcileIntegrations() {
96191
+ await this.reconciler().reconcile();
96064
96192
  }
96193
+ /** Lifecycle events: only an explicit Deleted/Disabled naming an integration removes devices. */
96065
96194
  subscribeIntegrationLifecycle() {
96066
- const handler = (event) => {
96195
+ const on = (kind) => (event) => {
96067
96196
  const addonId = event.data["addonId"];
96068
96197
  if (typeof addonId === "string" && addonId !== this.ctx.id) return;
96069
- this.reconcileIntegrations();
96198
+ const integrationId = event.data["integrationId"];
96199
+ this.reconciler().onLifecycle(kind, typeof integrationId === "string" ? integrationId : null);
96070
96200
  };
96071
- this.ctx.eventBus.subscribe({ category: EventCategory.IntegrationEnabled }, handler);
96072
- this.ctx.eventBus.subscribe({ category: EventCategory.IntegrationDisabled }, handler);
96073
- this.ctx.eventBus.subscribe({ category: EventCategory.IntegrationDeleted }, handler);
96201
+ this.ctx.eventBus.subscribe({ category: EventCategory.IntegrationEnabled }, on("enabled"));
96202
+ this.ctx.eventBus.subscribe({ category: EventCategory.IntegrationDisabled }, on("disabled"));
96203
+ this.ctx.eventBus.subscribe({ category: EventCategory.IntegrationDeleted }, on("deleted"));
96074
96204
  }
96075
96205
  async cascadeRemoveDevicesForIntegration(integrationId) {
96076
96206
  const reg = this.ctx.kernel.deviceRegistry;
96077
96207
  const devices = this.ctx.kernel.devices;
96078
- if (!reg || !devices) return;
96079
- await cascadeRemoveDevicesForIntegration({
96208
+ if (!reg || !devices) return 0;
96209
+ return await cascadeRemoveDevicesForIntegration({
96080
96210
  reg,
96081
96211
  devices,
96082
96212
  addonId: this.addonId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-provider-unifi",
3
- "version": "0.2.151",
3
+ "version": "0.2.152",
4
4
  "description": "UniFi Network controller device-provider addon for CamStack — local-controller infra switches/APs (as containers) + network-client presence. No cameras.",
5
5
  "keywords": [
6
6
  "camstack",
@@ -57,7 +57,10 @@
57
57
  }
58
58
  ]
59
59
  }
60
- ]
60
+ ],
61
+ "requires": {
62
+ "server": ">=1.2.719"
63
+ }
61
64
  },
62
65
  "files": [
63
66
  "dist",