UNPKG

@fangcha/backend-kit

Version:
58 lines 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._FangchaState = void 0; const tslib_1 = require("tslib"); const logger_1 = require("@fangcha/logger"); const os = require("os"); const bot_kit_1 = require("@fangcha/bot-kit"); class __FangchaState { constructor() { this.appName = ''; this.env = 'development'; this.tags = []; this.codeVersion = ''; this.runningMachine = ''; this.retainHealthWord = ''; this.botProxy = new bot_kit_1.WecomProxy({}); this._checkHealthHandler = () => tslib_1.__awaiter(this, void 0, void 0, function* () { }); this.frontendConfig = {}; this._transferHandlers = []; this.transferSessionUserInfo = (userInfo) => tslib_1.__awaiter(this, void 0, void 0, function* () { for (const handler of this._transferHandlers) { userInfo = handler(userInfo); } return userInfo; }); this.codeVersion = process.env.CODE_VERSION || 'Unknown'; this.runningMachine = os.hostname() || 'Unknown'; } checkHealth() { return tslib_1.__awaiter(this, void 0, void 0, function* () { yield this._checkHealthHandler() .then(() => { logger_1.logger.info(`[${this.env}] Health Checking Passed.`); }) .catch((err) => { logger_1.logger.error(err); exports._FangchaState.botProxy.notifyHealthCheckingError(err.message); throw err; }); }); } appInfo() { return { env: this.env, tags: this.tags, codeVersion: this.codeVersion, runningMachine: this.runningMachine, }; } addUserInfoTransfer(handler) { this._transferHandlers.push(handler); } updateFrontendConfig(extras) { Object.assign(this.frontendConfig, extras); } } exports._FangchaState = new __FangchaState(); //# sourceMappingURL=_FangchaState.js.map