1- import optimizelySDK from '@optimizely/optimizely-sdk'
1+ import {
2+ createInstance ,
3+ createPollingProjectConfigManager ,
4+ createBatchEventProcessor ,
5+ createLogger ,
6+ createOdpManager ,
7+ OptimizelyDecideOption ,
8+ NOTIFICATION_TYPES ,
9+ ERROR ,
10+ INFO
11+ } from '@optimizely/optimizely-sdk'
212
313import { updateIntegrations } from './integrations/handler.js'
414
@@ -14,9 +24,7 @@ const DEFAULT_EVENTS_OPTIONS = {
1424
1525const DEFAULT_TIMEOUT = 500
1626
17- const { enums} = optimizelySDK
18-
19- const LOGGER_LEVEL = process . env . NODE_ENV === 'production' ? enums . error : enums . info
27+ const LOGGER_LEVEL = process . env . NODE_ENV === 'production' ? ERROR : INFO
2028
2129export default class OptimizelyAdapter {
2230 /**
@@ -44,35 +52,40 @@ export default class OptimizelyAdapter {
4452 * @param {string } param.sdkKey
4553 * @param {object= } param.datafile
4654 * @param {object } param.options datafile options https://docs.developers.optimizely.com/full-stack/docs/initialize-sdk-javascript-node
47- * @param {object } param.optimizely test purposes only, optimizely sdk
48- * @param {function } param.eventDispatcher https://docs.developers.optimizely.com/full-stack/docs/configure-event-dispatcher-javascript-node
4955 */
50- static createOptimizelyInstance ( {
51- options : optionParameter ,
52- sdkKey,
53- datafile,
54- optimizely = optimizelySDK ,
55- eventDispatcher = optimizelySDK . eventDispatcher
56- } ) {
57- const options = { ...DEFAULT_DATAFILE_OPTIONS , ...optionParameter }
58- optimizely . setLogLevel ( LOGGER_LEVEL )
59- optimizely . setLogger ( optimizely . logging . createLogger ( ) )
56+ static createOptimizelyInstance ( { options : optionParameter , sdkKey, datafile} ) {
6057 if ( ! datafile && typeof window !== 'undefined' && window . __INITIAL_CONTEXT_VALUE__ ?. pde ) {
6158 datafile = window . __INITIAL_CONTEXT_VALUE__ . pde
6259 sdkKey = undefined
6360 }
6461
6562 const isServer = typeof window === 'undefined'
66- const optimizelyInstance = optimizely . createInstance ( {
63+
64+ const projectConfigManager = createPollingProjectConfigManager ( {
6765 sdkKey,
68- datafileOptions : options ,
6966 datafile,
70- eventDispatcher,
67+ ...DEFAULT_DATAFILE_OPTIONS ,
68+ ...optionParameter
69+ } )
70+
71+ const eventProcessor = createBatchEventProcessor ( {
7172 ...DEFAULT_EVENTS_OPTIONS ,
72- defaultDecideOptions : isServer ? [ optimizely . OptimizelyDecideOption . DISABLE_DECISION_EVENT ] : [ ]
73+ ... optionParameter
7374 } )
7475
75- return optimizelyInstance
76+ const odpManager = createOdpManager ( )
77+
78+ const logger = createLogger ( {
79+ level : LOGGER_LEVEL
80+ } )
81+
82+ return createInstance ( {
83+ projectConfigManager,
84+ eventProcessor,
85+ odpManager,
86+ logger,
87+ defaultDecideOptions : isServer ? [ OptimizelyDecideOption . DISABLE_DECISION_EVENT ] : [ ]
88+ } )
7689 }
7790
7891 /**
@@ -133,9 +146,7 @@ export default class OptimizelyAdapter {
133146
134147 return user . decide (
135148 name ,
136- ! this . _hasUserConsents || isEventDisabled
137- ? [ optimizelySDK . OptimizelyDecideOption . DISABLE_DECISION_EVENT ]
138- : undefined
149+ ! this . _hasUserConsents || isEventDisabled ? [ OptimizelyDecideOption . DISABLE_DECISION_EVENT ] : undefined
139150 )
140151 }
141152
@@ -145,7 +156,7 @@ export default class OptimizelyAdapter {
145156 * @returns {number } notificationId
146157 */
147158 addDecideListener ( { onDecide} ) {
148- return this . _optimizely . notificationCenter . addNotificationListener ( enums . NOTIFICATION_TYPES . DECISION , onDecide )
159+ return this . _optimizely . notificationCenter . addNotificationListener ( NOTIFICATION_TYPES . DECISION , onDecide )
149160 }
150161
151162 /**
0 commit comments