@splitsoftware/splitio-commons
Version:
Split JavaScript SDK common components
25 lines (20 loc) • 823 B
text/typescript
import SplitIO from '../../types/splitio';
import { sdkClientFactory } from './sdkClient';
import { RETRIEVE_CLIENT_DEFAULT } from '../logger/constants';
import { ISdkFactoryContext } from '../sdkFactory/types';
/**
* Factory of client method for server-side SDKs
*/
export function sdkClientMethodFactory(params: ISdkFactoryContext): () => SplitIO.IClient | SplitIO.IAsyncClient {
const log = params.settings.log;
const clientInstance = sdkClientFactory(params);
// Only one client in server-side without bound key
params.clients[''] = clientInstance;
return function client() {
if (arguments.length > 0) {
throw new Error('Shared Client not supported by the storage mechanism. Create isolated instances instead.');
}
log.debug(RETRIEVE_CLIENT_DEFAULT);
return clientInstance;
};
}