@camstack/server 1.2.928 → 1.2.929

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 (237) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/package.json +10 -8
  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/core-blocks.addon.js +7887 -381
  35. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +7511 -5
  36. package/system/dist/builtins/core-notifier/core-notifier.addon.js +731 -21
  37. package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +711 -1
  38. package/system/dist/builtins/device-history/device-history.addon.js +110 -31
  39. package/system/dist/builtins/device-history/device-history.addon.mjs +81 -2
  40. package/system/dist/builtins/device-manager/device-manager.addon.js +12806 -227
  41. package/system/dist/builtins/device-manager/device-manager.addon.mjs +12583 -5
  42. package/system/dist/builtins/hub-forwarder/index.js +4 -3
  43. package/system/dist/builtins/hub-forwarder/index.mjs +2 -1
  44. package/system/dist/builtins/keychain/index.js +31 -28
  45. package/system/dist/builtins/keychain/index.mjs +7 -4
  46. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +15 -12
  47. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +4 -1
  48. package/system/dist/builtins/local-auth/local-auth.addon.js +140 -39
  49. package/system/dist/builtins/local-auth/local-auth.addon.mjs +106 -6
  50. package/system/dist/builtins/local-network/local-network.addon.js +43 -39
  51. package/system/dist/builtins/local-network/local-network.addon.mjs +7 -3
  52. package/system/dist/builtins/loki-logging/index.js +23 -17
  53. package/system/dist/builtins/loki-logging/index.mjs +7 -1
  54. package/system/dist/builtins/native-metrics/native-metrics.addon.js +156 -15
  55. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +151 -10
  56. package/system/dist/builtins/platform-probe/index.js +25 -23
  57. package/system/dist/builtins/platform-probe/index.mjs +12 -10
  58. package/system/dist/builtins/record-entries/index.js +9 -7
  59. package/system/dist/builtins/record-entries/index.mjs +3 -1
  60. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +4 -4
  61. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  62. package/system/dist/builtins/snapshot/index.js +97 -44
  63. package/system/dist/builtins/snapshot/index.mjs +54 -1
  64. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +5 -4
  65. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +21 -20
  66. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  67. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  68. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +87 -61
  69. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +29 -3
  70. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +81 -72
  71. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +10 -1
  72. package/system/dist/builtins/system-config/system-config.addon.js +17 -14
  73. package/system/dist/builtins/system-config/system-config.addon.mjs +118 -115
  74. package/system/dist/builtins/winston-logging/index.js +7 -5
  75. package/system/dist/builtins/winston-logging/index.mjs +3 -1
  76. package/system/dist/calendars.cap-CaFlShS9.js +155 -0
  77. package/system/dist/calendars.cap-_C4eD4fi.mjs +138 -0
  78. package/system/dist/camstack-error-DJ-TUAi1.js +23 -0
  79. package/system/dist/camstack-error-viZYfcj9.mjs +18 -0
  80. package/system/dist/cap-call-context-Bd76CbOW.js +95 -0
  81. package/system/dist/cap-call-context-DNwdgGSQ.mjs +78 -0
  82. package/system/dist/capability-definition-C2rJdVeX.mjs +177 -0
  83. package/system/dist/capability-definition-HCmTem8c.js +242 -0
  84. package/system/dist/{capture-engine-BcuwOSXv.js → capture-engine-DZ0LIUqA.js} +5 -4
  85. package/system/dist/{capture-engine-Bz7eXFjT.mjs → capture-engine-DiwbjoWp.mjs} +2 -1
  86. package/system/dist/command-origin-claim-Cief660O.js +35 -0
  87. package/system/dist/command-origin-claim-D1Wy7Qld.mjs +24 -0
  88. package/system/dist/composition-sources-Caqv7O7z.mjs +391 -0
  89. package/system/dist/composition-sources-CgnHjm8Q.js +408 -0
  90. package/system/dist/{constants-D2etJ02O.js → constants-Ba3FTIHl.js} +1 -1
  91. package/system/dist/constants-C860Y6U4.js +26 -0
  92. package/system/dist/{constants-BcUTQd1M.mjs → constants-DB4piTD5.mjs} +1 -1
  93. package/system/dist/constants-DCLpoF4L.mjs +21 -0
  94. package/system/dist/coral-accelerators-7o8hqvcN.js +564 -0
  95. package/system/dist/coral-accelerators-BKcXP59c.mjs +521 -0
  96. package/system/dist/core-blocks.cap-C6iKAZ-x.mjs +17986 -0
  97. package/system/dist/core-blocks.cap-LEMqVwxO.js +18705 -0
  98. package/system/dist/{custom-action-registry-N7flBDwT.mjs → custom-action-registry-B9zFBNVa.mjs} +37 -37
  99. package/system/dist/custom-actions-BFUSalC9.mjs +25 -0
  100. package/system/dist/custom-actions-D92NRi2c.js +36 -0
  101. package/system/dist/database-snapshot.cap-DF38e-0P.js +162 -0
  102. package/system/dist/database-snapshot.cap-dhrc9xnY.mjs +133 -0
  103. package/system/dist/declared-device-BWphj9WE.js +303 -0
  104. package/system/dist/declared-device-CKERA1Hi.mjs +286 -0
  105. package/system/dist/{device-ca-ExMN3xW3.mjs → device-ca-BLM6fccc.mjs} +2 -1
  106. package/system/dist/{device-ca-CU8zh9Pi.js → device-ca-C5kJE6mL.js} +7 -6
  107. package/system/dist/device-certificate-Cddm4Idn.mjs +91 -0
  108. package/system/dist/device-certificate-CguVACQO.js +162 -0
  109. package/system/dist/device-identifiers-BQg9EQi1.js +600 -0
  110. package/system/dist/device-identifiers-iSuQCKmK.mjs +529 -0
  111. package/system/dist/device-kind-BJ2pfsjw.mjs +78 -0
  112. package/system/dist/device-kind-CsSiv_YF.js +101 -0
  113. package/system/dist/device-manager.cap-2abwVLCM.js +2874 -0
  114. package/system/dist/device-manager.cap-CFZSPfUh.mjs +2749 -0
  115. package/system/dist/device-provider.cap-3Uvk6f5-.mjs +331 -0
  116. package/system/dist/device-provider.cap-D7TV2kVH.js +366 -0
  117. package/system/dist/{device-row-store-CeW_GWh9.mjs → device-row-store-YF3jtmkk.mjs} +4 -1
  118. package/system/dist/{device-row-store-BMIR-n3m.js → device-row-store-doTfMOqn.js} +12 -9
  119. package/system/dist/device-transitions.cap-B5w5PYU_.js +860 -0
  120. package/system/dist/device-transitions.cap-DojcwEuX.mjs +819 -0
  121. package/system/dist/device-type-CbQsnFdC.js +477 -0
  122. package/system/dist/device-type-DgEvK3ch.mjs +454 -0
  123. package/system/dist/entry-kind-D9MuVJCK.mjs +44 -0
  124. package/system/dist/entry-kind-cq90c--V.js +55 -0
  125. package/system/dist/error.cap-CSM_SRfR.mjs +3423 -0
  126. package/system/dist/error.cap-DBhgPeWK.js +3848 -0
  127. package/system/dist/file-host-worker.js +1 -1
  128. package/system/dist/file-host-worker.mjs +1 -1
  129. package/system/dist/history-catalog-BKRarIL_.js +831 -0
  130. package/system/dist/history-catalog-BwTeQ4Mr.mjs +802 -0
  131. package/system/dist/{hub-identity-Csxx2Q8k.js → hub-identity-BMdR3Mw9.js} +2 -2
  132. package/system/dist/{hub-identity-CYC1820R.mjs → hub-identity-DjMN9Ac2.mjs} +10 -10
  133. package/system/dist/{hub-mdns-ciao-By5577HM.js → hub-mdns-ciao--0v1TKME.js} +5 -5
  134. package/system/dist/{hub-mdns-ciao-CCDxM5qz.mjs → hub-mdns-ciao-DBrtHOcc.mjs} +2 -2
  135. package/system/dist/index.js +763 -151
  136. package/system/dist/index.mjs +832 -220
  137. package/system/dist/integration-instances.cap-Cl9O-k4h.mjs +538 -0
  138. package/system/dist/integration-instances.cap-dJIxg2_s.js +549 -0
  139. package/system/dist/keychain-admin.cap-Db_oFX4H.js +425 -0
  140. package/system/dist/keychain-admin.cap-GtM7gVGG.mjs +396 -0
  141. package/system/dist/l10n-Bu6aUvSY.mjs +10 -0
  142. package/system/dist/l10n-CGMvp7NF.js +15 -0
  143. package/system/dist/labels-DX5S8deC.js +81 -0
  144. package/system/dist/labels-DsBcU7md.mjs +64 -0
  145. package/system/dist/{legacy-integration-rows-door-CVwOo5aq.js → legacy-integration-rows-door-B1nzxxr5.js} +2 -2
  146. package/system/dist/{legacy-integration-rows-door-D9tQOUzh.mjs → legacy-integration-rows-door-nTvo_6jQ.mjs} +1 -1
  147. package/system/dist/log-destination.cap-CxZzAVaR.mjs +143 -0
  148. package/system/dist/log-destination.cap-DELPJkZ0.js +148 -0
  149. package/system/dist/low-power-sleep.cap-7lfVU41N.js +103 -0
  150. package/system/dist/low-power-sleep.cap-tGPmaZ_V.mjs +92 -0
  151. package/system/dist/mask-shape-Ci8Co9w0.mjs +57 -0
  152. package/system/dist/mask-shape-CmPA2fst.js +92 -0
  153. package/system/dist/metrics-provider.cap-BNmcHDkQ.mjs +405 -0
  154. package/system/dist/metrics-provider.cap-BcmQUt6l.js +410 -0
  155. package/system/dist/migration-BMjgkyG2.js +380 -0
  156. package/system/dist/migration-DRJAtdy7.mjs +321 -0
  157. package/system/dist/network-access.cap-B5TWLDCC.js +1099 -0
  158. package/system/dist/network-access.cap-BJnGbE6n.mjs +1004 -0
  159. package/system/dist/notification-rules.cap-B__YBgnG.js +3422 -0
  160. package/system/dist/notification-rules.cap-D9ArZlwx.mjs +3357 -0
  161. package/system/dist/ops-log-CB4pIdqi.mjs +64 -0
  162. package/system/dist/ops-log-pxt9176Z.js +81 -0
  163. package/system/dist/pinned-binary-BOhOSNff.js +28 -0
  164. package/system/dist/pinned-binary-CrIRAi4G.mjs +23 -0
  165. package/system/dist/platform-probe.cap-1WrMhWHx.js +250 -0
  166. package/system/dist/platform-probe.cap-BFeqFLtQ.mjs +233 -0
  167. package/system/dist/prefix-walk-B4b2-9aK.mjs +790 -0
  168. package/system/dist/prefix-walk-DC0ljmbB.js +843 -0
  169. package/system/dist/ptz-autotrack.cap-BW7w0zHD.js +229 -0
  170. package/system/dist/ptz-autotrack.cap-DT2GypXw.mjs +224 -0
  171. package/system/dist/quantity-D3g5SxsZ.mjs +114 -0
  172. package/system/dist/quantity-lY1KiTSZ.js +143 -0
  173. package/system/dist/raw-secret-migration-DxuBFtvi.js +50 -0
  174. package/system/dist/raw-secret-migration-iv88mLoc.mjs +39 -0
  175. package/system/dist/record-entries.cap-sMUhTvTU.mjs +75 -0
  176. package/system/dist/record-entries.cap-ti1C046R.js +80 -0
  177. package/system/dist/record-kind-DoBfYHCs.js +203 -0
  178. package/system/dist/record-kind-ub6NXqfh.mjs +162 -0
  179. package/system/dist/recording-archive.cap-7OrIn9e5.mjs +1299 -0
  180. package/system/dist/recording-archive.cap-D7bo-QSM.js +1328 -0
  181. package/system/dist/records.cap-ClcWV64i.js +329 -0
  182. package/system/dist/records.cap-CwLT2ByG.mjs +294 -0
  183. package/system/dist/relocate-CdVQAk-w.js +804 -0
  184. package/system/dist/relocate-CoZZTui1.mjs +661 -0
  185. package/system/dist/rename-composition-block-7WIICIDq.mjs +33525 -0
  186. package/system/dist/rename-composition-block-CcWLwVhG.js +34692 -0
  187. package/system/dist/{restore-archive-BJfyu0sG.mjs → restore-archive-CjAyKpgX.mjs} +96 -94
  188. package/system/dist/{restore-archive-CIFvqOze.js → restore-archive-CkTkv3Ss.js} +6 -4
  189. package/system/dist/scoped-settings-CylSSq_8.js +955 -0
  190. package/system/dist/scoped-settings-DVWUIP7Z.mjs +650 -0
  191. package/system/dist/server-name-BIhLuHvX.mjs +35 -0
  192. package/system/dist/server-name-OALNvpqC.js +52 -0
  193. package/system/dist/settings-store.cap-Ci4F2zul.mjs +569 -0
  194. package/system/dist/settings-store.cap-wlJhCspr.js +640 -0
  195. package/system/dist/snapshot.cap-3suPdBHV.js +250 -0
  196. package/system/dist/snapshot.cap-Bs8Oyaqh.mjs +245 -0
  197. package/system/dist/source-info-DGB7SdB_.mjs +190 -0
  198. package/system/dist/source-info-DtWf4k2j.js +225 -0
  199. package/system/dist/storage-admin.cap-BSv1NjKJ.mjs +883 -0
  200. package/system/dist/storage-admin.cap-he0OqvVM.js +906 -0
  201. package/system/dist/storage-location-CBT8GCD6.mjs +163 -0
  202. package/system/dist/storage-location-CTweDMZf.js +198 -0
  203. package/system/dist/storage-location-mode-B21UVRRX.mjs +167 -0
  204. package/system/dist/storage-location-mode-CS4sMzo-.js +232 -0
  205. package/system/dist/storage-migration.cap-CyyATY_p.js +330 -0
  206. package/system/dist/storage-migration.cap-D7QqGobp.mjs +313 -0
  207. package/system/dist/storage-occupancy.cap-2rmnS58Z.js +622 -0
  208. package/system/dist/storage-occupancy.cap-CqBztTl9.mjs +611 -0
  209. package/system/dist/storage-provider.cap-Bw0CfxVc.js +213 -0
  210. package/system/dist/storage-provider.cap-CMeck2w4.mjs +202 -0
  211. package/system/dist/stream-catalog.cap-Bp7SkgIf.mjs +6560 -0
  212. package/system/dist/stream-catalog.cap-D3uwePiA.js +6763 -0
  213. package/system/dist/streaming-shared-B8cXatuU.mjs +431 -0
  214. package/system/dist/streaming-shared-DQwFZOSi.js +526 -0
  215. package/system/dist/system-reasons-Be_k1W8g.js +25 -0
  216. package/system/dist/system-reasons-CYj4qwyS.mjs +20 -0
  217. package/system/dist/tag-BxLazvVb.js +2138 -0
  218. package/system/dist/tag-uZBAq6ox.mjs +2073 -0
  219. package/system/dist/user-management.cap-B9QDu8NE.js +825 -0
  220. package/system/dist/user-management.cap-DBIi77sB.mjs +766 -0
  221. package/system/dist/vector-store.cap-DnyfrYDn.js +330 -0
  222. package/system/dist/vector-store.cap-h2GHWQ1t.mjs +319 -0
  223. package/system/dist/{wal-maintenance-CTrCPzds.mjs → wal-maintenance-BG01rOn9.mjs} +0 -0
  224. package/system/dist/{wal-maintenance-dq7T3quB.js → wal-maintenance-DyrebYKF.js} +0 -0
  225. package/system/dist/zod-secret-DS7mj1bk.js +78 -0
  226. package/system/dist/zod-secret-zY4nM61M.mjs +73 -0
  227. package/system/package.json +1 -1
  228. package/system/dist/composition-sources-BI614LJx.mjs +0 -141
  229. package/system/dist/composition-sources-v_kkb8A9.js +0 -152
  230. package/system/dist/coral-accelerators-BSVsBVzt.js +0 -250
  231. package/system/dist/coral-accelerators-BW3OcrLD.mjs +0 -231
  232. package/system/dist/dist-BCHMSqzc.mjs +0 -143467
  233. package/system/dist/dist-BZfvhfS1.js +0 -146970
  234. package/system/dist/prefix-walk-DAOBSyH1.mjs +0 -88
  235. package/system/dist/prefix-walk-Dv6MLZlM.js +0 -99
  236. package/system/dist/rename-composition-block-C9HuBrKS.js +0 -112
  237. package/system/dist/rename-composition-block-DtaYmYAR.mjs +0 -101
@@ -3,8 +3,718 @@ 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_rules_cap = require("../../notification-rules.cap-B__YBgnG.js");
9
+ const require_entry_kind = require("../../entry-kind-cq90c--V.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/addon/compose-instance-kinds.mjs
14
+ /** No part holds the id a call named. */
15
+ var UnknownInstanceError = class extends Error {
16
+ instanceId;
17
+ constructor(instanceId) {
18
+ super(`Unknown instance '${instanceId}'`);
19
+ this.instanceId = instanceId;
20
+ this.name = "UnknownInstanceError";
21
+ }
22
+ };
23
+ /** A create or a form named no kind, or a kind no part serves. */
24
+ var UnknownInstanceKindError = class extends Error {
25
+ kindId;
26
+ constructor(kindId) {
27
+ super(kindId === void 0 ? "This provider has several kinds: name one" : `Unknown instance kind '${kindId}'`);
28
+ this.kindId = kindId;
29
+ this.name = "UnknownInstanceKindError";
30
+ }
31
+ };
32
+ function composeInstanceKinds(parts, base) {
33
+ const byKind = (kindId) => {
34
+ if (kindId === void 0) {
35
+ const only = parts.length === 1 ? parts[0] : void 0;
36
+ if (only === void 0) throw new UnknownInstanceKindError(void 0);
37
+ return only;
38
+ }
39
+ const part = parts.find((candidate) => candidate.kind.id === kindId);
40
+ if (part === void 0) throw new UnknownInstanceKindError(kindId);
41
+ return part;
42
+ };
43
+ /**
44
+ * Whether a part's kind offers a Test. A kind that states `canTest` is believed; one that does not
45
+ * takes what its OWN provider declares, never the composed base (a calendar or an integration
46
+ * inherited the account's `canTest: true` and offered a button nothing answered, planning#543).
47
+ */
48
+ const canTestPart = async (part) => part.kind.canTest ?? (await part.provider.describe()).canTest === true;
49
+ /**
50
+ * The part a DRAFT test runs on. A named kind is that kind; an unnamed one is the provider's only
51
+ * testable kind. Several testable kinds and none named is a typed refusal that lists them, never a throw.
52
+ */
53
+ const draftPart = async (kindId) => {
54
+ if (kindId !== void 0) return parts.find((candidate) => candidate.kind.id === kindId) ?? { error: `Unknown instance kind '${kindId}'` };
55
+ const flags = await Promise.all(parts.map(canTestPart));
56
+ const testable = parts.filter((_part, index) => flags[index] === true);
57
+ const only = testable.length === 1 ? testable[0] : parts.length === 1 ? parts[0] : void 0;
58
+ if (only !== void 0) return only;
59
+ return { error: `This provider has several kinds: name one of ${(testable.length > 0 ? testable : parts).map((part) => part.kind.id).join(", ")}` };
60
+ };
61
+ const holderOf = async (id) => {
62
+ for (const part of parts) if (await part.provider.getInstance({ id }) !== null) return part;
63
+ throw new UnknownInstanceError(id);
64
+ };
65
+ const tagged = (part, instance) => ({
66
+ ...instance,
67
+ kind: part.kind.id
68
+ });
69
+ return {
70
+ describe: async () => {
71
+ const links = (await Promise.all(parts.map(async (part) => (await part.provider.describe()).links ?? []))).flat();
72
+ return {
73
+ ...base,
74
+ kinds: await Promise.all(parts.map(async (part) => ({
75
+ ...part.kind,
76
+ canTest: await canTestPart(part)
77
+ }))),
78
+ ...links.length > 0 ? { links } : {}
79
+ };
80
+ },
81
+ instanceFormSchema: async ({ id, kind }) => {
82
+ return (id === null ? byKind(kind) : await holderOf(id)).provider.instanceFormSchema({ id });
83
+ },
84
+ listInstances: async (input) => {
85
+ return (await Promise.all(parts.map(async (part) => (await part.provider.listInstances(input)).map((instance) => tagged(part, instance))))).flat();
86
+ },
87
+ getInstance: async ({ id }) => {
88
+ for (const part of parts) {
89
+ const found = await part.provider.getInstance({ id });
90
+ if (found !== null) return tagged(part, found);
91
+ }
92
+ return null;
93
+ },
94
+ createInstance: async (input) => byKind(input.kind).provider.createInstance(input),
95
+ updateInstance: async (input) => (await holderOf(input.id)).provider.updateInstance(input),
96
+ setInstanceEnabled: async (input) => (await holderOf(input.id)).provider.setInstanceEnabled(input),
97
+ deleteInstance: async (input) => (await holderOf(input.id)).provider.deleteInstance(input),
98
+ testInstance: async (input) => {
99
+ const resolved = input.id === null ? await draftPart(input.kind) : await holderOf(input.id);
100
+ if ("error" in resolved) return {
101
+ success: false,
102
+ status: "inconclusive",
103
+ error: resolved.error
104
+ };
105
+ const test = resolved.provider.testInstance;
106
+ if (test === void 0) return {
107
+ success: false,
108
+ status: "inconclusive",
109
+ error: "This kind cannot be tested"
110
+ };
111
+ return test(input);
112
+ }
113
+ };
114
+ }
115
+ //#endregion
116
+ //#region ../types/dist/esm/addon/instances-of-cap.mjs
117
+ /**
118
+ * The kind's instances answer for `cap`: it is the kind's `functionCap`, or one the kind declares in
119
+ * `alsoServes`. The one rule a link (a picker, a resolver, a delete guard) matches a target by.
120
+ */
121
+ function kindServesCap(kind, cap) {
122
+ return kind.functionCap === cap || (kind.alsoServes ?? []).includes(cap);
123
+ }
124
+ async function instancesOfCap(source, cap, filter = {}) {
125
+ const instances = [];
126
+ const unreadable = [];
127
+ for (const addonId of await source.holders(cap)) try {
128
+ const kinds = ((await source.describe(addonId)).kinds ?? []).filter((kind) => kindServesCap(kind, cap));
129
+ if (kinds.length === 0) continue;
130
+ for (const instance of await source.listInstances(addonId)) {
131
+ const kind = kinds.find((candidate) => candidate.id === instance.kind);
132
+ if (kind === void 0) continue;
133
+ if (filter.kind !== void 0 && (kind.brokerKind ?? kind.id) !== filter.kind) continue;
134
+ instances.push({
135
+ addonId,
136
+ kind,
137
+ instance
138
+ });
139
+ }
140
+ } catch (err) {
141
+ unreadable.push({
142
+ addonId,
143
+ error: err instanceof Error ? err.message : String(err)
144
+ });
145
+ }
146
+ return {
147
+ instances,
148
+ unreadable
149
+ };
150
+ }
151
+ async function providersOf(api, name) {
152
+ const info = await api.capabilities.getCapability.query({ name });
153
+ if (info === null) throw new Error(`the capability registry did not answer for ${name}`);
154
+ return info.providers;
155
+ }
156
+ /**
157
+ * The source over `ctx.api`. Every provider of the cap is a holder, not only those that also serve
158
+ * `integration-instances`: a provider that does not (an addon older than the hub during an update)
159
+ * then fails `describe` and is reported unreadable, so its instances are retried as transient
160
+ * instead of vanishing from the catalogue and failing for good.
161
+ */
162
+ function instanceSourceOverApi(api) {
163
+ return {
164
+ holders: (cap) => providersOf(api, cap),
165
+ describe: (addonId) => api.integrationInstances.describe.query({ addonId }),
166
+ listInstances: (addonId) => api.integrationInstances.listInstances.query({ addonId })
167
+ };
168
+ }
169
+ //#endregion
170
+ //#region ../types/dist/esm/addon/notification-targets.mjs
171
+ /**
172
+ * Notification targets as instances of the function cap `notification-output` (epic #440, step 6).
173
+ *
174
+ * A notification target used to be one row of one record kind (`{ name, kind, addonId, enabled,
175
+ * config }`) with a free-form `config` blob whose secrets nobody could name. Now every target KIND
176
+ * the provider offers (ntfy, telegram, webhook, ...) is a record kind of its own whose flat body IS
177
+ * that kind's form: the adapter's `configSchema` lifted into a Zod object, a `password` field marked
178
+ * `.meta({ secret: true })` so the records door keeps it in the keychain, an `instance-select` field
179
+ * declared as a link so the hub refuses to delete what a target points at.
180
+ *
181
+ * Three providers (notifiers, Home Assistant, Alexa) serve the same shape, so the pieces are shared:
182
+ * - {@link defineNotificationTargetKind}: the record kind of one `TargetKind` descriptor;
183
+ * - {@link NotificationTargetStore}: the `Target`-shaped facade the provider's own code keeps
184
+ * using (send, the notification-center bridge), over one handle per kind;
185
+ * - {@link listNotificationTargets}: the targets as an addon on `ctx.api` reads them;
186
+ * - {@link buildNotificationTargetInstances}: the `integration-instances` provider, one kind each;
187
+ * - {@link moveTargetRows}: the D987 procedure that flattens the old `config` blobs into the bodies.
188
+ */
189
+ /** The function cap every notification target is an instance of. */
190
+ var NOTIFICATION_OUTPUT_CAP = "notification-output";
191
+ /** The most targets one provider lists (a settings page, not a table). */
192
+ var TARGETS_LIST_MAX = 1e3;
193
+ /** The record kind name of one target kind: `telegram` is stored under `notify-telegram`. */
194
+ function notificationTargetKindName(kind) {
195
+ return `notify-${kind}`;
196
+ }
197
+ /** The body schema of a target kind: the entry's name and switch plus the adapter's fields. */
198
+ var TargetBodyBaseSchema = /* @__PURE__ */ zod.z.looseObject({
199
+ name: /* @__PURE__ */ zod.z.string().min(1),
200
+ enabled: /* @__PURE__ */ zod.z.boolean().optional()
201
+ });
202
+ /** The shape of one `editable-array` row: the item fields, a `password` one a secret. */
203
+ function rowSchemaOf(itemFields) {
204
+ const shape = {};
205
+ let idKey = null;
206
+ let hasSecret = false;
207
+ for (const item of itemFields) {
208
+ if (item.type === "password") {
209
+ shape[item.key] = zod.z.string().optional().meta({ secret: true });
210
+ hasSecret = true;
211
+ continue;
212
+ }
213
+ shape[item.key] = zod.z.unknown().optional();
214
+ idKey ??= item.key;
215
+ }
216
+ return {
217
+ row: zod.z.looseObject(shape),
218
+ idKey,
219
+ hasSecret
220
+ };
221
+ }
222
+ /**
223
+ * The Zod fields of a descriptor's form. A `password` field is a secret; an `instance-select` field is
224
+ * a link to an instance of its function cap; an `editable-array` keeps its rows (a password inside a
225
+ * row is a secret matched by the row's first plain field); every other field keeps whatever the
226
+ * adapter's own parse accepts, because the form already validated its shape. The body is loose, so a key
227
+ * the schema does not know (the owner of a personal target) survives a write.
228
+ */
229
+ function fieldsOf(descriptor) {
230
+ const shape = {};
231
+ const secretArrayKeys = {};
232
+ for (const section of descriptor.configSchema.sections) for (const field of section.fields) switch (field.type) {
233
+ case "info": break;
234
+ case "password":
235
+ shape[field.key] = zod.z.string().optional().meta({ secret: true });
236
+ break;
237
+ case "instance-select":
238
+ shape[field.key] = require_base_addon.optionalLinkField({
239
+ cap: field.functionCap,
240
+ ...field.kind !== void 0 ? { kind: field.kind } : {}
241
+ });
242
+ break;
243
+ case "editable-array": {
244
+ const { row, idKey, hasSecret } = rowSchemaOf(field.itemFields);
245
+ shape[field.key] = zod.z.array(row).optional();
246
+ if (hasSecret && idKey !== null) secretArrayKeys[field.key] = idKey;
247
+ break;
248
+ }
249
+ default: shape[field.key] = zod.z.unknown().optional();
250
+ }
251
+ return {
252
+ shape,
253
+ secretArrayKeys
254
+ };
255
+ }
256
+ /** The record kind of one target kind, derived from its descriptor. */
257
+ function defineNotificationTargetKind(descriptor) {
258
+ const { shape, secretArrayKeys } = fieldsOf(descriptor);
259
+ return require_entry_kind.defineEntryKind(notificationTargetKindName(descriptor.kind), {
260
+ title: `${descriptor.label} notification targets`,
261
+ schema: TargetBodyBaseSchema.extend(shape),
262
+ writeTrigger: `an operator adds, edits, switches or removes a ${descriptor.label} notification target`,
263
+ ...Object.keys(secretArrayKeys).length > 0 ? { secretArrayKeys } : {}
264
+ });
265
+ }
266
+ /** The record kinds of a provider's descriptors, keyed by the record kind name (for `records.declare`). */
267
+ function notificationTargetKinds(descriptors) {
268
+ return Object.fromEntries(descriptors.map((descriptor) => {
269
+ const defined = defineNotificationTargetKind(descriptor);
270
+ return [defined.name, defined];
271
+ }));
272
+ }
273
+ /** The body a stored target becomes: the switch and the name, and the config fields flat beside them. */
274
+ function targetBody(target) {
275
+ return {
276
+ ...target.config,
277
+ name: target.name.length > 0 ? target.name : target.id,
278
+ enabled: target.enabled
279
+ };
280
+ }
281
+ /** The `Target` a record of a kind is; null when the row is not a target. */
282
+ function targetOfRecord(addonId, kind, id, data) {
283
+ const { name, enabled: _enabled, ...config } = data;
284
+ const parsed = require_notification_rules_cap.TargetSchema.safeParse({
285
+ id,
286
+ name,
287
+ kind,
288
+ addonId,
289
+ enabled: require_base_addon.isInstanceOn(id),
290
+ config
291
+ });
292
+ return parsed.success ? parsed.data : null;
293
+ }
294
+ function targetOfOld(addonId, row) {
295
+ return {
296
+ id: row.id,
297
+ name: row.name,
298
+ kind: row.kind,
299
+ addonId,
300
+ enabled: row.enabled,
301
+ config: { ...row.config }
302
+ };
303
+ }
304
+ /**
305
+ * The `Target`-shaped facade over one record kind per target kind. `list` returns the stored form (a
306
+ * secret is a keychain marker: every reader redacts it anyway); `getById` returns the target with its
307
+ * secrets resolved, which is what a send, a probe and an edit's secret merge need. A keychain that
308
+ * cannot answer throws: a write never goes ahead with a secret it could not read (D49).
309
+ */
310
+ var NotificationTargetStore = class NotificationTargetStore {
311
+ addonId;
312
+ handles;
313
+ options;
314
+ constructor(addonId, handles, options) {
315
+ this.addonId = addonId;
316
+ this.handles = handles;
317
+ this.options = options;
318
+ }
319
+ static of(records, addonId, kinds, descriptors, options = {}) {
320
+ const handles = [];
321
+ for (const descriptor of descriptors) {
322
+ const defined = kinds[notificationTargetKindName(descriptor.kind)];
323
+ if (defined === void 0) continue;
324
+ handles.push({
325
+ kind: descriptor.kind,
326
+ handle: records.kind(defined)
327
+ });
328
+ }
329
+ return new NotificationTargetStore(addonId, handles, options);
330
+ }
331
+ /** The record handle of each kind, for the migration ports. */
332
+ handlesByKind() {
333
+ return new Map(this.handles.map((entry) => [entry.kind, entry.handle]));
334
+ }
335
+ async list() {
336
+ const out = [];
337
+ for (const { kind, handle } of this.handles) {
338
+ const page = await handle.query({ limit: TARGETS_LIST_MAX });
339
+ for (const record of page.records) {
340
+ const target = targetOfRecord(this.addonId, kind, record.id, record.data);
341
+ if (target !== null) {
342
+ out.push(target);
343
+ continue;
344
+ }
345
+ this.options.logger?.warn("notification target record is not a valid target; left out of the list", { meta: {
346
+ targetId: record.id,
347
+ kind
348
+ } });
349
+ }
350
+ }
351
+ const held = new Set(out.map((target) => target.id));
352
+ for (const row of await this.legacyRows()) if (!held.has(row.id)) out.push(targetOfOld(this.addonId, row));
353
+ return out;
354
+ }
355
+ /** The legacy rows of a kind this provider serves (the others are not ours to show). */
356
+ async legacyRows() {
357
+ const legacy = this.options.legacy;
358
+ if (legacy === void 0) return [];
359
+ const served = new Set(this.handles.map((entry) => entry.kind));
360
+ return (await legacy.list()).filter((row) => served.has(row.kind));
361
+ }
362
+ async getById(id) {
363
+ for (const { kind, handle } of this.handles) {
364
+ const row = await handle.getResolved(id);
365
+ if (row !== null) return targetOfRecord(this.addonId, kind, row.id, row.data);
366
+ }
367
+ const old = (await this.legacyRows()).find((row) => row.id === id);
368
+ return old === void 0 ? null : targetOfOld(this.addonId, old);
369
+ }
370
+ /** Insert or replace by id; a target whose kind changed leaves the record of its old kind. */
371
+ async upsert(target) {
372
+ const own = this.handles.find((entry) => entry.kind === target.kind);
373
+ if (own === void 0) throw new Error(`invalid target '${target.id}': unknown kind '${target.kind}'`);
374
+ const { enabled: _switch, ...data } = targetBody(target);
375
+ await own.handle.put({
376
+ id: target.id,
377
+ data
378
+ });
379
+ require_base_addon.recordInstanceSwitch(target.id, target.enabled);
380
+ for (const other of this.handles) if (other !== own) await other.handle.delete(target.id);
381
+ await this.options.legacy?.delete(target.id);
382
+ }
383
+ async delete(id) {
384
+ for (const { handle } of this.handles) await handle.delete(id);
385
+ await this.options.legacy?.delete(id);
386
+ }
387
+ };
388
+ /**
389
+ * A probe's answer as the tri-state of `testInstance`: `ok` validated; a refusal that carries an HTTP
390
+ * status is the remote saying no (`rejected`); a failure with no answer at all (the network, a missing
391
+ * field) proves nothing about the credentials (`inconclusive`).
392
+ */
393
+ function probeToTestResult(probed) {
394
+ if (probed.ok) return {
395
+ success: true,
396
+ status: "validated",
397
+ ...probed.stateInstance !== void 0 ? { detail: probed.stateInstance } : {}
398
+ };
399
+ const error = probed.error ?? "the probe failed";
400
+ return {
401
+ success: false,
402
+ status: probed.httpStatus !== void 0 ? "rejected" : "inconclusive",
403
+ error
404
+ };
405
+ }
406
+ /** The form of a kind: the adapter's own sections. */
407
+ function formOf(descriptor) {
408
+ return descriptor.configSchema;
409
+ }
410
+ /** The instance kinds of a notification provider, one per target kind: a part a composition can take. */
411
+ function notificationTargetParts(records, spec) {
412
+ return spec.descriptors.flatMap((descriptor) => {
413
+ const defined = spec.kinds[notificationTargetKindName(descriptor.kind)];
414
+ if (defined === void 0) return [];
415
+ const canTest = spec.probe !== void 0 && spec.canProbe(descriptor.kind);
416
+ const kind = {
417
+ id: descriptor.kind,
418
+ label: descriptor.label,
419
+ functionCap: NOTIFICATION_OUTPUT_CAP,
420
+ role: "services",
421
+ canTest,
422
+ ...spec.widgets?.(descriptor.kind) !== void 0 ? { widgets: spec.widgets(descriptor.kind) } : {},
423
+ ...descriptor.iconUrl !== void 0 ? { iconUrl: descriptor.iconUrl } : {},
424
+ ...descriptor.iconMediaType !== void 0 ? { iconMediaType: descriptor.iconMediaType } : {}
425
+ };
426
+ return [{
427
+ kind,
428
+ provider: new require_base_addon.RecordIntegrationInstances(records, defined, {
429
+ description: {
430
+ role: "services",
431
+ instanceMode: "multiple",
432
+ kind: "target",
433
+ canTest,
434
+ kinds: [kind]
435
+ },
436
+ formSchema: () => formOf(descriptor),
437
+ initialBody: (name) => ({ name }),
438
+ mintId: () => spec.mintId(),
439
+ configured: () => true,
440
+ validateWrite: ({ body }) => spec.validate?.({
441
+ kind: descriptor.kind,
442
+ config: body
443
+ }),
444
+ test: async ({ id, values }) => {
445
+ if (spec.probe === void 0 || !canTest) return {
446
+ success: false,
447
+ status: "unsupported",
448
+ error: "This kind cannot be tested"
449
+ };
450
+ return probeToTestResult(await spec.probe({
451
+ kind: descriptor.kind,
452
+ config: values,
453
+ targetId: id ?? void 0
454
+ }));
455
+ }
456
+ }).toProvider()
457
+ }];
458
+ });
459
+ }
460
+ /** The `integration-instances` provider of a notification provider: one kind per target kind. */
461
+ function buildNotificationTargetInstances(records, spec) {
462
+ const parts = notificationTargetParts(records, spec);
463
+ return composeInstanceKinds(parts, {
464
+ role: "services",
465
+ instanceMode: "multiple",
466
+ kind: "target",
467
+ canTest: parts.some((part) => part.kind.canTest === true),
468
+ mintsId: true
469
+ });
470
+ }
471
+ /**
472
+ * Every notification target, read as the instances of `notification-output` (D1013 rule 5). A holder
473
+ * that could not answer is NAMED in `unreadable`: a caller that acts on a target's absence (drops a
474
+ * selection, refuses a send) must check it first, because a partial read is not "deleted" (D315, D49).
475
+ */
476
+ async function listNotificationTargets(api) {
477
+ const { instances, unreadable } = await instancesOfCap(instanceSourceOverApi(api), NOTIFICATION_OUTPUT_CAP);
478
+ return {
479
+ targets: instances.map(({ addonId, kind, instance }) => {
480
+ const owner = instance.formValues["ownerUserId"];
481
+ return {
482
+ id: instance.id,
483
+ name: instance.name,
484
+ kind: kind.id,
485
+ addonId,
486
+ enabled: instance.enabled !== false,
487
+ ...typeof owner === "string" && owner.length > 0 ? { ownerUserId: owner } : {}
488
+ };
489
+ }),
490
+ unreadable
491
+ };
492
+ }
493
+ //#endregion
494
+ //#region ../types/dist/esm/notification/schedule.mjs
495
+ var WEEKDAY_TO_DAY = {
496
+ Sun: 0,
497
+ Mon: 1,
498
+ Tue: 2,
499
+ Wed: 3,
500
+ Thu: 4,
501
+ Fri: 5,
502
+ Sat: 6
503
+ };
504
+ /**
505
+ * One formatter per timezone, built once (D647 review I4). Constructing an
506
+ * `Intl.DateTimeFormat` is the expensive part of this function, and a caller
507
+ * that asks about many instants — a window scan — used to build one per
508
+ * instant. `null` = an invalid IANA name (the host timezone is used).
509
+ */
510
+ var FORMATTERS = /* @__PURE__ */ new Map();
511
+ function formatterFor(timezone) {
512
+ const held = FORMATTERS.get(timezone);
513
+ if (held !== void 0) return held;
514
+ let made;
515
+ try {
516
+ made = new Intl.DateTimeFormat("en-US", {
517
+ timeZone: timezone,
518
+ weekday: "short",
519
+ hour: "numeric",
520
+ minute: "numeric",
521
+ hourCycle: "h23"
522
+ });
523
+ } catch {
524
+ made = null;
525
+ }
526
+ FORMATTERS.set(timezone, made);
527
+ return made;
528
+ }
529
+ /** Resolve (weekday, minute-of-day) of `atMs` in the schedule's timezone.
530
+ * An invalid/unknown IANA name falls back to the host timezone. */
531
+ function localDayMinute(atMs, timezone) {
532
+ const d = new Date(atMs);
533
+ const formatter = timezone !== void 0 ? formatterFor(timezone) : null;
534
+ if (formatter !== null) try {
535
+ const parts = formatter.formatToParts(d);
536
+ let weekday;
537
+ let hour;
538
+ let minute;
539
+ for (const p of parts) if (p.type === "weekday") weekday = p.value;
540
+ else if (p.type === "hour") hour = Number(p.value);
541
+ else if (p.type === "minute") minute = Number(p.value);
542
+ const day = weekday !== void 0 ? WEEKDAY_TO_DAY[weekday] : void 0;
543
+ if (day !== void 0 && hour !== void 0 && minute !== void 0) return {
544
+ day,
545
+ minute: hour * 60 + minute
546
+ };
547
+ } catch {}
548
+ return {
549
+ day: d.getDay(),
550
+ minute: d.getHours() * 60 + d.getMinutes()
551
+ };
552
+ }
553
+ /**
554
+ * Is the schedule active at `atMs`? No schedule = always active. Windows
555
+ * are OR'd; a window with `startMinute > endMinute` crosses midnight (it
556
+ * starts on a listed day and spills into the next). `invert` flips the
557
+ * result (active OUTSIDE the windows).
558
+ */
559
+ function isScheduleActive(schedule, atMs) {
560
+ if (schedule === void 0) return true;
561
+ const { day, minute } = localDayMinute(atMs, schedule.timezone);
562
+ const prevDay = (day + 6) % 7;
563
+ let inside = false;
564
+ for (const w of schedule.windows) if (w.startMinute <= w.endMinute) {
565
+ if (w.days.includes(day) && minute >= w.startMinute && minute < w.endMinute) {
566
+ inside = true;
567
+ break;
568
+ }
569
+ } else if (w.days.includes(day) && minute >= w.startMinute || w.days.includes(prevDay) && minute < w.endMinute) {
570
+ inside = true;
571
+ break;
572
+ }
573
+ return schedule.invert === true ? !inside : inside;
574
+ }
575
+ //#endregion
576
+ //#region ../types/dist/esm/notification/notifier-group.mjs
577
+ /**
578
+ * A notifier group: a notification target whose delivery is a fan-out to other targets (D1071).
579
+ *
580
+ * The group is an instance of `notification-output` of the record kind `notify-group`, owned by the
581
+ * core builtin `core-notifier`. Its body holds a `members` list; each member is a target id plus the
582
+ * policy that decides whether, and with what content, that member receives a notification.
583
+ *
584
+ * Everything here is pure: the schemas, the per-member decision, the content shaping and the clamp to a
585
+ * member's own capabilities. Delivery, the throttle and the retry ledger live in the builtin.
586
+ */
587
+ /** The target kind a group is. */
588
+ var NOTIFIER_GROUP_KIND = "group";
589
+ /** The core builtin that owns groups. */
590
+ var NOTIFIER_GROUP_ADDON_ID = "core-notifier";
591
+ /** When a member receives: always, inside a schedule, or while an alarm panel is in a state. */
592
+ var GroupMemberWhenSchema = /* @__PURE__ */ zod.z.discriminatedUnion("kind", [
593
+ /* @__PURE__ */ zod.z.object({ kind: /* @__PURE__ */ zod.z.literal("always") }),
594
+ /* @__PURE__ */ zod.z.object({
595
+ kind: /* @__PURE__ */ zod.z.literal("schedule"),
596
+ schedule: require_notification_rules_cap.NcScheduleSchema
597
+ }),
598
+ /* @__PURE__ */ zod.z.object({
599
+ kind: /* @__PURE__ */ zod.z.literal("alarm"),
600
+ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
601
+ states: /* @__PURE__ */ zod.z.array(require_notification_rules_cap.AlarmStateSchema).min(1)
602
+ })
603
+ ]);
604
+ /**
605
+ * One member's policy. Every key but `targetId` is optional and means "no restriction" when absent
606
+ * (never a Zod default: a default does not run on the addon cap path).
607
+ */
608
+ var GroupMemberSchema = /* @__PURE__ */ zod.z.object({
609
+ targetId: /* @__PURE__ */ zod.z.string().min(1),
610
+ enabled: /* @__PURE__ */ zod.z.boolean().optional(),
611
+ when: /* @__PURE__ */ GroupMemberWhenSchema.optional(),
612
+ /** Which message fields this member receives. Absent = all of them. */
613
+ fields: /* @__PURE__ */ zod.z.array(require_notification_rules_cap.NotificationFieldSchema).optional(),
614
+ /** `{{title}}`, `{{body}}`, `{{priority}}` and any `{{key}}` of the notification's metadata. */
615
+ templates: /* @__PURE__ */ zod.z.object({
616
+ title: /* @__PURE__ */ zod.z.string().optional(),
617
+ body: /* @__PURE__ */ zod.z.string().optional()
618
+ }).optional(),
619
+ minPriority: /* @__PURE__ */ zod.z.number().int().min(1).max(5).optional(),
620
+ /** At most one delivery per window; a burst becomes one. 0 or absent = no throttle. */
621
+ throttleSec: /* @__PURE__ */ zod.z.number().int().nonnegative().optional()
622
+ });
623
+ /** Read the `members` of a group's config; an unreadable row is counted, never silently dropped. */
624
+ function groupMembersOf(config) {
625
+ const rows = config["members"];
626
+ if (!Array.isArray(rows)) return {
627
+ members: [],
628
+ invalid: 0
629
+ };
630
+ const members = [];
631
+ let invalid = 0;
632
+ for (const row of rows) {
633
+ const parsed = GroupMemberSchema.safeParse(row);
634
+ if (parsed.success) members.push(parsed.data);
635
+ else invalid += 1;
636
+ }
637
+ return {
638
+ members,
639
+ invalid
640
+ };
641
+ }
642
+ /** The policy of one member that needs no state of the group: enabled, priority, schedule, alarm. */
643
+ function decideMember(input) {
644
+ const { member, notification, nowMs } = input;
645
+ if (member.enabled === false) return {
646
+ send: false,
647
+ reason: "member-disabled"
648
+ };
649
+ if (member.minPriority !== void 0 && notification.priority < member.minPriority) return {
650
+ send: false,
651
+ reason: "below-min-priority"
652
+ };
653
+ const when = member.when;
654
+ if (when?.kind === "schedule" && !isScheduleActive(when.schedule, nowMs)) return {
655
+ send: false,
656
+ reason: "schedule-inactive"
657
+ };
658
+ if (when?.kind === "alarm") {
659
+ if (input.alarmState === void 0 || input.alarmState === null) return {
660
+ send: false,
661
+ reason: "alarm-unreadable"
662
+ };
663
+ if (!when.states.includes(input.alarmState)) return {
664
+ send: false,
665
+ reason: "alarm-state"
666
+ };
667
+ }
668
+ return { send: true };
669
+ }
670
+ /** `{{name}}` filled from the notification; an unknown name is empty. */
671
+ function renderMemberTemplate(template, notification) {
672
+ return template.replace(/\{\{\s*([\w.-]+)\s*\}\}/g, (_match, name) => {
673
+ if (name === "title") return notification.title ?? "";
674
+ if (name === "body") return notification.body;
675
+ if (name === "priority") return String(notification.priority);
676
+ const value = notification.metadata?.[name];
677
+ return typeof value === "string" || typeof value === "number" ? String(value) : "";
678
+ });
679
+ }
680
+ /** The notification as this member should receive it: its templates applied, its fields kept. */
681
+ function shapeForMember(member, notification) {
682
+ const keep = (field) => member.fields === void 0 || member.fields.includes(field);
683
+ const title = member.templates?.title !== void 0 ? renderMemberTemplate(member.templates.title, notification) : notification.title;
684
+ const body = member.templates?.body !== void 0 ? renderMemberTemplate(member.templates.body, notification) : notification.body;
685
+ const { attachments, actions, sound, clickUrl, ...rest } = notification;
686
+ return {
687
+ ...rest,
688
+ body: keep("body") ? body : "",
689
+ ...keep("title") && title !== void 0 ? { title } : { title: void 0 },
690
+ priority: keep("priority") ? notification.priority : 3,
691
+ ...keep("attachments") && attachments !== void 0 ? { attachments } : {},
692
+ ...keep("actions") && actions !== void 0 ? { actions } : {},
693
+ ...keep("sound") && sound !== void 0 ? { sound } : {},
694
+ ...keep("clickUrl") && clickUrl !== void 0 ? { clickUrl } : {}
695
+ };
696
+ }
697
+ /**
698
+ * The notification as ONE member's own kind can take it: its text fields, body length, attachment
699
+ * media types and count, action count, level, sound and click URL. The group's own caps are permissive and only keep the
700
+ * notification center from stripping a field before the group sees it; a member gets its own limits.
701
+ */
702
+ function clampToCaps(notification, caps) {
703
+ const { attachments, actions, sound, clickUrl, level, ...rest } = notification;
704
+ const kept = (attachments ?? []).filter((attachment) => caps.attachments.mediaTypes.includes(attachment.mediaType)).slice(0, caps.attachments.max);
705
+ const buttons = (actions ?? []).slice(0, caps.actions);
706
+ return {
707
+ ...rest,
708
+ body: caps.text?.body === false ? "" : notification.body.slice(0, caps.bodyMaxLen),
709
+ ...caps.text?.title === false || notification.title === void 0 ? { title: void 0 } : { title: notification.title },
710
+ ...kept.length > 0 ? { attachments: kept } : {},
711
+ ...buttons.length > 0 ? { actions: buttons } : {},
712
+ ...level !== void 0 && caps.levels.some((known) => known.id === level) ? { level } : {},
713
+ ...caps.sound && sound !== void 0 ? { sound } : {},
714
+ ...caps.clickUrl && clickUrl !== void 0 ? { clickUrl } : {}
715
+ };
716
+ }
717
+ //#endregion
8
718
  //#region src/builtins/core-notifier/group-descriptor.ts
9
719
  /**
10
720
  * The `group` target kind a core-notifier serves: the descriptor the add flow lists, and the record
@@ -97,17 +807,17 @@ var GROUP_CAPS = {
97
807
  };
98
808
  function groupTargetKind() {
99
809
  return {
100
- kind: require_dist.NOTIFIER_GROUP_KIND,
810
+ kind: NOTIFIER_GROUP_KIND,
101
811
  label: "Group",
102
812
  icon: "users",
103
- addonId: require_dist.NOTIFIER_GROUP_ADDON_ID,
813
+ addonId: NOTIFIER_GROUP_ADDON_ID,
104
814
  configSchema: groupConfigSchema(),
105
815
  destinationKeys: [],
106
816
  supportsDiscovery: false,
107
817
  caps: GROUP_CAPS
108
818
  };
109
819
  }
110
- var groupRecordKinds = require_dist.notificationTargetKinds([groupTargetKind()]);
820
+ var groupRecordKinds = notificationTargetKinds([groupTargetKind()]);
111
821
  //#endregion
112
822
  //#region src/builtins/core-notifier/group-instances.ts
113
823
  /**
@@ -125,7 +835,7 @@ function validateGroupMembers(config, groupIds) {
125
835
  const members = [];
126
836
  const seen = /* @__PURE__ */ new Set();
127
837
  for (const row of rows) {
128
- const parsed = require_dist.GroupMemberSchema.safeParse(row);
838
+ const parsed = GroupMemberSchema.safeParse(row);
129
839
  if (!parsed.success) throw new Error("A group member row is not valid: it needs a notifier");
130
840
  const { targetId } = parsed.data;
131
841
  if (seen.has(targetId)) throw new Error(`The notifier ${targetId} is listed twice`);
@@ -345,7 +1055,7 @@ function createGroupNotificationOutputProvider(deps) {
345
1055
  if (!target.enabled) return skip("target-disabled");
346
1056
  if (deps.ledger.wasDelivered(group.id, notificationKey, member.targetId)) return skip("already-delivered");
347
1057
  const alarm = member.when?.kind === "alarm" ? await deps.readAlarmState(member.when.deviceId) : void 0;
348
- const decision = require_dist.decideMember({
1058
+ const decision = decideMember({
349
1059
  member,
350
1060
  notification,
351
1061
  nowMs: deps.now(),
@@ -353,13 +1063,13 @@ function createGroupNotificationOutputProvider(deps) {
353
1063
  });
354
1064
  if (!decision.send) return skip(decision.reason);
355
1065
  if (deps.ledger.isThrottled(group.id, member.targetId, member.throttleSec)) return skip("throttled");
356
- const shaped = require_dist.shapeForMember(member, notification);
1066
+ const shaped = shapeForMember(member, notification);
357
1067
  const ownCaps = byKind.get(target.kind);
358
1068
  try {
359
1069
  const result = await deps.sendToMember({
360
1070
  addonId: target.addonId,
361
1071
  targetId: member.targetId,
362
- notification: ownCaps === void 0 ? shaped : require_dist.clampToCaps(shaped, ownCaps)
1072
+ notification: ownCaps === void 0 ? shaped : clampToCaps(shaped, ownCaps)
363
1073
  });
364
1074
  if (!result.success) {
365
1075
  const error = result.error ?? "send failed";
@@ -384,7 +1094,7 @@ function createGroupNotificationOutputProvider(deps) {
384
1094
  status: "sent"
385
1095
  };
386
1096
  } catch (err) {
387
- const error = require_dist.errMsg(err);
1097
+ const error = require_scoped_settings.errMsg(err);
388
1098
  logger.warn("group member delivery threw", {
389
1099
  tags,
390
1100
  meta: {
@@ -401,7 +1111,7 @@ function createGroupNotificationOutputProvider(deps) {
401
1111
  }
402
1112
  }
403
1113
  async function deliver(group, notification) {
404
- const { members, invalid } = require_dist.groupMembersOf(group.config);
1114
+ const { members, invalid } = groupMembersOf(group.config);
405
1115
  if (invalid > 0) logger.warn("group has member rows that could not be read; they are not delivered to", {
406
1116
  tags: { groupId: group.id },
407
1117
  meta: {
@@ -416,7 +1126,7 @@ function createGroupNotificationOutputProvider(deps) {
416
1126
  const byKind = await deps.listMemberKinds().then((kinds) => new Map(kinds.map((kind) => [kind.kind, kind.caps]))).catch((err) => {
417
1127
  logger.warn("member kind caps could not be read; members degrade on their own", {
418
1128
  tags: { groupId: group.id },
419
- meta: { error: require_dist.errMsg(err) }
1129
+ meta: { error: require_scoped_settings.errMsg(err) }
420
1130
  });
421
1131
  return /* @__PURE__ */ new Map();
422
1132
  });
@@ -469,7 +1179,7 @@ function createGroupNotificationOutputProvider(deps) {
469
1179
  * is not an empty one (D49).
470
1180
  */
471
1181
  async function readMemberKinds(api) {
472
- return (await api.notificationOutput.listTargetKinds.query({})).filter((row) => row.addonId !== require_dist.NOTIFIER_GROUP_ADDON_ID).map((row) => ({
1182
+ return (await api.notificationOutput.listTargetKinds.query({})).filter((row) => row.addonId !== NOTIFIER_GROUP_ADDON_ID).map((row) => ({
473
1183
  kind: row.kind,
474
1184
  caps: row.caps
475
1185
  }));
@@ -484,8 +1194,8 @@ async function readMemberKinds(api) {
484
1194
  * "Send notification" step. Delivering to it is one `notificationOutput.send` per member, under the
485
1195
  * member's own policy. It keeps no credentials: members keep theirs.
486
1196
  */
487
- var CoreNotifierAddon = class extends require_dist.BaseAddon {
488
- id = require_dist.NOTIFIER_GROUP_ADDON_ID;
1197
+ var CoreNotifierAddon = class extends require_base_addon.BaseAddon {
1198
+ id = NOTIFIER_GROUP_ADDON_ID;
489
1199
  constructor() {
490
1200
  super({});
491
1201
  }
@@ -496,10 +1206,10 @@ var CoreNotifierAddon = class extends require_dist.BaseAddon {
496
1206
  if (api === void 0) throw new Error("core-notifier needs ctx.api to reach its members");
497
1207
  await records.declare(groupRecordKinds);
498
1208
  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 });
1209
+ const store = NotificationTargetStore.of(records, NOTIFIER_GROUP_ADDON_ID, groupRecordKinds, [groupTargetKind()], { logger });
500
1210
  const group = createGroupNotificationOutputProvider({
501
1211
  store,
502
- listTargets: () => require_dist.listNotificationTargets(api),
1212
+ listTargets: () => listNotificationTargets(api),
503
1213
  listMemberKinds: () => readMemberKinds(api),
504
1214
  sendToMember: (input) => api.notificationOutput.send.mutate({
505
1215
  addonId: input.addonId,
@@ -508,7 +1218,7 @@ var CoreNotifierAddon = class extends require_dist.BaseAddon {
508
1218
  }),
509
1219
  readAlarmState: async (deviceId) => {
510
1220
  try {
511
- const status = require_dist.AlarmPanelStatusSchema.safeParse(await api.alarmPanel.getStatus.query({ deviceId }));
1221
+ const status = require_notification_rules_cap.AlarmPanelStatusSchema.safeParse(await api.alarmPanel.getStatus.query({ deviceId }));
512
1222
  if (status.success) return status.data.state;
513
1223
  logger.warn("alarm panel status is not readable; the member is skipped", {
514
1224
  tags: { deviceId },
@@ -523,7 +1233,7 @@ var CoreNotifierAddon = class extends require_dist.BaseAddon {
523
1233
  tags: { deviceId },
524
1234
  meta: {
525
1235
  deviceId,
526
- error: require_dist.errMsg(err)
1236
+ error: require_scoped_settings.errMsg(err)
527
1237
  }
528
1238
  });
529
1239
  return null;
@@ -533,13 +1243,13 @@ var CoreNotifierAddon = class extends require_dist.BaseAddon {
533
1243
  now: () => Date.now(),
534
1244
  logger
535
1245
  });
536
- const instances = refuseNestedGroups(require_dist.buildNotificationTargetInstances(records, groupInstancesSpec({ mintId: () => (0, node_crypto.randomUUID)() })), async () => new Set((await store.list()).map((target) => target.id)));
1246
+ const instances = refuseNestedGroups(buildNotificationTargetInstances(records, groupInstancesSpec({ mintId: () => (0, node_crypto.randomUUID)() })), async () => new Set((await store.list()).map((target) => target.id)));
537
1247
  this.ctx.logger.info("CoreNotifier initialized");
538
1248
  return { providers: [{
539
- capability: require_dist.notificationOutputCapability,
1249
+ capability: require_notification_rules_cap.notificationOutputCapability,
540
1250
  provider: group.provider
541
1251
  }, {
542
- capability: require_dist.integrationInstancesCapability,
1252
+ capability: require_integration_instances_cap.integrationInstancesCapability,
543
1253
  provider: instances
544
1254
  }] };
545
1255
  }