module.exports = class Salix { constructor() { this.conf = null; this._logInfo = []; this._salixVersion = null; } async init(logger) { this.conf = logger.conf; setInterval(() => this.getSalixVersion, this.conf.salix.renewInterval); await this.salixLogInfo(); } async fetch(path) { let salixCall = await fetch(`${this.conf.salix.url}/${path}`, { method: "GET", }); const response = JSON.parse(await salixCall.text()); if (salixCall.status !== 200) { console.error(response.error); throw new Error(response.error.message); } this._salixVersion = salixCall.headers.get("Salix-version"); return response; } async getSalixVersion() { log("CHECK VERSION"); const salixVersion = await this.fetch("applications/version"); if (this._salixVersion !== salixVersion) fetch(); log("VERSION CHECKED"); } async salixLogInfo() { log("LOGINFO REQUEST"); let salixLogConfig = await this.fetch("schemas/logInfo"); this._logInfo = [salixLogConfig]; log("LOGINFO REQUESTED"); } log(param) { console.log(`${Salix.name} - ${param}`); } get logInfo() { return this._logInfo; } get salixVersion() { return this._salixVersion; } };