@iobroker/js-controller-common-db 7.0.2 → 7.0.3

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.
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
4
  "sourcesContent": ["/// <reference types=\"@iobroker/types-dev\" />\nexport * as tools from '@/lib/common/tools.js';\nexport { EXIT_CODES } from '@/lib/common/exitCodes.js';\nexport { password } from '@/lib/common/password.js';\nexport { logger } from '@/lib/common/logger.js';\nexport { defaultRedisInterview } from '@/lib/common/interview.js';\nexport { createAdapterStore as session } from '@/lib/common/session.js';\nexport * as constants from '@/lib/common/constants.js';\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AACA,YAAuB;AACvB,uBAA2B;AAC3B,sBAAyB;AACzB,oBAAuB;AACvB,uBAAsC;AACtC,qBAA8C;AAC9C,gBAA2B;",
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;AACA,YAAuB;AACvB,uBAA2B;AAC3B,sBAAyB;AACzB,oBAAuB;AACvB,uBAAsC;AACtC,qBAA8C;AAC9C,gBAA2B;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="@iobroker/types-dev" />
2
1
  interface ApplyAliasTransformerOptions {
3
2
  /** State used for calculations */
4
3
  state: ioBroker.State;
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/common/aliasProcessing.ts"],
4
4
  "sourcesContent": ["interface ApplyAliasTransformerOptions {\n /** State used for calculations */\n state: ioBroker.State;\n /** Properties from this StateCommon will be provided first to the conversion function */\n firstCommon: Partial<ioBroker.StateCommon>;\n /** Properties from this StateCommon will be provided second to the conversion function */\n secondCommon: Partial<ioBroker.StateCommon>;\n /** The actual transformer function as a string */\n transformer: string;\n /** If this is a read function, determines the naming of the passed variables */\n isRead: boolean;\n}\n\ninterface ApplyAliasConvenienceConversionOptions {\n /** State used for calculations */\n state: ioBroker.State;\n /** The common attribute of the alias target */\n targetCommon?: Partial<ioBroker.StateCommon>;\n}\n\ninterface ApplyAliasAutoScalingOptions extends ApplyAliasConvenienceConversionOptions {\n /** The common attribute of the alias source */\n sourceCommon?: Partial<ioBroker.StateCommon>;\n}\n\n/**\n * Applies a user-given transformer function and provides the type, min and max of the\n * passed StateCommon variables as well as the state's value\n *\n * @param options state, common information and transformer function\n */\nexport function applyAliasTransformer(options: ApplyAliasTransformerOptions): ioBroker.StateValue {\n const { state, firstCommon, secondCommon, transformer, isRead } = options;\n\n const prefix = isRead ? 's' : 't';\n\n const func = new Function(\n 'val',\n 'type',\n 'min',\n 'max',\n `${prefix}Type`,\n `${prefix}Min`,\n `${prefix}Max`,\n `return ${transformer}`,\n );\n\n return func(\n state.val,\n firstCommon.type,\n firstCommon.min,\n firstCommon.max,\n secondCommon.type,\n secondCommon.min,\n secondCommon.max,\n );\n}\n\n/**\n * Applies some convenience conversions of aliases, e.g. transforming string 'off' to a boolean false, if target is a boolean\n *\n * @param options state and target common information\n */\nexport function applyAliasConvenienceConversion(options: ApplyAliasConvenienceConversionOptions): ioBroker.StateValue {\n const { targetCommon, state } = options;\n\n if (targetCommon && typeof state.val !== targetCommon.type && state.val !== null) {\n if (targetCommon.type === 'boolean') {\n const lowerVal = typeof state.val === 'string' ? state.val.toLowerCase() : state.val;\n if (lowerVal === 'off' || lowerVal === 'aus' || state.val === '0') {\n return false;\n }\n // this also handles strings like \"EIN\" or such that will be true\n return !!state.val;\n } else if (targetCommon.type === 'number' && typeof state.val === 'string') {\n return parseFloat(state.val);\n } else if (targetCommon.type === 'string') {\n return state.val.toString();\n }\n }\n\n return state.val;\n}\n\n/**\n * Applies autoscaling between alias source and target if one has % unit and the other not\n *\n * @param options state, source and target common information\n */\nexport function applyAliasAutoScaling(options: ApplyAliasAutoScalingOptions): ioBroker.StateValue {\n const { state, sourceCommon, targetCommon } = options;\n\n // auto-scaling, only if val not null and unit for target (x)or source is %\n if (\n ((targetCommon?.alias && !targetCommon.alias.read) || (sourceCommon?.alias && !sourceCommon.alias.write)) &&\n state.val !== null\n ) {\n if (\n targetCommon &&\n targetCommon.type === 'number' &&\n targetCommon.unit === '%' &&\n sourceCommon &&\n sourceCommon.type === 'number' &&\n sourceCommon.unit !== '%' &&\n sourceCommon.min !== undefined &&\n sourceCommon.max !== undefined\n ) {\n // scale target between 0 and 100 % based on sources min/max\n return (((state.val as number) - sourceCommon.min) / (sourceCommon.max - sourceCommon.min)) * 100;\n } else if (\n sourceCommon &&\n sourceCommon.type === 'number' &&\n sourceCommon.unit === '%' &&\n targetCommon &&\n targetCommon.unit !== '%' &&\n targetCommon.type === 'number' &&\n targetCommon.min !== undefined &&\n targetCommon.max !== undefined\n ) {\n // scale target based on its min/max by its source (assuming source is meant to be 0 - 100 %)\n return ((targetCommon.max - targetCommon.min) * (state.val as number)) / 100 + targetCommon.min;\n }\n }\n\n return state.val;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAyBA;;;;;;;AAMM,SAAU,sBAAsB,SAAqC;AACvE,QAAM,EAAE,OAAO,aAAa,cAAc,aAAa,OAAM,IAAK;AAElE,QAAM,SAAS,SAAS,MAAM;AAE9B,QAAM,OAAO,IAAI,SACb,OACA,QACA,OACA,OACA,GAAG,cACH,GAAG,aACH,GAAG,aACH,UAAU,a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;AAEE,cAAU,MAAM,MAAiB,aAAa,QAAQ,aAAa,MAAM,aAAa,OAAQ;IAClG,WACI,gBACA,aAAa,SAAS,YACtB,aAAa,SAAS,OACtB,gBACA,aAAa,SAAS,OACtB,aAAa,SAAS,YACtB,aAAa,QAAQ,UACrB,aAAa,QAAQ,QACvB;AAEE,cAAS,aAAa,MAAM,aAAa,OAAQ,MAAM,MAAkB,MAAM,aAAa;IAChG;EACJ;AAEA,SAAO,MAAM;AACjB;",
6
6
  "names": []
7
7
  }
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/common/exitCodes.ts"],
4
4
  "sourcesContent": ["export enum EXIT_CODES {\n NO_ERROR = 0,\n JS_CONTROLLER_STOPPED = 1, // planned stop\n INVALID_ADAPTER_CONFIG = 2,\n NO_ADAPTER_CONFIG_FOUND = 3, // no config or adapter is disabled\n INVALID_CONFIG_OBJECT = 4,\n INVALID_ADAPTER_ID = 5,\n UNCAUGHT_EXCEPTION = 6,\n ADAPTER_ALREADY_RUNNING = 7,\n INSTANCE_IS_DISABLED = 8,\n CANNOT_GZIP_DIRECTORY = 9,\n CANNOT_FIND_ADAPTER_DIR = 10,\n ADAPTER_REQUESTED_TERMINATION = 11, // planned stop\n UNKNOWN_PACKET_NAME = 12,\n ADAPTER_REQUESTED_REBUILD = 13, // adapter detected invalid NODE_MODULE_VERSION and requires rebuild\n CANNOT_CREATE_USER_OR_GROUP = 14,\n UNKNOWN_ERROR = 15,\n NON_EXISTING_HOST = 16,\n CANNOT_READ_INSTANCES = 18,\n NO_MULTIPLE_INSTANCES_ALLOWED = 19,\n CANNOT_GET_HOST_INFO = 20,\n NO_MULTIPLE_INSTANCES_ALLOWED_ON_HOST = 21,\n NO_CONNECTION_TO_OBJ_DB = 22,\n NO_CONNECTION_TO_STATES_DB = 23,\n INSTANCE_ALREADY_EXISTS = 24,\n CANNOT_INSTALL_NPM_PACKET = 25,\n CANNOT_EXTRACT_FROM_ZIP = 26,\n INVALID_IO_PACKAGE_JSON = 27,\n CANNOT_COPY_DIR = 28,\n MISSING_ADAPTER_FILES = 29,\n INVALID_NPM_VERSION = 30,\n INVALID_NODE_VERSION = 31,\n INVALID_DEPENDENCY_VERSION = 32,\n INVALID_ARGUMENTS = 33,\n INVALID_PASSWORD = 34,\n INVALID_OS = 35,\n CANNOT_SYNC_FILES = 36,\n CANNOT_ENABLE_MULTIHOST = 37,\n MISSING_CONFIG_JSON = 40,\n CANNOT_DELETE_NON_DELETABLE = 41,\n CANNOT_UPLOAD_DATA = 42,\n CANNOT_SET_OBJECT = 43,\n CANNOT_UPDATE_VENDOR = 44,\n INVALID_REPO = 45,\n CANNOT_UPDATE_LICENSE = 46,\n CANNOT_DELETE_DEPENDENCY = 47,\n CANNOT_GET_STATES = 50,\n ADAPTER_ALREADY_INSTALLED = 51,\n CANNOT_RESTORE_BACKUP = 52,\n ADAPTER_NOT_FOUND = 53,\n MIGRATION_ERROR = 78,\n CONTROLLER_RUNNING = 99,\n CONTROLLER_NOT_RUNNING = 100,\n CANNOT_GET_UUID = 101,\n CANNOT_GET_REPO_LIST = 102,\n START_IMMEDIATELY_AFTER_STOP = 156,\n FILE_NOT_FOUND = 404,\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,IAAY;CAAZ,SAAYA,aAAU;AAClB,EAAAA,YAAAA,YAAA,cAAA,KAAA;AACA,EAAAA,YAAAA,YAAA,2BAAA,KAAA;AACA,EAAAA,YAAAA,YAAA,4BAAA,KAAA;AACA,EAAAA,YAAAA,YAAA,6BAAA,KAAA;AACA,EAAAA,YAAAA,YAAA,2BAAA,KAAA;AACA,EAAAA,YAAAA,YAAA,wBAAA,KAAA;AACA,EAAAA,YAAAA,YAAA,wBAAA,KAAA;AACA,EAAAA,YAAAA,YAAA,6BAAA,KAAA;AACA,EAAAA,YAAAA,YAAA,0BAAA,KAAA;AACA,EAAAA,YAAAA,YAAA,2BAAA,KAAA;AACA,EAAAA,YAA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AAA,YAAAA,YAAA,yBAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,qBAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,6BAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,oBAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,mBAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,sBAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,cAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,uBAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,0BAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,mBAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,2BAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,uBAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,mBAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,iBAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,oBAAA,IAAA,EAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,wBAAA,IAAA,GAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,iBAAA,IAAA,GAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,sBAAA,IAAA,GAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,8BAAA,IAAA,GAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,gBAAA,IAAA,GAAA,IAAA;AACJ,GAzDY,eAAA,aAAU,CAAA,EAAA;",
6
6
  "names": ["EXIT_CODES"]
7
7
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="@iobroker/types-dev" />
2
1
  type SharedDatabaseOptions = ioBroker.ObjectsDatabaseOptions | ioBroker.StatesDatabaseOptions;
3
2
  interface DefaultRedisInterviewOptions<TConfig extends SharedDatabaseOptions> {
4
3
  /** Database type */
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/common/interview.ts"],
4
4
  "sourcesContent": ["import rl from 'readline-sync';\nimport fs from 'fs-extra';\n\n/** Regex to limit inputs to yes/no shortcuts */\nconst YES_NO_REGEX = /^[YyNn]?$/;\n\ntype SharedDatabaseOptions = ioBroker.ObjectsDatabaseOptions | ioBroker.StatesDatabaseOptions;\n\ninterface DefaultRedisInterviewOptions<TConfig extends SharedDatabaseOptions> {\n /** Database type */\n type: 'objects' | 'states';\n /** Prefilled config */\n config: TConfig;\n}\n\n/**\n * The default redis interview shared between objects and states\n *\n * @param options config and type information\n */\nexport async function defaultRedisInterview<TConfig extends SharedDatabaseOptions>(\n options: DefaultRedisInterviewOptions<TConfig>,\n): Promise<TConfig> {\n const { type, config } = options;\n\n let answer = rl.question(`Do you use a TLS connection for your \"${type}\" redis-server? [y/N]:`, {\n limit: YES_NO_REGEX,\n defaultInput: 'N',\n });\n\n if (answer.toLowerCase() === 'n') {\n return config;\n }\n\n config.options.tls = {};\n\n answer = rl.question(`Do you use a self-signed certificate for your \"${type}\" redis-server? [y/N]:`, {\n limit: YES_NO_REGEX,\n defaultInput: 'N',\n });\n\n if (answer.toLowerCase() === 'y') {\n config.options.tls.rejectUnauthorized = false;\n }\n\n do {\n answer = rl.question(`Please specify the path to your \"${type}\" redis-server \"certificate\" file:`);\n\n try {\n const certContent = await fs.readFile(answer, { encoding: 'utf8' });\n config.options.tls.cert = certContent;\n } catch (e) {\n console.warn(`Could not read the \"certificate\" file: ${e.message}`);\n }\n } while (!config.options.tls.cert);\n\n do {\n answer = rl.question(`Please specify the path to your \"${type}\" redis-server \"key\" file:`);\n\n try {\n const keyContent = await fs.readFile(answer, { encoding: 'utf8' });\n config.options.tls.key = keyContent;\n } catch (e) {\n console.warn(`Could not read the \"key\" file: ${e.message}`);\n }\n } while (!config.options.tls.key);\n\n do {\n answer = rl.question(`Please specify the path to your \"${type}\" redis-server \"CA\" file:`);\n\n try {\n const caContent = await fs.readFile(answer, { encoding: 'utf8' });\n config.options.tls.ca = caContent;\n } catch (e) {\n console.warn(`Could not read the \"CA\" file: ${e.message}`);\n }\n } while (!config.options.tls.ca);\n\n return config;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;2BAAe;AACf,sBAAe;AAGf,MAAM,eAAe;AAgBrB,eAAsB,sBAClB,SAA8C;AAE9C,QAAM,EAAE,MAAM,OAAM,IAAK;AAEzB,MAAI,SAAS,qBAAAA,QAAG,SAAS,yCAAyC,8BAA8B;IAC5F,OAAO;IACP,cAAc;GACjB;AAED,MAAI,OAAO,YAAW,MAAO,KAAK;AAC9B,WAAO;EACX;AAEA,SAAO,QAAQ,MAAM,CAAA;AAErB,WAAS,qBAAAA,QAAG,SAAS,kDAAkD,8BAA8B;IACjG,OAAO;IACP,cAAc;GACjB;AAED,MAAI,OAAO,YAAW,MAAO,KAAK;AAC9B,WAAO,QAAQ,IAAI,qBAAqB;EAC5C;AAEA,KAAG;AACC,aAAS,qBAAAA,QAAG,SAAS,oCAAoC,wCAAwC;AAEjG,QAAI;AACA,YAAM,cAAc,MAAM,gBAAAC,QAAG,SAAS,QAAQ,EAAE,UAAU,OAAM,CAAE;AAClE,aAAO,QAAQ,IAAI,OAAO;IAC9B,SAAS,GAAP;AACE,cAAQ,KAAK,0CAA0C,EAAE,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Ac,MAAM,gBAAAC,QAAG,SAAS,QAAQ,EAAE,UAAU,OAAM,CAAE;AAClE,aAAO,QAAQ,IAAI,OAAO;IAC9B,SAAS,GAAG;AACR,cAAQ,KAAK,0CAA0C,EAAE,OAAO,EAAE;IACtE;EACJ,SAAS,CAAC,OAAO,QAAQ,IAAI;AAE7B,KAAG;AACC,aAAS,qBAAAD,QAAG,SAAS,oCAAoC,IAAI,4BAA4B;AAEzF,QAAI;AACA,YAAM,aAAa,MAAM,gBAAAC,QAAG,SAAS,QAAQ,EAAE,UAAU,OAAM,CAAE;AACjE,aAAO,QAAQ,IAAI,MAAM;IAC7B,SAAS,GAAG;AACR,cAAQ,KAAK,kCAAkC,EAAE,OAAO,EAAE;IAC9D;EACJ,SAAS,CAAC,OAAO,QAAQ,IAAI;AAE7B,KAAG;AACC,aAAS,qBAAAD,QAAG,SAAS,oCAAoC,IAAI,2BAA2B;AAExF,QAAI;AACA,YAAM,YAAY,MAAM,gBAAAC,QAAG,SAAS,QAAQ,EAAE,UAAU,OAAM,CAAE;AAChE,aAAO,QAAQ,IAAI,KAAK;IAC5B,SAAS,GAAG;AACR,cAAQ,KAAK,iCAAiC,EAAE,OAAO,EAAE;IAC7D;EACJ,SAAS,CAAC,OAAO,QAAQ,IAAI;AAE7B,SAAO;AACX;",
6
6
  "names": ["rl", "fs"]
7
7
  }
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -27,6 +31,7 @@ __export(logger_exports, {
27
31
  logger: () => logger
28
32
  });
29
33
  module.exports = __toCommonJS(logger_exports);
34
+ var __import_meta_url = typeof document === "undefined" ? new (require("url".replace("", ""))).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
30
35
  var import_winston = __toESM(require("winston"), 1);
31
36
  var import_winston_daily_rotate_file = __toESM(require("winston-daily-rotate-file"), 1);
32
37
  var import_node_fs = __toESM(require("node:fs"), 1);
@@ -38,9 +43,8 @@ var import_triple_beam = require("triple-beam");
38
43
  var import_deep_clone = __toESM(require("deep-clone"), 1);
39
44
  var url = __toESM(require("node:url"), 1);
40
45
  var import_node_module = require("node:module");
41
- const import_meta = {};
42
- const thisDir = url.fileURLToPath(new URL(".", import_meta.url || `file://${__filename}`));
43
- const require2 = (0, import_node_module.createRequire)(import_meta.url || `file://${__filename}`);
46
+ const thisDir = url.fileURLToPath(new URL(".", __import_meta_url || `file://${__filename}`));
47
+ const require2 = (0, import_node_module.createRequire)(__import_meta_url || `file://${__filename}`);
44
48
  const hostname = tools.getHostName();
45
49
  let SysLog;
46
50
  try {
@@ -263,10 +267,15 @@ function logger(level, files, noStdout, prefix) {
263
267
  filename: import_node_path.default.normalize(isNpm ? `${thisDir}/../../../log/${files[i]}` : `${thisDir}/../log/${files[i]}`),
264
268
  extension: ".log",
265
269
  datePattern: "YYYY-MM-DD",
270
+ //json: false, // If true, messages will be logged as JSON (default true). TODO format.json()
266
271
  level,
267
272
  silent: false,
268
273
  localTime: true,
274
+ //colorize: (userOptions.colorize === undefined) ? true : userOptions.colorize, // TODO format.colorize()
275
+ //timestamp: timestamp, // TODO: format.timestamp()
276
+ //label: prefix || '', // TODO format.label()
269
277
  handleExceptions: false
278
+ //maxSize: defaultMaxSize
270
279
  };
271
280
  options.transports.push(new import_winston_daily_rotate_file.default(opt));
272
281
  }
@@ -276,6 +285,9 @@ function logger(level, files, noStdout, prefix) {
276
285
  level,
277
286
  silent: false,
278
287
  format: import_winston.default.format.combine(import_winston.default.format.printf(formatter))
288
+ //colorize: (userOptions.colorize === undefined) ? true : userOptions.colorize, // TODO format.colorize()
289
+ //timestamp: timestamp, // TODO: format.timestamp()
290
+ //label: prefix || '' // TODO format.label()
279
291
  }));
280
292
  }
281
293
  options.transports.push(new NotifierTransport({
@@ -303,7 +315,12 @@ function logger(level, files, noStdout, prefix) {
303
315
  }
304
316
  this._fileChecker = setInterval(() => {
305
317
  this.transports.forEach((transport) => {
306
- if (transport.name !== "dailyRotateFile" || !transport.options || transport.options.name !== tools.appName) {
318
+ if (
319
+ /** @ts-expect-error we use undocumented stuff here TODO */
320
+ transport.name !== "dailyRotateFile" || /** @ts-expect-error we use undocumented stuff here TODO */
321
+ !transport.options || /** @ts-expect-error we use undocumented stuff here TODO */
322
+ transport.options.name !== tools.appName
323
+ ) {
307
324
  return;
308
325
  }
309
326
  if (transport && import_node_fs.default.existsSync(transport.dirname)) {
@@ -314,7 +331,7 @@ function logger(level, files, noStdout, prefix) {
314
331
  console.error(`host.${hostname} Cannot read log directory: ${e.message}`);
315
332
  return;
316
333
  }
317
- const forXdays = new Date();
334
+ const forXdays = /* @__PURE__ */ new Date();
318
335
  forXdays.setDate(forXdays.getDate() - daysCount - 1);
319
336
  for (let i = 0; i < files2.length; i++) {
320
337
  const match = files2[i].match(/.+\.(\d+-\d+-\d+)/);
@@ -332,10 +349,12 @@ function logger(level, files, noStdout, prefix) {
332
349
  this.log({
333
350
  level: import_node_os.default.platform().startsWith("win") ? "info" : "error",
334
351
  message: `host.${hostname} Cannot delete file "${import_node_path.default.normalize(
352
+ /** @ts-expect-error we use undocumented stuff here TODO */
335
353
  `${transport.dirname}/${files2[i]}`
336
354
  )}": ${e}`
337
355
  });
338
356
  console.log(`host.${hostname} Cannot delete file "${import_node_path.default.normalize(
357
+ /** @ts-expect-error we use undocumented stuff here TODO */
339
358
  `${transport.dirname}/${files2[i]}`
340
359
  )}": ${e.message}`);
341
360
  }
@@ -350,11 +369,11 @@ function logger(level, files, noStdout, prefix) {
350
369
  return log;
351
370
  }
352
371
  function getDate() {
353
- const ts = new Date();
372
+ const ts = /* @__PURE__ */ new Date();
354
373
  return `${ts.getFullYear()}-${(ts.getMonth() + 1).toString().padStart(2, "0")}-${ts.getDate().toString().padStart(2, "0")}`;
355
374
  }
356
375
  function timestamp(date) {
357
- const ts = date ? new Date(date) : new Date();
376
+ const ts = date ? new Date(date) : /* @__PURE__ */ new Date();
358
377
  return `${ts.getFullYear()}-${(ts.getMonth() + 1).toString().padStart(2, "0")}-${ts.getDate().toString().padStart(2, "0")} ${ts.getHours().toString().padStart(2, "0")}:${ts.getMinutes().toString().padStart(2, "0")}:${ts.getSeconds().toString().padStart(2, "0")}.${ts.getMilliseconds().toString().padStart(3, "0")} `;
359
378
  }
360
379
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../../src/lib/common/logger.ts"],
4
- "sourcesContent": ["import winston from 'winston';\nimport DailyRotateFile from 'winston-daily-rotate-file';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport os from 'node:os';\nimport * as tools from '@/lib/common/tools.js';\nimport Transport from 'winston-transport';\nimport { LEVEL } from 'triple-beam';\nimport deepClone from 'deep-clone';\nimport type { Syslog } from 'winston-syslog';\nimport type { SeqTransport } from '@datalust/winston-seq';\nimport * as url from 'node:url';\nimport { createRequire } from 'node:module';\n\n// eslint-disable-next-line unicorn/prefer-module\nconst thisDir = url.fileURLToPath(new URL('.', import.meta.url || `file://${__filename}`));\n\n// eslint-disable-next-line unicorn/prefer-module\nconst require = createRequire(import.meta.url || `file://${__filename}`);\n\nconst hostname = tools.getHostName();\n\nlet SysLog: typeof Syslog | undefined;\ntry {\n SysLog = require('winston-syslog').Syslog;\n} catch {\n //console.log('No syslog support');\n}\n\nlet Seq: typeof SeqTransport | undefined;\ntry {\n Seq = require('@datalust/winston-seq').SeqTransport;\n} catch {\n //console.log('No seq support');\n}\n\nexport type LogInfo = Record<string | symbol, any>;\n\n// We must check if SysLog is defined before extending it\nconst IoSysLog =\n SysLog &&\n class extends SysLog {\n constructor(options: any) {\n super(options);\n }\n log(info: LogInfo, callback: () => void): void {\n // we need to map the ioBroker loglevels to the Syslog ones\n const ioInfo = info;\n if (ioInfo[LEVEL] === 'warn') {\n ioInfo[LEVEL] = 'warning';\n }\n if (ioInfo[LEVEL] === 'info') {\n ioInfo[LEVEL] = 'notice';\n }\n if (ioInfo[LEVEL] === 'debug') {\n ioInfo[LEVEL] = 'info';\n }\n if (ioInfo[LEVEL] === 'silly') {\n ioInfo[LEVEL] = 'debug';\n }\n\n // No clue why log could ever be undefined, but hey...\n super.log?.(ioInfo, callback);\n }\n };\n\n// We want to enhance some data for Seq\nconst IoSeq =\n Seq &&\n class extends Seq {\n log(info: LogInfo, callback: () => void): void {\n const ioInfo = deepClone(info);\n ioInfo.props = ioInfo.props || {};\n\n // map our log levels to Seq levels\n const level = (ioInfo.level || '').toLowerCase();\n if (level.includes('error')) {\n ioInfo.level = 'Error';\n } else if (level.includes('warn')) {\n ioInfo.level = 'Warning';\n } else if (level.includes('info')) {\n ioInfo.level = 'Information';\n } else if (level.includes('debug')) {\n ioInfo.level = 'Debug';\n } else if (level.includes('silly')) {\n ioInfo.level = 'Verbose';\n } else {\n ioInfo.level = 'Information';\n }\n\n // we add own properties\n ioInfo.props.Hostname = tools.getHostName();\n if (ioInfo.message) {\n // handle as single line with s flag, to if message ends with CR, etc\n const msgParts = ioInfo.message.match(/^([^.]+\\.[0-9]+) \\(([^)]+)\\) (.*)$/s);\n if (msgParts) {\n ioInfo.props.Source = msgParts[1];\n ioInfo.props.Pid = msgParts[2];\n } else {\n ioInfo.props.Source = 'js-controller';\n }\n }\n super.log(ioInfo, callback);\n }\n };\n\n// Class used to inform adapter about new log entry\nclass NotifierTransport extends Transport {\n private name: string;\n constructor(opts: any) {\n super(opts);\n this.name = 'NT'; // NotifierTransport\n }\n\n log(info: LogInfo, callback: () => void): void {\n const msg = {\n severity: info[LEVEL],\n ts: new Date(info.timestamp).getTime(),\n message: info.message,\n };\n setImmediate(() => this.emit('logged', msg));\n callback();\n }\n}\n\nexport interface UserOptions {\n level: string;\n maxDays: number;\n noStdout: boolean;\n localTime?: string;\n colorize?: boolean;\n json?: boolean;\n prefix?: string;\n transport: Record<string, any>;\n}\n\ninterface Options {\n format?: winston.Logform.Format;\n transports: Transport[];\n}\n\nexport function logger(\n level: string | UserOptions,\n files?: string[] | string,\n noStdout?: boolean,\n prefix?: string,\n): winston.Logger {\n const options: Options = {\n transports: [],\n };\n\n //var defaultMaxSize;// = 10 * 1024 * 1024;\n\n if (typeof files === 'string') {\n files = [files];\n }\n\n const formatter = (info: LogInfo): string => `${timestamp(info.timestamp)} - ${info.level}: ${info.message}`;\n\n files = files || [];\n\n // indicator which is used to determine the log dir for developing, where it should be inside the repository\n const isNpm = !thisDir\n .replace(/\\\\/g, '/')\n .toLowerCase()\n .includes(`${tools.appName.toLowerCase()}.js-controller/packages/`);\n\n if (tools.isObject(level)) {\n const userOptions: UserOptions = deepClone(level);\n\n level = userOptions.level;\n prefix = userOptions.prefix || '';\n noStdout = userOptions.noStdout;\n const winstonFormats = [];\n /** @ts-expect-error formatter arg wrongly documented */\n winstonFormats.push(winston.format.timestamp({ format: timestamp }));\n if (userOptions.json === undefined || userOptions.json) {\n winstonFormats.push(winston.format.json());\n }\n if (prefix) {\n winstonFormats.push(winston.format.label({ label: prefix }));\n }\n if (userOptions.colorize === undefined || userOptions.colorize) {\n winstonFormats.push(winston.format.colorize());\n }\n options.format = winston.format.combine.apply(null, winstonFormats);\n\n if (userOptions.prefix !== undefined) {\n delete userOptions.prefix;\n }\n\n if (userOptions.transport) {\n let fName = 0;\n const isWindows = os.platform().startsWith('win');\n for (const transport of Object.values(userOptions.transport)) {\n transport._defaultConfigLoglevel = transport.level; // remember Loglevel if set\n transport.level = transport.level || level;\n\n if (transport.type === 'file' && transport.enabled !== false) {\n transport.filename = transport.filename || `log/${tools.appName}`;\n\n if (!transport.fileext && transport.filename.indexOf('.log') === -1) {\n transport.fileext = '.log';\n }\n\n if (!fName) {\n transport.systemLog = true;\n }\n\n transport.handleExceptions = false;\n transport.name = fName ? `dailyRotateFile${fName}` : tools.appName;\n fName++;\n transport.filename = transport.filename.replace(/\\\\/g, '/');\n if (transport.filename.match(/^\\w:\\/|^\\//)) {\n transport.filename = path.normalize(transport.filename);\n } else {\n transport.filename = path.normalize(\n `${tools.getControllerDir()}${isNpm ? '/../../' : '/'}${transport.filename}`,\n );\n }\n transport.auditFile = `${transport.filename}-audit.json`;\n\n transport.createSymlink =\n transport.createSymlink !== undefined ? transport.createSymlink : !isWindows;\n transport.symlinkName =\n transport.symlinkName !== undefined\n ? transport.symlinkName\n : path.basename(`${transport.filename}.current.log`);\n\n transport.filename += `.%DATE%${transport.fileext || ''}`;\n //transport.label = prefix || ''; //TODO format.label()\n // transport.json = (transport.json !== undefined) ? transport.json : false; // TODO format.json(), new Default!!\n transport.silent = transport.silent !== undefined ? transport.silent : false;\n // transport.colorize = (transport.colorize !== undefined) ? transport.colorize : ((userOptions.colorize === undefined) ? true : userOptions.colorize); //TODO format.colorize()\n transport.localTime =\n transport.localTime !== undefined\n ? transport.localTime\n : userOptions.localTime === undefined\n ? true\n : userOptions.localTime;\n transport.datePattern = 'YYYY-MM-DD';\n transport.format = winston.format.combine(winston.format.printf(formatter));\n /*transport.logException = function (message, info, next, err) {\n console.error(message);\n };*/\n transport.zippedArchive = isWindows\n ? false\n : transport.zippedArchive !== undefined\n ? transport.zippedArchive\n : true;\n\n if (transport.maxFiles === null && userOptions.maxDays) {\n transport.maxFiles = `${userOptions.maxDays}d`;\n }\n\n try {\n const _log = new DailyRotateFile(transport);\n\n _log.on('error', err => {\n console.error(`Error on log file rotation: ${err.message}`);\n });\n\n options.transports.push(_log);\n } catch (e) {\n if (e.code === 'EACCES') {\n // modify error code to make it unique for handling\n e.code = 'EACCES_LOG';\n }\n throw e;\n }\n } else if (transport.type === 'syslog' && transport.enabled !== false) {\n if (!IoSysLog) {\n console.error('Syslog configured, but not installed! Ignore');\n continue;\n }\n // host: The host running syslogd, defaults to localhost.\n // port: The port on the host that syslog is running on, defaults to syslogd's default port.\n // protocol: The network protocol to log over (e.g. tcp4, udp4, unix, unix-connect, etc).\n // path: The path to the syslog dgram socket (i.e. /dev/log or /var/run/syslog for OS X).\n // pid: PID of the process that log messages are coming from (Default process.pid).\n // facility: Syslog facility to use (Default: local0).\n // localhost: Host to indicate that log messages are coming from (Default: localhost).\n // sysLogType: The type of the syslog protocol to use (Default: BSD).\n // app_name: The name of the application (Default: process.title).\n // eol: The end of line character to be added to the end of the message (Default: Message without modifications).\n // replace the used by syslog attribute \"type\" with own \"sysLogType\"\n\n // If no name defined, use hostname as name\n transport.localhost = transport.localhost || hostname;\n transport.format = winston.format.combine(winston.format.printf(formatter));\n if (transport.sysLogType) {\n transport.type = transport.sysLogType;\n delete transport.sysLogType;\n } else {\n delete transport.type;\n }\n try {\n options.transports.push(new IoSysLog(transport));\n } catch (e) {\n console.error(`Cannot activate Syslog: ${e.message}`);\n }\n } else if (transport.type === 'http' && transport.enabled !== false) {\n // host: (Default: localhost) Remote host of the HTTP logging endpoint\n // port: (Default: 80 or 443) Remote port of the HTTP logging endpoint\n // path: (Default: /) Remote URI of the HTTP logging endpoint\n // auth: (Default: None) An object representing the username and password for HTTP Basic Auth\n // ssl: (Default: false) Value indicating if we should use HTTPS\n\n // If no name defined, use hostname as name\n transport.host = transport.host || 'localhost';\n\n try {\n options.transports.push(new winston.transports.Http(transport));\n } catch (e) {\n console.error(`Cannot activate HTTP: ${e.message}`);\n }\n } else if (transport.type === 'stream' && transport.enabled !== false) {\n // stream: any Node.js stream. If an objectMode stream is provided then the entire info object will be written. Otherwise info[MESSAGE] will be written.\n // level: Level of messages that this transport should log (default: level set on parent logger).\n // silent: Boolean flag indicating whether to suppress output (default false).\n // eol: Line-ending character to use. (default: os.EOL).\n\n // If no name defined, use hostname as name\n transport.host = transport.host || 'localhost';\n\n try {\n if (typeof transport.stream === 'string') {\n transport.stream = fs.createWriteStream(transport.stream);\n transport.stream.on('error', (err: Error) => {\n console.error(`Error in Stream: ${err.message}`);\n });\n }\n\n options.transports.push(new winston.transports.Stream(transport));\n } catch (e) {\n console.error(`Cannot activate Stream: ${e.message}`);\n }\n } else if (transport.type === 'seq' && transport.enabled !== false) {\n if (!IoSeq) {\n console.error('Seq configured, but not installed! Ignore');\n continue;\n }\n // serverUrl?: string;\n // apiKey?: string;\n // maxBatchingTime?: number;\n // eventSizeLimit?: number;\n // batchSizeLimit?: number;\n\n // Add only if serverUrl is configured at least\n if (transport.serverUrl) {\n try {\n transport.onError = (e: Error) => {\n console.log(`SEQ error: ${e.message}`);\n };\n const seqLogger = new IoSeq(transport);\n options.transports.push(seqLogger);\n } catch (e) {\n console.error(`Cannot activate SEQ: ${e.message}`);\n }\n } else {\n console.error('Cannot activate SEQ: No serverUrl specified');\n }\n }\n }\n }\n } else {\n for (let i = 0; i < files.length; i++) {\n const opt = {\n name: i ? `dailyRotateFile${i}` : tools.appName,\n filename: path.normalize(\n isNpm ? `${thisDir}/../../../log/${files[i]}` : `${thisDir}/../log/${files[i]}`,\n ),\n extension: '.log',\n datePattern: 'YYYY-MM-DD',\n //json: false, // If true, messages will be logged as JSON (default true). TODO format.json()\n level,\n silent: false,\n localTime: true,\n //colorize: (userOptions.colorize === undefined) ? true : userOptions.colorize, // TODO format.colorize()\n //timestamp: timestamp, // TODO: format.timestamp()\n //label: prefix || '', // TODO format.label()\n handleExceptions: false,\n //maxSize: defaultMaxSize\n };\n\n options.transports.push(new DailyRotateFile(opt));\n }\n }\n\n if (!noStdout) {\n options.transports.push(\n new winston.transports.Console({\n level,\n silent: false,\n format: winston.format.combine(winston.format.printf(formatter)),\n //colorize: (userOptions.colorize === undefined) ? true : userOptions.colorize, // TODO format.colorize()\n //timestamp: timestamp, // TODO: format.timestamp()\n //label: prefix || '' // TODO format.label()\n }),\n );\n }\n\n // Must be registered, for adapter.js notification about new logs\n options.transports.push(\n new NotifierTransport({\n level,\n silent: false,\n }),\n );\n\n const log = winston.createLogger(options);\n\n /** @ts-expect-error why do we override/add method to foreign instance? TODO */\n log.getFileName = function () {\n /** @ts-expect-error we use undocumented stuff here TODO */\n let transport = this.transports.find(t => (t.transport && t.transport.dirname) || t.dirname);\n if (transport) {\n /** @ts-expect-error we use undocumented stuff here TODO */\n transport = transport.transport ? transport.transport : transport;\n /** @ts-expect-error we use undocumented stuff here TODO */\n return `${transport.dirname}/${transport.filename.replace('%DATE%', getDate())}`;\n }\n return '';\n };\n\n log.on('error', error => {\n console.log(`Logger error: ${error.message}`);\n });\n\n // This cannot be deleted, because file rotate works with the size of files and not with the time\n // TODO research and open new issue in winston-daily-rotate-file repo\n /**\n * @param isEnabled\n * @param daysCount\n */\n // @ts-expect-error why do we override/add method to foreign instance? TODO\n log.activateDateChecker = function (isEnabled, daysCount) {\n /** @ts-expect-error we use undocumented stuff here TODO */\n if (!isEnabled && this._fileChecker) {\n /** @ts-expect-error we use undocumented stuff here TODO */\n clearInterval(this._fileChecker);\n /** @ts-expect-error we use undocumented stuff here TODO */\n } else if (isEnabled && !this._fileChecker) {\n if (!daysCount) {\n daysCount = 3;\n }\n\n // Check every hour\n /** @ts-expect-error we use undocumented stuff here TODO */\n this._fileChecker = setInterval(() => {\n this.transports.forEach(transport => {\n if (\n /** @ts-expect-error we use undocumented stuff here TODO */\n transport.name !== 'dailyRotateFile' ||\n /** @ts-expect-error we use undocumented stuff here TODO */\n !transport.options ||\n /** @ts-expect-error we use undocumented stuff here TODO */\n transport.options.name !== tools.appName\n ) {\n return;\n }\n\n /** @ts-expect-error we use undocumented stuff here TODO */\n if (transport && fs.existsSync(transport.dirname)) {\n let files;\n try {\n /** @ts-expect-error we use undocumented stuff here TODO */\n files = fs.readdirSync(transport.dirname);\n } catch (e) {\n console.error(`host.${hostname} Cannot read log directory: ${e.message}`);\n return;\n }\n const forXdays = new Date();\n forXdays.setDate(forXdays.getDate() - daysCount - 1); // normally winston now takes care, for old or on errors make sure fallback works a day later\n\n for (let i = 0; i < files.length; i++) {\n const match = files[i].match(/.+\\.(\\d+-\\d+-\\d+)/);\n if (match) {\n const date = new Date(match[1]);\n if (date < forXdays) {\n // delete file\n try {\n this.log({\n level: 'info',\n message: `host.${hostname} Delete log file ${files[i]}`,\n });\n console.log(`host.${hostname} Delete log file ${files[i]}`);\n /** @ts-expect-error we use undocumented stuff here TODO */\n fs.unlinkSync(`${transport.dirname}/${files[i]}`);\n } catch (e) {\n // there is a bug under windows, that file stays opened and cannot be deleted\n this.log({\n level: os.platform().startsWith('win') ? 'info' : 'error',\n message: `host.${hostname} Cannot delete file \"${path.normalize(\n /** @ts-expect-error we use undocumented stuff here TODO */\n `${transport.dirname}/${files[i]}`,\n )}\": ${e}`,\n });\n console.log(\n `host.${hostname} Cannot delete file \"${path.normalize(\n /** @ts-expect-error we use undocumented stuff here TODO */\n `${transport.dirname}/${files[i]}`,\n )}\": ${e.message}`,\n );\n }\n }\n }\n }\n }\n });\n }, 3_600_000); // every hour\n }\n };\n\n return log;\n}\n\nfunction getDate(): string {\n const ts = new Date();\n return `${ts.getFullYear()}-${(ts.getMonth() + 1).toString().padStart(2, '0')}-${ts\n .getDate()\n .toString()\n .padStart(2, '0')}`;\n}\n\nfunction timestamp(date: string): string {\n const ts = date ? new Date(date) : new Date();\n return `${ts.getFullYear()}-${(ts.getMonth() + 1).toString().padStart(2, '0')}-${ts\n .getDate()\n .toString()\n .padStart(2, '0')} ${ts.getHours().toString().padStart(2, '0')}:${ts\n .getMinutes()\n .toString()\n .padStart(2, '0')}:${ts.getSeconds().toString().padStart(2, '0')}.${ts\n .getMilliseconds()\n .toString()\n .padStart(3, '0')} `;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;qBAAoB;AACpB,uCAA4B;AAC5B,qBAAe;AACf,uBAAiB;AACjB,qBAAe;AACf,YAAuB;AACvB,+BAAsB;AACtB,yBAAsB;AACtB,wBA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,SAAS,UAAU,MAAY;AAC3B,QAAM,KAAK,OAAO,IAAI,KAAK,IAAI,IAAI,IAAI,KAAI;AAC3C,SAAO,GAAG,GAAG,YAAW,MAAO,GAAG,SAAQ,IAAK,GAAG,SAAQ,EAAG,SAAS,GAAG,GAAG,KAAK,GAC5E,QAAO,EACP,SAAQ,EACR,SAAS,GAAG,GAAG,KAAK,GAAG,SAAQ,EAAG,SAAQ,EAAG,SAAS,GAAG,GAAG,KAAK,GACjE,WAAU,EACV,SAAQ,EACR,SAAS,GAAG,GAAG,KAAK,GAAG,WAAU,EAAG,SAAQ,EAAG,SAAS,GAAG,GAAG,KAAK,GACnE,gBAAe,EACf,SAAQ,EACR,SAAS,GAAG,GAAG;AACxB;",
3
+ "sources": ["../../../../src/lib/common/logger.ts", "../../../../../../node_modules/@alcalzone/esm2cjs/shims/import.meta.url/shim.js"],
4
+ "sourcesContent": ["import winston from 'winston';\nimport DailyRotateFile from 'winston-daily-rotate-file';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport os from 'node:os';\nimport * as tools from '@/lib/common/tools.js';\nimport Transport from 'winston-transport';\nimport { LEVEL } from 'triple-beam';\nimport deepClone from 'deep-clone';\nimport type { Syslog } from 'winston-syslog';\nimport type { SeqTransport } from '@datalust/winston-seq';\nimport * as url from 'node:url';\nimport { createRequire } from 'node:module';\n\n// eslint-disable-next-line unicorn/prefer-module\nconst thisDir = url.fileURLToPath(new URL('.', import.meta.url || `file://${__filename}`));\n\n// eslint-disable-next-line unicorn/prefer-module\nconst require = createRequire(import.meta.url || `file://${__filename}`);\n\nconst hostname = tools.getHostName();\n\nlet SysLog: typeof Syslog | undefined;\ntry {\n SysLog = require('winston-syslog').Syslog;\n} catch {\n //console.log('No syslog support');\n}\n\nlet Seq: typeof SeqTransport | undefined;\ntry {\n Seq = require('@datalust/winston-seq').SeqTransport;\n} catch {\n //console.log('No seq support');\n}\n\nexport type LogInfo = Record<string | symbol, any>;\n\n// We must check if SysLog is defined before extending it\nconst IoSysLog =\n SysLog &&\n class extends SysLog {\n constructor(options: any) {\n super(options);\n }\n log(info: LogInfo, callback: () => void): void {\n // we need to map the ioBroker loglevels to the Syslog ones\n const ioInfo = info;\n if (ioInfo[LEVEL] === 'warn') {\n ioInfo[LEVEL] = 'warning';\n }\n if (ioInfo[LEVEL] === 'info') {\n ioInfo[LEVEL] = 'notice';\n }\n if (ioInfo[LEVEL] === 'debug') {\n ioInfo[LEVEL] = 'info';\n }\n if (ioInfo[LEVEL] === 'silly') {\n ioInfo[LEVEL] = 'debug';\n }\n\n // No clue why log could ever be undefined, but hey...\n super.log?.(ioInfo, callback);\n }\n };\n\n// We want to enhance some data for Seq\nconst IoSeq =\n Seq &&\n class extends Seq {\n log(info: LogInfo, callback: () => void): void {\n const ioInfo = deepClone(info);\n ioInfo.props = ioInfo.props || {};\n\n // map our log levels to Seq levels\n const level = (ioInfo.level || '').toLowerCase();\n if (level.includes('error')) {\n ioInfo.level = 'Error';\n } else if (level.includes('warn')) {\n ioInfo.level = 'Warning';\n } else if (level.includes('info')) {\n ioInfo.level = 'Information';\n } else if (level.includes('debug')) {\n ioInfo.level = 'Debug';\n } else if (level.includes('silly')) {\n ioInfo.level = 'Verbose';\n } else {\n ioInfo.level = 'Information';\n }\n\n // we add own properties\n ioInfo.props.Hostname = tools.getHostName();\n if (ioInfo.message) {\n // handle as single line with s flag, to if message ends with CR, etc\n const msgParts = ioInfo.message.match(/^([^.]+\\.[0-9]+) \\(([^)]+)\\) (.*)$/s);\n if (msgParts) {\n ioInfo.props.Source = msgParts[1];\n ioInfo.props.Pid = msgParts[2];\n } else {\n ioInfo.props.Source = 'js-controller';\n }\n }\n super.log(ioInfo, callback);\n }\n };\n\n// Class used to inform adapter about new log entry\nclass NotifierTransport extends Transport {\n private name: string;\n constructor(opts: any) {\n super(opts);\n this.name = 'NT'; // NotifierTransport\n }\n\n log(info: LogInfo, callback: () => void): void {\n const msg = {\n severity: info[LEVEL],\n ts: new Date(info.timestamp).getTime(),\n message: info.message,\n };\n setImmediate(() => this.emit('logged', msg));\n callback();\n }\n}\n\nexport interface UserOptions {\n level: string;\n maxDays: number;\n noStdout: boolean;\n localTime?: string;\n colorize?: boolean;\n json?: boolean;\n prefix?: string;\n transport: Record<string, any>;\n}\n\ninterface Options {\n format?: winston.Logform.Format;\n transports: Transport[];\n}\n\nexport function logger(\n level: string | UserOptions,\n files?: string[] | string,\n noStdout?: boolean,\n prefix?: string,\n): winston.Logger {\n const options: Options = {\n transports: [],\n };\n\n //var defaultMaxSize;// = 10 * 1024 * 1024;\n\n if (typeof files === 'string') {\n files = [files];\n }\n\n const formatter = (info: LogInfo): string => `${timestamp(info.timestamp)} - ${info.level}: ${info.message}`;\n\n files = files || [];\n\n // indicator which is used to determine the log dir for developing, where it should be inside the repository\n const isNpm = !thisDir\n .replace(/\\\\/g, '/')\n .toLowerCase()\n .includes(`${tools.appName.toLowerCase()}.js-controller/packages/`);\n\n if (tools.isObject(level)) {\n const userOptions: UserOptions = deepClone(level);\n\n level = userOptions.level;\n prefix = userOptions.prefix || '';\n noStdout = userOptions.noStdout;\n const winstonFormats = [];\n /** @ts-expect-error formatter arg wrongly documented */\n winstonFormats.push(winston.format.timestamp({ format: timestamp }));\n if (userOptions.json === undefined || userOptions.json) {\n winstonFormats.push(winston.format.json());\n }\n if (prefix) {\n winstonFormats.push(winston.format.label({ label: prefix }));\n }\n if (userOptions.colorize === undefined || userOptions.colorize) {\n winstonFormats.push(winston.format.colorize());\n }\n options.format = winston.format.combine.apply(null, winstonFormats);\n\n if (userOptions.prefix !== undefined) {\n delete userOptions.prefix;\n }\n\n if (userOptions.transport) {\n let fName = 0;\n const isWindows = os.platform().startsWith('win');\n for (const transport of Object.values(userOptions.transport)) {\n transport._defaultConfigLoglevel = transport.level; // remember Loglevel if set\n transport.level = transport.level || level;\n\n if (transport.type === 'file' && transport.enabled !== false) {\n transport.filename = transport.filename || `log/${tools.appName}`;\n\n if (!transport.fileext && transport.filename.indexOf('.log') === -1) {\n transport.fileext = '.log';\n }\n\n if (!fName) {\n transport.systemLog = true;\n }\n\n transport.handleExceptions = false;\n transport.name = fName ? `dailyRotateFile${fName}` : tools.appName;\n fName++;\n transport.filename = transport.filename.replace(/\\\\/g, '/');\n if (transport.filename.match(/^\\w:\\/|^\\//)) {\n transport.filename = path.normalize(transport.filename);\n } else {\n transport.filename = path.normalize(\n `${tools.getControllerDir()}${isNpm ? '/../../' : '/'}${transport.filename}`,\n );\n }\n transport.auditFile = `${transport.filename}-audit.json`;\n\n transport.createSymlink =\n transport.createSymlink !== undefined ? transport.createSymlink : !isWindows;\n transport.symlinkName =\n transport.symlinkName !== undefined\n ? transport.symlinkName\n : path.basename(`${transport.filename}.current.log`);\n\n transport.filename += `.%DATE%${transport.fileext || ''}`;\n //transport.label = prefix || ''; //TODO format.label()\n // transport.json = (transport.json !== undefined) ? transport.json : false; // TODO format.json(), new Default!!\n transport.silent = transport.silent !== undefined ? transport.silent : false;\n // transport.colorize = (transport.colorize !== undefined) ? transport.colorize : ((userOptions.colorize === undefined) ? true : userOptions.colorize); //TODO format.colorize()\n transport.localTime =\n transport.localTime !== undefined\n ? transport.localTime\n : userOptions.localTime === undefined\n ? true\n : userOptions.localTime;\n transport.datePattern = 'YYYY-MM-DD';\n transport.format = winston.format.combine(winston.format.printf(formatter));\n /*transport.logException = function (message, info, next, err) {\n console.error(message);\n };*/\n transport.zippedArchive = isWindows\n ? false\n : transport.zippedArchive !== undefined\n ? transport.zippedArchive\n : true;\n\n if (transport.maxFiles === null && userOptions.maxDays) {\n transport.maxFiles = `${userOptions.maxDays}d`;\n }\n\n try {\n const _log = new DailyRotateFile(transport);\n\n _log.on('error', err => {\n console.error(`Error on log file rotation: ${err.message}`);\n });\n\n options.transports.push(_log);\n } catch (e) {\n if (e.code === 'EACCES') {\n // modify error code to make it unique for handling\n e.code = 'EACCES_LOG';\n }\n throw e;\n }\n } else if (transport.type === 'syslog' && transport.enabled !== false) {\n if (!IoSysLog) {\n console.error('Syslog configured, but not installed! Ignore');\n continue;\n }\n // host: The host running syslogd, defaults to localhost.\n // port: The port on the host that syslog is running on, defaults to syslogd's default port.\n // protocol: The network protocol to log over (e.g. tcp4, udp4, unix, unix-connect, etc).\n // path: The path to the syslog dgram socket (i.e. /dev/log or /var/run/syslog for OS X).\n // pid: PID of the process that log messages are coming from (Default process.pid).\n // facility: Syslog facility to use (Default: local0).\n // localhost: Host to indicate that log messages are coming from (Default: localhost).\n // sysLogType: The type of the syslog protocol to use (Default: BSD).\n // app_name: The name of the application (Default: process.title).\n // eol: The end of line character to be added to the end of the message (Default: Message without modifications).\n // replace the used by syslog attribute \"type\" with own \"sysLogType\"\n\n // If no name defined, use hostname as name\n transport.localhost = transport.localhost || hostname;\n transport.format = winston.format.combine(winston.format.printf(formatter));\n if (transport.sysLogType) {\n transport.type = transport.sysLogType;\n delete transport.sysLogType;\n } else {\n delete transport.type;\n }\n try {\n options.transports.push(new IoSysLog(transport));\n } catch (e) {\n console.error(`Cannot activate Syslog: ${e.message}`);\n }\n } else if (transport.type === 'http' && transport.enabled !== false) {\n // host: (Default: localhost) Remote host of the HTTP logging endpoint\n // port: (Default: 80 or 443) Remote port of the HTTP logging endpoint\n // path: (Default: /) Remote URI of the HTTP logging endpoint\n // auth: (Default: None) An object representing the username and password for HTTP Basic Auth\n // ssl: (Default: false) Value indicating if we should use HTTPS\n\n // If no name defined, use hostname as name\n transport.host = transport.host || 'localhost';\n\n try {\n options.transports.push(new winston.transports.Http(transport));\n } catch (e) {\n console.error(`Cannot activate HTTP: ${e.message}`);\n }\n } else if (transport.type === 'stream' && transport.enabled !== false) {\n // stream: any Node.js stream. If an objectMode stream is provided then the entire info object will be written. Otherwise info[MESSAGE] will be written.\n // level: Level of messages that this transport should log (default: level set on parent logger).\n // silent: Boolean flag indicating whether to suppress output (default false).\n // eol: Line-ending character to use. (default: os.EOL).\n\n // If no name defined, use hostname as name\n transport.host = transport.host || 'localhost';\n\n try {\n if (typeof transport.stream === 'string') {\n transport.stream = fs.createWriteStream(transport.stream);\n transport.stream.on('error', (err: Error) => {\n console.error(`Error in Stream: ${err.message}`);\n });\n }\n\n options.transports.push(new winston.transports.Stream(transport));\n } catch (e) {\n console.error(`Cannot activate Stream: ${e.message}`);\n }\n } else if (transport.type === 'seq' && transport.enabled !== false) {\n if (!IoSeq) {\n console.error('Seq configured, but not installed! Ignore');\n continue;\n }\n // serverUrl?: string;\n // apiKey?: string;\n // maxBatchingTime?: number;\n // eventSizeLimit?: number;\n // batchSizeLimit?: number;\n\n // Add only if serverUrl is configured at least\n if (transport.serverUrl) {\n try {\n transport.onError = (e: Error) => {\n console.log(`SEQ error: ${e.message}`);\n };\n const seqLogger = new IoSeq(transport);\n options.transports.push(seqLogger);\n } catch (e) {\n console.error(`Cannot activate SEQ: ${e.message}`);\n }\n } else {\n console.error('Cannot activate SEQ: No serverUrl specified');\n }\n }\n }\n }\n } else {\n for (let i = 0; i < files.length; i++) {\n const opt = {\n name: i ? `dailyRotateFile${i}` : tools.appName,\n filename: path.normalize(\n isNpm ? `${thisDir}/../../../log/${files[i]}` : `${thisDir}/../log/${files[i]}`,\n ),\n extension: '.log',\n datePattern: 'YYYY-MM-DD',\n //json: false, // If true, messages will be logged as JSON (default true). TODO format.json()\n level,\n silent: false,\n localTime: true,\n //colorize: (userOptions.colorize === undefined) ? true : userOptions.colorize, // TODO format.colorize()\n //timestamp: timestamp, // TODO: format.timestamp()\n //label: prefix || '', // TODO format.label()\n handleExceptions: false,\n //maxSize: defaultMaxSize\n };\n\n options.transports.push(new DailyRotateFile(opt));\n }\n }\n\n if (!noStdout) {\n options.transports.push(\n new winston.transports.Console({\n level,\n silent: false,\n format: winston.format.combine(winston.format.printf(formatter)),\n //colorize: (userOptions.colorize === undefined) ? true : userOptions.colorize, // TODO format.colorize()\n //timestamp: timestamp, // TODO: format.timestamp()\n //label: prefix || '' // TODO format.label()\n }),\n );\n }\n\n // Must be registered, for adapter.js notification about new logs\n options.transports.push(\n new NotifierTransport({\n level,\n silent: false,\n }),\n );\n\n const log = winston.createLogger(options);\n\n /** @ts-expect-error why do we override/add method to foreign instance? TODO */\n log.getFileName = function () {\n /** @ts-expect-error we use undocumented stuff here TODO */\n let transport = this.transports.find(t => (t.transport && t.transport.dirname) || t.dirname);\n if (transport) {\n /** @ts-expect-error we use undocumented stuff here TODO */\n transport = transport.transport ? transport.transport : transport;\n /** @ts-expect-error we use undocumented stuff here TODO */\n return `${transport.dirname}/${transport.filename.replace('%DATE%', getDate())}`;\n }\n return '';\n };\n\n log.on('error', error => {\n console.log(`Logger error: ${error.message}`);\n });\n\n // This cannot be deleted, because file rotate works with the size of files and not with the time\n // TODO research and open new issue in winston-daily-rotate-file repo\n /**\n * @param isEnabled\n * @param daysCount\n */\n // @ts-expect-error why do we override/add method to foreign instance? TODO\n log.activateDateChecker = function (isEnabled, daysCount) {\n /** @ts-expect-error we use undocumented stuff here TODO */\n if (!isEnabled && this._fileChecker) {\n /** @ts-expect-error we use undocumented stuff here TODO */\n clearInterval(this._fileChecker);\n /** @ts-expect-error we use undocumented stuff here TODO */\n } else if (isEnabled && !this._fileChecker) {\n if (!daysCount) {\n daysCount = 3;\n }\n\n // Check every hour\n /** @ts-expect-error we use undocumented stuff here TODO */\n this._fileChecker = setInterval(() => {\n this.transports.forEach(transport => {\n if (\n /** @ts-expect-error we use undocumented stuff here TODO */\n transport.name !== 'dailyRotateFile' ||\n /** @ts-expect-error we use undocumented stuff here TODO */\n !transport.options ||\n /** @ts-expect-error we use undocumented stuff here TODO */\n transport.options.name !== tools.appName\n ) {\n return;\n }\n\n /** @ts-expect-error we use undocumented stuff here TODO */\n if (transport && fs.existsSync(transport.dirname)) {\n let files;\n try {\n /** @ts-expect-error we use undocumented stuff here TODO */\n files = fs.readdirSync(transport.dirname);\n } catch (e) {\n console.error(`host.${hostname} Cannot read log directory: ${e.message}`);\n return;\n }\n const forXdays = new Date();\n forXdays.setDate(forXdays.getDate() - daysCount - 1); // normally winston now takes care, for old or on errors make sure fallback works a day later\n\n for (let i = 0; i < files.length; i++) {\n const match = files[i].match(/.+\\.(\\d+-\\d+-\\d+)/);\n if (match) {\n const date = new Date(match[1]);\n if (date < forXdays) {\n // delete file\n try {\n this.log({\n level: 'info',\n message: `host.${hostname} Delete log file ${files[i]}`,\n });\n console.log(`host.${hostname} Delete log file ${files[i]}`);\n /** @ts-expect-error we use undocumented stuff here TODO */\n fs.unlinkSync(`${transport.dirname}/${files[i]}`);\n } catch (e) {\n // there is a bug under windows, that file stays opened and cannot be deleted\n this.log({\n level: os.platform().startsWith('win') ? 'info' : 'error',\n message: `host.${hostname} Cannot delete file \"${path.normalize(\n /** @ts-expect-error we use undocumented stuff here TODO */\n `${transport.dirname}/${files[i]}`,\n )}\": ${e}`,\n });\n console.log(\n `host.${hostname} Cannot delete file \"${path.normalize(\n /** @ts-expect-error we use undocumented stuff here TODO */\n `${transport.dirname}/${files[i]}`,\n )}\": ${e.message}`,\n );\n }\n }\n }\n }\n }\n });\n }, 3_600_000); // every hour\n }\n };\n\n return log;\n}\n\nfunction getDate(): string {\n const ts = new Date();\n return `${ts.getFullYear()}-${(ts.getMonth() + 1).toString().padStart(2, '0')}-${ts\n .getDate()\n .toString()\n .padStart(2, '0')}`;\n}\n\nfunction timestamp(date: string): string {\n const ts = date ? new Date(date) : new Date();\n return `${ts.getFullYear()}-${(ts.getMonth() + 1).toString().padStart(2, '0')}-${ts\n .getDate()\n .toString()\n .padStart(2, '0')} ${ts.getHours().toString().padStart(2, '0')}:${ts\n .getMinutes()\n .toString()\n .padStart(2, '0')}:${ts.getSeconds().toString().padStart(2, '0')}.${ts\n .getMilliseconds()\n .toString()\n .padStart(3, '0')} `;\n}\n", "export const __import_meta_url =\n typeof document === 'undefined' ? new (require('url'.replace('', '')).URL)('file:' + __filename).href :\n (document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href)\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;ACAO,IAAM,oBACX,OAAO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deepClone", "Transport", "winston", "os", "path", "DailyRotateFile", "fs", "files"]
7
7
  }
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/common/maybeCallback.ts"],
4
4
  "sourcesContent": ["// Beware, below be TypeScript dragons!\n\nimport { ERRORS } from '@/lib/common/tools.js';\n\ntype MaybeCbCallback<T extends any[]> = (...args: T) => void;\ntype MaybeCbErrCallback<T extends any[]> = (error: Error | null | undefined, ...args: T) => void;\n\n// Helper type to infer the return type of the maybeCallbackWithError function\n// If the callback is given, the return type is void\n// otherwise, the return type is a Promise whose resolved value type depends on the given arguments, or the error variable\ntype MaybeCbErrReturnType<\n TCb extends MaybeCbErrCallback<any> | null | undefined,\n TErr extends Error | string | null | undefined,\n TArgs extends any[],\n> =\n TCb extends MaybeCbErrCallback<any>\n ? void\n : // If there is an error given, the promise will never resolve\n TErr extends Error | string\n ? Promise<never>\n : // Infer the return type from the arguments\n Promise<\n [] extends TArgs\n ? void // if ([] === T) void\n : [any] extends TArgs\n ? TArgs[0] // else if (T has one element) => take first element\n : TArgs // else return T entirely\n >;\n\n// Helper type to infer the callback arguments for the maybeCallbackWithError function\n// If a callback is given, they must match its arguments. Otherwise, they are inferred and default to any[]\ntype MaybeCbErrCallbackParameters<\n CB extends MaybeCbErrCallback<any> | null | undefined,\n TErr extends Error | string | null | undefined,\n> =\n Exclude<CB, undefined | null> extends MaybeCbErrCallback<infer U>\n ? // If the error argument is given,\n TErr extends Error | string\n ? // don't require arguments, but allow passing them\n U | []\n : // Otherwise, require the correct args\n U\n : any[];\n\n// Helper type to infer the callback arguments for the maybeCallback function\n// If a callback is given, they must match its arguments. Otherwise, they are inferred and default to any[]\ntype MaybeCbCallbackParameters<CB extends MaybeCbCallback<any> | null | undefined> =\n Exclude<CB, undefined | null> extends MaybeCbCallback<infer U> ? U : any[];\n\n// Helper type to infer the return type of the maybeCallback function\n// If the callback is given, the return type is void\n// otherwise, the return type is a Promise whose resolved value type depends on the given arguments\ntype MaybeCbReturnType<TCb extends MaybeCbErrCallback<any> | null | undefined, TArgs extends any[]> =\n TCb extends MaybeCbCallback<any>\n ? void\n : // Infer the return type from the arguments\n Promise<\n [] extends TArgs\n ? void // if ([] === T) void\n : [any] extends TArgs\n ? TArgs[0] // else if (T has one element) => take first element\n : TArgs // else return T entirely\n >;\n\n// Helper type to lower the inference priority of an argument\ntype NoInfer<T> = T & { [K in keyof T]: T[K] };\n\n// This is the publicly visible signature of maybeCallback. The one below is just internal\n// and makes implementing the function much, much easier (although a bit unsound).\nexport function maybeCallback<\n // Limit the callback type to a valid callback type\n TCb extends MaybeCbCallback<any> | null | undefined,\n // The callback arguments must match the callback args\n TArgs extends MaybeCbCallbackParameters<TCb> = MaybeCbCallbackParameters<TCb>,\n>(\n callback: TCb,\n // Infer the arguments with lower priority than the callback - they need to match it.\n ...args: NoInfer<TArgs>\n): MaybeCbReturnType<TCb, TArgs>;\n\n/**\n * Checks if the given callback is a function and if so calls it with the given parameter immediately, else a resolved Promise is returned\n *\n * @param callback - callback function to be executed\n * @param args - as many arguments as needed, which will be returned by the callback function or by the Promise\n * @returns if Promise is resolved with multiple arguments, an array is returned\n */\nexport function maybeCallback<T extends any[]>(callback?: MaybeCbCallback<T> | null, ...args: T): Promise<any> | void {\n if (typeof callback === 'function') {\n // if function we call it with given param\n setImmediate(callback, ...args);\n } else {\n return Promise.resolve(args.length > 1 ? args : args[0]);\n }\n}\n\n// This is the publicly visible signature of maybeCallbackWithError. The one below is just internal\n// and makes implementing the function much, much easier (although a bit unsound).\nexport function maybeCallbackWithError<\n // Limit the callback type to a valid callback type\n TCb extends MaybeCbErrCallback<any> | null | undefined,\n // And the error to either an error or sting, or null/undefined\n TErr extends Error | string | null | undefined,\n // The callback arguments must match the callback args\n TArgs extends MaybeCbErrCallbackParameters<TCb, TErr> = MaybeCbErrCallbackParameters<TCb, TErr>,\n>(\n callback: TCb,\n error: TErr,\n // Infer the arguments with lower priority than the callback - they need to match it.\n ...args: NoInfer<TArgs>\n): MaybeCbErrReturnType<TCb, TErr, TArgs>;\n\n/**\n * Checks if the given callback is a function and if so calls it with the given error and parameter immediately, else a resolved or rejected Promise is returned. Error ERROR_DB_CLOSED are not rejecting the promise\n *\n * @param callback - callback function to be executed\n * @param error - error which will be used by the callback function. If callback is not a function and\n * error is given, a rejected Promise is returned. If error is given, but it is not an instance of Error, it is converted into one.\n * @param args - as many arguments as needed, which will be returned by the callback function or by the Promise\n * @returns if Promise is resolved with multiple arguments, an array is returned\n */\nexport function maybeCallbackWithError<T extends any[]>(\n callback: MaybeCbErrCallback<T> | null | undefined,\n error: Error | string | null | undefined,\n ...args: T\n): Promise<any> | void {\n if (error !== undefined && error !== null && !(error instanceof Error)) {\n // if it's not a real Error, we convert it into one\n error = new Error(error);\n }\n const isDbError = error ? error.message === ERRORS.ERROR_DB_CLOSED : false;\n\n if (typeof callback === 'function') {\n setImmediate(callback, error, ...args);\n } else if (error && !isDbError) {\n return Promise.reject(error);\n } else {\n return Promise.resolve(args.length > 1 ? args : args[0]);\n }\n}\n\n// This is the publicly visible signature of maybeCallbackWithRedisError, which is an exact copy of maybeCallbackWithError's signature.\n// The one below is just internal and makes implementing the function much, much easier (although a bit unsound).\nexport function maybeCallbackWithRedisError<\n // Limit the callback type to a valid callback type\n TCb extends MaybeCbErrCallback<any> | null | undefined,\n // And the error to either an error or sting, or null/undefined\n TErr extends Error | string | null | undefined,\n // The callback arguments must match the callback args\n TArgs extends MaybeCbErrCallbackParameters<TCb, TErr> = MaybeCbErrCallbackParameters<TCb, TErr>,\n>(\n callback: TCb,\n error: TErr,\n // Infer the arguments with lower priority than the callback - they need to match it.\n ...args: NoInfer<TArgs>\n): MaybeCbErrReturnType<TCb, TErr, TArgs>;\n\n/**\n * Checks if the given callback is a function and if so calls it with the given error and parameter immediately, else a resolved or rejected Promise is returned. Redis-Error \"Connection is closed.\" is converted into ERROR_DB_CLOSED\n *\n * @param callback - callback function to be executed\n * @param error - error which will be used by the callback function. If callback is not a function and\n * error is given, a rejected Promise is returned. If error is given, but it is not an instance of Error, it is converted into one.\n * @param args - as many arguments as needed, which will be returned by the callback function or by the Promise\n * @returns Promise if Promise is resolved with multiple arguments, an array is returned\n */\nexport function maybeCallbackWithRedisError<T extends any[]>(\n callback: MaybeCbErrCallback<T> | null | undefined,\n error: Error | string | null | undefined,\n ...args: T\n): Promise<any> | void {\n if (error instanceof Error && error.message.includes('Connection is closed')) {\n error.message = ERRORS.ERROR_DB_CLOSED;\n }\n return maybeCallbackWithError(callback, error, ...args);\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAEA,mBAAuB;AAqFjB,SAAU,cAA+B,aAAyC,MAAO;AAC3F,MAAI,OAAO,aAAa,YAAY;AAEhC,iBAAa,UAAU,GAAG,IAAI;EAClC,OAAO;AACH,WAAO,QAAQ,QAAQ,KAAK,SAAS,IAAI,OAAO,KAAK,EAAE;EAC3D;AACJ;AA2BM,SAAU,uBACZ,UACA,UACG,MAAO;AAEV,MAAI,UAAU,UAAa,UAAU,QAAQ,EAAE,iBAAiB,QAAQ;AAEpE,YAAQ,IAAI,MAAM,KAAK;EAC3B;AACA,QAAM,YAAY,QAAQ,MAAM,YAAY,oBAAO,kBAAkB;AAErE,MAAI,OAAO,aAAa,YAAY;AAChC,iBAAa,UAAU,OAAO,GAAG,IAAI;EACzC,WAAW,SAAS,CAAC,WAAW;AAC5B,WAAO,QAAQ,OAAO,KAAK;EAC/B,OAAO;AACH,WAAO,QAAQ,QAAQ,KAAK,SAAS,IAAI,OAAO,KAAK,EAAE;EAC3D;AACJ;AA2BM,SAAU,4BACZ,UACA,UACG,MAAO;AAEV,MAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,sBAAsB,GAAG;AAC1E,UAAM,UAAU,oBAAO;EAC3B;AACA,SAAO,uBAAuB,UAAU,OAAO,GAAG,IAAI;AAC1D;",
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;;;AAEA,mBAAuB;AAqFjB,SAAU,cAA+B,aAAyC,MAAO;AAC3F,MAAI,OAAO,aAAa,YAAY;AAEhC,iBAAa,UAAU,GAAG,IAAI;EAClC,OAAO;AACH,WAAO,QAAQ,QAAQ,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,CAAC;EAC3D;AACJ;AA2BM,SAAU,uBACZ,UACA,UACG,MAAO;AAEV,MAAI,UAAU,UAAa,UAAU,QAAQ,EAAE,iBAAiB,QAAQ;AAEpE,YAAQ,IAAI,MAAM,KAAK;EAC3B;AACA,QAAM,YAAY,QAAQ,MAAM,YAAY,oBAAO,kBAAkB;AAErE,MAAI,OAAO,aAAa,YAAY;AAChC,iBAAa,UAAU,OAAO,GAAG,IAAI;EACzC,WAAW,SAAS,CAAC,WAAW;AAC5B,WAAO,QAAQ,OAAO,KAAK;EAC/B,OAAO;AACH,WAAO,QAAQ,QAAQ,KAAK,SAAS,IAAI,OAAO,KAAK,CAAC,CAAC;EAC3D;AACJ;AA2BM,SAAU,4BACZ,UACA,UACG,MAAO;AAEV,MAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,sBAAsB,GAAG;AAC1E,UAAM,UAAU,oBAAO;EAC3B;AACA,SAAO,uBAAuB,UAAU,OAAO,GAAG,IAAI;AAC1D;",
6
6
  "names": []
7
7
  }
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  return to;
19
19
  };
20
20
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
25
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
26
  mod
23
27
  ));
@@ -62,7 +66,10 @@ function password(pw) {
62
66
  complexity: (password2, callback) => {
63
67
  let result = false;
64
68
  if (typeof password2 === "string") {
65
- result = password2.length >= 8 && /\d/.test(password2) && /[a-z]/.test(password2) && /[A-Z]/.test(password2);
69
+ result = password2.length >= 8 && // minimum length is 8
70
+ /\d/.test(password2) && // contains at least one digit
71
+ /[a-z]/.test(password2) && // contains at least one lower case letter
72
+ /[A-Z]/.test(password2);
66
73
  }
67
74
  typeof callback === "function" && callback(result);
68
75
  return result;
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/common/password.ts"],
4
4
  "sourcesContent": ["/**\n *\n * password hash and check\n *\n * 7'2014-2024 Bluefox <dogafox@gmail.com>\n * 2014 hobbyquaker <hq@ccu.io>\n *\n * derived from https://github.com/florianheinemann/password-hash-and-salt/ (MIT License)\n *\n * The created hash is of the following format: <algorithm>$<iterations>$<hash>$<salt>\n *\n * Usage Example:\n \n var password = require('./lib/password.js');\n \n password('test').hash(null, null, function (err, res) {\n console.log(res);\n \n password('test').check(res, function (err, res) {\n console.log('test: ' + res);\n });\n \n password('muh').check(res, function (err, res) {\n console.log('muh: ' + res);\n });\n \n });\n \n *\n */\n\nimport crypto from 'node:crypto';\n\nexport interface PasswordReturnValue {\n complexity: (password: string, callback: (isComplex: boolean) => void) => boolean;\n check: (hashedPassword: string, callback: (err?: Error | null, isOk?: boolean) => void) => void;\n hash: (\n salt: string | null,\n iterations: number | null,\n callback: (err?: Error | null, hash?: string) => void,\n ) => void;\n}\n\nexport function password(pw: string): PasswordReturnValue {\n return {\n hash: (salt, iterations, callback) => {\n salt = salt || crypto.randomBytes(16).toString('hex');\n iterations = iterations || 10_000;\n\n crypto.pbkdf2(pw, salt, iterations, 256, 'sha256', (err, key) => {\n if (err) {\n return callback(err);\n }\n\n callback(null, `pbkdf2$${iterations}$${key.toString('hex')}$${salt}`);\n });\n },\n check: function (hashedPassword, callback) {\n if (!hashedPassword) {\n return callback(null, false);\n }\n const key = hashedPassword.split('$');\n if (key.length !== 4 || !key[2] || !key[3]) {\n return callback(new Error('Hash not formatted correctly'));\n }\n if (key[0] !== 'pbkdf2') {\n return callback(new Error('Unknown'));\n }\n\n this.hash(key[3], parseInt(key[1], 10), (error, newHash) => {\n if (error) {\n callback(error);\n } else {\n callback(null, newHash === hashedPassword);\n }\n });\n },\n complexity: (password, callback) => {\n let result = false;\n if (typeof password === 'string') {\n result =\n password.length >= 8 && // minimum length is 8\n /\\d/.test(password) && // contains at least one digit\n /[a-z]/.test(password) && // contains at least one lower case letter\n /[A-Z]/.test(password); // contains at least one upper case letter\n }\n typeof callback === 'function' && callback(result);\n return result; // true if the complexity OK\n },\n };\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AA+BA,yBAAmB;AAYb,SAAU,SAAS,IAAU;AAC/B,SAAO;IACH,MAAM,CAAC,MAAM,YAAY,aAAY;AACjC,aAAO,QAAQ,mBAAAA,QAAO,YAAY,EAAE,EAAE,SAAS,KAAK;AACpD,mBAAa,cAAc;AAE3B,yBAAAA,QAAO,OAAO,IAAI,MAAM,YAAY,KAAK,UAAU,CAAC,KAAK,QAAO;AAC5D,YAAI,KAAK;AACL,iBAAO,SAAS,GAAG;QACvB;AAEA,iBAAS,MAAM,UAAU,cAAc,IAAI,SAAS,KAAK,KAAK,MAAM;MACxE,CAAC;IACL;IACA,OAAO,SAAU,gBAAgB,UAAQ;AACrC,UAAI,CAAC,gBAAgB;AACjB,eAAO,SAAS,MAAM,KAAK;MAC/B;AACA,YAAM,MAAM,eAAe,MAAM,GAAG;AACpC,UAAI,IAAI,WAAW,KAAK,CAAC,IAAI,MAAM,CAAC,IAAI,IAAI;AACxC,eAAO,SAAS,IAAI,MAAM,8BAA8B,CAAC;MAC7D;AACA,UAAI,IAAI,OAAO,UAAU;AACrB,eAAO,SAAS,IAAI,MAAM,SAAS,CAAC;MACxC;AAEA,WAAK,KAAK,IAAI,IAAI,SAAS,IAAI,IAAI,EAAE,GAAG,CAAC,OAAO,YAAW;AACvD,YAAI,OAAO;AACP,mBAAS,KAAK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S,KAAK;QAClB,OAAO;AACH,mBAAS,MAAM,YAAY,cAAc;QAC7C;MACJ,CAAC;IACL;IACA,YAAY,CAACC,WAAU,aAAY;AAC/B,UAAI,SAAS;AACb,UAAI,OAAOA,cAAa,UAAU;AAC9B,iBACIA,UAAS,UAAU;QACnB,KAAK,KAAKA,SAAQ;QAClB,QAAQ,KAAKA,SAAQ;QACrB,QAAQ,KAAKA,SAAQ;MAC7B;AACA,aAAO,aAAa,cAAc,SAAS,MAAM;AACjD,aAAO;IACX;;AAER;",
6
6
  "names": ["crypto", "password"]
7
7
  }
@@ -33,6 +33,12 @@ function createAdapterStore(session, defaultTtl = 3600) {
33
33
  }
34
34
  Store.call(this, options);
35
35
  }
36
+ /**
37
+ * Attempt to fetch session by the given `sid`.
38
+ *
39
+ * @param sid Session ID
40
+ * @param fn callback
41
+ */
36
42
  get(sid, fn) {
37
43
  this.adapter.getSession(sid, (obj) => {
38
44
  if (obj) {
@@ -46,6 +52,14 @@ function createAdapterStore(session, defaultTtl = 3600) {
46
52
  }
47
53
  });
48
54
  }
55
+ /**
56
+ * Commit the given `sess` object associated with the given `sid`.
57
+ *
58
+ * @param sid Session ID
59
+ * @param ttl Time to live
60
+ * @param sess the session
61
+ * @param fn callback
62
+ */
49
63
  set(sid, ttl, sess, fn) {
50
64
  if (typeof ttl === "object") {
51
65
  fn = sess;
@@ -57,6 +71,12 @@ function createAdapterStore(session, defaultTtl = 3600) {
57
71
  fn && fn.apply(this, arguments);
58
72
  });
59
73
  }
74
+ /**
75
+ * Destroy the session associated with the given `sid`.
76
+ *
77
+ * @param sid Session ID
78
+ * @param fn callback
79
+ */
60
80
  destroy(sid, fn) {
61
81
  this.adapter.destroySession(sid, fn);
62
82
  }
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/lib/common/session.ts"],
4
4
  "sourcesContent": ["type Session = any;\n\n// TODO: in the long term move this file somewhere where we have types access it is nowhere used in controller itself and just exported for adapters so it should go to js-controller-adapter package\ninterface AdapterStoreOptions {\n /** The ioBroker adapter */\n adapter: any;\n /** The cookie */\n cookie: any;\n}\n\n/**\n * Function to create an AdapterStore constructor\n *\n * @param session The session object\n * @param defaultTtl the default time to live\n * @returns the constructor to create a new AdapterStore\n */\nexport function createAdapterStore(session: Session, defaultTtl = 3600): any {\n const Store = session.Store;\n\n class AdapterStore extends Store {\n constructor(options: AdapterStoreOptions) {\n super(options);\n\n this.adapter = options.adapter;\n\n options = options || {};\n if (!options.cookie) {\n options.cookie = { maxAge: defaultTtl };\n }\n Store.call(this, options);\n }\n\n /**\n * Attempt to fetch session by the given `sid`.\n *\n * @param sid Session ID\n * @param fn callback\n */\n get(sid: string, fn: (err?: any, obj?: any) => void): void {\n this.adapter.getSession(sid, (obj: any) => {\n if (obj) {\n if (fn) {\n return fn(null, obj);\n }\n } else {\n if (fn) {\n return fn();\n }\n }\n });\n }\n\n /**\n * Commit the given `sess` object associated with the given `sid`.\n *\n * @param sid Session ID\n * @param ttl Time to live\n * @param sess the session\n * @param fn callback\n */\n set(sid: string, ttl: number, sess: Session, fn: (args: any) => void): void {\n if (typeof ttl === 'object') {\n fn = sess;\n sess = ttl;\n // analyse if the session is stored directly from express session\n ttl =\n sess && sess.cookie && sess.cookie.originalMaxAge\n ? Math.round(sess.cookie.originalMaxAge / 1000)\n : defaultTtl;\n }\n ttl = ttl || defaultTtl;\n this.adapter.setSession(sid, ttl, sess, function () {\n // @ts-expect-error fix later\n // eslint-disable-next-line prefer-rest-params\n fn && fn.apply(this, arguments);\n }); // do not use here => !!!\n }\n\n /**\n * Destroy the session associated with the given `sid`.\n *\n * @param sid Session ID\n * @param fn callback\n */\n destroy(sid: string, fn: () => void): void {\n this.adapter.destroySession(sid, fn);\n }\n }\n\n return AdapterStore;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAUA;;;;;AAOM,SAAU,mBAAmB,SAAkB,aAAa,MAAI;AAClE,QAAM,QAAQ,QAAQ;AAEtB,QAAM,qBAA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AAW,KAAK,CAAC,QAAY;AACtC,YAAI,KAAK;AACL,cAAI,IAAI;AACJ,mBAAO,GAAG,MAAM,GAAG;UACvB;QACJ,OAAO;AACH,cAAI,IAAI;AACJ,mBAAO,GAAE;UACb;QACJ;MACJ,CAAC;IACL;;;;;;;;;IAUA,IAAI,KAAa,KAAa,MAAe,IAAuB;AAChE,UAAI,OAAO,QAAQ,UAAU;AACzB,aAAK;AACL,eAAO;AAEP,cACI,QAAQ,KAAK,UAAU,KAAK,OAAO,iBAC7B,KAAK,MAAM,KAAK,OAAO,iBAAiB,GAAI,IAC5C;MACd;AACA,YAAM,OAAO;AACb,WAAK,QAAQ,WAAW,KAAK,KAAK,MAAM,WAAA;AAGpC,cAAM,GAAG,MAAM,MAAM,SAAS;MAClC,CAAC;IACL;;;;;;;IAQA,QAAQ,KAAa,IAAc;AAC/B,WAAK,QAAQ,eAAe,KAAK,EAAE;IACvC;;AAGJ,SAAO;AACX;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="@iobroker/types-dev" />
3
- /// <reference types="node" resolution-mode="require"/>
4
- /// <reference types="node" resolution-mode="require"/>
5
1
  import { type ChildProcessPromise } from 'promisify-child-process';
6
2
  import type { CommandResult, PackageManager } from '@alcalzone/pak';
7
3
  import type { ExecOptions } from 'node:child_process';