@camstack/addon-advanced-notifier 1.1.14 → 1.1.15
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/dist/addon.js +132 -102
- package/dist/addon.mjs +133 -103
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/addon.js
CHANGED
|
@@ -21503,42 +21503,120 @@ object({
|
|
|
21503
21503
|
schemaVersion: literal(1)
|
|
21504
21504
|
});
|
|
21505
21505
|
//#endregion
|
|
21506
|
-
//#region src/
|
|
21506
|
+
//#region src/history/audit-log.ts
|
|
21507
21507
|
var COLLECTION$1 = "addon-settings";
|
|
21508
|
-
var
|
|
21509
|
-
var
|
|
21508
|
+
var LOG_KEY = "notifier-history:log";
|
|
21509
|
+
var AuditLog = class {
|
|
21510
21510
|
api;
|
|
21511
|
-
|
|
21511
|
+
maxEntries;
|
|
21512
|
+
constructor(api, maxEntries = 1e3) {
|
|
21512
21513
|
this.api = api;
|
|
21514
|
+
this.maxEntries = maxEntries;
|
|
21513
21515
|
}
|
|
21514
|
-
async
|
|
21516
|
+
async record(entry) {
|
|
21517
|
+
const updated = [...await this.getAll(), entry];
|
|
21518
|
+
const trimmed = updated.length > this.maxEntries ? updated.slice(updated.length - this.maxEntries) : updated;
|
|
21519
|
+
await this.api.settingsStore.set.mutate({
|
|
21520
|
+
collection: COLLECTION$1,
|
|
21521
|
+
key: LOG_KEY,
|
|
21522
|
+
value: trimmed
|
|
21523
|
+
});
|
|
21524
|
+
}
|
|
21525
|
+
async getHistory(filter) {
|
|
21526
|
+
let entries = await this.getAll();
|
|
21527
|
+
if (filter?.ruleId) entries = entries.filter((e) => e.ruleId === filter.ruleId);
|
|
21528
|
+
if (filter?.deviceId) {
|
|
21529
|
+
const deviceId = filter.deviceId;
|
|
21530
|
+
entries = entries.filter((e) => e.deviceId === deviceId);
|
|
21531
|
+
}
|
|
21532
|
+
if (filter?.from !== void 0) {
|
|
21533
|
+
const from = filter.from;
|
|
21534
|
+
entries = entries.filter((e) => e.timestamp >= from);
|
|
21535
|
+
}
|
|
21536
|
+
if (filter?.to !== void 0) {
|
|
21537
|
+
const to = filter.to;
|
|
21538
|
+
entries = entries.filter((e) => e.timestamp <= to);
|
|
21539
|
+
}
|
|
21540
|
+
if (filter?.limit) entries = entries.slice(-filter.limit);
|
|
21541
|
+
return entries;
|
|
21542
|
+
}
|
|
21543
|
+
async getAll() {
|
|
21515
21544
|
const raw = await this.api.settingsStore.get.query({
|
|
21516
21545
|
collection: COLLECTION$1,
|
|
21517
|
-
key:
|
|
21546
|
+
key: LOG_KEY
|
|
21518
21547
|
});
|
|
21519
21548
|
if (!raw || !Array.isArray(raw)) return [];
|
|
21520
21549
|
return raw;
|
|
21521
21550
|
}
|
|
21522
|
-
|
|
21523
|
-
|
|
21524
|
-
|
|
21525
|
-
|
|
21526
|
-
|
|
21551
|
+
};
|
|
21552
|
+
//#endregion
|
|
21553
|
+
//#region src/outputs/console.ts
|
|
21554
|
+
var ConsoleOutput = class {
|
|
21555
|
+
id = "console";
|
|
21556
|
+
name = "Console Log";
|
|
21557
|
+
icon = "terminal";
|
|
21558
|
+
logger;
|
|
21559
|
+
constructor(logger) {
|
|
21560
|
+
this.logger = logger;
|
|
21561
|
+
}
|
|
21562
|
+
async send(notification) {
|
|
21563
|
+
this.logger.info(`[p${notification.priority}] ${notification.title ?? ""}: ${notification.body}`, notification.deviceId !== void 0 ? { tags: { deviceId: notification.deviceId } } : void 0);
|
|
21564
|
+
}
|
|
21565
|
+
async sendTest() {
|
|
21566
|
+
await this.send({
|
|
21567
|
+
title: "Test",
|
|
21568
|
+
body: "Console output working",
|
|
21569
|
+
format: "text",
|
|
21570
|
+
priority: 3
|
|
21527
21571
|
});
|
|
21572
|
+
return { success: true };
|
|
21528
21573
|
}
|
|
21529
|
-
|
|
21530
|
-
|
|
21531
|
-
|
|
21532
|
-
|
|
21533
|
-
|
|
21534
|
-
|
|
21574
|
+
};
|
|
21575
|
+
//#endregion
|
|
21576
|
+
//#region src/rules/cooldown.ts
|
|
21577
|
+
var CooldownTracker = class {
|
|
21578
|
+
lastFired = /* @__PURE__ */ new Map();
|
|
21579
|
+
canFire(ruleId, cooldownSeconds) {
|
|
21580
|
+
const last = this.lastFired.get(ruleId);
|
|
21581
|
+
if (last === void 0) return true;
|
|
21582
|
+
return (Date.now() - last) / 1e3 >= cooldownSeconds;
|
|
21535
21583
|
}
|
|
21536
|
-
|
|
21537
|
-
|
|
21538
|
-
|
|
21584
|
+
recordFire(ruleId) {
|
|
21585
|
+
this.lastFired.set(ruleId, Date.now());
|
|
21586
|
+
}
|
|
21587
|
+
reset() {
|
|
21588
|
+
this.lastFired.clear();
|
|
21539
21589
|
}
|
|
21540
21590
|
};
|
|
21541
21591
|
//#endregion
|
|
21592
|
+
//#region src/rules/recent-events.ts
|
|
21593
|
+
/**
|
|
21594
|
+
* Rehydrate serialized recent events into `SystemEvent`s and drop any that
|
|
21595
|
+
* fall before `since`. Order is preserved (the hub returns oldest → newest).
|
|
21596
|
+
*/
|
|
21597
|
+
function reconstructRecentEvents(serialized, since) {
|
|
21598
|
+
const sinceMs = since.getTime();
|
|
21599
|
+
const events = [];
|
|
21600
|
+
for (const e of serialized) {
|
|
21601
|
+
const timestamp = new Date(e.timestamp);
|
|
21602
|
+
if (timestamp.getTime() < sinceMs) continue;
|
|
21603
|
+
events.push({
|
|
21604
|
+
id: e.id,
|
|
21605
|
+
timestamp,
|
|
21606
|
+
source: {
|
|
21607
|
+
type: e.source.type,
|
|
21608
|
+
id: e.source.id,
|
|
21609
|
+
...e.source.nodeId !== void 0 ? { nodeId: e.source.nodeId } : {},
|
|
21610
|
+
...e.source.addonId !== void 0 ? { addonId: e.source.addonId } : {},
|
|
21611
|
+
...e.source.deviceId !== void 0 ? { deviceId: e.source.deviceId } : {}
|
|
21612
|
+
},
|
|
21613
|
+
category: e.category,
|
|
21614
|
+
data: e.data
|
|
21615
|
+
});
|
|
21616
|
+
}
|
|
21617
|
+
return events;
|
|
21618
|
+
}
|
|
21619
|
+
//#endregion
|
|
21542
21620
|
//#region src/rules/rule-engine.ts
|
|
21543
21621
|
var RuleEngine = class {
|
|
21544
21622
|
clip;
|
|
@@ -21611,19 +21689,39 @@ var RuleEngine = class {
|
|
|
21611
21689
|
}
|
|
21612
21690
|
};
|
|
21613
21691
|
//#endregion
|
|
21614
|
-
//#region src/rules/
|
|
21615
|
-
var
|
|
21616
|
-
|
|
21617
|
-
|
|
21618
|
-
|
|
21619
|
-
|
|
21620
|
-
|
|
21692
|
+
//#region src/rules/rule-store.ts
|
|
21693
|
+
var COLLECTION = "addon-settings";
|
|
21694
|
+
var KEY = "advanced-notifier:rules";
|
|
21695
|
+
var RuleStore = class {
|
|
21696
|
+
api;
|
|
21697
|
+
constructor(api) {
|
|
21698
|
+
this.api = api;
|
|
21621
21699
|
}
|
|
21622
|
-
|
|
21623
|
-
this.
|
|
21700
|
+
async getRules() {
|
|
21701
|
+
const raw = await this.api.settingsStore.get.query({
|
|
21702
|
+
collection: COLLECTION,
|
|
21703
|
+
key: KEY
|
|
21704
|
+
});
|
|
21705
|
+
if (!raw || !Array.isArray(raw)) return [];
|
|
21706
|
+
return raw;
|
|
21624
21707
|
}
|
|
21625
|
-
|
|
21626
|
-
this.
|
|
21708
|
+
async saveRules(rules) {
|
|
21709
|
+
await this.api.settingsStore.set.mutate({
|
|
21710
|
+
collection: COLLECTION,
|
|
21711
|
+
key: KEY,
|
|
21712
|
+
value: [...rules]
|
|
21713
|
+
});
|
|
21714
|
+
}
|
|
21715
|
+
async upsertRule(rule) {
|
|
21716
|
+
const rules = await this.getRules();
|
|
21717
|
+
const idx = rules.findIndex((r) => r.id === rule.id);
|
|
21718
|
+
if (idx >= 0) rules[idx] = rule;
|
|
21719
|
+
else rules.push(rule);
|
|
21720
|
+
await this.saveRules(rules);
|
|
21721
|
+
}
|
|
21722
|
+
async deleteRule(ruleId) {
|
|
21723
|
+
const rules = await this.getRules();
|
|
21724
|
+
await this.saveRules(rules.filter((r) => r.id !== ruleId));
|
|
21627
21725
|
}
|
|
21628
21726
|
};
|
|
21629
21727
|
//#endregion
|
|
@@ -21635,76 +21733,6 @@ function renderTemplate(template, variables) {
|
|
|
21635
21733
|
});
|
|
21636
21734
|
}
|
|
21637
21735
|
//#endregion
|
|
21638
|
-
//#region src/outputs/console.ts
|
|
21639
|
-
var ConsoleOutput = class {
|
|
21640
|
-
id = "console";
|
|
21641
|
-
name = "Console Log";
|
|
21642
|
-
icon = "terminal";
|
|
21643
|
-
logger;
|
|
21644
|
-
constructor(logger) {
|
|
21645
|
-
this.logger = logger;
|
|
21646
|
-
}
|
|
21647
|
-
async send(notification) {
|
|
21648
|
-
this.logger.info(`[p${notification.priority}] ${notification.title ?? ""}: ${notification.body}`, notification.deviceId !== void 0 ? { tags: { deviceId: notification.deviceId } } : void 0);
|
|
21649
|
-
}
|
|
21650
|
-
async sendTest() {
|
|
21651
|
-
await this.send({
|
|
21652
|
-
title: "Test",
|
|
21653
|
-
body: "Console output working",
|
|
21654
|
-
format: "text",
|
|
21655
|
-
priority: 3
|
|
21656
|
-
});
|
|
21657
|
-
return { success: true };
|
|
21658
|
-
}
|
|
21659
|
-
};
|
|
21660
|
-
//#endregion
|
|
21661
|
-
//#region src/history/audit-log.ts
|
|
21662
|
-
var COLLECTION = "addon-settings";
|
|
21663
|
-
var LOG_KEY = "notifier-history:log";
|
|
21664
|
-
var AuditLog = class {
|
|
21665
|
-
api;
|
|
21666
|
-
maxEntries;
|
|
21667
|
-
constructor(api, maxEntries = 1e3) {
|
|
21668
|
-
this.api = api;
|
|
21669
|
-
this.maxEntries = maxEntries;
|
|
21670
|
-
}
|
|
21671
|
-
async record(entry) {
|
|
21672
|
-
const updated = [...await this.getAll(), entry];
|
|
21673
|
-
const trimmed = updated.length > this.maxEntries ? updated.slice(updated.length - this.maxEntries) : updated;
|
|
21674
|
-
await this.api.settingsStore.set.mutate({
|
|
21675
|
-
collection: COLLECTION,
|
|
21676
|
-
key: LOG_KEY,
|
|
21677
|
-
value: trimmed
|
|
21678
|
-
});
|
|
21679
|
-
}
|
|
21680
|
-
async getHistory(filter) {
|
|
21681
|
-
let entries = await this.getAll();
|
|
21682
|
-
if (filter?.ruleId) entries = entries.filter((e) => e.ruleId === filter.ruleId);
|
|
21683
|
-
if (filter?.deviceId) {
|
|
21684
|
-
const deviceId = filter.deviceId;
|
|
21685
|
-
entries = entries.filter((e) => e.deviceId === deviceId);
|
|
21686
|
-
}
|
|
21687
|
-
if (filter?.from !== void 0) {
|
|
21688
|
-
const from = filter.from;
|
|
21689
|
-
entries = entries.filter((e) => e.timestamp >= from);
|
|
21690
|
-
}
|
|
21691
|
-
if (filter?.to !== void 0) {
|
|
21692
|
-
const to = filter.to;
|
|
21693
|
-
entries = entries.filter((e) => e.timestamp <= to);
|
|
21694
|
-
}
|
|
21695
|
-
if (filter?.limit) entries = entries.slice(-filter.limit);
|
|
21696
|
-
return entries;
|
|
21697
|
-
}
|
|
21698
|
-
async getAll() {
|
|
21699
|
-
const raw = await this.api.settingsStore.get.query({
|
|
21700
|
-
collection: COLLECTION,
|
|
21701
|
-
key: LOG_KEY
|
|
21702
|
-
});
|
|
21703
|
-
if (!raw || !Array.isArray(raw)) return [];
|
|
21704
|
-
return raw;
|
|
21705
|
-
}
|
|
21706
|
-
};
|
|
21707
|
-
//#endregion
|
|
21708
21736
|
//#region src/addon.ts
|
|
21709
21737
|
var EVENT_CATEGORIES = [
|
|
21710
21738
|
EventCategory.DetectionRaw,
|
|
@@ -21756,7 +21784,9 @@ var AdvancedNotifierAddon = class extends BaseAddon {
|
|
|
21756
21784
|
const rule = this.cachedRules.find((r) => r.id === ruleId);
|
|
21757
21785
|
if (!rule) return { results: [] };
|
|
21758
21786
|
const since = /* @__PURE__ */ new Date(Date.now() - lookbackMinutes * 60 * 1e3);
|
|
21759
|
-
|
|
21787
|
+
const api = this.ctx.api;
|
|
21788
|
+
if (!api) return { results: [] };
|
|
21789
|
+
return { results: reconstructRecentEvents(await api.eventBusProxy.getRecent.query({ limit: 1e3 }), since).map((event) => {
|
|
21760
21790
|
const matched = this.ruleEngine.evaluate(event, [rule]);
|
|
21761
21791
|
return {
|
|
21762
21792
|
ruleId,
|
package/dist/addon.mjs
CHANGED
|
@@ -21499,42 +21499,120 @@ object({
|
|
|
21499
21499
|
schemaVersion: literal(1)
|
|
21500
21500
|
});
|
|
21501
21501
|
//#endregion
|
|
21502
|
-
//#region src/
|
|
21502
|
+
//#region src/history/audit-log.ts
|
|
21503
21503
|
var COLLECTION$1 = "addon-settings";
|
|
21504
|
-
var
|
|
21505
|
-
var
|
|
21504
|
+
var LOG_KEY = "notifier-history:log";
|
|
21505
|
+
var AuditLog = class {
|
|
21506
21506
|
api;
|
|
21507
|
-
|
|
21507
|
+
maxEntries;
|
|
21508
|
+
constructor(api, maxEntries = 1e3) {
|
|
21508
21509
|
this.api = api;
|
|
21510
|
+
this.maxEntries = maxEntries;
|
|
21509
21511
|
}
|
|
21510
|
-
async
|
|
21512
|
+
async record(entry) {
|
|
21513
|
+
const updated = [...await this.getAll(), entry];
|
|
21514
|
+
const trimmed = updated.length > this.maxEntries ? updated.slice(updated.length - this.maxEntries) : updated;
|
|
21515
|
+
await this.api.settingsStore.set.mutate({
|
|
21516
|
+
collection: COLLECTION$1,
|
|
21517
|
+
key: LOG_KEY,
|
|
21518
|
+
value: trimmed
|
|
21519
|
+
});
|
|
21520
|
+
}
|
|
21521
|
+
async getHistory(filter) {
|
|
21522
|
+
let entries = await this.getAll();
|
|
21523
|
+
if (filter?.ruleId) entries = entries.filter((e) => e.ruleId === filter.ruleId);
|
|
21524
|
+
if (filter?.deviceId) {
|
|
21525
|
+
const deviceId = filter.deviceId;
|
|
21526
|
+
entries = entries.filter((e) => e.deviceId === deviceId);
|
|
21527
|
+
}
|
|
21528
|
+
if (filter?.from !== void 0) {
|
|
21529
|
+
const from = filter.from;
|
|
21530
|
+
entries = entries.filter((e) => e.timestamp >= from);
|
|
21531
|
+
}
|
|
21532
|
+
if (filter?.to !== void 0) {
|
|
21533
|
+
const to = filter.to;
|
|
21534
|
+
entries = entries.filter((e) => e.timestamp <= to);
|
|
21535
|
+
}
|
|
21536
|
+
if (filter?.limit) entries = entries.slice(-filter.limit);
|
|
21537
|
+
return entries;
|
|
21538
|
+
}
|
|
21539
|
+
async getAll() {
|
|
21511
21540
|
const raw = await this.api.settingsStore.get.query({
|
|
21512
21541
|
collection: COLLECTION$1,
|
|
21513
|
-
key:
|
|
21542
|
+
key: LOG_KEY
|
|
21514
21543
|
});
|
|
21515
21544
|
if (!raw || !Array.isArray(raw)) return [];
|
|
21516
21545
|
return raw;
|
|
21517
21546
|
}
|
|
21518
|
-
|
|
21519
|
-
|
|
21520
|
-
|
|
21521
|
-
|
|
21522
|
-
|
|
21547
|
+
};
|
|
21548
|
+
//#endregion
|
|
21549
|
+
//#region src/outputs/console.ts
|
|
21550
|
+
var ConsoleOutput = class {
|
|
21551
|
+
id = "console";
|
|
21552
|
+
name = "Console Log";
|
|
21553
|
+
icon = "terminal";
|
|
21554
|
+
logger;
|
|
21555
|
+
constructor(logger) {
|
|
21556
|
+
this.logger = logger;
|
|
21557
|
+
}
|
|
21558
|
+
async send(notification) {
|
|
21559
|
+
this.logger.info(`[p${notification.priority}] ${notification.title ?? ""}: ${notification.body}`, notification.deviceId !== void 0 ? { tags: { deviceId: notification.deviceId } } : void 0);
|
|
21560
|
+
}
|
|
21561
|
+
async sendTest() {
|
|
21562
|
+
await this.send({
|
|
21563
|
+
title: "Test",
|
|
21564
|
+
body: "Console output working",
|
|
21565
|
+
format: "text",
|
|
21566
|
+
priority: 3
|
|
21523
21567
|
});
|
|
21568
|
+
return { success: true };
|
|
21524
21569
|
}
|
|
21525
|
-
|
|
21526
|
-
|
|
21527
|
-
|
|
21528
|
-
|
|
21529
|
-
|
|
21530
|
-
|
|
21570
|
+
};
|
|
21571
|
+
//#endregion
|
|
21572
|
+
//#region src/rules/cooldown.ts
|
|
21573
|
+
var CooldownTracker = class {
|
|
21574
|
+
lastFired = /* @__PURE__ */ new Map();
|
|
21575
|
+
canFire(ruleId, cooldownSeconds) {
|
|
21576
|
+
const last = this.lastFired.get(ruleId);
|
|
21577
|
+
if (last === void 0) return true;
|
|
21578
|
+
return (Date.now() - last) / 1e3 >= cooldownSeconds;
|
|
21531
21579
|
}
|
|
21532
|
-
|
|
21533
|
-
|
|
21534
|
-
|
|
21580
|
+
recordFire(ruleId) {
|
|
21581
|
+
this.lastFired.set(ruleId, Date.now());
|
|
21582
|
+
}
|
|
21583
|
+
reset() {
|
|
21584
|
+
this.lastFired.clear();
|
|
21535
21585
|
}
|
|
21536
21586
|
};
|
|
21537
21587
|
//#endregion
|
|
21588
|
+
//#region src/rules/recent-events.ts
|
|
21589
|
+
/**
|
|
21590
|
+
* Rehydrate serialized recent events into `SystemEvent`s and drop any that
|
|
21591
|
+
* fall before `since`. Order is preserved (the hub returns oldest → newest).
|
|
21592
|
+
*/
|
|
21593
|
+
function reconstructRecentEvents(serialized, since) {
|
|
21594
|
+
const sinceMs = since.getTime();
|
|
21595
|
+
const events = [];
|
|
21596
|
+
for (const e of serialized) {
|
|
21597
|
+
const timestamp = new Date(e.timestamp);
|
|
21598
|
+
if (timestamp.getTime() < sinceMs) continue;
|
|
21599
|
+
events.push({
|
|
21600
|
+
id: e.id,
|
|
21601
|
+
timestamp,
|
|
21602
|
+
source: {
|
|
21603
|
+
type: e.source.type,
|
|
21604
|
+
id: e.source.id,
|
|
21605
|
+
...e.source.nodeId !== void 0 ? { nodeId: e.source.nodeId } : {},
|
|
21606
|
+
...e.source.addonId !== void 0 ? { addonId: e.source.addonId } : {},
|
|
21607
|
+
...e.source.deviceId !== void 0 ? { deviceId: e.source.deviceId } : {}
|
|
21608
|
+
},
|
|
21609
|
+
category: e.category,
|
|
21610
|
+
data: e.data
|
|
21611
|
+
});
|
|
21612
|
+
}
|
|
21613
|
+
return events;
|
|
21614
|
+
}
|
|
21615
|
+
//#endregion
|
|
21538
21616
|
//#region src/rules/rule-engine.ts
|
|
21539
21617
|
var RuleEngine = class {
|
|
21540
21618
|
clip;
|
|
@@ -21607,19 +21685,39 @@ var RuleEngine = class {
|
|
|
21607
21685
|
}
|
|
21608
21686
|
};
|
|
21609
21687
|
//#endregion
|
|
21610
|
-
//#region src/rules/
|
|
21611
|
-
var
|
|
21612
|
-
|
|
21613
|
-
|
|
21614
|
-
|
|
21615
|
-
|
|
21616
|
-
|
|
21688
|
+
//#region src/rules/rule-store.ts
|
|
21689
|
+
var COLLECTION = "addon-settings";
|
|
21690
|
+
var KEY = "advanced-notifier:rules";
|
|
21691
|
+
var RuleStore = class {
|
|
21692
|
+
api;
|
|
21693
|
+
constructor(api) {
|
|
21694
|
+
this.api = api;
|
|
21617
21695
|
}
|
|
21618
|
-
|
|
21619
|
-
this.
|
|
21696
|
+
async getRules() {
|
|
21697
|
+
const raw = await this.api.settingsStore.get.query({
|
|
21698
|
+
collection: COLLECTION,
|
|
21699
|
+
key: KEY
|
|
21700
|
+
});
|
|
21701
|
+
if (!raw || !Array.isArray(raw)) return [];
|
|
21702
|
+
return raw;
|
|
21620
21703
|
}
|
|
21621
|
-
|
|
21622
|
-
this.
|
|
21704
|
+
async saveRules(rules) {
|
|
21705
|
+
await this.api.settingsStore.set.mutate({
|
|
21706
|
+
collection: COLLECTION,
|
|
21707
|
+
key: KEY,
|
|
21708
|
+
value: [...rules]
|
|
21709
|
+
});
|
|
21710
|
+
}
|
|
21711
|
+
async upsertRule(rule) {
|
|
21712
|
+
const rules = await this.getRules();
|
|
21713
|
+
const idx = rules.findIndex((r) => r.id === rule.id);
|
|
21714
|
+
if (idx >= 0) rules[idx] = rule;
|
|
21715
|
+
else rules.push(rule);
|
|
21716
|
+
await this.saveRules(rules);
|
|
21717
|
+
}
|
|
21718
|
+
async deleteRule(ruleId) {
|
|
21719
|
+
const rules = await this.getRules();
|
|
21720
|
+
await this.saveRules(rules.filter((r) => r.id !== ruleId));
|
|
21623
21721
|
}
|
|
21624
21722
|
};
|
|
21625
21723
|
//#endregion
|
|
@@ -21631,76 +21729,6 @@ function renderTemplate(template, variables) {
|
|
|
21631
21729
|
});
|
|
21632
21730
|
}
|
|
21633
21731
|
//#endregion
|
|
21634
|
-
//#region src/outputs/console.ts
|
|
21635
|
-
var ConsoleOutput = class {
|
|
21636
|
-
id = "console";
|
|
21637
|
-
name = "Console Log";
|
|
21638
|
-
icon = "terminal";
|
|
21639
|
-
logger;
|
|
21640
|
-
constructor(logger) {
|
|
21641
|
-
this.logger = logger;
|
|
21642
|
-
}
|
|
21643
|
-
async send(notification) {
|
|
21644
|
-
this.logger.info(`[p${notification.priority}] ${notification.title ?? ""}: ${notification.body}`, notification.deviceId !== void 0 ? { tags: { deviceId: notification.deviceId } } : void 0);
|
|
21645
|
-
}
|
|
21646
|
-
async sendTest() {
|
|
21647
|
-
await this.send({
|
|
21648
|
-
title: "Test",
|
|
21649
|
-
body: "Console output working",
|
|
21650
|
-
format: "text",
|
|
21651
|
-
priority: 3
|
|
21652
|
-
});
|
|
21653
|
-
return { success: true };
|
|
21654
|
-
}
|
|
21655
|
-
};
|
|
21656
|
-
//#endregion
|
|
21657
|
-
//#region src/history/audit-log.ts
|
|
21658
|
-
var COLLECTION = "addon-settings";
|
|
21659
|
-
var LOG_KEY = "notifier-history:log";
|
|
21660
|
-
var AuditLog = class {
|
|
21661
|
-
api;
|
|
21662
|
-
maxEntries;
|
|
21663
|
-
constructor(api, maxEntries = 1e3) {
|
|
21664
|
-
this.api = api;
|
|
21665
|
-
this.maxEntries = maxEntries;
|
|
21666
|
-
}
|
|
21667
|
-
async record(entry) {
|
|
21668
|
-
const updated = [...await this.getAll(), entry];
|
|
21669
|
-
const trimmed = updated.length > this.maxEntries ? updated.slice(updated.length - this.maxEntries) : updated;
|
|
21670
|
-
await this.api.settingsStore.set.mutate({
|
|
21671
|
-
collection: COLLECTION,
|
|
21672
|
-
key: LOG_KEY,
|
|
21673
|
-
value: trimmed
|
|
21674
|
-
});
|
|
21675
|
-
}
|
|
21676
|
-
async getHistory(filter) {
|
|
21677
|
-
let entries = await this.getAll();
|
|
21678
|
-
if (filter?.ruleId) entries = entries.filter((e) => e.ruleId === filter.ruleId);
|
|
21679
|
-
if (filter?.deviceId) {
|
|
21680
|
-
const deviceId = filter.deviceId;
|
|
21681
|
-
entries = entries.filter((e) => e.deviceId === deviceId);
|
|
21682
|
-
}
|
|
21683
|
-
if (filter?.from !== void 0) {
|
|
21684
|
-
const from = filter.from;
|
|
21685
|
-
entries = entries.filter((e) => e.timestamp >= from);
|
|
21686
|
-
}
|
|
21687
|
-
if (filter?.to !== void 0) {
|
|
21688
|
-
const to = filter.to;
|
|
21689
|
-
entries = entries.filter((e) => e.timestamp <= to);
|
|
21690
|
-
}
|
|
21691
|
-
if (filter?.limit) entries = entries.slice(-filter.limit);
|
|
21692
|
-
return entries;
|
|
21693
|
-
}
|
|
21694
|
-
async getAll() {
|
|
21695
|
-
const raw = await this.api.settingsStore.get.query({
|
|
21696
|
-
collection: COLLECTION,
|
|
21697
|
-
key: LOG_KEY
|
|
21698
|
-
});
|
|
21699
|
-
if (!raw || !Array.isArray(raw)) return [];
|
|
21700
|
-
return raw;
|
|
21701
|
-
}
|
|
21702
|
-
};
|
|
21703
|
-
//#endregion
|
|
21704
21732
|
//#region src/addon.ts
|
|
21705
21733
|
var EVENT_CATEGORIES = [
|
|
21706
21734
|
EventCategory.DetectionRaw,
|
|
@@ -21752,7 +21780,9 @@ var AdvancedNotifierAddon = class extends BaseAddon {
|
|
|
21752
21780
|
const rule = this.cachedRules.find((r) => r.id === ruleId);
|
|
21753
21781
|
if (!rule) return { results: [] };
|
|
21754
21782
|
const since = /* @__PURE__ */ new Date(Date.now() - lookbackMinutes * 60 * 1e3);
|
|
21755
|
-
|
|
21783
|
+
const api = this.ctx.api;
|
|
21784
|
+
if (!api) return { results: [] };
|
|
21785
|
+
return { results: reconstructRecentEvents(await api.eventBusProxy.getRecent.query({ limit: 1e3 }), since).map((event) => {
|
|
21756
21786
|
const matched = this.ruleEngine.evaluate(event, [rule]);
|
|
21757
21787
|
return {
|
|
21758
21788
|
ruleId,
|
|
@@ -21980,4 +22010,4 @@ var AdvancedNotifierAddon = class extends BaseAddon {
|
|
|
21980
22010
|
}
|
|
21981
22011
|
};
|
|
21982
22012
|
//#endregion
|
|
21983
|
-
export { AdvancedNotifierAddon, AdvancedNotifierAddon as default,
|
|
22013
|
+
export { AdvancedNotifierAddon, AdvancedNotifierAddon as default, ConsoleOutput as a, CooldownTracker as i, RuleStore as n, AuditLog as o, RuleEngine as r, renderTemplate as t };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AdvancedNotifierAddon, a as
|
|
1
|
+
import { AdvancedNotifierAddon, a as ConsoleOutput, i as CooldownTracker, n as RuleStore, o as AuditLog, r as RuleEngine, t as renderTemplate } from "./addon.mjs";
|
|
2
2
|
//#region src/outputs/http.ts
|
|
3
3
|
/**
|
|
4
4
|
* Outbound HTTP helper for notification outputs.
|