Skip to content

Commit 0a8cdf6

Browse files
committed
fix
1 parent 4190139 commit 0a8cdf6

File tree

9 files changed

+61
-157
lines changed

9 files changed

+61
-157
lines changed

lib/export_types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,4 @@ export {
4646
TrackListenerPayload,
4747
NotificationCenter,
4848
OptimizelySegmentOption,
49-
ICache,
5049
} from './shared_types';

lib/index.browser.tests.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import configValidator from './utils/config_validator';
2626
import OptimizelyUserContext from './optimizely_user_context';
2727

2828
import { LOG_MESSAGES, ODP_EVENT_ACTION } from './utils/enums';
29-
import { BrowserOdpManager } from './odp/odp_manager.browser';
3029
import { OdpConfig } from './odp/odp_config';
3130
import { BrowserOdpEventManager } from './odp/event_manager/event_manager.browser';
3231
import { BrowserOdpEventApiManager } from './odp/event_manager/event_api_manager.browser';
@@ -637,21 +636,21 @@ describe('javascript-sdk (Browser)', function() {
637636
sinon.assert.calledWith(fakeOptimizely.identifyUser, testFsUserId);
638637
});
639638

640-
it('should log info when odp is disabled', () => {
641-
const disabledClient = optimizelyFactory.createInstance({
642-
datafile: testData.getTestProjectConfigWithFeatures(),
643-
errorHandler: fakeErrorHandler,
644-
eventDispatcher: fakeEventDispatcher,
645-
eventBatchSize: null,
646-
logger,
647-
odpOptions: { disabled: true },
648-
odpManager: BrowserOdpManager.createInstance({
649-
logger,
650-
odpOptions: {
651-
disabled: true,
652-
},
653-
}),
654-
});
639+
// it('should log info when odp is disabled', () => {
640+
// const disabledClient = optimizelyFactory.createInstance({
641+
// datafile: testData.getTestProjectConfigWithFeatures(),
642+
// errorHandler: fakeErrorHandler,
643+
// eventDispatcher: fakeEventDispatcher,
644+
// eventBatchSize: null,
645+
// logger,
646+
// odpOptions: { disabled: true },
647+
// odpManager: BrowserOdpManager.createInstance({
648+
// logger,
649+
// odpOptions: {
650+
// disabled: true,
651+
// },
652+
// }),
653+
// });
655654

656655
sinon.assert.calledWith(logger.log, optimizelyFactory.enums.LOG_LEVEL.INFO, LOG_MESSAGES.ODP_DISABLED);
657656
});

lib/index.browser.ts

Lines changed: 9 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ import * as enums from './utils/enums';
2424
import * as loggerPlugin from './plugins/logger';
2525
import { createNotificationCenter } from './notification_center';
2626
import { OptimizelyDecideOption, Client, Config, OptimizelyOptions } from './shared_types';
27-
import { BrowserOdpManager } from './odp/odp_manager.browser';
2827
import Optimizely from './optimizely';
2928
import { UserAgentParser } from './odp/ua_parser/user_agent_parser';
3029
import { getUserAgentParser } from './odp/ua_parser/ua_parser.browser';
3130
import * as commonExports from './common_exports';
3231
import { PollingConfigManagerConfig } from './project_config/config_manager_factory';
3332
import { createPollingProjectConfigManager } from './project_config/config_manager_factory.browser';
3433
import { createBatchEventProcessor, createForwardingEventProcessor } from './event_processor/event_processor_factory.browser';
34+
import { createVuidManager } from './vuid/vuid_manager_factory.browser';
35+
import { createOdpManager } from './odp/odp_manager_factory.browser';
36+
3537

3638
const logger = getLogger();
3739
logHelper.setLogHandler(loggerPlugin.createLogger());
@@ -75,73 +77,19 @@ const createInstance = function(config: Config): Client | null {
7577
logger.error(ex);
7678
}
7779

78-
// let eventDispatcher;
79-
// // prettier-ignore
80-
// if (config.eventDispatcher == null) { // eslint-disable-line eqeqeq
81-
// // only wrap the event dispatcher with pending events retry if the user didnt override
82-
// eventDispatcher = new LocalStoragePendingEventsDispatcher({
83-
// eventDispatcher: defaultEventDispatcher,
84-
// });
85-
86-
// if (!hasRetriedEvents) {
87-
// eventDispatcher.sendPendingEvents();
88-
// hasRetriedEvents = true;
89-
// }
90-
// } else {
91-
// eventDispatcher = config.eventDispatcher;
92-
// }
93-
94-
// let closingDispatcher = config.closingEventDispatcher;
95-
96-
// if (!config.eventDispatcher && !closingDispatcher && window.navigator && 'sendBeacon' in window.navigator) {
97-
// closingDispatcher = sendBeaconEventDispatcher;
98-
// }
99-
100-
// let eventBatchSize = config.eventBatchSize;
101-
// let eventFlushInterval = config.eventFlushInterval;
102-
103-
// if (!eventProcessorConfigValidator.validateEventBatchSize(config.eventBatchSize)) {
104-
// logger.warn('Invalid eventBatchSize %s, defaulting to %s', config.eventBatchSize, DEFAULT_EVENT_BATCH_SIZE);
105-
// eventBatchSize = DEFAULT_EVENT_BATCH_SIZE;
106-
// }
107-
// if (!eventProcessorConfigValidator.validateEventFlushInterval(config.eventFlushInterval)) {
108-
// logger.warn(
109-
// 'Invalid eventFlushInterval %s, defaulting to %s',
110-
// config.eventFlushInterval,
111-
// DEFAULT_EVENT_FLUSH_INTERVAL
112-
// );
113-
// eventFlushInterval = DEFAULT_EVENT_FLUSH_INTERVAL;
114-
// }
115-
11680
const errorHandler = getErrorHandler();
11781
const notificationCenter = createNotificationCenter({ logger: logger, errorHandler: errorHandler });
11882

119-
// const eventProcessorConfig = {
120-
// dispatcher: eventDispatcher,
121-
// closingDispatcher,
122-
// flushInterval: eventFlushInterval,
123-
// batchSize: eventBatchSize,
124-
// maxQueueSize: config.eventMaxQueueSize || DEFAULT_EVENT_MAX_QUEUE_SIZE,
125-
// notificationCenter,
126-
// };
127-
128-
const odpExplicitlyOff = config.odpOptions?.disabled === true;
129-
if (odpExplicitlyOff) {
130-
logger.info(enums.LOG_MESSAGES.ODP_DISABLED);
131-
}
132-
13383
const { clientEngine, clientVersion } = config;
13484

13585
const optimizelyOptions: OptimizelyOptions = {
136-
clientEngine: enums.JAVASCRIPT_CLIENT_ENGINE,
13786
...config,
138-
// eventProcessor: eventProcessor.createEventProcessor(eventProcessorConfig),
87+
clientEngine: clientEngine || enums.NODE_CLIENT_ENGINE,
88+
clientVersion: clientVersion || enums.CLIENT_VERSION,
13989
logger,
14090
errorHandler,
14191
notificationCenter,
14292
isValidInstance,
143-
odpManager: odpExplicitlyOff ? undefined
144-
: BrowserOdpManager.createInstance({ logger, odpOptions: config.odpOptions, clientEngine, clientVersion }),
14593
};
14694

14795
const optimizely = new Optimizely(optimizelyOptions);
@@ -197,6 +145,8 @@ export {
197145
createPollingProjectConfigManager,
198146
createForwardingEventProcessor,
199147
createBatchEventProcessor,
148+
createOdpManager,
149+
createVuidManager,
200150
};
201151

202152
export * from './common_exports';
@@ -217,6 +167,8 @@ export default {
217167
createPollingProjectConfigManager,
218168
createForwardingEventProcessor,
219169
createBatchEventProcessor,
170+
createOdpManager,
171+
createVuidManager,
220172
};
221173

222174
export * from './export_types';

lib/index.node.ts

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ import defaultErrorHandler from './plugins/error_handler';
2323
import defaultEventDispatcher from './event_processor/event_dispatcher/default_dispatcher.node';
2424
import { createNotificationCenter } from './notification_center';
2525
import { OptimizelyDecideOption, Client, Config } from './shared_types';
26-
import { NodeOdpManager } from './odp/odp_manager.node';
2726
import * as commonExports from './common_exports';
2827
import { createPollingProjectConfigManager } from './project_config/config_manager_factory.node';
2928
import { createForwardingEventProcessor, createBatchEventProcessor } from './event_processor/event_processor_factory.node';
29+
import { createVuidManager } from './vuid/vuid_manager_factory.browser';
30+
import { createOdpManager } from './odp/odp_manager_factory.browser';
3031

3132
const logger = getLogger();
3233
setLogLevel(LogLevel.ERROR);
@@ -72,53 +73,20 @@ const createInstance = function(config: Config): Client | null {
7273
}
7374
}
7475

75-
// let eventBatchSize = config.eventBatchSize;
76-
// let eventFlushInterval = config.eventFlushInterval;
77-
78-
// if (!eventProcessorConfigValidator.validateEventBatchSize(config.eventBatchSize)) {
79-
// logger.warn('Invalid eventBatchSize %s, defaulting to %s', config.eventBatchSize, DEFAULT_EVENT_BATCH_SIZE);
80-
// eventBatchSize = DEFAULT_EVENT_BATCH_SIZE;
81-
// }
82-
// if (!eventProcessorConfigValidator.validateEventFlushInterval(config.eventFlushInterval)) {
83-
// logger.warn(
84-
// 'Invalid eventFlushInterval %s, defaulting to %s',
85-
// config.eventFlushInterval,
86-
// DEFAULT_EVENT_FLUSH_INTERVAL
87-
// );
88-
// eventFlushInterval = DEFAULT_EVENT_FLUSH_INTERVAL;
89-
// }
9076

9177
const errorHandler = getErrorHandler();
9278
const notificationCenter = createNotificationCenter({ logger: logger, errorHandler: errorHandler });
9379

94-
// const eventProcessorConfig = {
95-
// dispatcher: config.eventDispatcher || defaultEventDispatcher,
96-
// flushInterval: eventFlushInterval,
97-
// batchSize: eventBatchSize,
98-
// maxQueueSize: config.eventMaxQueueSize || DEFAULT_EVENT_MAX_QUEUE_SIZE,
99-
// notificationCenter,
100-
// };
101-
102-
// const eventProcessor = createEventProcessor(eventProcessorConfig);
103-
// const eventProcessor = config.eventProcessor;
104-
105-
const odpExplicitlyOff = config.odpOptions?.disabled === true;
106-
if (odpExplicitlyOff) {
107-
logger.info(enums.LOG_MESSAGES.ODP_DISABLED);
108-
}
109-
11080
const { clientEngine, clientVersion } = config;
11181

11282
const optimizelyOptions = {
113-
clientEngine: enums.NODE_CLIENT_ENGINE,
11483
...config,
115-
// eventProcessor,
84+
clientEngine: clientEngine || enums.NODE_CLIENT_ENGINE,
85+
clientVersion: clientVersion || enums.CLIENT_VERSION,
11686
logger,
11787
errorHandler,
11888
notificationCenter,
11989
isValidInstance,
120-
odpManager: odpExplicitlyOff ? undefined
121-
: NodeOdpManager.createInstance({ logger, odpOptions: config.odpOptions, clientEngine, clientVersion }),
12290
};
12391

12492
return new Optimizely(optimizelyOptions);
@@ -144,6 +112,8 @@ export {
144112
createPollingProjectConfigManager,
145113
createForwardingEventProcessor,
146114
createBatchEventProcessor,
115+
createOdpManager,
116+
createVuidManager,
147117
};
148118

149119
export * from './common_exports';
@@ -161,6 +131,8 @@ export default {
161131
createPollingProjectConfigManager,
162132
createForwardingEventProcessor,
163133
createBatchEventProcessor,
134+
createOdpManager,
135+
createVuidManager,
164136
};
165137

166138
export * from './export_types';

lib/index.react_native.ts

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ import * as loggerPlugin from './plugins/logger/index.react_native';
2323
import defaultEventDispatcher from './event_processor/event_dispatcher/default_dispatcher.browser';
2424
import { createNotificationCenter } from './notification_center';
2525
import { OptimizelyDecideOption, Client, Config } from './shared_types';
26-
import { BrowserOdpManager } from './odp/odp_manager.browser';
2726
import * as commonExports from './common_exports';
2827
import { createPollingProjectConfigManager } from './project_config/config_manager_factory.react_native';
2928
import { createBatchEventProcessor, createForwardingEventProcessor } from './event_processor/event_processor_factory.react_native';
29+
import { createOdpManager } from './odp/odp_manager_factory.react_native';
30+
import { createVuidManager } from './vuid/vuid_manager_factory.react_native';
3031

3132
import 'fast-text-encoding';
3233
import 'react-native-get-random-values';
@@ -70,53 +71,19 @@ const createInstance = function(config: Config): Client | null {
7071
logger.error(ex);
7172
}
7273

73-
// let eventBatchSize = config.eventBatchSize;
74-
// let eventFlushInterval = config.eventFlushInterval;
75-
76-
// if (!eventProcessorConfigValidator.validateEventBatchSize(config.eventBatchSize)) {
77-
// logger.warn('Invalid eventBatchSize %s, defaulting to %s', config.eventBatchSize, DEFAULT_EVENT_BATCH_SIZE);
78-
// eventBatchSize = DEFAULT_EVENT_BATCH_SIZE;
79-
// }
80-
// if (!eventProcessorConfigValidator.validateEventFlushInterval(config.eventFlushInterval)) {
81-
// logger.warn(
82-
// 'Invalid eventFlushInterval %s, defaulting to %s',
83-
// config.eventFlushInterval,
84-
// DEFAULT_EVENT_FLUSH_INTERVAL
85-
// );
86-
// eventFlushInterval = DEFAULT_EVENT_FLUSH_INTERVAL;
87-
// }
88-
8974
const errorHandler = getErrorHandler();
9075
const notificationCenter = createNotificationCenter({ logger: logger, errorHandler: errorHandler });
9176

92-
// const eventProcessorConfig = {
93-
// dispatcher: config.eventDispatcher || defaultEventDispatcher,
94-
// flushInterval: eventFlushInterval,
95-
// batchSize: eventBatchSize,
96-
// maxQueueSize: config.eventMaxQueueSize || DEFAULT_EVENT_MAX_QUEUE_SIZE,
97-
// notificationCenter,
98-
// peristentCacheProvider: config.persistentCacheProvider,
99-
// };
100-
101-
// const eventProcessor = createEventProcessor(eventProcessorConfig);
102-
103-
const odpExplicitlyOff = config.odpOptions?.disabled === true;
104-
if (odpExplicitlyOff) {
105-
logger.info(enums.LOG_MESSAGES.ODP_DISABLED);
106-
}
107-
10877
const { clientEngine, clientVersion } = config;
10978

11079
const optimizelyOptions = {
111-
clientEngine: enums.REACT_NATIVE_JS_CLIENT_ENGINE,
11280
...config,
113-
// eventProcessor,
81+
clientEngine: clientEngine || enums.NODE_CLIENT_ENGINE,
82+
clientVersion: clientVersion || enums.CLIENT_VERSION,
11483
logger,
11584
errorHandler,
11685
notificationCenter,
11786
isValidInstance: isValidInstance,
118-
odpManager: odpExplicitlyOff ? undefined
119-
:BrowserOdpManager.createInstance({ logger, odpOptions: config.odpOptions, clientEngine, clientVersion }),
12087
};
12188

12289
// If client engine is react, convert it to react native.
@@ -147,6 +114,8 @@ export {
147114
createPollingProjectConfigManager,
148115
createForwardingEventProcessor,
149116
createBatchEventProcessor,
117+
createOdpManager,
118+
createVuidManager,
150119
};
151120

152121
export * from './common_exports';
@@ -164,6 +133,8 @@ export default {
164133
createPollingProjectConfigManager,
165134
createForwardingEventProcessor,
166135
createBatchEventProcessor,
136+
createOdpManager,
137+
createVuidManager,
167138
};
168139

169140
export * from './export_types';

lib/odp/odp_manager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface OdpManager extends Service {
3636
identifyUser(userId: string, vuid?: string): void;
3737
sendEvent(event: OdpEvent): void;
3838
setClientInfo(clientEngine: string, clientVersion: string): void;
39+
setVuid(vuid: string): void;
3940
}
4041

4142
export type OdpManagerConfig = {

0 commit comments

Comments
 (0)