UNPKG

@larksuiteoapi/core

Version:
59 lines 2.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getConfigByCtx = exports.newConfig = exports.newConfigWithOpts = exports.newTestConfig = exports.Config = void 0; const log_1 = require("../log/log"); const store_1 = require("../store/store"); const ctxKeyConfig = "ctxKeyConfig"; class Config { constructor(domain, appSettings, opts) { const loggerLevel = opts.loggerLevel ? opts.loggerLevel : log_1.LoggerLevel.ERROR; const logger = opts.logger ? opts.logger : new log_1.ConsoleLogger(); const store = opts.store ? opts.store : new store_1.DefaultStore(); this.domain = domain; this.appSettings = appSettings; this.logger = new log_1.LoggerProxy(loggerLevel, logger); this.store = store; this.helpDeskAuthorization = appSettings.helpDeskAuthorization(); } withContext(ctx) { ctx.set(ctxKeyConfig, this); } getDomain() { return this.domain; } getAppSettings() { return this.appSettings; } getLogger() { return this.logger; } getStore() { return this.store; } getHelpDeskAuthorization() { return this.helpDeskAuthorization; } } exports.Config = Config; function newTestConfig(domain, appSettings) { return newConfig(domain, appSettings, new log_1.ConsoleLogger(), log_1.LoggerLevel.DEBUG, new store_1.DefaultStore()); } exports.newTestConfig = newTestConfig; function newConfigWithOpts(domain, appSettings, opts) { opts = opts ? opts : {}; return new Config(domain, appSettings, opts); } exports.newConfigWithOpts = newConfigWithOpts; function newConfig(domain, appSettings, logger, loggerLevel, store) { return new Config(domain, appSettings, { loggerLevel: loggerLevel, logger: logger, store: store }); } exports.newConfig = newConfig; function getConfigByCtx(ctx) { return ctx.get(ctxKeyConfig); } exports.getConfigByCtx = getConfigByCtx; //# sourceMappingURL=config.js.map