import {getGlobalConfig, setGlobalConfig} from '../../global'; const {cloneDeep} = require('lodash') interface IOppexConfig { oppexApiKey: string oppexServiceKey?: string } const trimKey = (value: any): string => typeof value === 'string' ? value.trim() : ''; let obj: IOppexConfig | null = null; /** * Setting up config in the singleation, use this function on your application init * @sync * @stable * @param oppexApiKey * @param oppexServiceKey */ export const setOppexConfig = (oppexApiKey: string, oppexServiceKey?: string) => { obj = { oppexApiKey: trimKey(oppexApiKey), oppexServiceKey: trimKey(oppexServiceKey) || undefined } setGlobalConfig(obj, 'oppexConfig') console.log(obj) } /** * Used to get config from the singleation, mostly used internally * @sync * @stable * @internal */ export const getOppexConfig = ():IOppexConfig => { return cloneDeep(getGlobalConfig('oppexConfig')) || { oppexApiKey: '' } }