Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FSSDK-9494] Bug bash & fixes #214

Merged
merged 77 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
558b0a9
Remove devcontainer comments
mikechu-optimizely Aug 4, 2023
6f8aa75
Testing bug bash devcontainer config
mikechu-optimizely Aug 4, 2023
d83ba72
Remove the separate dev container conf
mikechu-optimizely Aug 4, 2023
cbb4845
Add setup & exec as npm scripts
mikechu-optimizely Aug 4, 2023
674b50c
Merge branch 'master' into mike/bug-bash
mikechu-optimizely Aug 4, 2023
772fdd4
Use LF by default when in devcontainer
mikechu-optimizely Aug 4, 2023
2eac90f
Update jest config
mikechu-optimizely Aug 4, 2023
a5df270
Update JS SDK via yarn.lock
mikechu-optimizely Aug 4, 2023
7d8d053
Convert to TS for bug bash
mikechu-optimizely Aug 4, 2023
75fc610
Prompt for SDK key for the bug bash
mikechu-optimizely Aug 4, 2023
4bf5c51
Ignore the .env file
mikechu-optimizely Aug 4, 2023
cca1084
Enhance setup.sh
mikechu-optimizely Aug 4, 2023
41c0e41
Conditionally npm
mikechu-optimizely Aug 4, 2023
6d67dfe
Change back to scripty .js
mikechu-optimizely Aug 4, 2023
b014634
Add boilerplate React bug-bash/app
mikechu-optimizely Aug 4, 2023
7d84ab0
Update setup.sh to install + run React app
mikechu-optimizely Aug 4, 2023
803a6ee
Update npm script to run bug-bash
mikechu-optimizely Aug 4, 2023
b72491c
Simplify setup.sh
mikechu-optimizely Aug 4, 2023
0c41798
Simplify the react app
mikechu-optimizely Aug 4, 2023
835911b
WIP: Update App + use local @optimizely/react-sdk
mikechu-optimizely Aug 4, 2023
4dc1db5
Add local React & dotenv
mikechu-optimizely Aug 7, 2023
a14a677
Update setup script
mikechu-optimizely Aug 7, 2023
52de93b
Remove dotenv
mikechu-optimizely Aug 8, 2023
a89ad2c
WIP bring .env values in
mikechu-optimizely Aug 8, 2023
07ecfe4
Complete WIP on reading SDK from .env
mikechu-optimizely Aug 14, 2023
2eb812c
Transfer @rafinutshaw-optimizely's work in
mikechu-optimizely Aug 14, 2023
88df778
Small style fix
mikechu-optimizely Aug 14, 2023
df3e319
Minor semantic HTML changes
mikechu-optimizely Aug 14, 2023
43cf5ad
A bunch'o NITs for my comfort
mikechu-optimizely Aug 14, 2023
55d55fd
Rename bug-bash setup & add run
mikechu-optimizely Aug 15, 2023
1d29b80
Ensure shell scripts use LF line endings
mikechu-optimizely Aug 15, 2023
d4f75a6
WIP testing & refactoring tests
mikechu-optimizely Aug 15, 2023
f88d129
Better doc & UI + Refactors
mikechu-optimizely Aug 16, 2023
dc4485b
Move Decision; Finish refactor existing tests
mikechu-optimizely Aug 18, 2023
381c42a
Add more tests based on spreadsheet\
mikechu-optimizely Aug 18, 2023
c55cb44
Add sendOdpEvent tests
mikechu-optimizely Aug 18, 2023
5a0c9c8
Last bits of documentation
mikechu-optimizely Aug 18, 2023
659e936
Update to use js sdk 5.0.0-beta4
mikechu-optimizely Aug 22, 2023
8d91b30
WIP test updates
mikechu-optimizely Aug 22, 2023
1f26f39
Update path to logging
mikechu-optimizely Aug 22, 2023
4ca21b6
Update bug bash to package-lock.json
mikechu-optimizely Aug 22, 2023
9f4c00c
Add @types/uuid 🤔
mikechu-optimizely Aug 22, 2023
ec875cd
Use /lib/ instead of /dist/ from JS SDK
mikechu-optimizely Aug 22, 2023
03f4779
Reset for other bashers
mikechu-optimizely Aug 22, 2023
47460ef
Add more documentation
mikechu-optimizely Aug 23, 2023
04dc93f
Upgrade vulnerable tough-cookie to v4.1.3
mikechu-optimizely Aug 25, 2023
07b779e
Add "repository" field to package.json
mikechu-optimizely Aug 25, 2023
c997ba2
Add `useContext` documentation from...
mikechu-optimizely Aug 28, 2023
0cc6b3d
Add EOF lines
mikechu-optimizely Aug 28, 2023
aaf637c
Merge branch 'master' into mike/bug-bash
mikechu-optimizely Aug 28, 2023
0e59549
Remove React.StrictMode
mikechu-optimizely Sep 1, 2023
4ebbb43
Remove Vite icon ref
mikechu-optimizely Sep 1, 2023
814d54e
Add decision button to change userId
mikechu-optimizely Sep 1, 2023
5667758
Remove variationKey validation
mikechu-optimizely Sep 1, 2023
4cd67ed
Upgrade to JS SDK 5.0.0-beta5
mikechu-optimizely Sep 1, 2023
3a958b8
Fix references to remove /lib
mikechu-optimizely Sep 1, 2023
25befbf
WIP: Fixing getLogger ref from JS 5-beta5
mikechu-optimizely Sep 1, 2023
4a49829
Explicitly optimizeDep-endcy JS SDK
mikechu-optimizely Sep 6, 2023
8977fd7
Export OptimizelySegmentOption from JS SDK
mikechu-optimizely Sep 6, 2023
518fc86
Use OptimizelySegmentOption from React SDK export
mikechu-optimizely Sep 6, 2023
727d7b5
Update bug bash package-lock
mikechu-optimizely Sep 6, 2023
3dae9cf
Remove optimizeDeps from viteconfig
mikechu-optimizely Sep 6, 2023
7aac7f3
Add test comment
mikechu-optimizely Sep 6, 2023
e6c86a3
Changed optimizelyClient init location in BB app
mikechu-optimizely Sep 7, 2023
5f9bef3
Add VSCode launch.json
mikechu-optimizely Sep 13, 2023
d9ccb9d
Add conditional to auto fetchQualifiedSegments
mikechu-optimizely Sep 13, 2023
4dad16f
Merge branch 'master' into mike/bug-bash
Sep 21, 2023
dc8b25b
Merge branch 'master' into mike/bug-bash
Sep 21, 2023
b9c4a72
Format .vscode files
Sep 21, 2023
5513283
Leave out tough-cookie dep
Sep 21, 2023
d8a4708
Minor clean ups
Sep 21, 2023
0bb360b
Update package-json
Sep 21, 2023
0846634
PR review change
Sep 22, 2023
ec6602e
Remove bug bash app
Sep 22, 2023
f44ab78
Refinement of PR request
Sep 22, 2023
61fcfbd
PR correction
Sep 22, 2023
90a50a6
Remove VSC lauch.json since no bug-bash
Sep 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "msedge",
"request": "launch",
"name": "Launch Edge against localhost",
"url": "http://127.0.0.1:5173",
"webRoot": "${workspaceFolder}/bug-bash/app/src",
"runtimeArgs": ["--preserve-symlinks"]
}
]
}
4 changes: 1 addition & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"jest.autoRun": {
"onStartup": ["all-tests"]
},
"jest.jestCommandLine": "./node_modules/.bin/jest",
"jest.autoRevealOutput": "on-exec-error"
}
}
33 changes: 17 additions & 16 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -239,23 +239,24 @@ class OptimizelyReactSDKClient implements ReactSDKClient {
});

if (this._client) {
this._client.onReady().then(() => {
this.isClientReady = true;
});

this.dataReadyPromise = Promise.all([this.userPromise, this._client!.onReady()]).then(res => {
mikechu-optimizely marked this conversation as resolved.
Show resolved Hide resolved
this.dataReadyPromise = Promise.all([this.userPromise, this._client.onReady()]).then(
([userResult, clientResult]) => {
this.isClientReady = true;
mikechu-optimizely marked this conversation as resolved.
Show resolved Hide resolved
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',
Expand Down Expand Up @@ -308,14 +309,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;
Expand Down
8 changes: 4 additions & 4 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 7 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/**
* 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,
* 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.
*/

export { OptimizelyContext, OptimizelyContextConsumer, OptimizelyContextProvider } from './Context';
export { OptimizelyProvider } from './Provider';
export { OptimizelyFeature } from './Feature';
Expand All @@ -22,8 +23,7 @@ export { OptimizelyExperiment } from './Experiment';
export { OptimizelyVariation } from './Variation';
export { OptimizelyDecision } from './utils';

export
{
export {
logging,
errorHandler,
setLogger,
Expand All @@ -33,9 +33,9 @@ export
OptimizelyDecideOption,
ActivateListenerPayload,
TrackListenerPayload,
ListenerPayload
}
from '@optimizely/optimizely-sdk';
ListenerPayload,
OptimizelySegmentOption,
} from '@optimizely/optimizely-sdk';

export { createInstance, ReactSDKClient } from './client';

Expand Down