@camstack/server 1.2.941 → 1.2.943

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/api/trpc/generated-cap-mounts.js +19 -1
  3. package/dist/api/trpc/generated-cap-routers.js +676 -596
  4. package/package.json +13 -11
  5. package/system/dist/action-index-B1fgpQBt.mjs +9925 -0
  6. package/system/dist/action-index-B_cLRwXJ.js +9972 -0
  7. package/system/dist/alert-episode-Be--PngO.mjs +64 -0
  8. package/system/dist/alert-episode-Bqktmt-i.js +93 -0
  9. package/system/dist/{base-addon-Md14i7pe.mjs → base-addon-BcS6r1cT.mjs} +20 -7
  10. package/system/dist/{base-addon-DD5dIfcZ.js → base-addon-CRsXtYFG.js} +20 -7
  11. package/system/dist/{base-device-CH8rfD9j.js → base-device-DAdWzDOl.js} +138 -34
  12. package/system/dist/{base-device-BcGO6LTT.mjs → base-device-DJXF5eDN.mjs} +138 -34
  13. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  14. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  15. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  16. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  17. package/system/dist/builtins/alerts/alert-episode-policy.d.ts +9 -5
  18. package/system/dist/builtins/alerts/alerts.addon.js +30 -80
  19. package/system/dist/builtins/alerts/alerts.addon.mjs +18 -68
  20. package/system/dist/builtins/autotrack/index.js +2 -2
  21. package/system/dist/builtins/autotrack/index.mjs +2 -2
  22. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
  23. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
  24. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  25. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  26. package/system/dist/builtins/camera-grid/index.js +9 -9
  27. package/system/dist/builtins/camera-grid/index.mjs +6 -6
  28. package/system/dist/builtins/composer/composer.addon.js +99 -99
  29. package/system/dist/builtins/composer/composer.addon.mjs +11 -11
  30. package/system/dist/builtins/console-logging/index.js +1 -1
  31. package/system/dist/builtins/console-logging/index.mjs +1 -1
  32. package/system/dist/builtins/core-blocks/automation-template-instances.d.ts +14 -1
  33. package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +6 -0
  34. package/system/dist/builtins/core-blocks/core-blocks.addon.js +296 -193
  35. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +237 -134
  36. package/system/dist/builtins/core-blocks/link-contributions.d.ts +2 -0
  37. package/system/dist/builtins/core-notifier/core-notifier.addon.js +91 -18
  38. package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +91 -18
  39. package/system/dist/builtins/core-notifier/group-notification-output.d.ts +8 -16
  40. package/system/dist/builtins/device-history/device-history.addon.d.ts +8 -0
  41. package/system/dist/builtins/device-history/device-history.addon.js +580 -60
  42. package/system/dist/builtins/device-history/device-history.addon.mjs +569 -49
  43. package/system/dist/builtins/device-history/retention/device-raw-overrides.d.ts +16 -0
  44. package/system/dist/builtins/device-history/retention/retention-knobs.d.ts +14 -0
  45. package/system/dist/builtins/device-history/retention/retention.d.ts +21 -1
  46. package/system/dist/builtins/device-history/transitions/change-coalescing.d.ts +48 -0
  47. package/system/dist/builtins/device-history/transitions/derived-changes.d.ts +49 -0
  48. package/system/dist/builtins/device-history/transitions/history-change-port.d.ts +20 -0
  49. package/system/dist/builtins/device-history/transitions/transitions-service.d.ts +18 -3
  50. package/system/dist/builtins/device-manager/device-config-secrets.d.ts +14 -0
  51. package/system/dist/builtins/device-manager/device-identity-index.d.ts +2 -2
  52. package/system/dist/builtins/device-manager/device-manager.addon.js +226 -479
  53. package/system/dist/builtins/device-manager/device-manager.addon.mjs +218 -471
  54. package/system/dist/builtins/device-manager/device-state-mirror.d.ts +0 -5
  55. package/system/dist/builtins/device-manager/identity-link-reconciler.d.ts +5 -0
  56. package/system/dist/builtins/device-manager/transitions/command-recorder.d.ts +38 -0
  57. package/system/dist/builtins/device-manager/transitions/transitions-wiring.d.ts +8 -9
  58. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  59. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  60. package/system/dist/builtins/keychain/index.js +2 -2
  61. package/system/dist/builtins/keychain/index.mjs +2 -2
  62. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +2 -2
  63. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +2 -2
  64. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  65. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  66. package/system/dist/builtins/local-network/address-book.d.ts +3 -1
  67. package/system/dist/builtins/local-network/local-network.addon.d.ts +26 -1
  68. package/system/dist/builtins/local-network/local-network.addon.js +66 -11
  69. package/system/dist/builtins/local-network/local-network.addon.mjs +66 -11
  70. package/system/dist/builtins/loki-logging/index.js +1 -1
  71. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  72. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  73. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  74. package/system/dist/builtins/platform-probe/index.js +1 -1
  75. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  76. package/system/dist/builtins/record-entries/index.js +1 -1
  77. package/system/dist/builtins/record-entries/index.mjs +1 -1
  78. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  79. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  80. package/system/dist/builtins/snapshot/index.js +4 -4
  81. package/system/dist/builtins/snapshot/index.mjs +4 -4
  82. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  83. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  84. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  85. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  86. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  87. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  88. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  89. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  90. package/system/dist/builtins/system-config/system-config.addon.js +1 -1
  91. package/system/dist/builtins/system-config/system-config.addon.mjs +1 -1
  92. package/system/dist/builtins/winston-logging/index.js +1 -1
  93. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  94. package/system/dist/{capture-engine-CUZ3W0oZ.mjs → capture-engine-B2MmoNND.mjs} +1 -1
  95. package/system/dist/{capture-engine-mtDXEBAq.js → capture-engine-D_1IJmMs.js} +1 -1
  96. package/system/dist/command-catalog-C29hVOOg.js +210 -0
  97. package/system/dist/command-catalog-xAeqxbZk.mjs +169 -0
  98. package/system/dist/{error.cap-DCwbIGEF.mjs → compile-OBMHlqD-.mjs} +97 -100
  99. package/system/dist/{error.cap-BxLEHP6z.js → compile-SpeAhaZ6.js} +107 -116
  100. package/system/dist/{composition-sources-B56CU8hi.mjs → composition-sources-C327LGFn.mjs} +2 -2
  101. package/system/dist/{composition-sources-D_Bfwji0.js → composition-sources-Do5qM6EB.js} +17 -17
  102. package/system/dist/{core-blocks.cap-xt5_fK5Z.js → core-blocks.cap-CdTGUKtr.js} +194 -10110
  103. package/system/dist/{core-blocks.cap-DDECcMeI.mjs → core-blocks.cap-DLkEfV5b.mjs} +54 -9910
  104. package/system/dist/{device-kind-BJ2pfsjw.mjs → device-kind-C37Ra2wd.mjs} +4 -2
  105. package/system/dist/{device-kind-CsSiv_YF.js → device-kind-FMhJg8uC.js} +4 -2
  106. package/system/dist/{device-manager.cap-DyHOIh5T.js → device-manager.cap-DJs8izI6.js} +13 -4
  107. package/system/dist/{device-manager.cap-DIBK62-r.mjs → device-manager.cap-eYrj1Ezp.mjs} +13 -4
  108. package/system/dist/{device-provider.cap-BKUGJSo0.js → device-provider.cap-CNlYBQ5D.js} +1 -1
  109. package/system/dist/{device-provider.cap-DU6HMUXH.mjs → device-provider.cap-D8mJllVM.mjs} +1 -1
  110. package/system/dist/{device-row-store-O4mNbp5q.js → device-row-store-C0P2H18h.js} +2 -2
  111. package/system/dist/{device-row-store-C-_R-h1Z.mjs → device-row-store-CTocYKqC.mjs} +2 -2
  112. package/system/dist/{device-type-CbQsnFdC.js → device-type-Cnc0NiSX.js} +13 -0
  113. package/system/dist/{device-type-DgEvK3ch.mjs → device-type-TUGqGmaI.mjs} +13 -0
  114. package/system/dist/error.cap-BuKbL3Ac.js +125 -0
  115. package/system/dist/error.cap-CU1FB6uE.mjs +102 -0
  116. package/system/dist/file-host-worker.js +1 -1
  117. package/system/dist/file-host-worker.mjs +1 -1
  118. package/system/dist/{history-catalog-BwTeQ4Mr.mjs → history-catalog-A_dzXNpv.mjs} +98 -3
  119. package/system/dist/{history-catalog-BKRarIL_.js → history-catalog-CiTMP3-E.js} +98 -3
  120. package/system/dist/index.js +28 -6
  121. package/system/dist/index.mjs +28 -6
  122. package/system/dist/kernel/addon-version-policy.d.ts +10 -0
  123. package/system/dist/{legacy-integration-rows-door-B1nzxxr5.js → legacy-integration-rows-door-CdqYAj-o.js} +1 -1
  124. package/system/dist/{legacy-integration-rows-door-nTvo_6jQ.mjs → legacy-integration-rows-door-LSgpClpX.mjs} +1 -1
  125. package/system/dist/{low-power-sleep.cap-B6mz6ojP.js → low-power-sleep.cap-BJWyAuUQ.js} +1 -1
  126. package/system/dist/{low-power-sleep.cap-C3Vi8Vxj.mjs → low-power-sleep.cap-D9Orx3LS.mjs} +1 -1
  127. package/system/dist/migrations/hub/2026-11-22-device-transitions-commands-only.d.ts +10 -0
  128. package/system/dist/{network-access.cap-BEN_uRVb.js → network-access.cap-CTQ2WQoi.js} +38 -12
  129. package/system/dist/{network-access.cap-Dy8FNNVs.mjs → network-access.cap-Dx5K0I5i.mjs} +33 -13
  130. package/system/dist/{notification-rules.cap-Drwz-A4n.js → notification-rules.cap-BJKUjizS.js} +45 -9
  131. package/system/dist/{notification-rules.cap-0vVvsxQ1.mjs → notification-rules.cap-BUIuYPlQ.mjs} +45 -9
  132. package/system/dist/{notification-targets-DR-D-vIt.mjs → notification-targets-4bGYH5J7.mjs} +2 -2
  133. package/system/dist/{notification-targets-Cc_3OBH9.js → notification-targets-DMW7xgR2.js} +2 -2
  134. package/system/dist/{prefix-walk-CCO_VZVo.js → prefix-walk-BFnw8NBu.js} +5 -5
  135. package/system/dist/{prefix-walk-BhT0ZoKl.mjs → prefix-walk-Mtij0NNT.mjs} +2 -2
  136. package/system/dist/{ptz-autotrack.cap-DOz0xL0O.js → ptz-autotrack.cap-B9eyZU8w.js} +1 -1
  137. package/system/dist/{ptz-autotrack.cap-CDF6FeTK.mjs → ptz-autotrack.cap-Dw2k-po9.mjs} +1 -1
  138. package/system/dist/{recording-archive.cap-RHAN45fa.mjs → recording-archive.cap-CTlm86R8.mjs} +1 -1
  139. package/system/dist/{recording-archive.cap-BPJ7kvnd.js → recording-archive.cap-Wo-hEZhz.js} +1 -1
  140. package/system/dist/{rename-composition-block-DWUkrazx.mjs → rename-composition-block-Cdh-dRmY.mjs} +395 -20
  141. package/system/dist/{rename-composition-block-CH2vRIW7.js → rename-composition-block-D9Uc1AF7.js} +406 -31
  142. package/system/dist/{retention-CUOVI1p7.mjs → retention-CQs8QR1B.mjs} +33 -3
  143. package/system/dist/{device-transitions.cap-DCXP3zwY.mjs → retention-source.cap-550kkyp5.mjs} +98 -21
  144. package/system/dist/{device-transitions.cap-zOGvAIHz.js → retention-source.cap-C6Hy0hlM.js} +103 -20
  145. package/system/dist/{retention-BcOSL6b9.js → retention-xcjk_k1w.js} +33 -3
  146. package/system/dist/{snapshot.cap-Cis6JRwn.js → snapshot.cap-CHm29hBs.js} +1 -1
  147. package/system/dist/{snapshot.cap-BkfHpJVO.mjs → snapshot.cap-CO68YvJU.mjs} +1 -1
  148. package/system/dist/{stream-catalog.cap-D8Y-uXcy.js → stream-catalog.cap-CjEQFknc.js} +2 -2
  149. package/system/dist/{stream-catalog.cap-D1Hy19Yc.mjs → stream-catalog.cap-DVniDdRD.mjs} +2 -2
  150. package/system/dist/{user-management.cap-Ctd4c_im.mjs → user-management.cap-4IEUCSdL.mjs} +2 -2
  151. package/system/dist/{user-management.cap-DyVb68rY.js → user-management.cap-DV9Jfsj3.js} +2 -2
  152. package/system/dist/{wal-maintenance-CjpslZUL.mjs → wal-maintenance-Bey5ChBb.mjs} +0 -0
  153. package/system/dist/{wal-maintenance-DKTXQ7UF.js → wal-maintenance-BgYiAy5b.js} +0 -0
  154. package/system/package.json +4 -1
  155. package/system/dist/builtins/device-manager/transitions/transition-correlator.d.ts +0 -81
@@ -3,10 +3,10 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_base_addon = require("../../base-addon-DD5dIfcZ.js");
6
+ const require_base_addon = require("../../base-addon-CRsXtYFG.js");
7
7
  const require_scoped_settings = require("../../scoped-settings-CylSSq_8.js");
8
- const require_notification_targets = require("../../notification-targets-Cc_3OBH9.js");
9
- const require_notification_rules_cap = require("../../notification-rules.cap-Drwz-A4n.js");
8
+ const require_notification_targets = require("../../notification-targets-DMW7xgR2.js");
9
+ const require_notification_rules_cap = require("../../notification-rules.cap-BJKUjizS.js");
10
10
  const require_integration_instances_cap = require("../../integration-instances.cap-DSieF1w3.js");
11
11
  let zod = require("zod");
12
12
  let node_crypto = require("node:crypto");
@@ -120,6 +120,32 @@ var GroupMemberWhenSchema = /* @__PURE__ */ zod.z.discriminatedUnion("kind", [
120
120
  states: /* @__PURE__ */ zod.z.array(require_notification_rules_cap.AlarmStateSchema).min(1)
121
121
  })
122
122
  ]);
123
+ /** The `metadata` key a sender stamps with the kind of event behind a notification. */
124
+ var NOTIFICATION_META_EVENT_KIND = "eventKind";
125
+ /** The `metadata` key a sender stamps with the detected class (person, car, ...) of a notification. */
126
+ var NOTIFICATION_META_CLASS_NAME = "className";
127
+ /** What kind of event a notification is about, as a member's content filter names it. */
128
+ var NotificationEventKindSchema = /* @__PURE__ */ zod.z.enum([
129
+ "detection",
130
+ "audio",
131
+ "device-event",
132
+ "occupancy",
133
+ "package",
134
+ "appliance",
135
+ "system-event",
136
+ "timelapse",
137
+ "summary",
138
+ "calendar"
139
+ ]);
140
+ /**
141
+ * Which notifications a member receives by content. Each list that is set must match; a
142
+ * notification that does not carry the value (no event kind, no class) does not match it.
143
+ */
144
+ var GroupMemberFilterSchema = /* @__PURE__ */ zod.z.object({
145
+ eventKinds: /* @__PURE__ */ zod.z.array(NotificationEventKindSchema).min(1).optional(),
146
+ /** Detected classes, compared without case. */
147
+ classes: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.string().min(1)).min(1).optional()
148
+ });
123
149
  /**
124
150
  * One member's policy. Every key but `targetId` is optional and means "no restriction" when absent
125
151
  * (never a Zod default: a default does not run on the addon cap path).
@@ -137,7 +163,14 @@ var GroupMemberSchema = /* @__PURE__ */ zod.z.object({
137
163
  }).optional(),
138
164
  minPriority: /* @__PURE__ */ zod.z.number().int().min(1).max(5).optional(),
139
165
  /** At most one delivery per window; a burst becomes one. 0 or absent = no throttle. */
140
- throttleSec: /* @__PURE__ */ zod.z.number().int().nonnegative().optional()
166
+ throttleSec: /* @__PURE__ */ zod.z.number().int().nonnegative().optional(),
167
+ /** Receives only the notifications of these event kinds / classes. Absent = all of them. */
168
+ filter: /* @__PURE__ */ GroupMemberFilterSchema.optional(),
169
+ /**
170
+ * Escalation: the target ids of other members of this group. This member is tried only when
171
+ * NONE of them was delivered in the same send (each failed or was skipped). Absent = always tried.
172
+ */
173
+ onlyIfUndelivered: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.string().min(1)).min(1).optional()
141
174
  });
142
175
  /** Read the `members` of a group's config; an unreadable row is counted, never silently dropped. */
143
176
  function groupMembersOf(config) {
@@ -158,6 +191,31 @@ function groupMembersOf(config) {
158
191
  invalid
159
192
  };
160
193
  }
194
+ /** Whether a notification is one the filter names: every list that is set must match. */
195
+ function matchesMemberFilter(filter, notification) {
196
+ const kind = notification.metadata?.[NOTIFICATION_META_EVENT_KIND];
197
+ if (filter.eventKinds !== void 0) {
198
+ const parsed = NotificationEventKindSchema.safeParse(kind);
199
+ if (!parsed.success || !filter.eventKinds.includes(parsed.data)) return false;
200
+ }
201
+ if (filter.classes !== void 0) {
202
+ const className = notification.metadata?.[NOTIFICATION_META_CLASS_NAME];
203
+ if (typeof className !== "string") return false;
204
+ const wanted = className.toLowerCase();
205
+ if (!filter.classes.some((name) => name.toLowerCase() === wanted)) return false;
206
+ }
207
+ return true;
208
+ }
209
+ /**
210
+ * Whether a fallback member is needed: none of the members it backs up was delivered. A member
211
+ * skipped as `already-delivered` got this notification on an earlier attempt, so it counts as
212
+ * delivered; one with no outcome yet (listed later, or not in the group) counts as not delivered.
213
+ */
214
+ function escalationNeeded(member, outcomes) {
215
+ if (member.onlyIfUndelivered === void 0) return true;
216
+ const delivered = new Set(outcomes.filter((outcome) => outcome.status === "sent" || outcome.status === "skipped" && outcome.reason === "already-delivered").map((outcome) => outcome.targetId));
217
+ return !member.onlyIfUndelivered.some((targetId) => delivered.has(targetId));
218
+ }
161
219
  /** The policy of one member that needs no state of the group: enabled, priority, schedule, alarm. */
162
220
  function decideMember(input) {
163
221
  const { member, notification, nowMs } = input;
@@ -169,6 +227,10 @@ function decideMember(input) {
169
227
  send: false,
170
228
  reason: "below-min-priority"
171
229
  };
230
+ if (member.filter !== void 0 && input.ignoreFilter !== true && !matchesMemberFilter(member.filter, notification)) return {
231
+ send: false,
232
+ reason: "content-filter"
233
+ };
172
234
  const when = member.when;
173
235
  if (when?.kind === "schedule" && !isScheduleActive(when.schedule, nowMs)) return {
174
236
  send: false,
@@ -360,6 +422,7 @@ function validateGroupMembers(config, groupIds) {
360
422
  if (seen.has(targetId)) throw new Error(`The notifier ${targetId} is listed twice`);
361
423
  seen.add(targetId);
362
424
  if (groupIds.has(targetId)) throw new Error("A group cannot contain another group");
425
+ for (const primary of parsed.data.onlyIfUndelivered ?? []) if (primary === targetId || !seen.has(primary)) throw new Error(`The notifier ${targetId} can only be a fallback for a member listed before it (${primary} is not)`);
363
426
  members.push(parsed.data);
364
427
  }
365
428
  return members;
@@ -504,7 +567,10 @@ var MemberLedger = class {
504
567
  *
505
568
  * Rules: fan-out goes through `ctx.api.notificationOutput.send` (the `sendToMember` port); a member
506
569
  * that is itself a group is refused (`nested-group`); every skip is logged with its reason and the
507
- * group's tags (D391); a retry re-sends only the members that failed (the ledger).
570
+ * group's tags (D391); a retry re-sends only the members that failed (the ledger); a test press bypasses that ledger
571
+ * and the content filter. A member with `onlyIfUndelivered` is a fallback: tried only when none of the
572
+ * members it names was delivered in the same send.
573
+ * `SendResult.members` carries every member's outcome.
508
574
  */
509
575
  var CANNED = {
510
576
  title: "CamStack",
@@ -518,7 +584,7 @@ function summary(outcomes) {
518
584
  }
519
585
  function createGroupNotificationOutputProvider(deps) {
520
586
  const { logger } = deps;
521
- async function deliverMember(group, member, notification, notificationKey, targets, unreadableHolders, byKind) {
587
+ async function deliverMember(group, member, notification, notificationKey, targets, unreadableHolders, byKind, isTest, earlier) {
522
588
  const tags = {
523
589
  groupId: group.id,
524
590
  ...notification.deviceId !== void 0 ? { deviceId: notification.deviceId } : {}
@@ -572,15 +638,17 @@ function createGroupNotificationOutputProvider(deps) {
572
638
  }
573
639
  if (target.kind === "group") return skip("nested-group");
574
640
  if (!target.enabled) return skip("target-disabled");
575
- if (deps.ledger.wasDelivered(group.id, notificationKey, member.targetId)) return skip("already-delivered");
641
+ if (!isTest && deps.ledger.wasDelivered(group.id, notificationKey, member.targetId)) return skip("already-delivered");
576
642
  const alarm = member.when?.kind === "alarm" ? await deps.readAlarmState(member.when.deviceId) : void 0;
577
643
  const decision = decideMember({
578
644
  member,
579
645
  notification,
580
646
  nowMs: deps.now(),
581
- ...alarm !== void 0 ? { alarmState: alarm } : {}
647
+ ...alarm !== void 0 ? { alarmState: alarm } : {},
648
+ ...isTest ? { ignoreFilter: true } : {}
582
649
  });
583
650
  if (!decision.send) return skip(decision.reason);
651
+ if (!escalationNeeded(member, earlier)) return skip("escalation-not-needed");
584
652
  if (deps.ledger.isThrottled(group.id, member.targetId, member.throttleSec)) return skip("throttled");
585
653
  const shaped = shapeForMember(member, notification);
586
654
  const ownCaps = byKind.get(target.kind);
@@ -606,7 +674,7 @@ function createGroupNotificationOutputProvider(deps) {
606
674
  error
607
675
  };
608
676
  }
609
- deps.ledger.markDelivered(group.id, notificationKey, member.targetId);
677
+ if (!isTest) deps.ledger.markDelivered(group.id, notificationKey, member.targetId);
610
678
  deps.ledger.markSent(group.id, member.targetId);
611
679
  return {
612
680
  targetId: member.targetId,
@@ -629,7 +697,7 @@ function createGroupNotificationOutputProvider(deps) {
629
697
  };
630
698
  }
631
699
  }
632
- async function deliver(group, notification) {
700
+ async function deliver(group, notification, isTest = false) {
633
701
  const { members, invalid } = groupMembersOf(group.config);
634
702
  if (invalid > 0) logger.warn("group has member rows that could not be read; they are not delivered to", {
635
703
  tags: { groupId: group.id },
@@ -650,22 +718,27 @@ function createGroupNotificationOutputProvider(deps) {
650
718
  return /* @__PURE__ */ new Map();
651
719
  });
652
720
  const outcomes = [];
653
- for (const member of members) outcomes.push(await deliverMember(group, member, notification, key, targets, unreadableHolders, byKind));
721
+ for (const member of members) outcomes.push(await deliverMember(group, member, notification, key, targets, unreadableHolders, byKind, isTest, outcomes));
654
722
  return {
655
723
  groupId: group.id,
656
724
  outcomes
657
725
  };
658
726
  }
659
- async function sendTo(group, id, notification) {
727
+ async function sendTo(group, id, notification, isTest) {
660
728
  if (group === null) return {
661
729
  success: false,
662
730
  error: `Unknown target '${id}'`
663
731
  };
664
- const report = await deliver(group, notification);
665
- return report.outcomes.some((outcome) => outcome.status === "failed") ? {
732
+ const report = await deliver(group, notification, isTest);
733
+ const members = [...report.outcomes];
734
+ return members.some((outcome) => outcome.status === "failed") ? {
666
735
  success: false,
667
- error: summary(report.outcomes)
668
- } : { success: true };
736
+ error: summary(report.outcomes),
737
+ members
738
+ } : {
739
+ success: true,
740
+ members
741
+ };
669
742
  }
670
743
  return {
671
744
  provider: {
@@ -682,9 +755,9 @@ function createGroupNotificationOutputProvider(deps) {
682
755
  success: false,
683
756
  error: "Target is disabled"
684
757
  };
685
- return sendTo(group, targetId, notification);
758
+ return sendTo(group, targetId, notification, false);
686
759
  },
687
- testTarget: async ({ targetId, sample }) => sendTo(await deps.store.getById(targetId), targetId, sample ?? CANNED)
760
+ testTarget: async ({ targetId, sample }) => sendTo(await deps.store.getById(targetId), targetId, sample ?? CANNED, true)
688
761
  },
689
762
  deliver
690
763
  };
@@ -1,7 +1,7 @@
1
- import { t as BaseAddon } from "../../base-addon-Md14i7pe.mjs";
1
+ import { t as BaseAddon } from "../../base-addon-BcS6r1cT.mjs";
2
2
  import { Z as errMsg } from "../../scoped-settings-DVWUIP7Z.mjs";
3
- import { i as notificationTargetKinds, n as buildNotificationTargetInstances, r as listNotificationTargets, t as NotificationTargetStore } from "../../notification-targets-DR-D-vIt.mjs";
4
- import { f as notificationOutputCapability, l as NotificationFieldSchema, o as AlarmPanelStatusSchema, r as NcScheduleSchema, s as AlarmStateSchema } from "../../notification-rules.cap-0vVvsxQ1.mjs";
3
+ import { i as notificationTargetKinds, n as buildNotificationTargetInstances, r as listNotificationTargets, t as NotificationTargetStore } from "../../notification-targets-4bGYH5J7.mjs";
4
+ import { f as notificationOutputCapability, l as NotificationFieldSchema, o as AlarmPanelStatusSchema, r as NcScheduleSchema, s as AlarmStateSchema } from "../../notification-rules.cap-BUIuYPlQ.mjs";
5
5
  import { t as integrationInstancesCapability } from "../../integration-instances.cap-BWttO42A.mjs";
6
6
  import { z } from "zod";
7
7
  import { createHash, randomUUID } from "node:crypto";
@@ -115,6 +115,32 @@ var GroupMemberWhenSchema = /* @__PURE__ */ z.discriminatedUnion("kind", [
115
115
  states: /* @__PURE__ */ z.array(AlarmStateSchema).min(1)
116
116
  })
117
117
  ]);
118
+ /** The `metadata` key a sender stamps with the kind of event behind a notification. */
119
+ var NOTIFICATION_META_EVENT_KIND = "eventKind";
120
+ /** The `metadata` key a sender stamps with the detected class (person, car, ...) of a notification. */
121
+ var NOTIFICATION_META_CLASS_NAME = "className";
122
+ /** What kind of event a notification is about, as a member's content filter names it. */
123
+ var NotificationEventKindSchema = /* @__PURE__ */ z.enum([
124
+ "detection",
125
+ "audio",
126
+ "device-event",
127
+ "occupancy",
128
+ "package",
129
+ "appliance",
130
+ "system-event",
131
+ "timelapse",
132
+ "summary",
133
+ "calendar"
134
+ ]);
135
+ /**
136
+ * Which notifications a member receives by content. Each list that is set must match; a
137
+ * notification that does not carry the value (no event kind, no class) does not match it.
138
+ */
139
+ var GroupMemberFilterSchema = /* @__PURE__ */ z.object({
140
+ eventKinds: /* @__PURE__ */ z.array(NotificationEventKindSchema).min(1).optional(),
141
+ /** Detected classes, compared without case. */
142
+ classes: /* @__PURE__ */ z.array(/* @__PURE__ */ z.string().min(1)).min(1).optional()
143
+ });
118
144
  /**
119
145
  * One member's policy. Every key but `targetId` is optional and means "no restriction" when absent
120
146
  * (never a Zod default: a default does not run on the addon cap path).
@@ -132,7 +158,14 @@ var GroupMemberSchema = /* @__PURE__ */ z.object({
132
158
  }).optional(),
133
159
  minPriority: /* @__PURE__ */ z.number().int().min(1).max(5).optional(),
134
160
  /** At most one delivery per window; a burst becomes one. 0 or absent = no throttle. */
135
- throttleSec: /* @__PURE__ */ z.number().int().nonnegative().optional()
161
+ throttleSec: /* @__PURE__ */ z.number().int().nonnegative().optional(),
162
+ /** Receives only the notifications of these event kinds / classes. Absent = all of them. */
163
+ filter: /* @__PURE__ */ GroupMemberFilterSchema.optional(),
164
+ /**
165
+ * Escalation: the target ids of other members of this group. This member is tried only when
166
+ * NONE of them was delivered in the same send (each failed or was skipped). Absent = always tried.
167
+ */
168
+ onlyIfUndelivered: /* @__PURE__ */ z.array(/* @__PURE__ */ z.string().min(1)).min(1).optional()
136
169
  });
137
170
  /** Read the `members` of a group's config; an unreadable row is counted, never silently dropped. */
138
171
  function groupMembersOf(config) {
@@ -153,6 +186,31 @@ function groupMembersOf(config) {
153
186
  invalid
154
187
  };
155
188
  }
189
+ /** Whether a notification is one the filter names: every list that is set must match. */
190
+ function matchesMemberFilter(filter, notification) {
191
+ const kind = notification.metadata?.[NOTIFICATION_META_EVENT_KIND];
192
+ if (filter.eventKinds !== void 0) {
193
+ const parsed = NotificationEventKindSchema.safeParse(kind);
194
+ if (!parsed.success || !filter.eventKinds.includes(parsed.data)) return false;
195
+ }
196
+ if (filter.classes !== void 0) {
197
+ const className = notification.metadata?.[NOTIFICATION_META_CLASS_NAME];
198
+ if (typeof className !== "string") return false;
199
+ const wanted = className.toLowerCase();
200
+ if (!filter.classes.some((name) => name.toLowerCase() === wanted)) return false;
201
+ }
202
+ return true;
203
+ }
204
+ /**
205
+ * Whether a fallback member is needed: none of the members it backs up was delivered. A member
206
+ * skipped as `already-delivered` got this notification on an earlier attempt, so it counts as
207
+ * delivered; one with no outcome yet (listed later, or not in the group) counts as not delivered.
208
+ */
209
+ function escalationNeeded(member, outcomes) {
210
+ if (member.onlyIfUndelivered === void 0) return true;
211
+ const delivered = new Set(outcomes.filter((outcome) => outcome.status === "sent" || outcome.status === "skipped" && outcome.reason === "already-delivered").map((outcome) => outcome.targetId));
212
+ return !member.onlyIfUndelivered.some((targetId) => delivered.has(targetId));
213
+ }
156
214
  /** The policy of one member that needs no state of the group: enabled, priority, schedule, alarm. */
157
215
  function decideMember(input) {
158
216
  const { member, notification, nowMs } = input;
@@ -164,6 +222,10 @@ function decideMember(input) {
164
222
  send: false,
165
223
  reason: "below-min-priority"
166
224
  };
225
+ if (member.filter !== void 0 && input.ignoreFilter !== true && !matchesMemberFilter(member.filter, notification)) return {
226
+ send: false,
227
+ reason: "content-filter"
228
+ };
167
229
  const when = member.when;
168
230
  if (when?.kind === "schedule" && !isScheduleActive(when.schedule, nowMs)) return {
169
231
  send: false,
@@ -355,6 +417,7 @@ function validateGroupMembers(config, groupIds) {
355
417
  if (seen.has(targetId)) throw new Error(`The notifier ${targetId} is listed twice`);
356
418
  seen.add(targetId);
357
419
  if (groupIds.has(targetId)) throw new Error("A group cannot contain another group");
420
+ for (const primary of parsed.data.onlyIfUndelivered ?? []) if (primary === targetId || !seen.has(primary)) throw new Error(`The notifier ${targetId} can only be a fallback for a member listed before it (${primary} is not)`);
358
421
  members.push(parsed.data);
359
422
  }
360
423
  return members;
@@ -499,7 +562,10 @@ var MemberLedger = class {
499
562
  *
500
563
  * Rules: fan-out goes through `ctx.api.notificationOutput.send` (the `sendToMember` port); a member
501
564
  * that is itself a group is refused (`nested-group`); every skip is logged with its reason and the
502
- * group's tags (D391); a retry re-sends only the members that failed (the ledger).
565
+ * group's tags (D391); a retry re-sends only the members that failed (the ledger); a test press bypasses that ledger
566
+ * and the content filter. A member with `onlyIfUndelivered` is a fallback: tried only when none of the
567
+ * members it names was delivered in the same send.
568
+ * `SendResult.members` carries every member's outcome.
503
569
  */
504
570
  var CANNED = {
505
571
  title: "CamStack",
@@ -513,7 +579,7 @@ function summary(outcomes) {
513
579
  }
514
580
  function createGroupNotificationOutputProvider(deps) {
515
581
  const { logger } = deps;
516
- async function deliverMember(group, member, notification, notificationKey, targets, unreadableHolders, byKind) {
582
+ async function deliverMember(group, member, notification, notificationKey, targets, unreadableHolders, byKind, isTest, earlier) {
517
583
  const tags = {
518
584
  groupId: group.id,
519
585
  ...notification.deviceId !== void 0 ? { deviceId: notification.deviceId } : {}
@@ -567,15 +633,17 @@ function createGroupNotificationOutputProvider(deps) {
567
633
  }
568
634
  if (target.kind === "group") return skip("nested-group");
569
635
  if (!target.enabled) return skip("target-disabled");
570
- if (deps.ledger.wasDelivered(group.id, notificationKey, member.targetId)) return skip("already-delivered");
636
+ if (!isTest && deps.ledger.wasDelivered(group.id, notificationKey, member.targetId)) return skip("already-delivered");
571
637
  const alarm = member.when?.kind === "alarm" ? await deps.readAlarmState(member.when.deviceId) : void 0;
572
638
  const decision = decideMember({
573
639
  member,
574
640
  notification,
575
641
  nowMs: deps.now(),
576
- ...alarm !== void 0 ? { alarmState: alarm } : {}
642
+ ...alarm !== void 0 ? { alarmState: alarm } : {},
643
+ ...isTest ? { ignoreFilter: true } : {}
577
644
  });
578
645
  if (!decision.send) return skip(decision.reason);
646
+ if (!escalationNeeded(member, earlier)) return skip("escalation-not-needed");
579
647
  if (deps.ledger.isThrottled(group.id, member.targetId, member.throttleSec)) return skip("throttled");
580
648
  const shaped = shapeForMember(member, notification);
581
649
  const ownCaps = byKind.get(target.kind);
@@ -601,7 +669,7 @@ function createGroupNotificationOutputProvider(deps) {
601
669
  error
602
670
  };
603
671
  }
604
- deps.ledger.markDelivered(group.id, notificationKey, member.targetId);
672
+ if (!isTest) deps.ledger.markDelivered(group.id, notificationKey, member.targetId);
605
673
  deps.ledger.markSent(group.id, member.targetId);
606
674
  return {
607
675
  targetId: member.targetId,
@@ -624,7 +692,7 @@ function createGroupNotificationOutputProvider(deps) {
624
692
  };
625
693
  }
626
694
  }
627
- async function deliver(group, notification) {
695
+ async function deliver(group, notification, isTest = false) {
628
696
  const { members, invalid } = groupMembersOf(group.config);
629
697
  if (invalid > 0) logger.warn("group has member rows that could not be read; they are not delivered to", {
630
698
  tags: { groupId: group.id },
@@ -645,22 +713,27 @@ function createGroupNotificationOutputProvider(deps) {
645
713
  return /* @__PURE__ */ new Map();
646
714
  });
647
715
  const outcomes = [];
648
- for (const member of members) outcomes.push(await deliverMember(group, member, notification, key, targets, unreadableHolders, byKind));
716
+ for (const member of members) outcomes.push(await deliverMember(group, member, notification, key, targets, unreadableHolders, byKind, isTest, outcomes));
649
717
  return {
650
718
  groupId: group.id,
651
719
  outcomes
652
720
  };
653
721
  }
654
- async function sendTo(group, id, notification) {
722
+ async function sendTo(group, id, notification, isTest) {
655
723
  if (group === null) return {
656
724
  success: false,
657
725
  error: `Unknown target '${id}'`
658
726
  };
659
- const report = await deliver(group, notification);
660
- return report.outcomes.some((outcome) => outcome.status === "failed") ? {
727
+ const report = await deliver(group, notification, isTest);
728
+ const members = [...report.outcomes];
729
+ return members.some((outcome) => outcome.status === "failed") ? {
661
730
  success: false,
662
- error: summary(report.outcomes)
663
- } : { success: true };
731
+ error: summary(report.outcomes),
732
+ members
733
+ } : {
734
+ success: true,
735
+ members
736
+ };
664
737
  }
665
738
  return {
666
739
  provider: {
@@ -677,9 +750,9 @@ function createGroupNotificationOutputProvider(deps) {
677
750
  success: false,
678
751
  error: "Target is disabled"
679
752
  };
680
- return sendTo(group, targetId, notification);
753
+ return sendTo(group, targetId, notification, false);
681
754
  },
682
- testTarget: async ({ targetId, sample }) => sendTo(await deps.store.getById(targetId), targetId, sample ?? CANNED)
755
+ testTarget: async ({ targetId, sample }) => sendTo(await deps.store.getById(targetId), targetId, sample ?? CANNED, true)
683
756
  },
684
757
  deliver
685
758
  };
@@ -7,28 +7,20 @@
7
7
  *
8
8
  * Rules: fan-out goes through `ctx.api.notificationOutput.send` (the `sendToMember` port); a member
9
9
  * that is itself a group is refused (`nested-group`); every skip is logged with its reason and the
10
- * group's tags (D391); a retry re-sends only the members that failed (the ledger).
10
+ * group's tags (D391); a retry re-sends only the members that failed (the ledger); a test press bypasses that ledger
11
+ * and the content filter. A member with `onlyIfUndelivered` is a fallback: tried only when none of the
12
+ * members it names was delivered in the same send.
13
+ * `SendResult.members` carries every member's outcome.
11
14
  */
12
- import { type AlarmState, type GroupSkipReason, type INotificationOutputProvider, type IScopedLogger, type Notification, type NotificationTargetRef, type NotificationTargetStore, type SendResult, type Target, type TargetKindCaps } from "@camstack/types";
15
+ import { type AlarmState, type GroupMemberOutcome, type INotificationOutputProvider, type IScopedLogger, type Notification, type NotificationTargetRef, type NotificationTargetStore, type SendResult, type Target, type TargetKindCaps } from "@camstack/types";
13
16
  import { MemberLedger } from "./member-ledger.js";
14
17
  /** A target kind and what it delivers. */
15
18
  export interface MemberKindCaps {
16
19
  readonly kind: string;
17
20
  readonly caps: TargetKindCaps;
18
21
  }
19
- /** What happened to one member of one send. */
20
- export type MemberOutcome = {
21
- readonly targetId: string;
22
- readonly status: "sent";
23
- } | {
24
- readonly targetId: string;
25
- readonly status: "skipped";
26
- readonly reason: GroupSkipReason;
27
- } | {
28
- readonly targetId: string;
29
- readonly status: "failed";
30
- readonly error: string;
31
- };
22
+ /** What happened to one member of one send: the type of an entry of `SendResult.members`. */
23
+ export type MemberOutcome = GroupMemberOutcome;
32
24
  /** What a send to a group did, member by member. */
33
25
  export interface GroupDeliveryReport {
34
26
  readonly groupId: string;
@@ -59,5 +51,5 @@ export interface GroupNotificationOutputDeps {
59
51
  }
60
52
  export declare function createGroupNotificationOutputProvider(deps: GroupNotificationOutputDeps): {
61
53
  readonly provider: INotificationOutputProvider;
62
- readonly deliver: (group: Target, notification: Notification) => Promise<GroupDeliveryReport>;
54
+ readonly deliver: (group: Target, notification: Notification, isTest?: boolean) => Promise<GroupDeliveryReport>;
63
55
  };
@@ -21,7 +21,10 @@
21
21
  */
22
22
  import { BaseAddon, type ConfigUISchema, type ProviderRegistration } from "@camstack/types";
23
23
  export interface DeviceHistoryConfig extends Record<string, unknown> {
24
+ /** Raw points of a continuous series (`gauge`, `counter`). */
24
25
  rawDays: number;
26
+ /** Raw points of a discrete series (`boolean`, `enum`). */
27
+ rawDiscreteDays: number;
25
28
  fiveMinuteDays: number;
26
29
  hourDays: number;
27
30
  /** `0` keeps the daily tier forever. */
@@ -58,6 +61,11 @@ export declare class DeviceHistoryAddon extends BaseAddon<DeviceHistoryConfig> {
58
61
  private stopRuntime;
59
62
  protected override onShutdown(): Promise<void>;
60
63
  protected override scopedSettingsCapabilities(): readonly string[];
64
+ /**
65
+ * D865: the two raw windows a device may override, in the standard per-device store. Unset
66
+ * means the device follows the cluster value (shown by the retention catalog).
67
+ */
68
+ protected override deviceSettingsSchema(): ConfigUISchema | null;
61
69
  protected override clusterSettingsSchema(cap: string): Promise<ConfigUISchema | null>;
62
70
  }
63
71
  export default DeviceHistoryAddon;