import logger from '../utils/Logger';
export class ChargingStationConfigurationUtils {
+ private constructor() {
+ // This is intentional
+ }
+
public static getConfigurationKey(
chargingStation: ChargingStation,
key: string | StandardParametersKey,
import path from 'path';
export class ChargingStationUtils {
+ private constructor() {
+ // This is intentional
+ }
+
public static getChargingStationId(
index: number,
stationTemplate: ChargingStationTemplate
export class OCPPServiceUtils {
+ protected constructor() {
+ // This is intentional
+ }
+
protected static getLimitFromSampledValueTemplateCustomValue(
value: string,
limit: number,
import { ApplicationProtocol } from '../../types/UIProtocol';
import Configuration from '../../utils/Configuration';
import { ServerOptions } from '../../types/ConfigurationData';
+import { UIServiceUtils } from './ui-services/UIServiceUtils';
import UIWebSocketServer from './UIWebSocketServer';
+import chalk from 'chalk';
export default class UIServerFactory {
private constructor() {
applicationProtocol: ApplicationProtocol,
options?: ServerOptions
): AbstractUIServer | null {
+ if (!UIServiceUtils.isLoopback(options?.host)) {
+ console.warn(
+ chalk.magenta(
+ 'Loopback address not detected in UI server configuration. This is not recommended.'
+ )
+ );
+ }
switch (applicationProtocol) {
case ApplicationProtocol.WS:
return new UIWebSocketServer(options ?? Configuration.getUIServer().options);
import logger from '../../../utils/Logger';
export class UIServiceUtils {
+ private constructor() {
+ // This is intentional
+ }
+
public static handleProtocols = (
protocols: Set<string>,
request: IncomingMessage
);
return false;
};
+
+ public static isLoopback(address: string): boolean {
+ const isLoopbackRegExp = new RegExp(
+ // eslint-disable-next-line no-useless-escape
+ /^localhost$|^127(?:\.\d+){0,2}\.\d+$|^(?:0*\:)*?:?0*1$/,
+ 'i'
+ );
+ return isLoopbackRegExp.test(address);
+ }
}
private static configuration: ConfigurationData | null = null;
private static configurationChangeCallback: () => Promise<void>;
+ private constructor() {
+ // This is intentional
+ }
+
static setConfigurationChangeCallback(cb: () => Promise<void>): void {
Configuration.configurationChangeCallback = cb;
}
},
};
if (Configuration.objectHasOwnProperty(Configuration.getConfig(), 'uiServer')) {
- uiServerConfiguration = {
- ...uiServerConfiguration,
- ...Configuration.getConfig().uiServer,
- };
+ uiServerConfiguration = Configuration.deepMerge(
+ uiServerConfiguration,
+ Configuration.getConfig().uiServer
+ );
}
return uiServerConfiguration;
}
}
}
+ private static isObject(item): boolean {
+ return item && typeof item === 'object' && !Array.isArray(item);
+ }
+
+ private static deepMerge(target: object, ...sources: object[]): object {
+ if (!sources.length) {
+ return target;
+ }
+ const source = sources.shift();
+
+ if (Configuration.isObject(target) && Configuration.isObject(source)) {
+ for (const key in source) {
+ if (Configuration.isObject(source[key])) {
+ if (!target[key]) {
+ Object.assign(target, { [key]: {} });
+ }
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
+ Configuration.deepMerge(target[key], source[key]);
+ } else {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
+ Object.assign(target, { [key]: source[key] });
+ }
+ }
+ }
+ return Configuration.deepMerge(target, ...sources);
+ }
+
private static objectHasOwnProperty(object: unknown, property: string): boolean {
return Object.prototype.hasOwnProperty.call(object, property) as boolean;
}
* Targeted to AC related values calculation.
*/
export class ACElectricUtils {
+ private constructor() {
+ // This is intentional
+ }
+
static amperageTotal(nbOfPhases: number, Iph: number): number {
return nbOfPhases * Iph;
}
import logger from './Logger';
export default class FileUtils {
+ private constructor() {
+ // This is intentional
+ }
+
public static watchJsonFile<T extends JsonType>(
logPrefix: string,
fileType: FileType,
import { v4 as uuid } from 'uuid';
export default class Utils {
+ private constructor() {
+ // This is intentional
+ }
+
public static logPrefix(prefixString = ''): string {
return new Date().toLocaleString() + prefixString;
}
import chalk from 'chalk';
export class WorkerUtils {
+ private constructor() {
+ // This is intentional
+ }
+
public static defaultExitHandler = (code: number): void => {
if (code !== 0) {
console.error(chalk.red(`Worker stopped with exit code ${code}`));