+ return Configuration.getConfig().supervisionUrls;
+ }
+
+ static getSupervisionUrlDistribution(): SupervisionUrlDistribution {
+ Configuration.warnDeprecatedConfigurationKey(
+ 'distributeStationToTenantEqually',
+ null,
+ "Use 'supervisionUrlDistribution' instead"
+ );
+ Configuration.warnDeprecatedConfigurationKey(
+ 'distributeStationsToTenantsEqually',
+ null,
+ "Use 'supervisionUrlDistribution' instead"
+ );
+ return Configuration.objectHasOwnProperty(
+ Configuration.getConfig(),
+ 'supervisionUrlDistribution'
+ )
+ ? Configuration.getConfig().supervisionUrlDistribution
+ : SupervisionUrlDistribution.ROUND_ROBIN;
+ }
+
+ private static logPrefix(): string {
+ return new Date().toLocaleString() + ' Simulator configuration |';
+ }
+
+ private static warnDeprecatedConfigurationKey(
+ key: string,
+ sectionName?: string,
+ logMsgToAppend = ''
+ ) {
+ if (
+ sectionName &&
+ !Configuration.isUndefined(Configuration.getConfig()[sectionName]) &&
+ !Configuration.isUndefined(
+ (Configuration.getConfig()[sectionName] as Record<string, unknown>)[key]
+ )
+ ) {
+ console.error(
+ chalk`{green ${Configuration.logPrefix()}} {red Deprecated configuration key '${key}' usage in section '${sectionName}'${
+ logMsgToAppend && '. ' + logMsgToAppend
+ }}`
+ );
+ } else if (!Configuration.isUndefined(Configuration.getConfig()[key])) {
+ console.error(
+ chalk`{green ${Configuration.logPrefix()}} {red Deprecated configuration key '${key}' usage${
+ logMsgToAppend && '. ' + logMsgToAppend
+ }}`
+ );
+ }
+ }
+
+ // Read the config file
+ private static getConfig(): ConfigurationData {
+ if (!Configuration.configuration) {
+ try {
+ Configuration.configuration = JSON.parse(
+ fs.readFileSync(Configuration.configurationFile, 'utf8')
+ ) as ConfigurationData;
+ } catch (error) {
+ Configuration.handleFileException(
+ Configuration.logPrefix(),
+ FileType.Configuration,
+ Configuration.configurationFile,
+ error as NodeJS.ErrnoException
+ );
+ }
+ if (!Configuration.configurationFileWatcher) {
+ Configuration.configurationFileWatcher = Configuration.getConfigurationFileWatcher();
+ }
+ }
+ return Configuration.configuration;
+ }
+
+ private static getConfigurationFileWatcher(): fs.FSWatcher {
+ try {
+ return fs.watch(Configuration.configurationFile, (event, filename): void => {
+ if (filename && event === 'change') {
+ // Nullify to force configuration file reading
+ Configuration.configuration = null;
+ if (!Configuration.isUndefined(Configuration.configurationChangeCallback)) {
+ Configuration.configurationChangeCallback().catch((error) => {
+ throw typeof error === 'string' ? new Error(error) : error;
+ });
+ }
+ }
+ });
+ } catch (error) {
+ Configuration.handleFileException(
+ Configuration.logPrefix(),
+ FileType.Configuration,
+ Configuration.configurationFile,
+ error as NodeJS.ErrnoException
+ );
+ }
+ }
+
+ private static isCFEnvironment(): boolean {
+ return process.env.VCAP_APPLICATION !== undefined;
+ }
+
+ private static getDefaultPerformanceStorageUri(storageType: StorageType) {
+ const SQLiteFileName = `${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db`;
+ switch (storageType) {
+ case StorageType.JSON_FILE:
+ return `file://${path.join(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'),
+ Constants.DEFAULT_PERFORMANCE_RECORDS_FILENAME
+ )}`;
+ case StorageType.SQLITE:
+ return `file://${path.join(
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../'),
+ SQLiteFileName
+ )}`;
+ default:
+ throw new Error(`Performance storage URI is mandatory with storage type '${storageType}'`);
+ }
+ }
+
+ private static isObject(item): boolean {
+ return item && typeof item === 'object' && Array.isArray(item) === false;
+ }
+
+ private static objectHasOwnProperty(object: unknown, property: string): boolean {
+ return Object.prototype.hasOwnProperty.call(object, property) as boolean;
+ }
+
+ private static isUndefined(obj: unknown): boolean {
+ return typeof obj === 'undefined';