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