@camstack/server 1.2.923 → 1.2.925
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 +13 -0
- package/package.json +8 -9
- package/system/assets/core-notifier/icon.svg +5 -0
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
- package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
- package/system/dist/builtins/alerts/alerts.addon.js +1 -1
- package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
- package/system/dist/builtins/autotrack/index.js +1 -1
- package/system/dist/builtins/autotrack/index.mjs +1 -1
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
- package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
- package/system/dist/builtins/calendars/calendars.addon.js +1 -1
- package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
- package/system/dist/builtins/camera-grid/index.js +1 -1
- package/system/dist/builtins/camera-grid/index.mjs +1 -1
- package/system/dist/builtins/composer/composer.addon.js +4 -4
- package/system/dist/builtins/composer/composer.addon.mjs +4 -4
- package/system/dist/builtins/console-logging/index.js +1 -1
- package/system/dist/builtins/console-logging/index.mjs +1 -1
- package/system/dist/builtins/core-blocks/core-blocks.addon.js +4 -4
- package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +4 -4
- package/system/dist/builtins/core-notifier/core-notifier.addon.d.ts +7 -0
- package/system/dist/builtins/core-notifier/core-notifier.addon.js +549 -0
- package/system/dist/builtins/core-notifier/core-notifier.addon.mjs +543 -0
- package/system/dist/builtins/core-notifier/group-descriptor.d.ts +16 -0
- package/system/dist/builtins/core-notifier/group-instances.d.ts +20 -0
- package/system/dist/builtins/core-notifier/group-notification-output.d.ts +63 -0
- package/system/dist/builtins/core-notifier/index.d.ts +1 -0
- package/system/dist/builtins/core-notifier/index.js +8 -0
- package/system/dist/builtins/core-notifier/index.mjs +2 -0
- package/system/dist/builtins/core-notifier/member-kinds.d.ts +22 -0
- package/system/dist/builtins/core-notifier/member-ledger.d.ts +40 -0
- package/system/dist/builtins/device-history/device-history.addon.js +2 -2
- package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
- package/system/dist/builtins/device-manager/device-manager.addon.js +104 -21
- package/system/dist/builtins/device-manager/device-manager.addon.mjs +104 -21
- package/system/dist/builtins/device-manager/state-refresh-scheduler.d.ts +34 -1
- package/system/dist/builtins/hub-forwarder/index.js +1 -1
- package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
- package/system/dist/builtins/keychain/index.js +4 -4
- package/system/dist/builtins/keychain/index.mjs +4 -4
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
- package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
- package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
- package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
- package/system/dist/builtins/local-network/local-network.addon.js +3 -3
- package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
- package/system/dist/builtins/loki-logging/index.js +1 -1
- package/system/dist/builtins/loki-logging/index.mjs +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
- package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
- package/system/dist/builtins/platform-probe/index.js +1 -1
- package/system/dist/builtins/platform-probe/index.mjs +1 -1
- package/system/dist/builtins/record-entries/index.js +1 -1
- package/system/dist/builtins/record-entries/index.mjs +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
- package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/snapshot/index.js +1 -1
- package/system/dist/builtins/snapshot/index.mjs +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
- package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
- 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 +3 -3
- package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
- package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
- package/system/dist/builtins/system-config/system-config.addon.js +3 -3
- package/system/dist/builtins/system-config/system-config.addon.mjs +284 -284
- package/system/dist/builtins/winston-logging/index.js +1 -1
- package/system/dist/builtins/winston-logging/index.mjs +1 -1
- package/system/dist/{capture-engine-Cm7ZL3jx.js → capture-engine-BEXh051r.js} +1 -1
- package/system/dist/{capture-engine-Bjuf7szh.mjs → capture-engine-CWfylyT8.mjs} +1 -1
- package/system/dist/{composition-sources-DFRtvVCC.js → composition-sources-B3_FuKde.js} +1 -1
- package/system/dist/{composition-sources-CMa04YwQ.mjs → composition-sources-CcpMUxus.mjs} +1 -1
- package/system/dist/{constants-ttjAKMDn.js → constants-B0tqNa2l.js} +1 -1
- package/system/dist/{constants-B_z2KueR.mjs → constants-fPesBGmF.mjs} +1 -1
- package/system/dist/{device-ca-B4U-0_tL.mjs → device-ca-B98SR8Xf.mjs} +1 -1
- package/system/dist/{device-ca-DLbha6bn.js → device-ca-Bh0GEstW.js} +1 -1
- package/system/dist/{device-row-store-n7N6WKAJ.mjs → device-row-store-BBByy029.mjs} +1 -1
- package/system/dist/{device-row-store-BPvPzZXw.js → device-row-store-CfWN8mLZ.js} +1 -1
- package/system/dist/{dist-D4OoBk4J.mjs → dist-CH-iCceM.mjs} +719 -11
- package/system/dist/{dist-DyPraj2b.js → dist-CVjsCA7D.js} +796 -10
- package/system/dist/file-host-worker.js +1 -1
- package/system/dist/file-host-worker.mjs +1 -1
- package/system/dist/{hub-identity-DTe2rzm0.js → hub-identity-BU4XzogT.js} +1 -1
- package/system/dist/{hub-identity-DKSKuA9T.mjs → hub-identity-DCqJbSVn.mjs} +1 -1
- package/system/dist/{hub-mdns-ciao-cwf2mysq.js → hub-mdns-ciao-BNzmwsIH.js} +2 -2
- package/system/dist/{hub-mdns-ciao-C3S8zMoF.mjs → hub-mdns-ciao-IOM82NRd.mjs} +2 -2
- package/system/dist/index.d.ts +1 -0
- package/system/dist/index.js +11 -8
- package/system/dist/index.mjs +11 -9
- package/system/dist/{legacy-integration-rows-door-BVTSfMBP.js → legacy-integration-rows-door-CRcvhOWb.js} +1 -1
- package/system/dist/{legacy-integration-rows-door-DNXKIchh.mjs → legacy-integration-rows-door-nQzjUyPU.mjs} +1 -1
- package/system/dist/{rename-composition-block-DbDlfizP.mjs → rename-composition-block-CJ-C9HoY.mjs} +1 -1
- package/system/dist/{rename-composition-block-B0vOvO8o.js → rename-composition-block-oOfXrUWs.js} +1 -1
- package/system/dist/{restore-archive-DTgUyT_Z.js → restore-archive-BSdudYif.js} +1 -1
- package/system/dist/{restore-archive-BSMhMFzE.mjs → restore-archive-WK8ttFhW.mjs} +82 -82
- package/system/dist/{wal-maintenance-BrO5LKDF.js → wal-maintenance-BRc_MNtZ.js} +0 -0
- package/system/dist/{wal-maintenance-DTAHv1Ih.mjs → wal-maintenance-CyOVe3E1.mjs} +0 -0
- package/system/package.json +22 -1
|
@@ -1462,6 +1462,10 @@ function isInstanceOn(id) {
|
|
|
1462
1462
|
const owner = OWNER_OF.get(id);
|
|
1463
1463
|
return owner === void 0 ? PENDING.size === 0 : !PENDING.has(owner);
|
|
1464
1464
|
}
|
|
1465
|
+
/** Record a state this process holds for `id` (a local mirror; the registry may not have a row yet). */
|
|
1466
|
+
function recordInstanceSwitch(id, enabled) {
|
|
1467
|
+
SWITCHES.set(id, enabled);
|
|
1468
|
+
}
|
|
1465
1469
|
/** Record what the hub told: the registry holds a row of `id` in this state. */
|
|
1466
1470
|
function recordRegistrySwitch(id, enabled) {
|
|
1467
1471
|
SWITCHES.set(id, enabled);
|
|
@@ -2441,6 +2445,13 @@ var TransactRefusedError = class TransactRefusedError extends RecordsError {
|
|
|
2441
2445
|
this.name = "TransactRefusedError";
|
|
2442
2446
|
}
|
|
2443
2447
|
};
|
|
2448
|
+
/**
|
|
2449
|
+
* A link that may stay empty (absent): for a link the addon fills itself, or one an instance does not
|
|
2450
|
+
* always need. The meta rides on the optional wrapper, where {@link linksOfKind} reads it.
|
|
2451
|
+
*/
|
|
2452
|
+
function optionalLinkField(target) {
|
|
2453
|
+
return zod.z.string().optional().meta({ link: target });
|
|
2454
|
+
}
|
|
2444
2455
|
function linkTargetOf(meta) {
|
|
2445
2456
|
if (typeof meta !== "object" || meta === null) return void 0;
|
|
2446
2457
|
const link = Reflect.get(meta, "link");
|
|
@@ -23374,9 +23385,9 @@ var WEEKDAY_INDEX = {
|
|
|
23374
23385
|
Fri: 5,
|
|
23375
23386
|
Sat: 6
|
|
23376
23387
|
};
|
|
23377
|
-
var FORMATTERS = /* @__PURE__ */ new Map();
|
|
23378
|
-
function formatterFor(timeZone) {
|
|
23379
|
-
const held = FORMATTERS.get(timeZone);
|
|
23388
|
+
var FORMATTERS$1 = /* @__PURE__ */ new Map();
|
|
23389
|
+
function formatterFor$2(timeZone) {
|
|
23390
|
+
const held = FORMATTERS$1.get(timeZone);
|
|
23380
23391
|
if (held !== void 0) return held;
|
|
23381
23392
|
let made;
|
|
23382
23393
|
try {
|
|
@@ -23394,11 +23405,11 @@ function formatterFor(timeZone) {
|
|
|
23394
23405
|
} catch {
|
|
23395
23406
|
made = null;
|
|
23396
23407
|
}
|
|
23397
|
-
FORMATTERS.set(timeZone, made);
|
|
23408
|
+
FORMATTERS$1.set(timeZone, made);
|
|
23398
23409
|
return made;
|
|
23399
23410
|
}
|
|
23400
23411
|
function zonedClock(ms, timeZone) {
|
|
23401
|
-
const formatter = formatterFor(timeZone);
|
|
23412
|
+
const formatter = formatterFor$2(timeZone);
|
|
23402
23413
|
if (formatter === null) return null;
|
|
23403
23414
|
const parts = formatter.formatToParts(new Date(ms));
|
|
23404
23415
|
const read = (type) => parts.find((part) => part.type === type)?.value;
|
|
@@ -25247,6 +25258,107 @@ var ADDON_INSTANCE_ID_RE = /^[A-Za-z0-9._-]{1,64}$/;
|
|
|
25247
25258
|
function isAddonInstanceId(value) {
|
|
25248
25259
|
return ADDON_INSTANCE_ID_RE.test(value);
|
|
25249
25260
|
}
|
|
25261
|
+
/** No part holds the id a call named. */
|
|
25262
|
+
var UnknownInstanceError = class extends Error {
|
|
25263
|
+
instanceId;
|
|
25264
|
+
constructor(instanceId) {
|
|
25265
|
+
super(`Unknown instance '${instanceId}'`);
|
|
25266
|
+
this.instanceId = instanceId;
|
|
25267
|
+
this.name = "UnknownInstanceError";
|
|
25268
|
+
}
|
|
25269
|
+
};
|
|
25270
|
+
/** A create or a form named no kind, or a kind no part serves. */
|
|
25271
|
+
var UnknownInstanceKindError = class extends Error {
|
|
25272
|
+
kindId;
|
|
25273
|
+
constructor(kindId) {
|
|
25274
|
+
super(kindId === void 0 ? "This provider has several kinds: name one" : `Unknown instance kind '${kindId}'`);
|
|
25275
|
+
this.kindId = kindId;
|
|
25276
|
+
this.name = "UnknownInstanceKindError";
|
|
25277
|
+
}
|
|
25278
|
+
};
|
|
25279
|
+
function composeInstanceKinds(parts, base) {
|
|
25280
|
+
const byKind = (kindId) => {
|
|
25281
|
+
if (kindId === void 0) {
|
|
25282
|
+
const only = parts.length === 1 ? parts[0] : void 0;
|
|
25283
|
+
if (only === void 0) throw new UnknownInstanceKindError(void 0);
|
|
25284
|
+
return only;
|
|
25285
|
+
}
|
|
25286
|
+
const part = parts.find((candidate) => candidate.kind.id === kindId);
|
|
25287
|
+
if (part === void 0) throw new UnknownInstanceKindError(kindId);
|
|
25288
|
+
return part;
|
|
25289
|
+
};
|
|
25290
|
+
/**
|
|
25291
|
+
* Whether a part's kind offers a Test. A kind that states `canTest` is believed; one that does not
|
|
25292
|
+
* takes what its OWN provider declares, never the composed base (a calendar or an integration
|
|
25293
|
+
* inherited the account's `canTest: true` and offered a button nothing answered, planning#543).
|
|
25294
|
+
*/
|
|
25295
|
+
const canTestPart = async (part) => part.kind.canTest ?? (await part.provider.describe()).canTest === true;
|
|
25296
|
+
/**
|
|
25297
|
+
* The part a DRAFT test runs on. A named kind is that kind; an unnamed one is the provider's only
|
|
25298
|
+
* testable kind. Several testable kinds and none named is a typed refusal that lists them, never a throw.
|
|
25299
|
+
*/
|
|
25300
|
+
const draftPart = async (kindId) => {
|
|
25301
|
+
if (kindId !== void 0) return parts.find((candidate) => candidate.kind.id === kindId) ?? { error: `Unknown instance kind '${kindId}'` };
|
|
25302
|
+
const flags = await Promise.all(parts.map(canTestPart));
|
|
25303
|
+
const testable = parts.filter((_part, index) => flags[index] === true);
|
|
25304
|
+
const only = testable.length === 1 ? testable[0] : parts.length === 1 ? parts[0] : void 0;
|
|
25305
|
+
if (only !== void 0) return only;
|
|
25306
|
+
return { error: `This provider has several kinds: name one of ${(testable.length > 0 ? testable : parts).map((part) => part.kind.id).join(", ")}` };
|
|
25307
|
+
};
|
|
25308
|
+
const holderOf = async (id) => {
|
|
25309
|
+
for (const part of parts) if (await part.provider.getInstance({ id }) !== null) return part;
|
|
25310
|
+
throw new UnknownInstanceError(id);
|
|
25311
|
+
};
|
|
25312
|
+
const tagged = (part, instance) => ({
|
|
25313
|
+
...instance,
|
|
25314
|
+
kind: part.kind.id
|
|
25315
|
+
});
|
|
25316
|
+
return {
|
|
25317
|
+
describe: async () => {
|
|
25318
|
+
const links = (await Promise.all(parts.map(async (part) => (await part.provider.describe()).links ?? []))).flat();
|
|
25319
|
+
return {
|
|
25320
|
+
...base,
|
|
25321
|
+
kinds: await Promise.all(parts.map(async (part) => ({
|
|
25322
|
+
...part.kind,
|
|
25323
|
+
canTest: await canTestPart(part)
|
|
25324
|
+
}))),
|
|
25325
|
+
...links.length > 0 ? { links } : {}
|
|
25326
|
+
};
|
|
25327
|
+
},
|
|
25328
|
+
instanceFormSchema: async ({ id, kind }) => {
|
|
25329
|
+
return (id === null ? byKind(kind) : await holderOf(id)).provider.instanceFormSchema({ id });
|
|
25330
|
+
},
|
|
25331
|
+
listInstances: async (input) => {
|
|
25332
|
+
return (await Promise.all(parts.map(async (part) => (await part.provider.listInstances(input)).map((instance) => tagged(part, instance))))).flat();
|
|
25333
|
+
},
|
|
25334
|
+
getInstance: async ({ id }) => {
|
|
25335
|
+
for (const part of parts) {
|
|
25336
|
+
const found = await part.provider.getInstance({ id });
|
|
25337
|
+
if (found !== null) return tagged(part, found);
|
|
25338
|
+
}
|
|
25339
|
+
return null;
|
|
25340
|
+
},
|
|
25341
|
+
createInstance: async (input) => byKind(input.kind).provider.createInstance(input),
|
|
25342
|
+
updateInstance: async (input) => (await holderOf(input.id)).provider.updateInstance(input),
|
|
25343
|
+
setInstanceEnabled: async (input) => (await holderOf(input.id)).provider.setInstanceEnabled(input),
|
|
25344
|
+
deleteInstance: async (input) => (await holderOf(input.id)).provider.deleteInstance(input),
|
|
25345
|
+
testInstance: async (input) => {
|
|
25346
|
+
const resolved = input.id === null ? await draftPart(input.kind) : await holderOf(input.id);
|
|
25347
|
+
if ("error" in resolved) return {
|
|
25348
|
+
success: false,
|
|
25349
|
+
status: "inconclusive",
|
|
25350
|
+
error: resolved.error
|
|
25351
|
+
};
|
|
25352
|
+
const test = resolved.provider.testInstance;
|
|
25353
|
+
if (test === void 0) return {
|
|
25354
|
+
success: false,
|
|
25355
|
+
status: "inconclusive",
|
|
25356
|
+
error: "This kind cannot be tested"
|
|
25357
|
+
};
|
|
25358
|
+
return test(input);
|
|
25359
|
+
}
|
|
25360
|
+
};
|
|
25361
|
+
}
|
|
25250
25362
|
/**
|
|
25251
25363
|
* notification-output — canonical, capability-gated notification delivery.
|
|
25252
25364
|
*
|
|
@@ -25499,7 +25611,12 @@ var TargetKindTextCapsSchema = zod.z.object({
|
|
|
25499
25611
|
title: zod.z.boolean(),
|
|
25500
25612
|
body: zod.z.boolean()
|
|
25501
25613
|
});
|
|
25502
|
-
|
|
25614
|
+
/**
|
|
25615
|
+
* The message fields a rule can author for a target (#483). Derived from a
|
|
25616
|
+
* kind's caps by `deliverableFields` — the ONE reading of the declaration, used
|
|
25617
|
+
* by the dispatcher (drop), the admin rule editor (show) and the viewer.
|
|
25618
|
+
*/
|
|
25619
|
+
var NotificationFieldSchema = zod.z.enum([
|
|
25503
25620
|
"title",
|
|
25504
25621
|
"body",
|
|
25505
25622
|
"attachments",
|
|
@@ -25687,12 +25804,382 @@ var notificationOutputCapability = {
|
|
|
25687
25804
|
},
|
|
25688
25805
|
vocabulary: { notOperatorFacing: "notification delivery — reached through notifier devices and rules" }
|
|
25689
25806
|
};
|
|
25690
|
-
|
|
25807
|
+
/**
|
|
25808
|
+
* The kind's instances answer for `cap`: it is the kind's `functionCap`, or one the kind declares in
|
|
25809
|
+
* `alsoServes`. The one rule a link (a picker, a resolver, a delete guard) matches a target by.
|
|
25810
|
+
*/
|
|
25811
|
+
function kindServesCap(kind, cap) {
|
|
25812
|
+
return kind.functionCap === cap || (kind.alsoServes ?? []).includes(cap);
|
|
25813
|
+
}
|
|
25814
|
+
async function instancesOfCap(source, cap, filter = {}) {
|
|
25815
|
+
const instances = [];
|
|
25816
|
+
const unreadable = [];
|
|
25817
|
+
for (const addonId of await source.holders(cap)) try {
|
|
25818
|
+
const kinds = ((await source.describe(addonId)).kinds ?? []).filter((kind) => kindServesCap(kind, cap));
|
|
25819
|
+
if (kinds.length === 0) continue;
|
|
25820
|
+
for (const instance of await source.listInstances(addonId)) {
|
|
25821
|
+
const kind = kinds.find((candidate) => candidate.id === instance.kind);
|
|
25822
|
+
if (kind === void 0) continue;
|
|
25823
|
+
if (filter.kind !== void 0 && (kind.brokerKind ?? kind.id) !== filter.kind) continue;
|
|
25824
|
+
instances.push({
|
|
25825
|
+
addonId,
|
|
25826
|
+
kind,
|
|
25827
|
+
instance
|
|
25828
|
+
});
|
|
25829
|
+
}
|
|
25830
|
+
} catch (err) {
|
|
25831
|
+
unreadable.push({
|
|
25832
|
+
addonId,
|
|
25833
|
+
error: err instanceof Error ? err.message : String(err)
|
|
25834
|
+
});
|
|
25835
|
+
}
|
|
25836
|
+
return {
|
|
25837
|
+
instances,
|
|
25838
|
+
unreadable
|
|
25839
|
+
};
|
|
25840
|
+
}
|
|
25841
|
+
async function providersOf(api, name) {
|
|
25842
|
+
const info = await api.capabilities.getCapability.query({ name });
|
|
25843
|
+
if (info === null) throw new Error(`the capability registry did not answer for ${name}`);
|
|
25844
|
+
return info.providers;
|
|
25845
|
+
}
|
|
25846
|
+
/**
|
|
25847
|
+
* The source over `ctx.api`. Every provider of the cap is a holder, not only those that also serve
|
|
25848
|
+
* `integration-instances`: a provider that does not (an addon older than the hub during an update)
|
|
25849
|
+
* then fails `describe` and is reported unreadable, so its instances are retried as transient
|
|
25850
|
+
* instead of vanishing from the catalogue and failing for good.
|
|
25851
|
+
*/
|
|
25852
|
+
function instanceSourceOverApi(api) {
|
|
25853
|
+
return {
|
|
25854
|
+
holders: (cap) => providersOf(api, cap),
|
|
25855
|
+
describe: (addonId) => api.integrationInstances.describe.query({ addonId }),
|
|
25856
|
+
listInstances: (addonId) => api.integrationInstances.listInstances.query({ addonId })
|
|
25857
|
+
};
|
|
25858
|
+
}
|
|
25859
|
+
/**
|
|
25860
|
+
* Notification targets as instances of the function cap `notification-output` (epic #440, step 6).
|
|
25861
|
+
*
|
|
25862
|
+
* A notification target used to be one row of one record kind (`{ name, kind, addonId, enabled,
|
|
25863
|
+
* config }`) with a free-form `config` blob whose secrets nobody could name. Now every target KIND
|
|
25864
|
+
* the provider offers (ntfy, telegram, webhook, ...) is a record kind of its own whose flat body IS
|
|
25865
|
+
* that kind's form: the adapter's `configSchema` lifted into a Zod object, a `password` field marked
|
|
25866
|
+
* `.meta({ secret: true })` so the records door keeps it in the keychain, an `instance-select` field
|
|
25867
|
+
* declared as a link so the hub refuses to delete what a target points at.
|
|
25868
|
+
*
|
|
25869
|
+
* Three providers (notifiers, Home Assistant, Alexa) serve the same shape, so the pieces are shared:
|
|
25870
|
+
* - {@link defineNotificationTargetKind}: the record kind of one `TargetKind` descriptor;
|
|
25871
|
+
* - {@link NotificationTargetStore}: the `Target`-shaped facade the provider's own code keeps
|
|
25872
|
+
* using (send, the notification-center bridge), over one handle per kind;
|
|
25873
|
+
* - {@link listNotificationTargets}: the targets as an addon on `ctx.api` reads them;
|
|
25874
|
+
* - {@link buildNotificationTargetInstances}: the `integration-instances` provider, one kind each;
|
|
25875
|
+
* - {@link moveTargetRows}: the D987 procedure that flattens the old `config` blobs into the bodies.
|
|
25876
|
+
*/
|
|
25877
|
+
/** The function cap every notification target is an instance of. */
|
|
25878
|
+
var NOTIFICATION_OUTPUT_CAP = "notification-output";
|
|
25879
|
+
/** The most targets one provider lists (a settings page, not a table). */
|
|
25880
|
+
var TARGETS_LIST_MAX = 1e3;
|
|
25881
|
+
/** The record kind name of one target kind: `telegram` is stored under `notify-telegram`. */
|
|
25882
|
+
function notificationTargetKindName(kind) {
|
|
25883
|
+
return `notify-${kind}`;
|
|
25884
|
+
}
|
|
25885
|
+
/** The body schema of a target kind: the entry's name and switch plus the adapter's fields. */
|
|
25886
|
+
var TargetBodyBaseSchema = zod.z.looseObject({
|
|
25691
25887
|
name: zod.z.string().min(1),
|
|
25692
25888
|
enabled: zod.z.boolean().optional()
|
|
25693
25889
|
});
|
|
25890
|
+
/** The shape of one `editable-array` row: the item fields, a `password` one a secret. */
|
|
25891
|
+
function rowSchemaOf(itemFields) {
|
|
25892
|
+
const shape = {};
|
|
25893
|
+
let idKey = null;
|
|
25894
|
+
let hasSecret = false;
|
|
25895
|
+
for (const item of itemFields) {
|
|
25896
|
+
if (item.type === "password") {
|
|
25897
|
+
shape[item.key] = zod.z.string().optional().meta({ secret: true });
|
|
25898
|
+
hasSecret = true;
|
|
25899
|
+
continue;
|
|
25900
|
+
}
|
|
25901
|
+
shape[item.key] = zod.z.unknown().optional();
|
|
25902
|
+
idKey ??= item.key;
|
|
25903
|
+
}
|
|
25904
|
+
return {
|
|
25905
|
+
row: zod.z.looseObject(shape),
|
|
25906
|
+
idKey,
|
|
25907
|
+
hasSecret
|
|
25908
|
+
};
|
|
25909
|
+
}
|
|
25910
|
+
/**
|
|
25911
|
+
* The Zod fields of a descriptor's form. A `password` field is a secret; an `instance-select` field is
|
|
25912
|
+
* a link to an instance of its function cap; an `editable-array` keeps its rows (a password inside a
|
|
25913
|
+
* row is a secret matched by the row's first plain field); every other field keeps whatever the
|
|
25914
|
+
* adapter's own parse accepts, because the form already validated its shape. The body is loose, so a key
|
|
25915
|
+
* the schema does not know (the owner of a personal target) survives a write.
|
|
25916
|
+
*/
|
|
25917
|
+
function fieldsOf$1(descriptor) {
|
|
25918
|
+
const shape = {};
|
|
25919
|
+
const secretArrayKeys = {};
|
|
25920
|
+
for (const section of descriptor.configSchema.sections) for (const field of section.fields) switch (field.type) {
|
|
25921
|
+
case "info": break;
|
|
25922
|
+
case "password":
|
|
25923
|
+
shape[field.key] = zod.z.string().optional().meta({ secret: true });
|
|
25924
|
+
break;
|
|
25925
|
+
case "instance-select":
|
|
25926
|
+
shape[field.key] = optionalLinkField({
|
|
25927
|
+
cap: field.functionCap,
|
|
25928
|
+
...field.kind !== void 0 ? { kind: field.kind } : {}
|
|
25929
|
+
});
|
|
25930
|
+
break;
|
|
25931
|
+
case "editable-array": {
|
|
25932
|
+
const { row, idKey, hasSecret } = rowSchemaOf(field.itemFields);
|
|
25933
|
+
shape[field.key] = zod.z.array(row).optional();
|
|
25934
|
+
if (hasSecret && idKey !== null) secretArrayKeys[field.key] = idKey;
|
|
25935
|
+
break;
|
|
25936
|
+
}
|
|
25937
|
+
default: shape[field.key] = zod.z.unknown().optional();
|
|
25938
|
+
}
|
|
25939
|
+
return {
|
|
25940
|
+
shape,
|
|
25941
|
+
secretArrayKeys
|
|
25942
|
+
};
|
|
25943
|
+
}
|
|
25944
|
+
/** The record kind of one target kind, derived from its descriptor. */
|
|
25945
|
+
function defineNotificationTargetKind(descriptor) {
|
|
25946
|
+
const { shape, secretArrayKeys } = fieldsOf$1(descriptor);
|
|
25947
|
+
return defineEntryKind(notificationTargetKindName(descriptor.kind), {
|
|
25948
|
+
title: `${descriptor.label} notification targets`,
|
|
25949
|
+
schema: TargetBodyBaseSchema.extend(shape),
|
|
25950
|
+
writeTrigger: `an operator adds, edits, switches or removes a ${descriptor.label} notification target`,
|
|
25951
|
+
...Object.keys(secretArrayKeys).length > 0 ? { secretArrayKeys } : {}
|
|
25952
|
+
});
|
|
25953
|
+
}
|
|
25954
|
+
/** The record kinds of a provider's descriptors, keyed by the record kind name (for `records.declare`). */
|
|
25955
|
+
function notificationTargetKinds(descriptors) {
|
|
25956
|
+
return Object.fromEntries(descriptors.map((descriptor) => {
|
|
25957
|
+
const defined = defineNotificationTargetKind(descriptor);
|
|
25958
|
+
return [defined.name, defined];
|
|
25959
|
+
}));
|
|
25960
|
+
}
|
|
25961
|
+
/** The body a stored target becomes: the switch and the name, and the config fields flat beside them. */
|
|
25962
|
+
function targetBody(target) {
|
|
25963
|
+
return {
|
|
25964
|
+
...target.config,
|
|
25965
|
+
name: target.name.length > 0 ? target.name : target.id,
|
|
25966
|
+
enabled: target.enabled
|
|
25967
|
+
};
|
|
25968
|
+
}
|
|
25969
|
+
/** The `Target` a record of a kind is; null when the row is not a target. */
|
|
25970
|
+
function targetOfRecord(addonId, kind, id, data) {
|
|
25971
|
+
const { name, enabled: _enabled, ...config } = data;
|
|
25972
|
+
const parsed = TargetSchema.safeParse({
|
|
25973
|
+
id,
|
|
25974
|
+
name,
|
|
25975
|
+
kind,
|
|
25976
|
+
addonId,
|
|
25977
|
+
enabled: isInstanceOn(id),
|
|
25978
|
+
config
|
|
25979
|
+
});
|
|
25980
|
+
return parsed.success ? parsed.data : null;
|
|
25981
|
+
}
|
|
25982
|
+
function targetOfOld(addonId, row) {
|
|
25983
|
+
return {
|
|
25984
|
+
id: row.id,
|
|
25985
|
+
name: row.name,
|
|
25986
|
+
kind: row.kind,
|
|
25987
|
+
addonId,
|
|
25988
|
+
enabled: row.enabled,
|
|
25989
|
+
config: { ...row.config }
|
|
25990
|
+
};
|
|
25991
|
+
}
|
|
25992
|
+
/**
|
|
25993
|
+
* The `Target`-shaped facade over one record kind per target kind. `list` returns the stored form (a
|
|
25994
|
+
* secret is a keychain marker: every reader redacts it anyway); `getById` returns the target with its
|
|
25995
|
+
* secrets resolved, which is what a send, a probe and an edit's secret merge need. A keychain that
|
|
25996
|
+
* cannot answer throws: a write never goes ahead with a secret it could not read (D49).
|
|
25997
|
+
*/
|
|
25998
|
+
var NotificationTargetStore = class NotificationTargetStore {
|
|
25999
|
+
addonId;
|
|
26000
|
+
handles;
|
|
26001
|
+
options;
|
|
26002
|
+
constructor(addonId, handles, options) {
|
|
26003
|
+
this.addonId = addonId;
|
|
26004
|
+
this.handles = handles;
|
|
26005
|
+
this.options = options;
|
|
26006
|
+
}
|
|
26007
|
+
static of(records, addonId, kinds, descriptors, options = {}) {
|
|
26008
|
+
const handles = [];
|
|
26009
|
+
for (const descriptor of descriptors) {
|
|
26010
|
+
const defined = kinds[notificationTargetKindName(descriptor.kind)];
|
|
26011
|
+
if (defined === void 0) continue;
|
|
26012
|
+
handles.push({
|
|
26013
|
+
kind: descriptor.kind,
|
|
26014
|
+
handle: records.kind(defined)
|
|
26015
|
+
});
|
|
26016
|
+
}
|
|
26017
|
+
return new NotificationTargetStore(addonId, handles, options);
|
|
26018
|
+
}
|
|
26019
|
+
/** The record handle of each kind, for the migration ports. */
|
|
26020
|
+
handlesByKind() {
|
|
26021
|
+
return new Map(this.handles.map((entry) => [entry.kind, entry.handle]));
|
|
26022
|
+
}
|
|
26023
|
+
async list() {
|
|
26024
|
+
const out = [];
|
|
26025
|
+
for (const { kind, handle } of this.handles) {
|
|
26026
|
+
const page = await handle.query({ limit: TARGETS_LIST_MAX });
|
|
26027
|
+
for (const record of page.records) {
|
|
26028
|
+
const target = targetOfRecord(this.addonId, kind, record.id, record.data);
|
|
26029
|
+
if (target !== null) {
|
|
26030
|
+
out.push(target);
|
|
26031
|
+
continue;
|
|
26032
|
+
}
|
|
26033
|
+
this.options.logger?.warn("notification target record is not a valid target; left out of the list", { meta: {
|
|
26034
|
+
targetId: record.id,
|
|
26035
|
+
kind
|
|
26036
|
+
} });
|
|
26037
|
+
}
|
|
26038
|
+
}
|
|
26039
|
+
const held = new Set(out.map((target) => target.id));
|
|
26040
|
+
for (const row of await this.legacyRows()) if (!held.has(row.id)) out.push(targetOfOld(this.addonId, row));
|
|
26041
|
+
return out;
|
|
26042
|
+
}
|
|
26043
|
+
/** The legacy rows of a kind this provider serves (the others are not ours to show). */
|
|
26044
|
+
async legacyRows() {
|
|
26045
|
+
const legacy = this.options.legacy;
|
|
26046
|
+
if (legacy === void 0) return [];
|
|
26047
|
+
const served = new Set(this.handles.map((entry) => entry.kind));
|
|
26048
|
+
return (await legacy.list()).filter((row) => served.has(row.kind));
|
|
26049
|
+
}
|
|
26050
|
+
async getById(id) {
|
|
26051
|
+
for (const { kind, handle } of this.handles) {
|
|
26052
|
+
const row = await handle.getResolved(id);
|
|
26053
|
+
if (row !== null) return targetOfRecord(this.addonId, kind, row.id, row.data);
|
|
26054
|
+
}
|
|
26055
|
+
const old = (await this.legacyRows()).find((row) => row.id === id);
|
|
26056
|
+
return old === void 0 ? null : targetOfOld(this.addonId, old);
|
|
26057
|
+
}
|
|
26058
|
+
/** Insert or replace by id; a target whose kind changed leaves the record of its old kind. */
|
|
26059
|
+
async upsert(target) {
|
|
26060
|
+
const own = this.handles.find((entry) => entry.kind === target.kind);
|
|
26061
|
+
if (own === void 0) throw new Error(`invalid target '${target.id}': unknown kind '${target.kind}'`);
|
|
26062
|
+
const { enabled: _switch, ...data } = targetBody(target);
|
|
26063
|
+
await own.handle.put({
|
|
26064
|
+
id: target.id,
|
|
26065
|
+
data
|
|
26066
|
+
});
|
|
26067
|
+
recordInstanceSwitch(target.id, target.enabled);
|
|
26068
|
+
for (const other of this.handles) if (other !== own) await other.handle.delete(target.id);
|
|
26069
|
+
await this.options.legacy?.delete(target.id);
|
|
26070
|
+
}
|
|
26071
|
+
async delete(id) {
|
|
26072
|
+
for (const { handle } of this.handles) await handle.delete(id);
|
|
26073
|
+
await this.options.legacy?.delete(id);
|
|
26074
|
+
}
|
|
26075
|
+
};
|
|
26076
|
+
/**
|
|
26077
|
+
* A probe's answer as the tri-state of `testInstance`: `ok` validated; a refusal that carries an HTTP
|
|
26078
|
+
* status is the remote saying no (`rejected`); a failure with no answer at all (the network, a missing
|
|
26079
|
+
* field) proves nothing about the credentials (`inconclusive`).
|
|
26080
|
+
*/
|
|
26081
|
+
function probeToTestResult(probed) {
|
|
26082
|
+
if (probed.ok) return {
|
|
26083
|
+
success: true,
|
|
26084
|
+
status: "validated",
|
|
26085
|
+
...probed.stateInstance !== void 0 ? { detail: probed.stateInstance } : {}
|
|
26086
|
+
};
|
|
26087
|
+
const error = probed.error ?? "the probe failed";
|
|
26088
|
+
return {
|
|
26089
|
+
success: false,
|
|
26090
|
+
status: probed.httpStatus !== void 0 ? "rejected" : "inconclusive",
|
|
26091
|
+
error
|
|
26092
|
+
};
|
|
26093
|
+
}
|
|
26094
|
+
/** The form of a kind: the adapter's own sections. */
|
|
26095
|
+
function formOf(descriptor) {
|
|
26096
|
+
return descriptor.configSchema;
|
|
26097
|
+
}
|
|
26098
|
+
/** The instance kinds of a notification provider, one per target kind: a part a composition can take. */
|
|
26099
|
+
function notificationTargetParts(records, spec) {
|
|
26100
|
+
return spec.descriptors.flatMap((descriptor) => {
|
|
26101
|
+
const defined = spec.kinds[notificationTargetKindName(descriptor.kind)];
|
|
26102
|
+
if (defined === void 0) return [];
|
|
26103
|
+
const canTest = spec.probe !== void 0 && spec.canProbe(descriptor.kind);
|
|
26104
|
+
const kind = {
|
|
26105
|
+
id: descriptor.kind,
|
|
26106
|
+
label: descriptor.label,
|
|
26107
|
+
functionCap: NOTIFICATION_OUTPUT_CAP,
|
|
26108
|
+
role: "services",
|
|
26109
|
+
canTest,
|
|
26110
|
+
...spec.widgets?.(descriptor.kind) !== void 0 ? { widgets: spec.widgets(descriptor.kind) } : {},
|
|
26111
|
+
...descriptor.iconUrl !== void 0 ? { iconUrl: descriptor.iconUrl } : {},
|
|
26112
|
+
...descriptor.iconMediaType !== void 0 ? { iconMediaType: descriptor.iconMediaType } : {}
|
|
26113
|
+
};
|
|
26114
|
+
return [{
|
|
26115
|
+
kind,
|
|
26116
|
+
provider: new RecordIntegrationInstances(records, defined, {
|
|
26117
|
+
description: {
|
|
26118
|
+
role: "services",
|
|
26119
|
+
instanceMode: "multiple",
|
|
26120
|
+
kind: "target",
|
|
26121
|
+
canTest,
|
|
26122
|
+
kinds: [kind]
|
|
26123
|
+
},
|
|
26124
|
+
formSchema: () => formOf(descriptor),
|
|
26125
|
+
initialBody: (name) => ({ name }),
|
|
26126
|
+
mintId: () => spec.mintId(),
|
|
26127
|
+
configured: () => true,
|
|
26128
|
+
validateWrite: ({ body }) => spec.validate?.({
|
|
26129
|
+
kind: descriptor.kind,
|
|
26130
|
+
config: body
|
|
26131
|
+
}),
|
|
26132
|
+
test: async ({ id, values }) => {
|
|
26133
|
+
if (spec.probe === void 0 || !canTest) return {
|
|
26134
|
+
success: false,
|
|
26135
|
+
status: "unsupported",
|
|
26136
|
+
error: "This kind cannot be tested"
|
|
26137
|
+
};
|
|
26138
|
+
return probeToTestResult(await spec.probe({
|
|
26139
|
+
kind: descriptor.kind,
|
|
26140
|
+
config: values,
|
|
26141
|
+
targetId: id ?? void 0
|
|
26142
|
+
}));
|
|
26143
|
+
}
|
|
26144
|
+
}).toProvider()
|
|
26145
|
+
}];
|
|
26146
|
+
});
|
|
26147
|
+
}
|
|
26148
|
+
/** The `integration-instances` provider of a notification provider: one kind per target kind. */
|
|
26149
|
+
function buildNotificationTargetInstances(records, spec) {
|
|
26150
|
+
const parts = notificationTargetParts(records, spec);
|
|
26151
|
+
return composeInstanceKinds(parts, {
|
|
26152
|
+
role: "services",
|
|
26153
|
+
instanceMode: "multiple",
|
|
26154
|
+
kind: "target",
|
|
26155
|
+
canTest: parts.some((part) => part.kind.canTest === true),
|
|
26156
|
+
mintsId: true
|
|
26157
|
+
});
|
|
26158
|
+
}
|
|
25694
26159
|
TargetSchema.omit({ id: true });
|
|
25695
26160
|
/**
|
|
26161
|
+
* Every notification target, read as the instances of `notification-output` (D1013 rule 5). A holder
|
|
26162
|
+
* that could not answer is NAMED in `unreadable`: a caller that acts on a target's absence (drops a
|
|
26163
|
+
* selection, refuses a send) must check it first, because a partial read is not "deleted" (D315, D49).
|
|
26164
|
+
*/
|
|
26165
|
+
async function listNotificationTargets(api) {
|
|
26166
|
+
const { instances, unreadable } = await instancesOfCap(instanceSourceOverApi(api), NOTIFICATION_OUTPUT_CAP);
|
|
26167
|
+
return {
|
|
26168
|
+
targets: instances.map(({ addonId, kind, instance }) => {
|
|
26169
|
+
const owner = instance.formValues["ownerUserId"];
|
|
26170
|
+
return {
|
|
26171
|
+
id: instance.id,
|
|
26172
|
+
name: instance.name,
|
|
26173
|
+
kind: kind.id,
|
|
26174
|
+
addonId,
|
|
26175
|
+
enabled: instance.enabled !== false,
|
|
26176
|
+
...typeof owner === "string" && owner.length > 0 ? { ownerUserId: owner } : {}
|
|
26177
|
+
};
|
|
26178
|
+
}),
|
|
26179
|
+
unreadable
|
|
26180
|
+
};
|
|
26181
|
+
}
|
|
26182
|
+
/**
|
|
25696
26183
|
* Shared video / audio encode profile schemas used by every consumer
|
|
25697
26184
|
* that asks the stream broker to spawn a derived stream
|
|
25698
26185
|
* (WebRTC, HAP, Alexa, custom addons).
|
|
@@ -77076,9 +77563,10 @@ zod.z.object({
|
|
|
77076
77563
|
/** Longest silence a push integration may keep before the core re-reads it and asks it to resubscribe. */
|
|
77077
77564
|
heartbeatMs: zod.z.number().int().positive().optional(),
|
|
77078
77565
|
/**
|
|
77079
|
-
*
|
|
77080
|
-
*
|
|
77081
|
-
*
|
|
77566
|
+
* Changes on every reconnect of the provider's push subscription; any change
|
|
77567
|
+
* makes the core read every device of the integration once (pushes lost while
|
|
77568
|
+
* it was down; events may be dropped, D8). It need not grow: a provider whose
|
|
77569
|
+
* counter restarts with its process is still understood.
|
|
77082
77570
|
*/
|
|
77083
77571
|
connectionEpoch: zod.z.number().int().nonnegative().optional()
|
|
77084
77572
|
});
|
|
@@ -140891,6 +141379,86 @@ function systemEventKindsOfFamily(family) {
|
|
|
140891
141379
|
return NC_SYSTEM_EVENT_KIND_GROUP_SPECS.filter((g) => g.family === family).flatMap((g) => g.kinds);
|
|
140892
141380
|
}
|
|
140893
141381
|
NC_AUDIO_DEFAULTS.hitPercent, NC_AUDIO_DEFAULTS.samplingSeconds;
|
|
141382
|
+
var WEEKDAY_TO_DAY = {
|
|
141383
|
+
Sun: 0,
|
|
141384
|
+
Mon: 1,
|
|
141385
|
+
Tue: 2,
|
|
141386
|
+
Wed: 3,
|
|
141387
|
+
Thu: 4,
|
|
141388
|
+
Fri: 5,
|
|
141389
|
+
Sat: 6
|
|
141390
|
+
};
|
|
141391
|
+
/**
|
|
141392
|
+
* One formatter per timezone, built once (D647 review I4). Constructing an
|
|
141393
|
+
* `Intl.DateTimeFormat` is the expensive part of this function, and a caller
|
|
141394
|
+
* that asks about many instants — a window scan — used to build one per
|
|
141395
|
+
* instant. `null` = an invalid IANA name (the host timezone is used).
|
|
141396
|
+
*/
|
|
141397
|
+
var FORMATTERS = /* @__PURE__ */ new Map();
|
|
141398
|
+
function formatterFor(timezone) {
|
|
141399
|
+
const held = FORMATTERS.get(timezone);
|
|
141400
|
+
if (held !== void 0) return held;
|
|
141401
|
+
let made;
|
|
141402
|
+
try {
|
|
141403
|
+
made = new Intl.DateTimeFormat("en-US", {
|
|
141404
|
+
timeZone: timezone,
|
|
141405
|
+
weekday: "short",
|
|
141406
|
+
hour: "numeric",
|
|
141407
|
+
minute: "numeric",
|
|
141408
|
+
hourCycle: "h23"
|
|
141409
|
+
});
|
|
141410
|
+
} catch {
|
|
141411
|
+
made = null;
|
|
141412
|
+
}
|
|
141413
|
+
FORMATTERS.set(timezone, made);
|
|
141414
|
+
return made;
|
|
141415
|
+
}
|
|
141416
|
+
/** Resolve (weekday, minute-of-day) of `atMs` in the schedule's timezone.
|
|
141417
|
+
* An invalid/unknown IANA name falls back to the host timezone. */
|
|
141418
|
+
function localDayMinute(atMs, timezone) {
|
|
141419
|
+
const d = new Date(atMs);
|
|
141420
|
+
const formatter = timezone !== void 0 ? formatterFor(timezone) : null;
|
|
141421
|
+
if (formatter !== null) try {
|
|
141422
|
+
const parts = formatter.formatToParts(d);
|
|
141423
|
+
let weekday;
|
|
141424
|
+
let hour;
|
|
141425
|
+
let minute;
|
|
141426
|
+
for (const p of parts) if (p.type === "weekday") weekday = p.value;
|
|
141427
|
+
else if (p.type === "hour") hour = Number(p.value);
|
|
141428
|
+
else if (p.type === "minute") minute = Number(p.value);
|
|
141429
|
+
const day = weekday !== void 0 ? WEEKDAY_TO_DAY[weekday] : void 0;
|
|
141430
|
+
if (day !== void 0 && hour !== void 0 && minute !== void 0) return {
|
|
141431
|
+
day,
|
|
141432
|
+
minute: hour * 60 + minute
|
|
141433
|
+
};
|
|
141434
|
+
} catch {}
|
|
141435
|
+
return {
|
|
141436
|
+
day: d.getDay(),
|
|
141437
|
+
minute: d.getHours() * 60 + d.getMinutes()
|
|
141438
|
+
};
|
|
141439
|
+
}
|
|
141440
|
+
/**
|
|
141441
|
+
* Is the schedule active at `atMs`? No schedule = always active. Windows
|
|
141442
|
+
* are OR'd; a window with `startMinute > endMinute` crosses midnight (it
|
|
141443
|
+
* starts on a listed day and spills into the next). `invert` flips the
|
|
141444
|
+
* result (active OUTSIDE the windows).
|
|
141445
|
+
*/
|
|
141446
|
+
function isScheduleActive(schedule, atMs) {
|
|
141447
|
+
if (schedule === void 0) return true;
|
|
141448
|
+
const { day, minute } = localDayMinute(atMs, schedule.timezone);
|
|
141449
|
+
const prevDay = (day + 6) % 7;
|
|
141450
|
+
let inside = false;
|
|
141451
|
+
for (const w of schedule.windows) if (w.startMinute <= w.endMinute) {
|
|
141452
|
+
if (w.days.includes(day) && minute >= w.startMinute && minute < w.endMinute) {
|
|
141453
|
+
inside = true;
|
|
141454
|
+
break;
|
|
141455
|
+
}
|
|
141456
|
+
} else if (w.days.includes(day) && minute >= w.startMinute || w.days.includes(prevDay) && minute < w.endMinute) {
|
|
141457
|
+
inside = true;
|
|
141458
|
+
break;
|
|
141459
|
+
}
|
|
141460
|
+
return schedule.invert === true ? !inside : inside;
|
|
141461
|
+
}
|
|
140894
141462
|
new Set([
|
|
140895
141463
|
"alarm.trigger",
|
|
140896
141464
|
"alarm.disarm",
|
|
@@ -142432,6 +143000,146 @@ function resolveCommandHold(cap, method, args, current, option, shown = current)
|
|
|
142432
143000
|
holdMs: clampHoldMs(option?.holdMs ?? commandHoldMs(cap, method, args))
|
|
142433
143001
|
};
|
|
142434
143002
|
}
|
|
143003
|
+
/**
|
|
143004
|
+
* A notifier group: a notification target whose delivery is a fan-out to other targets (D1071).
|
|
143005
|
+
*
|
|
143006
|
+
* The group is an instance of `notification-output` of the record kind `notify-group`, owned by the
|
|
143007
|
+
* core builtin `core-notifier`. Its body holds a `members` list; each member is a target id plus the
|
|
143008
|
+
* policy that decides whether, and with what content, that member receives a notification.
|
|
143009
|
+
*
|
|
143010
|
+
* Everything here is pure: the schemas, the per-member decision, the content shaping and the clamp to a
|
|
143011
|
+
* member's own capabilities. Delivery, the throttle and the retry ledger live in the builtin.
|
|
143012
|
+
*/
|
|
143013
|
+
/** The target kind a group is. */
|
|
143014
|
+
var NOTIFIER_GROUP_KIND = "group";
|
|
143015
|
+
/** The core builtin that owns groups. */
|
|
143016
|
+
var NOTIFIER_GROUP_ADDON_ID = "core-notifier";
|
|
143017
|
+
/** When a member receives: always, inside a schedule, or while an alarm panel is in a state. */
|
|
143018
|
+
var GroupMemberWhenSchema = zod.z.discriminatedUnion("kind", [
|
|
143019
|
+
zod.z.object({ kind: zod.z.literal("always") }),
|
|
143020
|
+
zod.z.object({
|
|
143021
|
+
kind: zod.z.literal("schedule"),
|
|
143022
|
+
schedule: NcScheduleSchema
|
|
143023
|
+
}),
|
|
143024
|
+
zod.z.object({
|
|
143025
|
+
kind: zod.z.literal("alarm"),
|
|
143026
|
+
deviceId: zod.z.number().int().nonnegative(),
|
|
143027
|
+
states: zod.z.array(AlarmStateSchema).min(1)
|
|
143028
|
+
})
|
|
143029
|
+
]);
|
|
143030
|
+
/**
|
|
143031
|
+
* One member's policy. Every key but `targetId` is optional and means "no restriction" when absent
|
|
143032
|
+
* (never a Zod default: a default does not run on the addon cap path).
|
|
143033
|
+
*/
|
|
143034
|
+
var GroupMemberSchema = zod.z.object({
|
|
143035
|
+
targetId: zod.z.string().min(1),
|
|
143036
|
+
enabled: zod.z.boolean().optional(),
|
|
143037
|
+
when: GroupMemberWhenSchema.optional(),
|
|
143038
|
+
/** Which message fields this member receives. Absent = all of them. */
|
|
143039
|
+
fields: zod.z.array(NotificationFieldSchema).optional(),
|
|
143040
|
+
/** `{{title}}`, `{{body}}`, `{{priority}}` and any `{{key}}` of the notification's metadata. */
|
|
143041
|
+
templates: zod.z.object({
|
|
143042
|
+
title: zod.z.string().optional(),
|
|
143043
|
+
body: zod.z.string().optional()
|
|
143044
|
+
}).optional(),
|
|
143045
|
+
minPriority: zod.z.number().int().min(1).max(5).optional(),
|
|
143046
|
+
/** At most one delivery per window; a burst becomes one. 0 or absent = no throttle. */
|
|
143047
|
+
throttleSec: zod.z.number().int().nonnegative().optional()
|
|
143048
|
+
});
|
|
143049
|
+
/** Read the `members` of a group's config; an unreadable row is counted, never silently dropped. */
|
|
143050
|
+
function groupMembersOf(config) {
|
|
143051
|
+
const rows = config["members"];
|
|
143052
|
+
if (!Array.isArray(rows)) return {
|
|
143053
|
+
members: [],
|
|
143054
|
+
invalid: 0
|
|
143055
|
+
};
|
|
143056
|
+
const members = [];
|
|
143057
|
+
let invalid = 0;
|
|
143058
|
+
for (const row of rows) {
|
|
143059
|
+
const parsed = GroupMemberSchema.safeParse(row);
|
|
143060
|
+
if (parsed.success) members.push(parsed.data);
|
|
143061
|
+
else invalid += 1;
|
|
143062
|
+
}
|
|
143063
|
+
return {
|
|
143064
|
+
members,
|
|
143065
|
+
invalid
|
|
143066
|
+
};
|
|
143067
|
+
}
|
|
143068
|
+
/** The policy of one member that needs no state of the group: enabled, priority, schedule, alarm. */
|
|
143069
|
+
function decideMember(input) {
|
|
143070
|
+
const { member, notification, nowMs } = input;
|
|
143071
|
+
if (member.enabled === false) return {
|
|
143072
|
+
send: false,
|
|
143073
|
+
reason: "member-disabled"
|
|
143074
|
+
};
|
|
143075
|
+
if (member.minPriority !== void 0 && notification.priority < member.minPriority) return {
|
|
143076
|
+
send: false,
|
|
143077
|
+
reason: "below-min-priority"
|
|
143078
|
+
};
|
|
143079
|
+
const when = member.when;
|
|
143080
|
+
if (when?.kind === "schedule" && !isScheduleActive(when.schedule, nowMs)) return {
|
|
143081
|
+
send: false,
|
|
143082
|
+
reason: "schedule-inactive"
|
|
143083
|
+
};
|
|
143084
|
+
if (when?.kind === "alarm") {
|
|
143085
|
+
if (input.alarmState === void 0 || input.alarmState === null) return {
|
|
143086
|
+
send: false,
|
|
143087
|
+
reason: "alarm-unreadable"
|
|
143088
|
+
};
|
|
143089
|
+
if (!when.states.includes(input.alarmState)) return {
|
|
143090
|
+
send: false,
|
|
143091
|
+
reason: "alarm-state"
|
|
143092
|
+
};
|
|
143093
|
+
}
|
|
143094
|
+
return { send: true };
|
|
143095
|
+
}
|
|
143096
|
+
/** `{{name}}` filled from the notification; an unknown name is empty. */
|
|
143097
|
+
function renderMemberTemplate(template, notification) {
|
|
143098
|
+
return template.replace(/\{\{\s*([\w.-]+)\s*\}\}/g, (_match, name) => {
|
|
143099
|
+
if (name === "title") return notification.title ?? "";
|
|
143100
|
+
if (name === "body") return notification.body;
|
|
143101
|
+
if (name === "priority") return String(notification.priority);
|
|
143102
|
+
const value = notification.metadata?.[name];
|
|
143103
|
+
return typeof value === "string" || typeof value === "number" ? String(value) : "";
|
|
143104
|
+
});
|
|
143105
|
+
}
|
|
143106
|
+
/** The notification as this member should receive it: its templates applied, its fields kept. */
|
|
143107
|
+
function shapeForMember(member, notification) {
|
|
143108
|
+
const keep = (field) => member.fields === void 0 || member.fields.includes(field);
|
|
143109
|
+
const title = member.templates?.title !== void 0 ? renderMemberTemplate(member.templates.title, notification) : notification.title;
|
|
143110
|
+
const body = member.templates?.body !== void 0 ? renderMemberTemplate(member.templates.body, notification) : notification.body;
|
|
143111
|
+
const { attachments, actions, sound, clickUrl, ...rest } = notification;
|
|
143112
|
+
return {
|
|
143113
|
+
...rest,
|
|
143114
|
+
body: keep("body") ? body : "",
|
|
143115
|
+
...keep("title") && title !== void 0 ? { title } : { title: void 0 },
|
|
143116
|
+
priority: keep("priority") ? notification.priority : 3,
|
|
143117
|
+
...keep("attachments") && attachments !== void 0 ? { attachments } : {},
|
|
143118
|
+
...keep("actions") && actions !== void 0 ? { actions } : {},
|
|
143119
|
+
...keep("sound") && sound !== void 0 ? { sound } : {},
|
|
143120
|
+
...keep("clickUrl") && clickUrl !== void 0 ? { clickUrl } : {}
|
|
143121
|
+
};
|
|
143122
|
+
}
|
|
143123
|
+
/**
|
|
143124
|
+
* The notification as ONE member's own kind can take it: its text fields, body length, attachment
|
|
143125
|
+
* media types and count, action count, level, sound and click URL. The group's own caps are permissive and only keep the
|
|
143126
|
+
* notification center from stripping a field before the group sees it; a member gets its own limits.
|
|
143127
|
+
*/
|
|
143128
|
+
function clampToCaps(notification, caps) {
|
|
143129
|
+
const { attachments, actions, sound, clickUrl, level, ...rest } = notification;
|
|
143130
|
+
const kept = (attachments ?? []).filter((attachment) => caps.attachments.mediaTypes.includes(attachment.mediaType)).slice(0, caps.attachments.max);
|
|
143131
|
+
const buttons = (actions ?? []).slice(0, caps.actions);
|
|
143132
|
+
return {
|
|
143133
|
+
...rest,
|
|
143134
|
+
body: caps.text?.body === false ? "" : notification.body.slice(0, caps.bodyMaxLen),
|
|
143135
|
+
...caps.text?.title === false || notification.title === void 0 ? { title: void 0 } : { title: notification.title },
|
|
143136
|
+
...kept.length > 0 ? { attachments: kept } : {},
|
|
143137
|
+
...buttons.length > 0 ? { actions: buttons } : {},
|
|
143138
|
+
...level !== void 0 && caps.levels.some((known) => known.id === level) ? { level } : {},
|
|
143139
|
+
...caps.sound && sound !== void 0 ? { sound } : {},
|
|
143140
|
+
...caps.clickUrl && clickUrl !== void 0 ? { clickUrl } : {}
|
|
143141
|
+
};
|
|
143142
|
+
}
|
|
142435
143143
|
//#endregion
|
|
142436
143144
|
Object.defineProperty(exports, "ACTION_RUN_MAX_MS", {
|
|
142437
143145
|
enumerable: true,
|
|
@@ -142505,6 +143213,12 @@ Object.defineProperty(exports, "ActionVariableSchema", {
|
|
|
142505
143213
|
return ActionVariableSchema;
|
|
142506
143214
|
}
|
|
142507
143215
|
});
|
|
143216
|
+
Object.defineProperty(exports, "AlarmPanelStatusSchema", {
|
|
143217
|
+
enumerable: true,
|
|
143218
|
+
get: function() {
|
|
143219
|
+
return AlarmPanelStatusSchema;
|
|
143220
|
+
}
|
|
143221
|
+
});
|
|
142508
143222
|
Object.defineProperty(exports, "AlertSchema", {
|
|
142509
143223
|
enumerable: true,
|
|
142510
143224
|
get: function() {
|
|
@@ -142997,6 +143711,12 @@ Object.defineProperty(exports, "GroupCommandResultSchema", {
|
|
|
142997
143711
|
return GroupCommandResultSchema;
|
|
142998
143712
|
}
|
|
142999
143713
|
});
|
|
143714
|
+
Object.defineProperty(exports, "GroupMemberSchema", {
|
|
143715
|
+
enumerable: true,
|
|
143716
|
+
get: function() {
|
|
143717
|
+
return GroupMemberSchema;
|
|
143718
|
+
}
|
|
143719
|
+
});
|
|
143000
143720
|
Object.defineProperty(exports, "HISTORY_CATALOG", {
|
|
143001
143721
|
enumerable: true,
|
|
143002
143722
|
get: function() {
|
|
@@ -143171,6 +143891,18 @@ Object.defineProperty(exports, "MigrationMetaSchema", {
|
|
|
143171
143891
|
return MigrationMetaSchema;
|
|
143172
143892
|
}
|
|
143173
143893
|
});
|
|
143894
|
+
Object.defineProperty(exports, "NOTIFIER_GROUP_ADDON_ID", {
|
|
143895
|
+
enumerable: true,
|
|
143896
|
+
get: function() {
|
|
143897
|
+
return NOTIFIER_GROUP_ADDON_ID;
|
|
143898
|
+
}
|
|
143899
|
+
});
|
|
143900
|
+
Object.defineProperty(exports, "NOTIFIER_GROUP_KIND", {
|
|
143901
|
+
enumerable: true,
|
|
143902
|
+
get: function() {
|
|
143903
|
+
return NOTIFIER_GROUP_KIND;
|
|
143904
|
+
}
|
|
143905
|
+
});
|
|
143174
143906
|
Object.defineProperty(exports, "NcTaggedRuleKindSchema", {
|
|
143175
143907
|
enumerable: true,
|
|
143176
143908
|
get: function() {
|
|
@@ -143189,6 +143921,12 @@ Object.defineProperty(exports, "NoCallerError", {
|
|
|
143189
143921
|
return NoCallerError;
|
|
143190
143922
|
}
|
|
143191
143923
|
});
|
|
143924
|
+
Object.defineProperty(exports, "NotificationTargetStore", {
|
|
143925
|
+
enumerable: true,
|
|
143926
|
+
get: function() {
|
|
143927
|
+
return NotificationTargetStore;
|
|
143928
|
+
}
|
|
143929
|
+
});
|
|
143192
143930
|
Object.defineProperty(exports, "ONE_SHOT_HOLD_MS", {
|
|
143193
143931
|
enumerable: true,
|
|
143194
143932
|
get: function() {
|
|
@@ -143765,6 +144503,12 @@ Object.defineProperty(exports, "buildHeroModel", {
|
|
|
143765
144503
|
return buildHeroModel;
|
|
143766
144504
|
}
|
|
143767
144505
|
});
|
|
144506
|
+
Object.defineProperty(exports, "buildNotificationTargetInstances", {
|
|
144507
|
+
enumerable: true,
|
|
144508
|
+
get: function() {
|
|
144509
|
+
return buildNotificationTargetInstances;
|
|
144510
|
+
}
|
|
144511
|
+
});
|
|
143768
144512
|
Object.defineProperty(exports, "buildSecretRef", {
|
|
143769
144513
|
enumerable: true,
|
|
143770
144514
|
get: function() {
|
|
@@ -143855,6 +144599,12 @@ Object.defineProperty(exports, "checkTemplatePayload", {
|
|
|
143855
144599
|
return checkTemplatePayload;
|
|
143856
144600
|
}
|
|
143857
144601
|
});
|
|
144602
|
+
Object.defineProperty(exports, "clampToCaps", {
|
|
144603
|
+
enumerable: true,
|
|
144604
|
+
get: function() {
|
|
144605
|
+
return clampToCaps;
|
|
144606
|
+
}
|
|
144607
|
+
});
|
|
143858
144608
|
Object.defineProperty(exports, "climateControlCapability", {
|
|
143859
144609
|
enumerable: true,
|
|
143860
144610
|
get: function() {
|
|
@@ -144095,6 +144845,12 @@ Object.defineProperty(exports, "databaseSnapshotCapability", {
|
|
|
144095
144845
|
return databaseSnapshotCapability;
|
|
144096
144846
|
}
|
|
144097
144847
|
});
|
|
144848
|
+
Object.defineProperty(exports, "decideMember", {
|
|
144849
|
+
enumerable: true,
|
|
144850
|
+
get: function() {
|
|
144851
|
+
return decideMember;
|
|
144852
|
+
}
|
|
144853
|
+
});
|
|
144098
144854
|
Object.defineProperty(exports, "declarationOwnerNodeId", {
|
|
144099
144855
|
enumerable: true,
|
|
144100
144856
|
get: function() {
|
|
@@ -144467,6 +145223,12 @@ Object.defineProperty(exports, "groupCommandsCapability", {
|
|
|
144467
145223
|
return groupCommandsCapability;
|
|
144468
145224
|
}
|
|
144469
145225
|
});
|
|
145226
|
+
Object.defineProperty(exports, "groupMembersOf", {
|
|
145227
|
+
enumerable: true,
|
|
145228
|
+
get: function() {
|
|
145229
|
+
return groupMembersOf;
|
|
145230
|
+
}
|
|
145231
|
+
});
|
|
144470
145232
|
Object.defineProperty(exports, "groupTemplate", {
|
|
144471
145233
|
enumerable: true,
|
|
144472
145234
|
get: function() {
|
|
@@ -144809,6 +145571,12 @@ Object.defineProperty(exports, "lifecycleJobSchema", {
|
|
|
144809
145571
|
return lifecycleJobSchema;
|
|
144810
145572
|
}
|
|
144811
145573
|
});
|
|
145574
|
+
Object.defineProperty(exports, "listNotificationTargets", {
|
|
145575
|
+
enumerable: true,
|
|
145576
|
+
get: function() {
|
|
145577
|
+
return listNotificationTargets;
|
|
145578
|
+
}
|
|
145579
|
+
});
|
|
144812
145580
|
Object.defineProperty(exports, "localDateOf", {
|
|
144813
145581
|
enumerable: true,
|
|
144814
145582
|
get: function() {
|
|
@@ -145019,6 +145787,18 @@ Object.defineProperty(exports, "normalizeUnit", {
|
|
|
145019
145787
|
return normalizeUnit;
|
|
145020
145788
|
}
|
|
145021
145789
|
});
|
|
145790
|
+
Object.defineProperty(exports, "notificationOutputCapability", {
|
|
145791
|
+
enumerable: true,
|
|
145792
|
+
get: function() {
|
|
145793
|
+
return notificationOutputCapability;
|
|
145794
|
+
}
|
|
145795
|
+
});
|
|
145796
|
+
Object.defineProperty(exports, "notificationTargetKinds", {
|
|
145797
|
+
enumerable: true,
|
|
145798
|
+
get: function() {
|
|
145799
|
+
return notificationTargetKinds;
|
|
145800
|
+
}
|
|
145801
|
+
});
|
|
145022
145802
|
Object.defineProperty(exports, "objectInputDeclaresAddonId", {
|
|
145023
145803
|
enumerable: true,
|
|
145024
145804
|
get: function() {
|
|
@@ -145529,6 +146309,12 @@ Object.defineProperty(exports, "settleDeviceFeatures", {
|
|
|
145529
146309
|
return settleDeviceFeatures;
|
|
145530
146310
|
}
|
|
145531
146311
|
});
|
|
146312
|
+
Object.defineProperty(exports, "shapeForMember", {
|
|
146313
|
+
enumerable: true,
|
|
146314
|
+
get: function() {
|
|
146315
|
+
return shapeForMember;
|
|
146316
|
+
}
|
|
146317
|
+
});
|
|
145532
146318
|
Object.defineProperty(exports, "sharedActuatorFeatures", {
|
|
145533
146319
|
enumerable: true,
|
|
145534
146320
|
get: function() {
|