@camstack/server 1.2.928 → 1.2.930

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 (241) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +10 -10
  3. package/system/dist/addon-id-CVg1_r5E.mjs +39 -0
  4. package/system/dist/addon-id-Di0lNJ89.js +50 -0
  5. package/system/dist/addon-pages.cap-Df9FQwN1.js +49 -0
  6. package/system/dist/addon-pages.cap-DksUlE8j.mjs +44 -0
  7. package/system/dist/addon-settings.cap-3-TIIMq_.mjs +592 -0
  8. package/system/dist/addon-settings.cap-DAiE0Nb0.js +651 -0
  9. package/system/dist/addon-utils.mjs +1 -1
  10. package/system/dist/addon-widgets.cap-C4jxflbF.js +200 -0
  11. package/system/dist/addon-widgets.cap-D9m48X78.mjs +183 -0
  12. package/system/dist/base-addon-DD5dIfcZ.js +4624 -0
  13. package/system/dist/base-addon-Md14i7pe.mjs +4505 -0
  14. package/system/dist/base-device-2sL1DMm1.js +1103 -0
  15. package/system/dist/base-device-IuM1AwXZ.mjs +1098 -0
  16. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +8 -6
  17. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +6 -4
  18. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +8 -6
  19. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +7 -5
  20. package/system/dist/builtins/alerts/alerts.addon.js +113 -56
  21. package/system/dist/builtins/alerts/alerts.addon.mjs +60 -3
  22. package/system/dist/builtins/autotrack/index.js +21 -17
  23. package/system/dist/builtins/autotrack/index.mjs +5 -1
  24. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +14 -11
  25. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +8 -5
  26. package/system/dist/builtins/calendars/calendars.addon.js +8 -6
  27. package/system/dist/builtins/calendars/calendars.addon.mjs +3 -1
  28. package/system/dist/builtins/camera-grid/index.js +615 -58
  29. package/system/dist/builtins/camera-grid/index.mjs +558 -1
  30. package/system/dist/builtins/composer/composer.addon.js +788 -209
  31. package/system/dist/builtins/composer/composer.addon.mjs +583 -4
  32. package/system/dist/builtins/console-logging/index.js +4 -3
  33. package/system/dist/builtins/console-logging/index.mjs +2 -1
  34. package/system/dist/builtins/core-blocks/actions-service.d.ts +18 -1
  35. package/system/dist/builtins/core-blocks/core-blocks.addon.js +8670 -386
  36. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +8294 -11
  37. package/system/dist/builtins/core-blocks/tcp-connect.d.ts +3 -0
  38. package/system/dist/builtins/core-notifier/core-notifier.addon.js +250 -21
  39. package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +230 -1
  40. package/system/dist/builtins/device-history/device-history.addon.js +110 -31
  41. package/system/dist/builtins/device-history/device-history.addon.mjs +81 -2
  42. package/system/dist/builtins/device-manager/device-manager.addon.js +12806 -227
  43. package/system/dist/builtins/device-manager/device-manager.addon.mjs +12583 -5
  44. package/system/dist/builtins/hub-forwarder/index.js +4 -3
  45. package/system/dist/builtins/hub-forwarder/index.mjs +2 -1
  46. package/system/dist/builtins/keychain/index.js +31 -28
  47. package/system/dist/builtins/keychain/index.mjs +7 -4
  48. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +15 -12
  49. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +4 -1
  50. package/system/dist/builtins/local-auth/local-auth.addon.js +140 -39
  51. package/system/dist/builtins/local-auth/local-auth.addon.mjs +106 -6
  52. package/system/dist/builtins/local-network/local-network.addon.js +43 -39
  53. package/system/dist/builtins/local-network/local-network.addon.mjs +7 -3
  54. package/system/dist/builtins/loki-logging/index.js +23 -17
  55. package/system/dist/builtins/loki-logging/index.mjs +7 -1
  56. package/system/dist/builtins/native-metrics/native-metrics.addon.js +156 -15
  57. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +151 -10
  58. package/system/dist/builtins/platform-probe/index.js +25 -23
  59. package/system/dist/builtins/platform-probe/index.mjs +12 -10
  60. package/system/dist/builtins/record-entries/index.js +9 -7
  61. package/system/dist/builtins/record-entries/index.mjs +3 -1
  62. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +4 -4
  63. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  64. package/system/dist/builtins/snapshot/index.js +97 -44
  65. package/system/dist/builtins/snapshot/index.mjs +54 -1
  66. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +5 -4
  67. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +21 -20
  68. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  69. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  70. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +87 -61
  71. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +29 -3
  72. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +81 -72
  73. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +10 -1
  74. package/system/dist/builtins/system-config/system-config.addon.js +17 -14
  75. package/system/dist/builtins/system-config/system-config.addon.mjs +118 -115
  76. package/system/dist/builtins/winston-logging/index.js +7 -5
  77. package/system/dist/builtins/winston-logging/index.mjs +3 -1
  78. package/system/dist/calendars.cap-CaFlShS9.js +155 -0
  79. package/system/dist/calendars.cap-_C4eD4fi.mjs +138 -0
  80. package/system/dist/camstack-error-DJ-TUAi1.js +23 -0
  81. package/system/dist/camstack-error-viZYfcj9.mjs +18 -0
  82. package/system/dist/cap-call-context-Bd76CbOW.js +95 -0
  83. package/system/dist/cap-call-context-DNwdgGSQ.mjs +78 -0
  84. package/system/dist/capability-definition-C2rJdVeX.mjs +177 -0
  85. package/system/dist/capability-definition-HCmTem8c.js +242 -0
  86. package/system/dist/{capture-engine-BcuwOSXv.js → capture-engine-DZ0LIUqA.js} +5 -4
  87. package/system/dist/{capture-engine-Bz7eXFjT.mjs → capture-engine-DiwbjoWp.mjs} +2 -1
  88. package/system/dist/command-origin-claim-Cief660O.js +35 -0
  89. package/system/dist/command-origin-claim-D1Wy7Qld.mjs +24 -0
  90. package/system/dist/composition-sources-BEUWn2s_.mjs +391 -0
  91. package/system/dist/composition-sources-acfR4hDq.js +408 -0
  92. package/system/dist/{constants-D2etJ02O.js → constants-Ba3FTIHl.js} +1 -1
  93. package/system/dist/constants-C860Y6U4.js +26 -0
  94. package/system/dist/{constants-BcUTQd1M.mjs → constants-DB4piTD5.mjs} +1 -1
  95. package/system/dist/constants-DCLpoF4L.mjs +21 -0
  96. package/system/dist/coral-accelerators-7o8hqvcN.js +564 -0
  97. package/system/dist/coral-accelerators-BKcXP59c.mjs +521 -0
  98. package/system/dist/core-blocks.cap-BMeMCBrx.js +18733 -0
  99. package/system/dist/core-blocks.cap-BRPsLAij.mjs +18008 -0
  100. package/system/dist/{custom-action-registry-N7flBDwT.mjs → custom-action-registry-B9zFBNVa.mjs} +37 -37
  101. package/system/dist/custom-actions-BFUSalC9.mjs +25 -0
  102. package/system/dist/custom-actions-D92NRi2c.js +36 -0
  103. package/system/dist/database-snapshot.cap-DF38e-0P.js +162 -0
  104. package/system/dist/database-snapshot.cap-dhrc9xnY.mjs +133 -0
  105. package/system/dist/declared-device-BWphj9WE.js +303 -0
  106. package/system/dist/declared-device-CKERA1Hi.mjs +286 -0
  107. package/system/dist/{device-ca-ExMN3xW3.mjs → device-ca-BLM6fccc.mjs} +2 -1
  108. package/system/dist/{device-ca-CU8zh9Pi.js → device-ca-C5kJE6mL.js} +7 -6
  109. package/system/dist/device-certificate-Cddm4Idn.mjs +91 -0
  110. package/system/dist/device-certificate-CguVACQO.js +162 -0
  111. package/system/dist/device-identifiers-BQg9EQi1.js +600 -0
  112. package/system/dist/device-identifiers-iSuQCKmK.mjs +529 -0
  113. package/system/dist/device-kind-BJ2pfsjw.mjs +78 -0
  114. package/system/dist/device-kind-CsSiv_YF.js +101 -0
  115. package/system/dist/device-manager.cap-2abwVLCM.js +2874 -0
  116. package/system/dist/device-manager.cap-CFZSPfUh.mjs +2749 -0
  117. package/system/dist/device-provider.cap-3Uvk6f5-.mjs +331 -0
  118. package/system/dist/device-provider.cap-D7TV2kVH.js +366 -0
  119. package/system/dist/{device-row-store-CeW_GWh9.mjs → device-row-store-YF3jtmkk.mjs} +4 -1
  120. package/system/dist/{device-row-store-BMIR-n3m.js → device-row-store-doTfMOqn.js} +12 -9
  121. package/system/dist/device-transitions.cap-B5w5PYU_.js +860 -0
  122. package/system/dist/device-transitions.cap-DojcwEuX.mjs +819 -0
  123. package/system/dist/device-type-CbQsnFdC.js +477 -0
  124. package/system/dist/device-type-DgEvK3ch.mjs +454 -0
  125. package/system/dist/entry-kind-D9MuVJCK.mjs +44 -0
  126. package/system/dist/entry-kind-cq90c--V.js +55 -0
  127. package/system/dist/error.cap-CSM_SRfR.mjs +3423 -0
  128. package/system/dist/error.cap-DBhgPeWK.js +3848 -0
  129. package/system/dist/file-host-worker.js +1 -1
  130. package/system/dist/file-host-worker.mjs +1 -1
  131. package/system/dist/history-catalog-BKRarIL_.js +831 -0
  132. package/system/dist/history-catalog-BwTeQ4Mr.mjs +802 -0
  133. package/system/dist/{hub-identity-Csxx2Q8k.js → hub-identity-BMdR3Mw9.js} +2 -2
  134. package/system/dist/{hub-identity-CYC1820R.mjs → hub-identity-DjMN9Ac2.mjs} +10 -10
  135. package/system/dist/{hub-mdns-ciao-By5577HM.js → hub-mdns-ciao--0v1TKME.js} +5 -5
  136. package/system/dist/{hub-mdns-ciao-CCDxM5qz.mjs → hub-mdns-ciao-DBrtHOcc.mjs} +2 -2
  137. package/system/dist/index.js +763 -151
  138. package/system/dist/index.mjs +832 -220
  139. package/system/dist/integration-instances.cap-Cl9O-k4h.mjs +538 -0
  140. package/system/dist/integration-instances.cap-dJIxg2_s.js +549 -0
  141. package/system/dist/keychain-admin.cap-Db_oFX4H.js +425 -0
  142. package/system/dist/keychain-admin.cap-GtM7gVGG.mjs +396 -0
  143. package/system/dist/l10n-Bu6aUvSY.mjs +10 -0
  144. package/system/dist/l10n-CGMvp7NF.js +15 -0
  145. package/system/dist/labels-DX5S8deC.js +81 -0
  146. package/system/dist/labels-DsBcU7md.mjs +64 -0
  147. package/system/dist/{legacy-integration-rows-door-CVwOo5aq.js → legacy-integration-rows-door-B1nzxxr5.js} +2 -2
  148. package/system/dist/{legacy-integration-rows-door-D9tQOUzh.mjs → legacy-integration-rows-door-nTvo_6jQ.mjs} +1 -1
  149. package/system/dist/log-destination.cap-CxZzAVaR.mjs +143 -0
  150. package/system/dist/log-destination.cap-DELPJkZ0.js +148 -0
  151. package/system/dist/low-power-sleep.cap-7lfVU41N.js +103 -0
  152. package/system/dist/low-power-sleep.cap-tGPmaZ_V.mjs +92 -0
  153. package/system/dist/mask-shape-Ci8Co9w0.mjs +57 -0
  154. package/system/dist/mask-shape-CmPA2fst.js +92 -0
  155. package/system/dist/metrics-provider.cap-BNmcHDkQ.mjs +405 -0
  156. package/system/dist/metrics-provider.cap-BcmQUt6l.js +410 -0
  157. package/system/dist/migration-BMjgkyG2.js +380 -0
  158. package/system/dist/migration-DRJAtdy7.mjs +321 -0
  159. package/system/dist/network-access.cap-B5TWLDCC.js +1099 -0
  160. package/system/dist/network-access.cap-BJnGbE6n.mjs +1004 -0
  161. package/system/dist/notification-rules.cap-BDh0LDhV.js +3428 -0
  162. package/system/dist/notification-rules.cap-DUmiMBQB.mjs +3357 -0
  163. package/system/dist/notification-targets-CRH-9Dy5.js +509 -0
  164. package/system/dist/notification-targets-DaNE-pIt.mjs +486 -0
  165. package/system/dist/ops-log-CB4pIdqi.mjs +64 -0
  166. package/system/dist/ops-log-pxt9176Z.js +81 -0
  167. package/system/dist/pinned-binary-BOhOSNff.js +28 -0
  168. package/system/dist/pinned-binary-CrIRAi4G.mjs +23 -0
  169. package/system/dist/platform-probe.cap-1WrMhWHx.js +250 -0
  170. package/system/dist/platform-probe.cap-BFeqFLtQ.mjs +233 -0
  171. package/system/dist/prefix-walk-BkMxoXpL.js +843 -0
  172. package/system/dist/prefix-walk-ifwg_ukx.mjs +790 -0
  173. package/system/dist/ptz-autotrack.cap-BW7w0zHD.js +229 -0
  174. package/system/dist/ptz-autotrack.cap-DT2GypXw.mjs +224 -0
  175. package/system/dist/quantity-D3g5SxsZ.mjs +114 -0
  176. package/system/dist/quantity-lY1KiTSZ.js +143 -0
  177. package/system/dist/raw-secret-migration-DxuBFtvi.js +50 -0
  178. package/system/dist/raw-secret-migration-iv88mLoc.mjs +39 -0
  179. package/system/dist/record-entries.cap-sMUhTvTU.mjs +75 -0
  180. package/system/dist/record-entries.cap-ti1C046R.js +80 -0
  181. package/system/dist/record-kind-DoBfYHCs.js +203 -0
  182. package/system/dist/record-kind-ub6NXqfh.mjs +162 -0
  183. package/system/dist/recording-archive.cap-7OrIn9e5.mjs +1299 -0
  184. package/system/dist/recording-archive.cap-D7bo-QSM.js +1328 -0
  185. package/system/dist/records.cap-ClcWV64i.js +329 -0
  186. package/system/dist/records.cap-CwLT2ByG.mjs +294 -0
  187. package/system/dist/relocate-CdVQAk-w.js +804 -0
  188. package/system/dist/relocate-CoZZTui1.mjs +661 -0
  189. package/system/dist/rename-composition-block-BJsL58Ih.js +34798 -0
  190. package/system/dist/rename-composition-block-OAtErZgq.mjs +33631 -0
  191. package/system/dist/{restore-archive-BJfyu0sG.mjs → restore-archive-CjAyKpgX.mjs} +96 -94
  192. package/system/dist/{restore-archive-CIFvqOze.js → restore-archive-CkTkv3Ss.js} +6 -4
  193. package/system/dist/scoped-settings-CylSSq_8.js +955 -0
  194. package/system/dist/scoped-settings-DVWUIP7Z.mjs +650 -0
  195. package/system/dist/server-name-BIhLuHvX.mjs +35 -0
  196. package/system/dist/server-name-OALNvpqC.js +52 -0
  197. package/system/dist/settings-store.cap-Ci4F2zul.mjs +569 -0
  198. package/system/dist/settings-store.cap-wlJhCspr.js +640 -0
  199. package/system/dist/snapshot.cap-3suPdBHV.js +250 -0
  200. package/system/dist/snapshot.cap-Bs8Oyaqh.mjs +245 -0
  201. package/system/dist/source-info-DGB7SdB_.mjs +190 -0
  202. package/system/dist/source-info-DtWf4k2j.js +225 -0
  203. package/system/dist/storage-admin.cap-BSv1NjKJ.mjs +883 -0
  204. package/system/dist/storage-admin.cap-he0OqvVM.js +906 -0
  205. package/system/dist/storage-location-CBT8GCD6.mjs +163 -0
  206. package/system/dist/storage-location-CTweDMZf.js +198 -0
  207. package/system/dist/storage-location-mode-B21UVRRX.mjs +167 -0
  208. package/system/dist/storage-location-mode-CS4sMzo-.js +232 -0
  209. package/system/dist/storage-migration.cap-CyyATY_p.js +330 -0
  210. package/system/dist/storage-migration.cap-D7QqGobp.mjs +313 -0
  211. package/system/dist/storage-occupancy.cap-2rmnS58Z.js +622 -0
  212. package/system/dist/storage-occupancy.cap-CqBztTl9.mjs +611 -0
  213. package/system/dist/storage-provider.cap-Bw0CfxVc.js +213 -0
  214. package/system/dist/storage-provider.cap-CMeck2w4.mjs +202 -0
  215. package/system/dist/stream-catalog.cap-Bp7SkgIf.mjs +6560 -0
  216. package/system/dist/stream-catalog.cap-D3uwePiA.js +6763 -0
  217. package/system/dist/streaming-shared-B8cXatuU.mjs +431 -0
  218. package/system/dist/streaming-shared-DQwFZOSi.js +526 -0
  219. package/system/dist/system-reasons-Be_k1W8g.js +25 -0
  220. package/system/dist/system-reasons-CYj4qwyS.mjs +20 -0
  221. package/system/dist/tag-BxLazvVb.js +2138 -0
  222. package/system/dist/tag-uZBAq6ox.mjs +2073 -0
  223. package/system/dist/user-management.cap-B9QDu8NE.js +825 -0
  224. package/system/dist/user-management.cap-DBIi77sB.mjs +766 -0
  225. package/system/dist/vector-store.cap-DnyfrYDn.js +330 -0
  226. package/system/dist/vector-store.cap-h2GHWQ1t.mjs +319 -0
  227. package/system/dist/{wal-maintenance-CTrCPzds.mjs → wal-maintenance-BG01rOn9.mjs} +0 -0
  228. package/system/dist/{wal-maintenance-dq7T3quB.js → wal-maintenance-DyrebYKF.js} +0 -0
  229. package/system/dist/zod-secret-DS7mj1bk.js +78 -0
  230. package/system/dist/zod-secret-zY4nM61M.mjs +73 -0
  231. package/system/package.json +1 -1
  232. package/system/dist/composition-sources-BI614LJx.mjs +0 -141
  233. package/system/dist/composition-sources-v_kkb8A9.js +0 -152
  234. package/system/dist/coral-accelerators-BSVsBVzt.js +0 -250
  235. package/system/dist/coral-accelerators-BW3OcrLD.mjs +0 -231
  236. package/system/dist/dist-BCHMSqzc.mjs +0 -143467
  237. package/system/dist/dist-BZfvhfS1.js +0 -146970
  238. package/system/dist/prefix-walk-DAOBSyH1.mjs +0 -88
  239. package/system/dist/prefix-walk-Dv6MLZlM.js +0 -99
  240. package/system/dist/rename-composition-block-C9HuBrKS.js +0 -112
  241. package/system/dist/rename-composition-block-DtaYmYAR.mjs +0 -101
@@ -0,0 +1,3 @@
1
+ import type { TcpConnect } from "@camstack/types";
2
+ /** Open a TCP connection and close it again: resolves when the port answered, rejects with the reason. */
3
+ export declare const tcpConnect: TcpConnect;
@@ -3,8 +3,237 @@ Object.defineProperties(exports, {
3
3
  [Symbol.toStringTag]: { value: "Module" }
4
4
  });
5
5
  require("../../chunk-Cek0wNdY.js");
6
- const require_dist = require("../../dist-BZfvhfS1.js");
6
+ const require_base_addon = require("../../base-addon-DD5dIfcZ.js");
7
+ const require_scoped_settings = require("../../scoped-settings-CylSSq_8.js");
8
+ const require_notification_targets = require("../../notification-targets-CRH-9Dy5.js");
9
+ const require_notification_rules_cap = require("../../notification-rules.cap-BDh0LDhV.js");
10
+ const require_integration_instances_cap = require("../../integration-instances.cap-dJIxg2_s.js");
11
+ let zod = require("zod");
7
12
  let node_crypto = require("node:crypto");
13
+ //#region ../types/dist/esm/notification/schedule.mjs
14
+ var WEEKDAY_TO_DAY = {
15
+ Sun: 0,
16
+ Mon: 1,
17
+ Tue: 2,
18
+ Wed: 3,
19
+ Thu: 4,
20
+ Fri: 5,
21
+ Sat: 6
22
+ };
23
+ /**
24
+ * One formatter per timezone, built once (D647 review I4). Constructing an
25
+ * `Intl.DateTimeFormat` is the expensive part of this function, and a caller
26
+ * that asks about many instants — a window scan — used to build one per
27
+ * instant. `null` = an invalid IANA name (the host timezone is used).
28
+ */
29
+ var FORMATTERS = /* @__PURE__ */ new Map();
30
+ function formatterFor(timezone) {
31
+ const held = FORMATTERS.get(timezone);
32
+ if (held !== void 0) return held;
33
+ let made;
34
+ try {
35
+ made = new Intl.DateTimeFormat("en-US", {
36
+ timeZone: timezone,
37
+ weekday: "short",
38
+ hour: "numeric",
39
+ minute: "numeric",
40
+ hourCycle: "h23"
41
+ });
42
+ } catch {
43
+ made = null;
44
+ }
45
+ FORMATTERS.set(timezone, made);
46
+ return made;
47
+ }
48
+ /** Resolve (weekday, minute-of-day) of `atMs` in the schedule's timezone.
49
+ * An invalid/unknown IANA name falls back to the host timezone. */
50
+ function localDayMinute(atMs, timezone) {
51
+ const d = new Date(atMs);
52
+ const formatter = timezone !== void 0 ? formatterFor(timezone) : null;
53
+ if (formatter !== null) try {
54
+ const parts = formatter.formatToParts(d);
55
+ let weekday;
56
+ let hour;
57
+ let minute;
58
+ for (const p of parts) if (p.type === "weekday") weekday = p.value;
59
+ else if (p.type === "hour") hour = Number(p.value);
60
+ else if (p.type === "minute") minute = Number(p.value);
61
+ const day = weekday !== void 0 ? WEEKDAY_TO_DAY[weekday] : void 0;
62
+ if (day !== void 0 && hour !== void 0 && minute !== void 0) return {
63
+ day,
64
+ minute: hour * 60 + minute
65
+ };
66
+ } catch {}
67
+ return {
68
+ day: d.getDay(),
69
+ minute: d.getHours() * 60 + d.getMinutes()
70
+ };
71
+ }
72
+ /**
73
+ * Is the schedule active at `atMs`? No schedule = always active. Windows
74
+ * are OR'd; a window with `startMinute > endMinute` crosses midnight (it
75
+ * starts on a listed day and spills into the next). `invert` flips the
76
+ * result (active OUTSIDE the windows).
77
+ */
78
+ function isScheduleActive(schedule, atMs) {
79
+ if (schedule === void 0) return true;
80
+ const { day, minute } = localDayMinute(atMs, schedule.timezone);
81
+ const prevDay = (day + 6) % 7;
82
+ let inside = false;
83
+ for (const w of schedule.windows) if (w.startMinute <= w.endMinute) {
84
+ if (w.days.includes(day) && minute >= w.startMinute && minute < w.endMinute) {
85
+ inside = true;
86
+ break;
87
+ }
88
+ } else if (w.days.includes(day) && minute >= w.startMinute || w.days.includes(prevDay) && minute < w.endMinute) {
89
+ inside = true;
90
+ break;
91
+ }
92
+ return schedule.invert === true ? !inside : inside;
93
+ }
94
+ //#endregion
95
+ //#region ../types/dist/esm/notification/notifier-group.mjs
96
+ /**
97
+ * A notifier group: a notification target whose delivery is a fan-out to other targets (D1071).
98
+ *
99
+ * The group is an instance of `notification-output` of the record kind `notify-group`, owned by the
100
+ * core builtin `core-notifier`. Its body holds a `members` list; each member is a target id plus the
101
+ * policy that decides whether, and with what content, that member receives a notification.
102
+ *
103
+ * Everything here is pure: the schemas, the per-member decision, the content shaping and the clamp to a
104
+ * member's own capabilities. Delivery, the throttle and the retry ledger live in the builtin.
105
+ */
106
+ /** The target kind a group is. */
107
+ var NOTIFIER_GROUP_KIND = "group";
108
+ /** The core builtin that owns groups. */
109
+ var NOTIFIER_GROUP_ADDON_ID = "core-notifier";
110
+ /** When a member receives: always, inside a schedule, or while an alarm panel is in a state. */
111
+ var GroupMemberWhenSchema = /* @__PURE__ */ zod.z.discriminatedUnion("kind", [
112
+ /* @__PURE__ */ zod.z.object({ kind: /* @__PURE__ */ zod.z.literal("always") }),
113
+ /* @__PURE__ */ zod.z.object({
114
+ kind: /* @__PURE__ */ zod.z.literal("schedule"),
115
+ schedule: require_notification_rules_cap.NcScheduleSchema
116
+ }),
117
+ /* @__PURE__ */ zod.z.object({
118
+ kind: /* @__PURE__ */ zod.z.literal("alarm"),
119
+ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
120
+ states: /* @__PURE__ */ zod.z.array(require_notification_rules_cap.AlarmStateSchema).min(1)
121
+ })
122
+ ]);
123
+ /**
124
+ * One member's policy. Every key but `targetId` is optional and means "no restriction" when absent
125
+ * (never a Zod default: a default does not run on the addon cap path).
126
+ */
127
+ var GroupMemberSchema = /* @__PURE__ */ zod.z.object({
128
+ targetId: /* @__PURE__ */ zod.z.string().min(1),
129
+ enabled: /* @__PURE__ */ zod.z.boolean().optional(),
130
+ when: /* @__PURE__ */ GroupMemberWhenSchema.optional(),
131
+ /** Which message fields this member receives. Absent = all of them. */
132
+ fields: /* @__PURE__ */ zod.z.array(require_notification_rules_cap.NotificationFieldSchema).optional(),
133
+ /** `{{title}}`, `{{body}}`, `{{priority}}` and any `{{key}}` of the notification's metadata. */
134
+ templates: /* @__PURE__ */ zod.z.object({
135
+ title: /* @__PURE__ */ zod.z.string().optional(),
136
+ body: /* @__PURE__ */ zod.z.string().optional()
137
+ }).optional(),
138
+ minPriority: /* @__PURE__ */ zod.z.number().int().min(1).max(5).optional(),
139
+ /** At most one delivery per window; a burst becomes one. 0 or absent = no throttle. */
140
+ throttleSec: /* @__PURE__ */ zod.z.number().int().nonnegative().optional()
141
+ });
142
+ /** Read the `members` of a group's config; an unreadable row is counted, never silently dropped. */
143
+ function groupMembersOf(config) {
144
+ const rows = config["members"];
145
+ if (!Array.isArray(rows)) return {
146
+ members: [],
147
+ invalid: 0
148
+ };
149
+ const members = [];
150
+ let invalid = 0;
151
+ for (const row of rows) {
152
+ const parsed = GroupMemberSchema.safeParse(row);
153
+ if (parsed.success) members.push(parsed.data);
154
+ else invalid += 1;
155
+ }
156
+ return {
157
+ members,
158
+ invalid
159
+ };
160
+ }
161
+ /** The policy of one member that needs no state of the group: enabled, priority, schedule, alarm. */
162
+ function decideMember(input) {
163
+ const { member, notification, nowMs } = input;
164
+ if (member.enabled === false) return {
165
+ send: false,
166
+ reason: "member-disabled"
167
+ };
168
+ if (member.minPriority !== void 0 && notification.priority < member.minPriority) return {
169
+ send: false,
170
+ reason: "below-min-priority"
171
+ };
172
+ const when = member.when;
173
+ if (when?.kind === "schedule" && !isScheduleActive(when.schedule, nowMs)) return {
174
+ send: false,
175
+ reason: "schedule-inactive"
176
+ };
177
+ if (when?.kind === "alarm") {
178
+ if (input.alarmState === void 0 || input.alarmState === null) return {
179
+ send: false,
180
+ reason: "alarm-unreadable"
181
+ };
182
+ if (!when.states.includes(input.alarmState)) return {
183
+ send: false,
184
+ reason: "alarm-state"
185
+ };
186
+ }
187
+ return { send: true };
188
+ }
189
+ /** `{{name}}` filled from the notification; an unknown name is empty. */
190
+ function renderMemberTemplate(template, notification) {
191
+ return template.replace(/\{\{\s*([\w.-]+)\s*\}\}/g, (_match, name) => {
192
+ if (name === "title") return notification.title ?? "";
193
+ if (name === "body") return notification.body;
194
+ if (name === "priority") return String(notification.priority);
195
+ const value = notification.metadata?.[name];
196
+ return typeof value === "string" || typeof value === "number" ? String(value) : "";
197
+ });
198
+ }
199
+ /** The notification as this member should receive it: its templates applied, its fields kept. */
200
+ function shapeForMember(member, notification) {
201
+ const keep = (field) => member.fields === void 0 || member.fields.includes(field);
202
+ const title = member.templates?.title !== void 0 ? renderMemberTemplate(member.templates.title, notification) : notification.title;
203
+ const body = member.templates?.body !== void 0 ? renderMemberTemplate(member.templates.body, notification) : notification.body;
204
+ const { attachments, actions, sound, clickUrl, ...rest } = notification;
205
+ return {
206
+ ...rest,
207
+ body: keep("body") ? body : "",
208
+ ...keep("title") && title !== void 0 ? { title } : { title: void 0 },
209
+ priority: keep("priority") ? notification.priority : 3,
210
+ ...keep("attachments") && attachments !== void 0 ? { attachments } : {},
211
+ ...keep("actions") && actions !== void 0 ? { actions } : {},
212
+ ...keep("sound") && sound !== void 0 ? { sound } : {},
213
+ ...keep("clickUrl") && clickUrl !== void 0 ? { clickUrl } : {}
214
+ };
215
+ }
216
+ /**
217
+ * The notification as ONE member's own kind can take it: its text fields, body length, attachment
218
+ * media types and count, action count, level, sound and click URL. The group's own caps are permissive and only keep the
219
+ * notification center from stripping a field before the group sees it; a member gets its own limits.
220
+ */
221
+ function clampToCaps(notification, caps) {
222
+ const { attachments, actions, sound, clickUrl, level, ...rest } = notification;
223
+ const kept = (attachments ?? []).filter((attachment) => caps.attachments.mediaTypes.includes(attachment.mediaType)).slice(0, caps.attachments.max);
224
+ const buttons = (actions ?? []).slice(0, caps.actions);
225
+ return {
226
+ ...rest,
227
+ body: caps.text?.body === false ? "" : notification.body.slice(0, caps.bodyMaxLen),
228
+ ...caps.text?.title === false || notification.title === void 0 ? { title: void 0 } : { title: notification.title },
229
+ ...kept.length > 0 ? { attachments: kept } : {},
230
+ ...buttons.length > 0 ? { actions: buttons } : {},
231
+ ...level !== void 0 && caps.levels.some((known) => known.id === level) ? { level } : {},
232
+ ...caps.sound && sound !== void 0 ? { sound } : {},
233
+ ...caps.clickUrl && clickUrl !== void 0 ? { clickUrl } : {}
234
+ };
235
+ }
236
+ //#endregion
8
237
  //#region src/builtins/core-notifier/group-descriptor.ts
9
238
  /**
10
239
  * The `group` target kind a core-notifier serves: the descriptor the add flow lists, and the record
@@ -97,17 +326,17 @@ var GROUP_CAPS = {
97
326
  };
98
327
  function groupTargetKind() {
99
328
  return {
100
- kind: require_dist.NOTIFIER_GROUP_KIND,
329
+ kind: NOTIFIER_GROUP_KIND,
101
330
  label: "Group",
102
331
  icon: "users",
103
- addonId: require_dist.NOTIFIER_GROUP_ADDON_ID,
332
+ addonId: NOTIFIER_GROUP_ADDON_ID,
104
333
  configSchema: groupConfigSchema(),
105
334
  destinationKeys: [],
106
335
  supportsDiscovery: false,
107
336
  caps: GROUP_CAPS
108
337
  };
109
338
  }
110
- var groupRecordKinds = require_dist.notificationTargetKinds([groupTargetKind()]);
339
+ var groupRecordKinds = require_notification_targets.notificationTargetKinds([groupTargetKind()]);
111
340
  //#endregion
112
341
  //#region src/builtins/core-notifier/group-instances.ts
113
342
  /**
@@ -125,7 +354,7 @@ function validateGroupMembers(config, groupIds) {
125
354
  const members = [];
126
355
  const seen = /* @__PURE__ */ new Set();
127
356
  for (const row of rows) {
128
- const parsed = require_dist.GroupMemberSchema.safeParse(row);
357
+ const parsed = GroupMemberSchema.safeParse(row);
129
358
  if (!parsed.success) throw new Error("A group member row is not valid: it needs a notifier");
130
359
  const { targetId } = parsed.data;
131
360
  if (seen.has(targetId)) throw new Error(`The notifier ${targetId} is listed twice`);
@@ -345,7 +574,7 @@ function createGroupNotificationOutputProvider(deps) {
345
574
  if (!target.enabled) return skip("target-disabled");
346
575
  if (deps.ledger.wasDelivered(group.id, notificationKey, member.targetId)) return skip("already-delivered");
347
576
  const alarm = member.when?.kind === "alarm" ? await deps.readAlarmState(member.when.deviceId) : void 0;
348
- const decision = require_dist.decideMember({
577
+ const decision = decideMember({
349
578
  member,
350
579
  notification,
351
580
  nowMs: deps.now(),
@@ -353,13 +582,13 @@ function createGroupNotificationOutputProvider(deps) {
353
582
  });
354
583
  if (!decision.send) return skip(decision.reason);
355
584
  if (deps.ledger.isThrottled(group.id, member.targetId, member.throttleSec)) return skip("throttled");
356
- const shaped = require_dist.shapeForMember(member, notification);
585
+ const shaped = shapeForMember(member, notification);
357
586
  const ownCaps = byKind.get(target.kind);
358
587
  try {
359
588
  const result = await deps.sendToMember({
360
589
  addonId: target.addonId,
361
590
  targetId: member.targetId,
362
- notification: ownCaps === void 0 ? shaped : require_dist.clampToCaps(shaped, ownCaps)
591
+ notification: ownCaps === void 0 ? shaped : clampToCaps(shaped, ownCaps)
363
592
  });
364
593
  if (!result.success) {
365
594
  const error = result.error ?? "send failed";
@@ -384,7 +613,7 @@ function createGroupNotificationOutputProvider(deps) {
384
613
  status: "sent"
385
614
  };
386
615
  } catch (err) {
387
- const error = require_dist.errMsg(err);
616
+ const error = require_scoped_settings.errMsg(err);
388
617
  logger.warn("group member delivery threw", {
389
618
  tags,
390
619
  meta: {
@@ -401,7 +630,7 @@ function createGroupNotificationOutputProvider(deps) {
401
630
  }
402
631
  }
403
632
  async function deliver(group, notification) {
404
- const { members, invalid } = require_dist.groupMembersOf(group.config);
633
+ const { members, invalid } = groupMembersOf(group.config);
405
634
  if (invalid > 0) logger.warn("group has member rows that could not be read; they are not delivered to", {
406
635
  tags: { groupId: group.id },
407
636
  meta: {
@@ -416,7 +645,7 @@ function createGroupNotificationOutputProvider(deps) {
416
645
  const byKind = await deps.listMemberKinds().then((kinds) => new Map(kinds.map((kind) => [kind.kind, kind.caps]))).catch((err) => {
417
646
  logger.warn("member kind caps could not be read; members degrade on their own", {
418
647
  tags: { groupId: group.id },
419
- meta: { error: require_dist.errMsg(err) }
648
+ meta: { error: require_scoped_settings.errMsg(err) }
420
649
  });
421
650
  return /* @__PURE__ */ new Map();
422
651
  });
@@ -469,7 +698,7 @@ function createGroupNotificationOutputProvider(deps) {
469
698
  * is not an empty one (D49).
470
699
  */
471
700
  async function readMemberKinds(api) {
472
- return (await api.notificationOutput.listTargetKinds.query({})).filter((row) => row.addonId !== require_dist.NOTIFIER_GROUP_ADDON_ID).map((row) => ({
701
+ return (await api.notificationOutput.listTargetKinds.query({})).filter((row) => row.addonId !== NOTIFIER_GROUP_ADDON_ID).map((row) => ({
473
702
  kind: row.kind,
474
703
  caps: row.caps
475
704
  }));
@@ -484,8 +713,8 @@ async function readMemberKinds(api) {
484
713
  * "Send notification" step. Delivering to it is one `notificationOutput.send` per member, under the
485
714
  * member's own policy. It keeps no credentials: members keep theirs.
486
715
  */
487
- var CoreNotifierAddon = class extends require_dist.BaseAddon {
488
- id = require_dist.NOTIFIER_GROUP_ADDON_ID;
716
+ var CoreNotifierAddon = class extends require_base_addon.BaseAddon {
717
+ id = NOTIFIER_GROUP_ADDON_ID;
489
718
  constructor() {
490
719
  super({});
491
720
  }
@@ -496,10 +725,10 @@ var CoreNotifierAddon = class extends require_dist.BaseAddon {
496
725
  if (api === void 0) throw new Error("core-notifier needs ctx.api to reach its members");
497
726
  await records.declare(groupRecordKinds);
498
727
  const logger = this.ctx.logger.child("notification-output");
499
- const store = require_dist.NotificationTargetStore.of(records, require_dist.NOTIFIER_GROUP_ADDON_ID, groupRecordKinds, [groupTargetKind()], { logger });
728
+ const store = require_notification_targets.NotificationTargetStore.of(records, NOTIFIER_GROUP_ADDON_ID, groupRecordKinds, [groupTargetKind()], { logger });
500
729
  const group = createGroupNotificationOutputProvider({
501
730
  store,
502
- listTargets: () => require_dist.listNotificationTargets(api),
731
+ listTargets: () => require_notification_targets.listNotificationTargets(api),
503
732
  listMemberKinds: () => readMemberKinds(api),
504
733
  sendToMember: (input) => api.notificationOutput.send.mutate({
505
734
  addonId: input.addonId,
@@ -508,7 +737,7 @@ var CoreNotifierAddon = class extends require_dist.BaseAddon {
508
737
  }),
509
738
  readAlarmState: async (deviceId) => {
510
739
  try {
511
- const status = require_dist.AlarmPanelStatusSchema.safeParse(await api.alarmPanel.getStatus.query({ deviceId }));
740
+ const status = require_notification_rules_cap.AlarmPanelStatusSchema.safeParse(await api.alarmPanel.getStatus.query({ deviceId }));
512
741
  if (status.success) return status.data.state;
513
742
  logger.warn("alarm panel status is not readable; the member is skipped", {
514
743
  tags: { deviceId },
@@ -523,7 +752,7 @@ var CoreNotifierAddon = class extends require_dist.BaseAddon {
523
752
  tags: { deviceId },
524
753
  meta: {
525
754
  deviceId,
526
- error: require_dist.errMsg(err)
755
+ error: require_scoped_settings.errMsg(err)
527
756
  }
528
757
  });
529
758
  return null;
@@ -533,13 +762,13 @@ var CoreNotifierAddon = class extends require_dist.BaseAddon {
533
762
  now: () => Date.now(),
534
763
  logger
535
764
  });
536
- const instances = refuseNestedGroups(require_dist.buildNotificationTargetInstances(records, groupInstancesSpec({ mintId: () => (0, node_crypto.randomUUID)() })), async () => new Set((await store.list()).map((target) => target.id)));
765
+ const instances = refuseNestedGroups(require_notification_targets.buildNotificationTargetInstances(records, groupInstancesSpec({ mintId: () => (0, node_crypto.randomUUID)() })), async () => new Set((await store.list()).map((target) => target.id)));
537
766
  this.ctx.logger.info("CoreNotifier initialized");
538
767
  return { providers: [{
539
- capability: require_dist.notificationOutputCapability,
768
+ capability: require_notification_rules_cap.notificationOutputCapability,
540
769
  provider: group.provider
541
770
  }, {
542
- capability: require_dist.integrationInstancesCapability,
771
+ capability: require_integration_instances_cap.integrationInstancesCapability,
543
772
  provider: instances
544
773
  }] };
545
774
  }
@@ -1,5 +1,234 @@
1
- import { Ct as GroupMemberSchema, Gi as integrationInstancesCapability, Hu as errMsg, Ii as groupMembersOf, Ja as notificationTargetKinds, Kt as NOTIFIER_GROUP_ADDON_ID, Lc as BaseAddon, Wr as decideMember, Xt as NotificationTargetStore, cs as shapeForMember, p as AlarmPanelStatusSchema, qa as notificationOutputCapability, qt as NOTIFIER_GROUP_KIND, sr as buildNotificationTargetInstances, va as listNotificationTargets, yr as clampToCaps } from "../../dist-BCHMSqzc.mjs";
1
+ import { t as BaseAddon } from "../../base-addon-Md14i7pe.mjs";
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-DaNE-pIt.mjs";
4
+ import { f as notificationOutputCapability, l as NotificationFieldSchema, o as AlarmPanelStatusSchema, r as NcScheduleSchema, s as AlarmStateSchema } from "../../notification-rules.cap-DUmiMBQB.mjs";
5
+ import { t as integrationInstancesCapability } from "../../integration-instances.cap-Cl9O-k4h.mjs";
6
+ import { z } from "zod";
2
7
  import { createHash, randomUUID } from "node:crypto";
8
+ //#region ../types/dist/esm/notification/schedule.mjs
9
+ var WEEKDAY_TO_DAY = {
10
+ Sun: 0,
11
+ Mon: 1,
12
+ Tue: 2,
13
+ Wed: 3,
14
+ Thu: 4,
15
+ Fri: 5,
16
+ Sat: 6
17
+ };
18
+ /**
19
+ * One formatter per timezone, built once (D647 review I4). Constructing an
20
+ * `Intl.DateTimeFormat` is the expensive part of this function, and a caller
21
+ * that asks about many instants — a window scan — used to build one per
22
+ * instant. `null` = an invalid IANA name (the host timezone is used).
23
+ */
24
+ var FORMATTERS = /* @__PURE__ */ new Map();
25
+ function formatterFor(timezone) {
26
+ const held = FORMATTERS.get(timezone);
27
+ if (held !== void 0) return held;
28
+ let made;
29
+ try {
30
+ made = new Intl.DateTimeFormat("en-US", {
31
+ timeZone: timezone,
32
+ weekday: "short",
33
+ hour: "numeric",
34
+ minute: "numeric",
35
+ hourCycle: "h23"
36
+ });
37
+ } catch {
38
+ made = null;
39
+ }
40
+ FORMATTERS.set(timezone, made);
41
+ return made;
42
+ }
43
+ /** Resolve (weekday, minute-of-day) of `atMs` in the schedule's timezone.
44
+ * An invalid/unknown IANA name falls back to the host timezone. */
45
+ function localDayMinute(atMs, timezone) {
46
+ const d = new Date(atMs);
47
+ const formatter = timezone !== void 0 ? formatterFor(timezone) : null;
48
+ if (formatter !== null) try {
49
+ const parts = formatter.formatToParts(d);
50
+ let weekday;
51
+ let hour;
52
+ let minute;
53
+ for (const p of parts) if (p.type === "weekday") weekday = p.value;
54
+ else if (p.type === "hour") hour = Number(p.value);
55
+ else if (p.type === "minute") minute = Number(p.value);
56
+ const day = weekday !== void 0 ? WEEKDAY_TO_DAY[weekday] : void 0;
57
+ if (day !== void 0 && hour !== void 0 && minute !== void 0) return {
58
+ day,
59
+ minute: hour * 60 + minute
60
+ };
61
+ } catch {}
62
+ return {
63
+ day: d.getDay(),
64
+ minute: d.getHours() * 60 + d.getMinutes()
65
+ };
66
+ }
67
+ /**
68
+ * Is the schedule active at `atMs`? No schedule = always active. Windows
69
+ * are OR'd; a window with `startMinute > endMinute` crosses midnight (it
70
+ * starts on a listed day and spills into the next). `invert` flips the
71
+ * result (active OUTSIDE the windows).
72
+ */
73
+ function isScheduleActive(schedule, atMs) {
74
+ if (schedule === void 0) return true;
75
+ const { day, minute } = localDayMinute(atMs, schedule.timezone);
76
+ const prevDay = (day + 6) % 7;
77
+ let inside = false;
78
+ for (const w of schedule.windows) if (w.startMinute <= w.endMinute) {
79
+ if (w.days.includes(day) && minute >= w.startMinute && minute < w.endMinute) {
80
+ inside = true;
81
+ break;
82
+ }
83
+ } else if (w.days.includes(day) && minute >= w.startMinute || w.days.includes(prevDay) && minute < w.endMinute) {
84
+ inside = true;
85
+ break;
86
+ }
87
+ return schedule.invert === true ? !inside : inside;
88
+ }
89
+ //#endregion
90
+ //#region ../types/dist/esm/notification/notifier-group.mjs
91
+ /**
92
+ * A notifier group: a notification target whose delivery is a fan-out to other targets (D1071).
93
+ *
94
+ * The group is an instance of `notification-output` of the record kind `notify-group`, owned by the
95
+ * core builtin `core-notifier`. Its body holds a `members` list; each member is a target id plus the
96
+ * policy that decides whether, and with what content, that member receives a notification.
97
+ *
98
+ * Everything here is pure: the schemas, the per-member decision, the content shaping and the clamp to a
99
+ * member's own capabilities. Delivery, the throttle and the retry ledger live in the builtin.
100
+ */
101
+ /** The target kind a group is. */
102
+ var NOTIFIER_GROUP_KIND = "group";
103
+ /** The core builtin that owns groups. */
104
+ var NOTIFIER_GROUP_ADDON_ID = "core-notifier";
105
+ /** When a member receives: always, inside a schedule, or while an alarm panel is in a state. */
106
+ var GroupMemberWhenSchema = /* @__PURE__ */ z.discriminatedUnion("kind", [
107
+ /* @__PURE__ */ z.object({ kind: /* @__PURE__ */ z.literal("always") }),
108
+ /* @__PURE__ */ z.object({
109
+ kind: /* @__PURE__ */ z.literal("schedule"),
110
+ schedule: NcScheduleSchema
111
+ }),
112
+ /* @__PURE__ */ z.object({
113
+ kind: /* @__PURE__ */ z.literal("alarm"),
114
+ deviceId: /* @__PURE__ */ z.number().int().nonnegative(),
115
+ states: /* @__PURE__ */ z.array(AlarmStateSchema).min(1)
116
+ })
117
+ ]);
118
+ /**
119
+ * One member's policy. Every key but `targetId` is optional and means "no restriction" when absent
120
+ * (never a Zod default: a default does not run on the addon cap path).
121
+ */
122
+ var GroupMemberSchema = /* @__PURE__ */ z.object({
123
+ targetId: /* @__PURE__ */ z.string().min(1),
124
+ enabled: /* @__PURE__ */ z.boolean().optional(),
125
+ when: /* @__PURE__ */ GroupMemberWhenSchema.optional(),
126
+ /** Which message fields this member receives. Absent = all of them. */
127
+ fields: /* @__PURE__ */ z.array(NotificationFieldSchema).optional(),
128
+ /** `{{title}}`, `{{body}}`, `{{priority}}` and any `{{key}}` of the notification's metadata. */
129
+ templates: /* @__PURE__ */ z.object({
130
+ title: /* @__PURE__ */ z.string().optional(),
131
+ body: /* @__PURE__ */ z.string().optional()
132
+ }).optional(),
133
+ minPriority: /* @__PURE__ */ z.number().int().min(1).max(5).optional(),
134
+ /** At most one delivery per window; a burst becomes one. 0 or absent = no throttle. */
135
+ throttleSec: /* @__PURE__ */ z.number().int().nonnegative().optional()
136
+ });
137
+ /** Read the `members` of a group's config; an unreadable row is counted, never silently dropped. */
138
+ function groupMembersOf(config) {
139
+ const rows = config["members"];
140
+ if (!Array.isArray(rows)) return {
141
+ members: [],
142
+ invalid: 0
143
+ };
144
+ const members = [];
145
+ let invalid = 0;
146
+ for (const row of rows) {
147
+ const parsed = GroupMemberSchema.safeParse(row);
148
+ if (parsed.success) members.push(parsed.data);
149
+ else invalid += 1;
150
+ }
151
+ return {
152
+ members,
153
+ invalid
154
+ };
155
+ }
156
+ /** The policy of one member that needs no state of the group: enabled, priority, schedule, alarm. */
157
+ function decideMember(input) {
158
+ const { member, notification, nowMs } = input;
159
+ if (member.enabled === false) return {
160
+ send: false,
161
+ reason: "member-disabled"
162
+ };
163
+ if (member.minPriority !== void 0 && notification.priority < member.minPriority) return {
164
+ send: false,
165
+ reason: "below-min-priority"
166
+ };
167
+ const when = member.when;
168
+ if (when?.kind === "schedule" && !isScheduleActive(when.schedule, nowMs)) return {
169
+ send: false,
170
+ reason: "schedule-inactive"
171
+ };
172
+ if (when?.kind === "alarm") {
173
+ if (input.alarmState === void 0 || input.alarmState === null) return {
174
+ send: false,
175
+ reason: "alarm-unreadable"
176
+ };
177
+ if (!when.states.includes(input.alarmState)) return {
178
+ send: false,
179
+ reason: "alarm-state"
180
+ };
181
+ }
182
+ return { send: true };
183
+ }
184
+ /** `{{name}}` filled from the notification; an unknown name is empty. */
185
+ function renderMemberTemplate(template, notification) {
186
+ return template.replace(/\{\{\s*([\w.-]+)\s*\}\}/g, (_match, name) => {
187
+ if (name === "title") return notification.title ?? "";
188
+ if (name === "body") return notification.body;
189
+ if (name === "priority") return String(notification.priority);
190
+ const value = notification.metadata?.[name];
191
+ return typeof value === "string" || typeof value === "number" ? String(value) : "";
192
+ });
193
+ }
194
+ /** The notification as this member should receive it: its templates applied, its fields kept. */
195
+ function shapeForMember(member, notification) {
196
+ const keep = (field) => member.fields === void 0 || member.fields.includes(field);
197
+ const title = member.templates?.title !== void 0 ? renderMemberTemplate(member.templates.title, notification) : notification.title;
198
+ const body = member.templates?.body !== void 0 ? renderMemberTemplate(member.templates.body, notification) : notification.body;
199
+ const { attachments, actions, sound, clickUrl, ...rest } = notification;
200
+ return {
201
+ ...rest,
202
+ body: keep("body") ? body : "",
203
+ ...keep("title") && title !== void 0 ? { title } : { title: void 0 },
204
+ priority: keep("priority") ? notification.priority : 3,
205
+ ...keep("attachments") && attachments !== void 0 ? { attachments } : {},
206
+ ...keep("actions") && actions !== void 0 ? { actions } : {},
207
+ ...keep("sound") && sound !== void 0 ? { sound } : {},
208
+ ...keep("clickUrl") && clickUrl !== void 0 ? { clickUrl } : {}
209
+ };
210
+ }
211
+ /**
212
+ * The notification as ONE member's own kind can take it: its text fields, body length, attachment
213
+ * media types and count, action count, level, sound and click URL. The group's own caps are permissive and only keep the
214
+ * notification center from stripping a field before the group sees it; a member gets its own limits.
215
+ */
216
+ function clampToCaps(notification, caps) {
217
+ const { attachments, actions, sound, clickUrl, level, ...rest } = notification;
218
+ const kept = (attachments ?? []).filter((attachment) => caps.attachments.mediaTypes.includes(attachment.mediaType)).slice(0, caps.attachments.max);
219
+ const buttons = (actions ?? []).slice(0, caps.actions);
220
+ return {
221
+ ...rest,
222
+ body: caps.text?.body === false ? "" : notification.body.slice(0, caps.bodyMaxLen),
223
+ ...caps.text?.title === false || notification.title === void 0 ? { title: void 0 } : { title: notification.title },
224
+ ...kept.length > 0 ? { attachments: kept } : {},
225
+ ...buttons.length > 0 ? { actions: buttons } : {},
226
+ ...level !== void 0 && caps.levels.some((known) => known.id === level) ? { level } : {},
227
+ ...caps.sound && sound !== void 0 ? { sound } : {},
228
+ ...caps.clickUrl && clickUrl !== void 0 ? { clickUrl } : {}
229
+ };
230
+ }
231
+ //#endregion
3
232
  //#region src/builtins/core-notifier/group-descriptor.ts
4
233
  /**
5
234
  * The `group` target kind a core-notifier serves: the descriptor the add flow lists, and the record