diff --git a/.vscode/settings.json b/.vscode/settings.json index ac3a885..669180a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,5 @@ { "jest.autoRun": { "onStartup": ["all-tests"] - }, - "jest.jestCommandLine": "./node_modules/.bin/jest", - "jest.autoRevealOutput": "on-exec-error" + } } diff --git a/src/client.ts b/src/client.ts index 250e38c..812b022 100644 --- a/src/client.ts +++ b/src/client.ts @@ -5,7 +5,7 @@ * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -243,19 +243,23 @@ class OptimizelyReactSDKClient implements ReactSDKClient { this.isClientReady = true; }); - this.dataReadyPromise = Promise.all([this.userPromise, this._client!.onReady()]).then(res => { + this.dataReadyPromise = Promise.all([this.userPromise, this._client.onReady()]).then( + ([userResult, clientResult]) => { + this.isReadyPromiseFulfilled = true; - // Client and user can become ready synchronously and/or asynchronously. This flag specifically indicates that they became ready asynchronously. - this.isReadyPromiseFulfilled = true; - return { - success: true, - message: 'Successfully resolved datafile and user information.', - }; - }); + const bothSuccessful = userResult.success && clientResult.success; + return { + success: true, // bothSuccessful, + message: bothSuccessful + ? 'Successfully resolved user information and client datafile.' + : 'User information or client datafile was not not ready.', + }; + } + ); } else { logger.warn('Unable to resolve datafile and user information because Optimizely client failed to initialize.'); - this.dataReadyPromise = new Promise((resolve, reject) => { + this.dataReadyPromise = new Promise(resolve => { resolve({ success: false, reason: 'NO_CLIENT', @@ -308,14 +312,14 @@ class OptimizelyReactSDKClient implements ReactSDKClient { return Promise.race([this.dataReadyPromise, timeoutPromise]).then(async res => { clearTimeout(timeoutId); - if (res.success) { + if (res.success && !this.initialConfig.odpOptions?.disabled) { const isSegmentsFetched = await this.fetchQualifiedSegments(); if (!isSegmentsFetched) { return { success: false, reason: 'USER_NOT_READY', message: 'Failed to fetch qualified segments', - } + }; } } return res; diff --git a/src/hooks.ts b/src/hooks.ts index 552db85..f13bd30 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -14,16 +14,16 @@ * limitations under the License. */ import { useCallback, useContext, useEffect, useState, useRef } from 'react'; -import { UserAttributes, OptimizelyDecideOption } from '@optimizely/optimizely-sdk'; -import { getLogger } from '@optimizely/optimizely-sdk'; -import { LoggerFacade } from '@optimizely/optimizely-sdk/dist/modules/logging'; + +import { UserAttributes, OptimizelyDecideOption, getLogger } from '@optimizely/optimizely-sdk'; + import { setupAutoUpdateListeners } from './autoUpdate'; import { ReactSDKClient, VariableValuesObject, OnReadyResult } from './client'; import { notifier } from './notifier'; import { OptimizelyContext } from './Context'; import { areAttributesEqual, OptimizelyDecision, createFailedDecision } from './utils'; -const hooksLogger: LoggerFacade = getLogger('ReactSDK'); +const hooksLogger = getLogger('ReactSDK'); enum HookType { EXPERIMENT = 'Experiment', diff --git a/src/index.ts b/src/index.ts index 5404f66..471ece6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,11 @@ /** - * Copyright 2018-2019, Optimizely + * Copyright 2018-2019, 2023 Optimizely * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + export { OptimizelyContext, OptimizelyContextConsumer, OptimizelyContextProvider } from './Context'; export { OptimizelyProvider } from './Provider'; export { OptimizelyFeature } from './Feature'; @@ -22,8 +23,7 @@ export { OptimizelyExperiment } from './Experiment'; export { OptimizelyVariation } from './Variation'; export { OptimizelyDecision } from './utils'; -export - { +export { logging, errorHandler, setLogger, @@ -33,9 +33,9 @@ export OptimizelyDecideOption, ActivateListenerPayload, TrackListenerPayload, - ListenerPayload -} -from '@optimizely/optimizely-sdk'; + ListenerPayload, + OptimizelySegmentOption, +} from '@optimizely/optimizely-sdk'; export { createInstance, ReactSDKClient } from './client';