Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createInstance: function(config) {
try {
var hasLogger = false;
config = config || {};
// TODO warn about setting per instance errorHandler / logger / logLevel
if (config.errorHandler) {
logging.setErrorHandler(config.errorHandler);
}
if (config.logger) {
// only set a logger in node if one is provided, by not setting we are noop-ing
hasLogger = true;
logging.setLogHandler(config.logger);
// respect the logger's shouldLog functionality
logging.setLogLevel(logging.LogLevel.NOTSET);
}
if (config.logLevel !== undefined) {
logging.setLogLevel(config.logLevel);
}
try {
configValidator.validate(config);
config.isValidInstance = true;
} catch (ex) {
if (hasLogger) {
logger.error(ex);
} else {
console.error(ex.message);
}
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var logging = require('@optimizely/js-sdk-logging');
var fns = require('./utils/fns');
var configValidator = require('./utils/config_validator');
var defaultErrorHandler = require('./plugins/error_handler');
var defaultEventDispatcher = require('./plugins/event_dispatcher/index.browser');
var enums = require('./utils/enums');
var loggerPlugin = require('./plugins/logger/index.react_native');
var Optimizely = require('./optimizely');
var eventProcessorConfigValidator = require('./utils/event_processor_config_validator');
var logger = logging.getLogger();
logging.setLogHandler(loggerPlugin.createLogger());
logging.setLogLevel(logging.LogLevel.INFO);
var DEFAULT_EVENT_BATCH_SIZE = 10;
var DEFAULT_EVENT_FLUSH_INTERVAL = 1000; // Unit is ms, default is 1s
/**
* Entry point into the Optimizely Javascript SDK for React Native
*/
module.exports = {
logging: loggerPlugin,
errorHandler: defaultErrorHandler,
eventDispatcher: defaultEventDispatcher,
enums: enums,
setLogger: logging.setLogHandler,
setLogLevel: logging.setLogLevel,
* limitations under the License.
*/
require('promise-polyfill/dist/polyfill');
var logging = require('@optimizely/js-sdk-logging');
var fns = require('./utils/fns');
var configValidator = require('./utils/config_validator');
var defaultErrorHandler = require('./plugins/error_handler');
var defaultEventDispatcher = require('./plugins/event_dispatcher/index.browser');
var enums = require('./utils/enums');
var eventProcessor = require('@optimizely/js-sdk-event-processor');
var loggerPlugin = require('./plugins/logger');
var Optimizely = require('./optimizely');
var eventProcessorConfigValidator = require('./utils/event_processor_config_validator');
var logger = logging.getLogger();
logging.setLogHandler(loggerPlugin.createLogger());
logging.setLogLevel(logging.LogLevel.INFO);
var MODULE_NAME = 'INDEX_BROWSER';
var DEFAULT_EVENT_BATCH_SIZE = 10;
var DEFAULT_EVENT_FLUSH_INTERVAL = 1000; // Unit is ms, default is 1s
var hasRetriedEvents = false;
/**
* Entry point into the Optimizely Browser SDK
*/
module.exports = {
logging: loggerPlugin,
errorHandler: defaultErrorHandler,
eventDispatcher: defaultEventDispatcher,
enums: enums,
createInstance: function(config) {
try {
config = config || {};
// TODO warn about setting per instance errorHandler / logger / logLevel
if (config.errorHandler) {
logging.setErrorHandler(config.errorHandler);
}
if (config.logger) {
logging.setLogHandler(config.logger);
// respect the logger's shouldLog functionality
logging.setLogLevel(logging.LogLevel.NOTSET);
}
if (config.logLevel !== undefined) {
logging.setLogLevel(config.logLevel);
}
try {
configValidator.validate(config);
config.isValidInstance = true;
} catch (ex) {
logger.error(ex);
config.isValidInstance = false;
}
// Explicitly check for null or undefined
createInstance: function(config) {
try {
config = config || {};
// TODO warn about setting per instance errorHandler / logger / logLevel
if (config.errorHandler) {
logging.setErrorHandler(config.errorHandler);
}
if (config.logger) {
logging.setLogHandler(config.logger);
// respect the logger's shouldLog functionality
logging.setLogLevel(logging.LogLevel.NOTSET);
}
if (config.logLevel !== undefined) {
logging.setLogLevel(config.logLevel);
}
try {
configValidator.validate(config);
config.isValidInstance = true;
} catch (ex) {
logger.error(ex);
config.isValidInstance = false;
}
// Explicitly check for null or undefined
sinon.stub(datafileManager, 'HttpPollingDatafileManager').returns({
start: sinon.stub(),
stop: sinon.stub(),
get: sinon.stub().returns(null),
on: sinon.stub().returns(function() {}),
onReady: sinon.stub().returns({ then: function() {} }),
});
globalStubErrorHandler = {
handleError: sinon.stub(),
};
logging.setErrorHandler(globalStubErrorHandler);
logging.setLogLevel('notset');
stubLogHandler = {
log: sinon.stub(),
};
logging.setLogHandler(stubLogHandler);
});