Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@iobroker/js-controller-common

Package Overview
Dependencies
Maintainers
0
Versions
402
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@iobroker/js-controller-common - npm Package Compare versions

Comparing version 6.0.12-alpha.0-20240907-52bf8f589 to 6.0.12-alpha.0-20240911-b159ac233

27

build/cjs/lib/common/notificationHandler.d.ts

@@ -7,2 +7,3 @@ /**

/// <reference types="node" resolution-mode="require"/>
/// <reference types="@iobroker/types-dev" />
import type { Client as StatesInRedisClient } from '@iobroker/db-states-redis';

@@ -32,3 +33,3 @@ import type { Client as ObjectsInRedisClient } from '@iobroker/db-objects-redis';

name: MultilingualObject;
/** `info` will only be shown by admin, while `notify` might also be used by messaging adapters, `alert` ensures both */
/** Allows defining the severity of the notification with `info` being the lowest, `notify` representing middle priority, `alert` representing high priority and often containing critical information */
severity: Severity;

@@ -42,2 +43,3 @@ description: MultilingualObject;

ts: number;
contextData?: ioBroker.NotificationContextData;
}

@@ -62,2 +64,14 @@ export interface FilteredNotificationInformation {

}
interface AddMessageOptions {
/** Scope of the message */
scope: string;
/** Category of the message, if non we check against regex of scope */
category?: string | null;
/** Message to add */
message: string;
/** Instance e.g., hm-rpc.1 or hostname, if hostname it needs to be prefixed like system.host.rpi */
instance: string;
/** Additional context for the notification which can be used by notification processing adapters */
contextData?: ioBroker.NotificationContextData;
}
export declare class NotificationHandler {

@@ -80,3 +94,3 @@ private states;

*
* @param notifications - notifications array
* @param notifications - Array with notifications
*/

@@ -87,8 +101,5 @@ addConfig(notifications: NotificationsConfigEntry[]): Promise<void>;

*
* @param scope - scope of the message
* @param category - category of the message, if non we check against regex of scope
* @param message - message to add
* @param instance - instance e.g., hm-rpc.1 or hostname, if hostname it needs to be prefixed like system.host.rpi
* @param options The scope, category, message, instance and contextData information
*/
addMessage(scope: string, category: string | null | undefined, message: string, instance: string): Promise<void>;
addMessage(options: AddMessageOptions): Promise<void>;
/**

@@ -106,3 +117,3 @@ * Updates all scope states by current notifications in RAM

/**
* Load notifications from file
* Load notifications from a file
*/

@@ -109,0 +120,0 @@ private _loadNotifications;

@@ -53,3 +53,3 @@ "use strict";

try {
obj = await this.objects.getObjectAsync(`system.host.${this.host}.notifications`);
obj = await this.objects.getObject(`system.host.${this.host}.notifications`);
} catch {

@@ -59,3 +59,3 @@ }

try {
await this.objects.setObjectAsync(`system.host.${this.host}.notifications`, {
await this.objects.setObject(`system.host.${this.host}.notifications`, {
type: "folder",

@@ -117,3 +117,3 @@ common: {

try {
obj = await this.objects.getObjectAsync(`system.host.${this.host}.notifications.${scopeObj.scope}`);
obj = await this.objects.getObject(`system.host.${this.host}.notifications.${scopeObj.scope}`);
} catch {

@@ -123,3 +123,3 @@ }

try {
await this.objects.setObjectAsync(`system.host.${this.host}.notifications.${scopeObj.scope}`, {
await this.objects.setObject(`system.host.${this.host}.notifications.${scopeObj.scope}`, {
type: "state",

@@ -172,3 +172,5 @@ common: {

}
async addMessage(scope, category, message, instance) {
async addMessage(options) {
const { message, scope, category, contextData } = options;
let { instance } = options;
if (typeof instance !== "string") {

@@ -204,3 +206,3 @@ this.log.error(`${this.logPrefix} [addMessage] Instance has to be of type "string", got "${typeof instance}"`);

}
this.currentNotifications[scope][_category][instance].unshift({ message, ts: Date.now() });
this.currentNotifications[scope][_category][instance].unshift({ message, ts: Date.now(), contextData });
}

@@ -215,3 +217,3 @@ }

try {
await this.states.setStateAsync(`system.host.${this.host}.notifications.${scope}`, {
await this.states.setState(`system.host.${this.host}.notifications.${scope}`, {
val: JSON.stringify(stateVal),

@@ -278,3 +280,7 @@ ack: true

}
res[scope] = { categories: {}, description: this.setup[scope].description, name: this.setup[scope].name };
res[scope] = {
categories: {},
description: this.setup[scope].description,
name: this.setup[scope].name
};
for (const category of Object.keys(this.currentNotifications[scope])) {

@@ -281,0 +287,0 @@ if (categoryFilter && categoryFilter !== category) {

@@ -7,2 +7,3 @@ /**

/// <reference types="node" resolution-mode="require"/>
/// <reference types="@iobroker/types-dev" />
import type { Client as StatesInRedisClient } from '@iobroker/db-states-redis';

@@ -32,3 +33,3 @@ import type { Client as ObjectsInRedisClient } from '@iobroker/db-objects-redis';

name: MultilingualObject;
/** `info` will only be shown by admin, while `notify` might also be used by messaging adapters, `alert` ensures both */
/** Allows defining the severity of the notification with `info` being the lowest, `notify` representing middle priority, `alert` representing high priority and often containing critical information */
severity: Severity;

@@ -42,2 +43,3 @@ description: MultilingualObject;

ts: number;
contextData?: ioBroker.NotificationContextData;
}

@@ -62,2 +64,14 @@ export interface FilteredNotificationInformation {

}
interface AddMessageOptions {
/** Scope of the message */
scope: string;
/** Category of the message, if non we check against regex of scope */
category?: string | null;
/** Message to add */
message: string;
/** Instance e.g., hm-rpc.1 or hostname, if hostname it needs to be prefixed like system.host.rpi */
instance: string;
/** Additional context for the notification which can be used by notification processing adapters */
contextData?: ioBroker.NotificationContextData;
}
export declare class NotificationHandler {

@@ -80,3 +94,3 @@ private states;

*
* @param notifications - notifications array
* @param notifications - Array with notifications
*/

@@ -87,8 +101,5 @@ addConfig(notifications: NotificationsConfigEntry[]): Promise<void>;

*
* @param scope - scope of the message
* @param category - category of the message, if non we check against regex of scope
* @param message - message to add
* @param instance - instance e.g., hm-rpc.1 or hostname, if hostname it needs to be prefixed like system.host.rpi
* @param options The scope, category, message, instance and contextData information
*/
addMessage(scope: string, category: string | null | undefined, message: string, instance: string): Promise<void>;
addMessage(options: AddMessageOptions): Promise<void>;
/**

@@ -106,3 +117,3 @@ * Updates all scope states by current notifications in RAM

/**
* Load notifications from file
* Load notifications from a file
*/

@@ -109,0 +120,0 @@ private _loadNotifications;

@@ -35,3 +35,3 @@ /**

try {
obj = await this.objects.getObjectAsync(`system.host.${this.host}.notifications`);
obj = await this.objects.getObject(`system.host.${this.host}.notifications`);
}

@@ -43,3 +43,3 @@ catch {

try {
await this.objects.setObjectAsync(`system.host.${this.host}.notifications`, {
await this.objects.setObject(`system.host.${this.host}.notifications`, {
type: 'folder',

@@ -76,3 +76,3 @@ common: {

for (const entry of res.rows) {
// check that instance has notifications settings
// check that instance has notification settings
if (entry.value.notifications) {

@@ -108,3 +108,3 @@ await this.addConfig(entry.value.notifications);

*
* @param notifications - notifications array
* @param notifications - Array with notifications
*/

@@ -118,3 +118,3 @@ async addConfig(notifications) {

try {
obj = await this.objects.getObjectAsync(`system.host.${this.host}.notifications.${scopeObj.scope}`);
obj = await this.objects.getObject(`system.host.${this.host}.notifications.${scopeObj.scope}`);
}

@@ -126,3 +126,3 @@ catch {

try {
await this.objects.setObjectAsync(`system.host.${this.host}.notifications.${scopeObj.scope}`, {
await this.objects.setObject(`system.host.${this.host}.notifications.${scopeObj.scope}`, {
type: 'state',

@@ -185,8 +185,7 @@ common: {

*
* @param scope - scope of the message
* @param category - category of the message, if non we check against regex of scope
* @param message - message to add
* @param instance - instance e.g., hm-rpc.1 or hostname, if hostname it needs to be prefixed like system.host.rpi
* @param options The scope, category, message, instance and contextData information
*/
async addMessage(scope, category, message, instance) {
async addMessage(options) {
const { message, scope, category, contextData } = options;
let { instance } = options;
if (typeof instance !== 'string') {

@@ -221,3 +220,3 @@ this.log.error(`${this.logPrefix} [addMessage] Instance has to be of type "string", got "${typeof instance}"`);

if (!this.setup[scope]?.categories[_category]) {
// no setup for this instance/category combination found - so nothing to add
// no setup for this instance/category combination found - so we have nothing to add
this.log.warn(`${this.logPrefix} No configuration found for scope "${scope}" and category "${_category}"`);

@@ -232,3 +231,3 @@ continue;

// add a new element at the beginning
this.currentNotifications[scope][_category][instance].unshift({ message, ts: Date.now() });
this.currentNotifications[scope][_category][instance].unshift({ message, ts: Date.now(), contextData });
}

@@ -245,3 +244,3 @@ }

try {
await this.states.setStateAsync(`system.host.${this.host}.notifications.${scope}`, {
await this.states.setState(`system.host.${this.host}.notifications.${scope}`, {
val: JSON.stringify(stateVal),

@@ -302,3 +301,3 @@ ack: true

/**
* Load notifications from file
* Load notifications from a file
*/

@@ -343,3 +342,7 @@ _loadNotifications() {

}
res[scope] = { categories: {}, description: this.setup[scope].description, name: this.setup[scope].name };
res[scope] = {
categories: {},
description: this.setup[scope].description,
name: this.setup[scope].name
};
for (const category of Object.keys(this.currentNotifications[scope])) {

@@ -346,0 +349,0 @@ if (categoryFilter && categoryFilter !== category) {

{
"name": "@iobroker/js-controller-common",
"type": "module",
"version": "6.0.12-alpha.0-20240907-52bf8f589",
"version": "6.0.12-alpha.0-20240911-b159ac233",
"engines": {

@@ -13,9 +13,9 @@ "node": ">=12.0.0"

"dependencies": {
"@iobroker/db-objects-file": "6.0.12-alpha.0-20240907-52bf8f589",
"@iobroker/db-objects-jsonl": "6.0.12-alpha.0-20240907-52bf8f589",
"@iobroker/db-objects-redis": "6.0.12-alpha.0-20240907-52bf8f589",
"@iobroker/db-states-file": "6.0.12-alpha.0-20240907-52bf8f589",
"@iobroker/db-states-jsonl": "6.0.12-alpha.0-20240907-52bf8f589",
"@iobroker/db-states-redis": "6.0.12-alpha.0-20240907-52bf8f589",
"@iobroker/js-controller-common-db": "6.0.12-alpha.0-20240907-52bf8f589",
"@iobroker/db-objects-file": "6.0.12-alpha.0-20240911-b159ac233",
"@iobroker/db-objects-jsonl": "6.0.12-alpha.0-20240911-b159ac233",
"@iobroker/db-objects-redis": "6.0.12-alpha.0-20240911-b159ac233",
"@iobroker/db-states-file": "6.0.12-alpha.0-20240911-b159ac233",
"@iobroker/db-states-jsonl": "6.0.12-alpha.0-20240911-b159ac233",
"@iobroker/db-states-redis": "6.0.12-alpha.0-20240911-b159ac233",
"@iobroker/js-controller-common-db": "6.0.12-alpha.0-20240911-b159ac233",
"fs-extra": "^11.1.0"

@@ -58,3 +58,3 @@ },

],
"gitHead": "bb3b41d995857d6c3eda9264077168cb9dc561db"
"gitHead": "170d556732bf8b902b83fd56a5d28021f60fb420"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc