Flag was off for everyone. Some reasons could include:
+
1. Your sample size of visitors was too small. Rerun, or increase the iterations in the FOR loop
+
+ 2. By default you have 2 keys for 2 project environments (dev/prod). Verify in Settings>Environments that you
+ used the right key for the environment where your flag is toggled to ON.
+
+ {`\nFlag ${
+ decision.enabled ? 'on' : 'off'
+ }. User number ${userId} saw flag variation: ${variationKey} and got products sorted by: ${sortMethod} config variable as part of flag rule: ${
+ decision.ruleKey
+ }`}
+
- Optimizely client invalid. Verify in Settings -> Environments that you used the primary environment's SDK key
+ Optimizely client invalid. Verify in Settings - Environments that you used the primary environment's SDK key
)}
@@ -64,7 +63,7 @@ function FlagsOffMessage({ projectId }) {
Flag was off for everyone. Some reasons could include:
1. Your sample size of visitors was too small. Rerun, or increase the iterations in the FOR loop
- 2. By default you have 2 keys for 2 project environments (dev/prod). Verify in Settings>Environments that you
+ 2. By default you have 2 keys for 2 project environments (dev/prod). Verify in Settings - Environments that you
used the right key for the environment where your flag is toggled to ON.
diff --git a/bug-bash/app/vite.config.ts b/bug-bash/app/vite.config.ts
index 861b04b3..1e1f3273 100644
--- a/bug-bash/app/vite.config.ts
+++ b/bug-bash/app/vite.config.ts
@@ -4,4 +4,7 @@ import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
+ define: {
+ 'process.env': process.env
+ }
})
From 07ecfe4a45ed050d15f5982fa461054d2f6c5b48 Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Mon, 14 Aug 2023 19:19:01 +0000
Subject: [PATCH 24/54] Complete WIP on reading SDK from .env
---
bug-bash/app/src/App.tsx | 2 +-
bug-bash/setup.sh | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index c71dfbb0..e7faf515 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -2,7 +2,7 @@ import { useState } from 'react';
import { createInstance, OptimizelyProvider, useDecision } from '@optimizely/react-sdk';
import './App.css';
-const sdkKey = import.meta.env.SDK_KEY;
+const sdkKey = import.meta.env.VITE_SDK_KEY;
console.log('>>> SDK_KEY', sdkKey);
const optimizelyClient = createInstance({ sdkKey });
diff --git a/bug-bash/setup.sh b/bug-bash/setup.sh
index 5c9782bc..71f04b2d 100644
--- a/bug-bash/setup.sh
+++ b/bug-bash/setup.sh
@@ -14,13 +14,13 @@ echo
echo "\033[1;38;2;0;55;255mPlease enter your SDK key: \033[0m\c"
read sdk_key
-# Check if .env file exists and contains SDK_KEY entry
-if [ -f .env ] && grep -q "SDK_KEY" .env; then
+# Check if .env.local file exists and contains SDK_KEY entry
+if [ -f .env.local ] && grep -q "VITE_SDK_KEY" .env.local; then
# If it does, replace the existing entry
- sed -i "s/^SDK_KEY=.*/SDK_KEY=$sdk_key/" .env
+ sed -i "s/^VITE_SDK_KEY=.*/VITE_SDK_KEY=$sdk_key/" .env.local
else
# If it doesn't, create the file and append the new entry
- echo "SDK_KEY=$sdk_key" > .env
+ echo "VITE_SDK_KEY=$sdk_key" > .env.local
fi
echo
From 2eb812c187d0c7397974c30320703c497fe7ff38 Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Mon, 14 Aug 2023 19:39:53 +0000
Subject: [PATCH 25/54] Transfer @rafinutshaw-optimizely's work in
---
bug-bash/app/src/App.css | 5 +
bug-bash/app/src/App.tsx | 296 ++++++++++++++++++++++++---------
bug-bash/app/src/App.types.tsx | 6 +
3 files changed, 232 insertions(+), 75 deletions(-)
create mode 100644 bug-bash/app/src/App.types.tsx
diff --git a/bug-bash/app/src/App.css b/bug-bash/app/src/App.css
index 902778b7..6a92df1f 100644
--- a/bug-bash/app/src/App.css
+++ b/bug-bash/app/src/App.css
@@ -4,3 +4,8 @@
padding: 2rem;
text-align: center;
}
+
+pre {
+ /* monospaced text*/
+ font-family: monospace;
+}
\ No newline at end of file
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index e7faf515..24806f57 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -1,84 +1,234 @@
-import { useState } from 'react';
+import React, { useEffect, useState } from 'react';
import { createInstance, OptimizelyProvider, useDecision } from '@optimizely/react-sdk';
-import './App.css';
-
-const sdkKey = import.meta.env.VITE_SDK_KEY;
-console.log('>>> SDK_KEY', sdkKey);
-const optimizelyClient = createInstance({ sdkKey });
-
-function Pre(props) {
- return
Flag was off for everyone. Some reasons could include:
-
1. Your sample size of visitors was too small. Rerun, or increase the iterations in the FOR loop
-
- 2. By default you have 2 keys for 2 project environments (dev/prod). Verify in Settings - Environments that you
- used the right key for the environment where your flag is toggled to ON.
-
{`\nFlag ${
decision.enabled ? 'on' : 'off'
}. User number ${userId} saw flag variation: ${variationKey} and got products sorted by: ${sortMethod} config variable as part of flag rule: ${
decision.ruleKey
}`}
-
+
);
}
diff --git a/bug-bash/app/src/App.types.tsx b/bug-bash/app/src/App.types.tsx
new file mode 100644
index 00000000..2d55e0bf
--- /dev/null
+++ b/bug-bash/app/src/App.types.tsx
@@ -0,0 +1,6 @@
+export type OptimizelyReturnType = {
+ success: boolean;
+ reason?: string;
+ message?: string;
+ };
+
\ No newline at end of file
From 88df7786fb1d9b4f59e9d58579a5aa14e1db184a Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Mon, 14 Aug 2023 19:40:02 +0000
Subject: [PATCH 26/54] Small style fix
---
bug-bash/app/src/index.css | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bug-bash/app/src/index.css b/bug-bash/app/src/index.css
index f342884e..207cac5c 100644
--- a/bug-bash/app/src/index.css
+++ b/bug-bash/app/src/index.css
@@ -15,7 +15,7 @@
}
body {
- margin: 0;
+ margin: 10px;
display: flex;
place-items: center;
min-width: 320px;
From df3e319db07b885b11a7dd9fff3c0ae3fd47a27c Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Mon, 14 Aug 2023 19:46:29 +0000
Subject: [PATCH 27/54] Minor semantic HTML changes
---
bug-bash/app/src/App.tsx | 28 +++++++++++++---------------
bug-bash/app/src/App.types.tsx | 2 +-
2 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index 24806f57..0b335d6d 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -11,8 +11,8 @@ export const App: React.FC = () => {
const [featureKey, setFeatureKey] = useState('some_key');
const [isSegmentsFetched, setIsSegmentsFetched] = useState(null);
const [readyResult, setReadyResult] = useState();
-
const [enableDecision, setEnableDecision] = useState(false);
+
// 1. console should show two qualified segments and a viud
const optimizelyClient = createInstance({ sdkKey });
const [userId] = useState('matjaz-user-1');
@@ -203,22 +203,22 @@ export const App: React.FC = () => {
{readyResult?.success && (
<>
-
Application Output
-
Please open your browser's "Developer tools" (Ctrl-Shift-I)
+
Bug Bash Output
+
Please open your browser's "Developer tools" (Ctrl-Shift-I) for Console output
-
{`Is segments fetched for user '${userId}': ${isSegmentsFetched ? 'Yes' : 'No'} `}
- {`\nFlag ${
- decision.enabled ? 'on' : 'off'
- }. User number ${userId} saw flag variation: ${variationKey} and got products sorted by: ${sortMethod} config variable as part of flag rule: ${
+
+ {`Flag ${ decision.enabled ? 'on' : 'off'}. User number ${userId} saw flag variation: ${variationKey} and got products sorted by: ${sortMethod} config variable as part of flag rule: ${
decision.ruleKey
}`}
-
+
);
}
diff --git a/bug-bash/app/src/App.types.tsx b/bug-bash/app/src/App.types.tsx
index 2d55e0bf..6ca0b06f 100644
--- a/bug-bash/app/src/App.types.tsx
+++ b/bug-bash/app/src/App.types.tsx
@@ -2,5 +2,5 @@ export type OptimizelyReturnType = {
success: boolean;
reason?: string;
message?: string;
- };
+};
\ No newline at end of file
From 43cf5ad16c3d9dbbf0411783afa6f16571436d72 Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Mon, 14 Aug 2023 19:52:17 +0000
Subject: [PATCH 28/54] A bunch'o NITs for my comfort
---
bug-bash/app/src/App.tsx | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index 0b335d6d..fbfdfc9a 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -13,6 +13,8 @@ export const App: React.FC = () => {
const [readyResult, setReadyResult] = useState();
const [enableDecision, setEnableDecision] = useState(false);
+ /* โฌ๏ธ Tests are below this line โฌ๏ธ */
+
// 1. console should show two qualified segments and a viud
const optimizelyClient = createInstance({ sdkKey });
const [userId] = useState('matjaz-user-1');
@@ -72,7 +74,6 @@ export const App: React.FC = () => {
// setIsSegmentsFetched(true);
// });
// };
-
// useEffect(() => {
// const callSegments = async () => {
// if (readyResult?.success) {
@@ -92,7 +93,6 @@ export const App: React.FC = () => {
// setIsSegmentsFetched(true);
// });
// };
-
// useEffect(() => {
// const callSegments = async () => {
// if (readyResult?.success) {
@@ -105,7 +105,6 @@ export const App: React.FC = () => {
// 8. there should be an error for the first call to fetchQualifiedSegments the second call should work fine
// const [userId] = useState('random-user-id');
-
// const prepareClient = () => {
// console.log('optimizelyClient');
// optimizelyClient.onReady().then(async (res: any) => {
@@ -118,7 +117,6 @@ export const App: React.FC = () => {
// 9. fetch should return error in the console, for segment fetch
// const optimizelyClient = createInstance({ sdkKey });
// const [userId] = useState('matjaz-user-2');
-
// const prepareClient = () => {
// optimizelyClient.onReady().then(async (res: any) => {
// setReadyResult(res);
@@ -136,7 +134,6 @@ export const App: React.FC = () => {
// },
// });
// const [userId] = useState('matjaz-user-2');
-
// const prepareClient = () => {
// optimizelyClient.onReady().then(async (res: any) => {
// setReadyResult(res);
@@ -170,7 +167,6 @@ export const App: React.FC = () => {
// },
// });
// const [userId] = useState('matjaz-user-2');
-
// const prepareClient = () => {
// optimizelyClient.onReady().then(async (res: any) => {
// setReadyResult(res);
@@ -178,7 +174,6 @@ export const App: React.FC = () => {
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
// });
// };
-
// useEffect(prepareClient, []);
// 13. call decide for a segment user is not a part of hence user should not qualify,
@@ -187,7 +182,6 @@ export const App: React.FC = () => {
// sdkKey,
// });
// const [userId] = useState('matjaz-user-2');
-
// const prepareClient = () => {
// optimizelyClient.onReady().then(async (res: any) => {
// setReadyResult(res);
@@ -197,6 +191,8 @@ export const App: React.FC = () => {
// });
// };
+ /* โฌ๏ธ Tests are above this line โฌ๏ธ */
+
useEffect(prepareClient, []);
return (
From 55d55fd7e01c08fc581b955d668977ec2f359f91 Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Tue, 15 Aug 2023 13:48:04 +0000
Subject: [PATCH 29/54] Rename bug-bash setup & add run
---
package.json | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/package.json b/package.json
index d1ec3c76..ed875297 100644
--- a/package.json
+++ b/package.json
@@ -28,7 +28,8 @@
"test": "jest --silent",
"prepublishOnly": "npm run test && npm run build",
"prepare": "npm run build",
- "bug-bash": "sh ./bug-bash/setup.sh"
+ "bug-bash:setup": "sh ./bug-bash/setup.sh",
+ "bug-bash": "cd bug-bash/app && npm run dev"
},
"publishConfig": {
"access": "public"
From 1d29b80f43ee7fec889df358b9966a14c84fc292 Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Tue, 15 Aug 2023 15:27:58 +0000
Subject: [PATCH 30/54] Ensure shell scripts use LF line endings
---
bug-bash/.gitattributes | 1 +
1 file changed, 1 insertion(+)
create mode 100644 bug-bash/.gitattributes
diff --git a/bug-bash/.gitattributes b/bug-bash/.gitattributes
new file mode 100644
index 00000000..526c8a38
--- /dev/null
+++ b/bug-bash/.gitattributes
@@ -0,0 +1 @@
+*.sh text eol=lf
\ No newline at end of file
From d4f75a631f6850ac62fc764f555ff60cc4d2168d Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Tue, 15 Aug 2023 21:25:43 +0000
Subject: [PATCH 31/54] WIP testing & refactoring tests
---
bug-bash/app/src/App.tsx | 140 +++++++++++++++++++--------------------
1 file changed, 67 insertions(+), 73 deletions(-)
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index fbfdfc9a..4e768a05 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -2,93 +2,94 @@ import React, { useEffect, useState } from 'react';
import { createInstance, OptimizelyProvider, useDecision } from '@optimizely/react-sdk';
import { OptimizelyReturnType } from './App.types';
-import { OdpSegmentManager } from '@optimizely/optimizely-sdk/lib/core/odp/odp_segment_manager';
-import { OptimizelySegmentOption } from '@optimizely/optimizely-sdk/lib/core/odp/optimizely_segment_option';
+import { OptimizelySegmentOption } from '@optimizely/optimizely-sdk';
const sdkKey = import.meta.env.VITE_SDK_KEY as string; // update in .env.local file
+const logLevel = 'info'; // adjust as you needed; 'debug' needed later
+const bugBashLog = (message: string) => {
+ console.log(`%c๐[BUG BASH] - ${message}`, "color: orange; font-size: 20px;");
+};
export const App: React.FC = () => {
const [featureKey, setFeatureKey] = useState('some_key');
- const [isSegmentsFetched, setIsSegmentsFetched] = useState(null);
const [readyResult, setReadyResult] = useState();
const [enableDecision, setEnableDecision] = useState(false);
+ const optimizelyClient = createInstance({ sdkKey, logLevel });
+
+ const handleReadyResult = async (res: OptimizelyReturnType) => {
+ const userContext = optimizelyClient?.userContext;
+ if (userContext) {
+ bugBashLog(`_qualifiedSegments: ${optimizelyClient['userContext']['_qualifiedSegments'] as string}`);
+ } else {
+ bugBashLog(`userContext is null`);
+ }
+
+ if (userId) {
+ bugBashLog(`userId: ${userId}`);
+ }
+
+ const currentVuid = localStorage.getItem('optimizely-vuid');
+ if (currentVuid) {
+ bugBashLog(`vuid: ${currentVuid}`);
+ }
+
+ setReadyResult(res);
+ };
+
/* โฌ๏ธ Tests are below this line โฌ๏ธ */
- // 1. console should show two qualified segments and a viud
- const optimizelyClient = createInstance({ sdkKey });
- const [userId] = useState('matjaz-user-1');
- const prepareClient = () => {
- optimizelyClient.onReady().then(async (res: any) => {
- setReadyResult(res);
- setIsSegmentsFetched(true);
- });
- };
+ /* 1. console [BUG BASH ๐] should show two qualified segments and a viud */
+ // const [userId] = useState('matjaz-user-1');
+ // const prepareClient = () => {
+ // optimizelyClient.onReady().then(handleReadyResult);
+ // };
- // 2. console should show three qualified segments and the same viud
- // const optimizelyClient = createInstance({ sdkKey });
+ /* 2. console should now show three qualified segments and the same viud */
// const [userId] = useState('matjaz-user-2');
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: any) => {
- // setReadyResult(res);
- // setIsSegmentsFetched(true);
- // });
+ // optimizelyClient.onReady().then(handleReadyResult);
// };
- // 3. console should show no qualified segments and the same viud
- // const optimizelyClient = createInstance({ sdkKey });
+ /* 3. console should show now show no qualified segments and the same vuid */
// const [userId] = useState('matjaz-user-3');
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: any) => {
- // setReadyResult(res);
- // setIsSegmentsFetched(true);
- // });
+ // optimizelyClient.onReady().then(handleReadyResult);
// };
- // 4. console should show no qualified segments and the same viud
+ /* 4. console should show no qualified segments and the same vuid */
// const [userId] = useState(null);
- // const optimizelyClient = createInstance({ sdkKey });
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: any) => {
- // setReadyResult(res);
- // setIsSegmentsFetched(true);
- // });
+ // optimizelyClient.onReady().then(handleReadyResult);
// };
- // 5. the network tab zaious call should be sending the vuid_xxxxx as the vuid and there shouldnt be a fs_userid sent
+ /* 5. the network tab has graphql calls
+ click the latest one and inspect the Payload
+ there should be a `vuid: vuid_xxxxx` as the vuid and there should not be a fs_userid sent */
// const [userId] = useState('vuid_overridden');
- // const optimizelyClient = createInstance({ sdkKey });
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: any) => {
- // setReadyResult(res);
- // setIsSegmentsFetched(true);
- // });
+ // optimizelyClient.onReady().then(handleReadyResult);
// };
- // 6. the network tab should show 2 graphql calls
- // const [userId] = useState('matjaz-user-3');
- // const optimizelyClient = createInstance({ sdkKey });
- // const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: any) => {
- // setReadyResult(res);
- // setIsSegmentsFetched(true);
- // });
- // };
- // useEffect(() => {
- // const callSegments = async () => {
- // if (readyResult?.success) {
- // await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.RESET_CACHE]);
- // await optimizelyClient.fetchQualifiedSegments();
- // }
- // };
- // callSegments();
- // }, [readyResult?.success]);
+ /* 6. the network tab should show 2 graphql calls */
+ const [userId] = useState('matjaz-user-3');
+ const prepareClient = () => {
+ optimizelyClient.onReady().then(handleReadyResult);
+ };
+ useEffect(() => {
+ const callSegments = async () => {
+ if (readyResult?.success) {
+ await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.RESET_CACHE]);
+ await optimizelyClient.fetchQualifiedSegments();
+ }
+ };
+ callSegments();
+ }, [readyResult?.success]);
// 7. the network tab should show 2 graphql calls
// const [userId] = useState('matjaz-user-3');
- // const optimizelyClient = createInstance({ sdkKey });
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: any) => {
+ // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
// setReadyResult(res);
// setIsSegmentsFetched(true);
// });
@@ -106,8 +107,7 @@ export const App: React.FC = () => {
// 8. there should be an error for the first call to fetchQualifiedSegments the second call should work fine
// const [userId] = useState('random-user-id');
// const prepareClient = () => {
- // console.log('optimizelyClient');
- // optimizelyClient.onReady().then(async (res: any) => {
+ // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
// setReadyResult(res);
// setIsSegmentsFetched(true);
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
@@ -115,10 +115,9 @@ export const App: React.FC = () => {
// };
// 9. fetch should return error in the console, for segment fetch
- // const optimizelyClient = createInstance({ sdkKey });
// const [userId] = useState('matjaz-user-2');
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: any) => {
+ // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
// setReadyResult(res);
// setIsSegmentsFetched(true);
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
@@ -127,7 +126,7 @@ export const App: React.FC = () => {
// 10. odp network error
// const optimizelyClient = createInstance({
- // logLevel: 'debug',
+ // logLevel,
// sdkKey,
// datafileOptions: {
// urlTemplate: 'https://httpstat.us/521?sdkKey=%s',
@@ -135,7 +134,7 @@ export const App: React.FC = () => {
// });
// const [userId] = useState('matjaz-user-2');
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: any) => {
+ // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
// setReadyResult(res);
// setIsSegmentsFetched(true);
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
@@ -150,9 +149,8 @@ export const App: React.FC = () => {
// },
// });
// const [userId] = useState('matjaz-user-2');
-
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: any) => {
+ // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
// setReadyResult(res);
// setIsSegmentsFetched(true);
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
@@ -168,7 +166,7 @@ export const App: React.FC = () => {
// });
// const [userId] = useState('matjaz-user-2');
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: any) => {
+ // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
// setReadyResult(res);
// setIsSegmentsFetched(true);
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
@@ -178,12 +176,9 @@ export const App: React.FC = () => {
// 13. call decide for a segment user is not a part of hence user should not qualify,
// later make the user part of the segment and call decide again to check if user qualifies
- // const optimizelyClient = createInstance({
- // sdkKey,
- // });
// const [userId] = useState('matjaz-user-2');
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: any) => {
+ // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
// setReadyResult(res);
// setFeatureKey('test_feature_1')
// setIsSegmentsFetched(true);
@@ -202,9 +197,6 @@ export const App: React.FC = () => {
Bug Bash Output
Please open your browser's "Developer tools" (Ctrl-Shift-I) for Console output
-
{`Is segments fetched for user '${userId}': ${isSegmentsFetched ? 'Yes' : 'No'} `}
- {`Flag ${ decision.enabled ? 'on' : 'off'}. User number ${userId} saw flag variation: ${variationKey} and got products sorted by: ${sortMethod} config variable as part of flag rule: ${
+ {`Flag ${
+ decision.enabled ? 'on' : 'off'
+ }. User number ${userId} saw flag variation: ${variationKey} and got products sorted by: ${sortMethod} config variable as part of flag rule: ${
decision.ruleKey
}`}
From f88d1296d7dc24f9f08c8880b6213296c226aa8a Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Wed, 16 Aug 2023 18:55:04 +0000
Subject: [PATCH 32/54] Better doc & UI + Refactors
---
bug-bash/app/src/App.css | 5 --
bug-bash/app/src/App.tsx | 139 ++++++++++++++++++---------------
bug-bash/app/src/App.types.tsx | 6 --
bug-bash/app/src/index.css | 1 -
4 files changed, 75 insertions(+), 76 deletions(-)
delete mode 100644 bug-bash/app/src/App.types.tsx
diff --git a/bug-bash/app/src/App.css b/bug-bash/app/src/App.css
index 6a92df1f..027945e4 100644
--- a/bug-bash/app/src/App.css
+++ b/bug-bash/app/src/App.css
@@ -3,9 +3,4 @@
margin: 0 auto;
padding: 2rem;
text-align: center;
-}
-
-pre {
- /* monospaced text*/
- font-family: monospace;
}
\ No newline at end of file
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index 4e768a05..341b6620 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from 'react';
import { createInstance, OptimizelyProvider, useDecision } from '@optimizely/react-sdk';
-import { OptimizelyReturnType } from './App.types';
import { OptimizelySegmentOption } from '@optimizely/optimizely-sdk';
@@ -8,14 +7,15 @@ const sdkKey = import.meta.env.VITE_SDK_KEY as string; // update in .env.local f
const logLevel = 'info'; // adjust as you needed; 'debug' needed later
const bugBashLog = (message: string) => {
- console.log(`%c๐[BUG BASH] - ${message}`, "color: orange; font-size: 20px;");
+ console.log(`%c๐[BUG BASH] - ${message}`, 'color: orange; font-size: 20px;');
};
export const App: React.FC = () => {
const [featureKey, setFeatureKey] = useState('some_key');
const [readyResult, setReadyResult] = useState();
const [enableDecision, setEnableDecision] = useState(false);
- const optimizelyClient = createInstance({ sdkKey, logLevel });
+ // Using let here because we need to reassign the client in some tests
+ let optimizelyClient = createInstance({ sdkKey, logLevel });
const handleReadyResult = async (res: OptimizelyReturnType) => {
const userContext = optimizelyClient?.userContext;
@@ -33,114 +33,124 @@ export const App: React.FC = () => {
if (currentVuid) {
bugBashLog(`vuid: ${currentVuid}`);
}
-
+
setReadyResult(res);
};
/* โฌ๏ธ Tests are below this line โฌ๏ธ */
- /* 1. console [BUG BASH ๐] should show two qualified segments and a viud */
+ /* Open the Developer Tools > Console tab
+ [BUG BASH ๐] items should show two qualified segments and a viud */
// const [userId] = useState('matjaz-user-1');
// const prepareClient = () => {
// optimizelyClient.onReady().then(handleReadyResult);
// };
- /* 2. console should now show three qualified segments and the same viud */
+ /* The Console tab should now show three qualified segments and the same viud */
// const [userId] = useState('matjaz-user-2');
// const prepareClient = () => {
// optimizelyClient.onReady().then(handleReadyResult);
// };
- /* 3. console should show now show no qualified segments and the same vuid */
+ /* The Console tab should now show no qualified segments and the same vuid */
// const [userId] = useState('matjaz-user-3');
// const prepareClient = () => {
// optimizelyClient.onReady().then(handleReadyResult);
// };
- /* 4. console should show no qualified segments and the same vuid */
+ /* The Console tab should show no qualified segments and the same vuid */
// const [userId] = useState(null);
// const prepareClient = () => {
// optimizelyClient.onReady().then(handleReadyResult);
// };
- /* 5. the network tab has graphql calls
- click the latest one and inspect the Payload
- there should be a `vuid: vuid_xxxxx` as the vuid and there should not be a fs_userid sent */
+ /* Open the Network tab.
+ Look for graphql calls that are POST requests (you can ignore the OPTIONS calls)
+ Click the latest one and inspect the Payload
+ There should be a `vuid: vuid_xxxxx` as the vuid and there should not be a fs_userid sent */
// const [userId] = useState('vuid_overridden');
// const prepareClient = () => {
// optimizelyClient.onReady().then(handleReadyResult);
// };
- /* 6. the network tab should show 2 graphql calls */
- const [userId] = useState('matjaz-user-3');
- const prepareClient = () => {
- optimizelyClient.onReady().then(handleReadyResult);
- };
- useEffect(() => {
- const callSegments = async () => {
- if (readyResult?.success) {
- await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.RESET_CACHE]);
- await optimizelyClient.fetchQualifiedSegments();
- }
- };
- callSegments();
- }, [readyResult?.success]);
-
- // 7. the network tab should show 2 graphql calls
+ /* In the Network tab, there should be 1 graphql POST calls since we're using the cache */
// const [userId] = useState('matjaz-user-3');
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
- // setReadyResult(res);
- // setIsSegmentsFetched(true);
- // });
+ // optimizelyClient.onReady().then(handleReadyResult);
// };
// useEffect(() => {
- // const callSegments = async () => {
+ // (async () => {
// if (readyResult?.success) {
- // await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
+ // await optimizelyClient.fetchQualifiedSegments();
// await optimizelyClient.fetchQualifiedSegments();
// }
- // };
- // callSegments();
+ // })();
// }, [readyResult?.success]);
- // 8. there should be an error for the first call to fetchQualifiedSegments the second call should work fine
- // const [userId] = useState('random-user-id');
+ /* Now the Network tab should show 2 identical graphql POSTs since we're resetting the cache */
+ // const [userId] = useState('matjaz-user-3');
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
- // setReadyResult(res);
- // setIsSegmentsFetched(true);
- // await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
- // });
+ // optimizelyClient.onReady().then(handleReadyResult);
// };
+ // useEffect(() => {
+ // (async () => {
+ // if (readyResult?.success) {
+ // await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.RESET_CACHE]);
+ // await optimizelyClient.fetchQualifiedSegments();
+ // }
+ // })();
+ // }, [readyResult?.success]);
- // 9. fetch should return error in the console, for segment fetch
- // const [userId] = useState('matjaz-user-2');
+ /* Again, in the Network tab should show 2 graphql calls since we're ignoring the cache */
+ // const [userId] = useState('matjaz-user-3');
// const prepareClient = () => {
+ // optimizelyClient.onReady().then(handleReadyResult);
+ // };
+ // useEffect(() => {
+ // (async () => {
+ // if (readyResult?.success) {
+ // await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
+ // await optimizelyClient.fetchQualifiedSegments();
+ // }
+ // })();
+ // }, [readyResult?.success]);
+
+ /* There should be an error for the first call to fetchQualifiedSegments the second call should work fine
+ because we have a stored VUID that has segments */
+ // const [userId] = useState('random-user-id');
+ // const prepareClient = () => {
+ // // not using handleReadyResult here because we want to test the error
// optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
- // setReadyResult(res);
- // setIsSegmentsFetched(true);
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
+ // setReadyResult(res);
// });
// };
- // 10. odp network error
- // const optimizelyClient = createInstance({
- // logLevel,
- // sdkKey,
- // datafileOptions: {
- // urlTemplate: 'https://httpstat.us/521?sdkKey=%s',
- // },
- // });
+ /* 9. fetch should return error in the console, for segment fetch */
// const [userId] = useState('matjaz-user-2');
// const prepareClient = () => {
// optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
- // setReadyResult(res);
- // setIsSegmentsFetched(true);
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
+ // setReadyResult(res);
// });
// };
+ /* 10. Testing ODP network error. You should see a status 521 in the Console & Network tabs */
+ optimizelyClient = createInstance({
+ logLevel,
+ sdkKey,
+ datafileOptions: {
+ urlTemplate: 'https://httpstat.us/521?sdkKey=%s',
+ },
+ });
+ const [userId] = useState('matjaz-user-2');
+ const prepareClient = () => {
+ optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
+ await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
+ setReadyResult(res);
+ });
+ };
+
// 11. segment api timeout error
// const optimizelyClient = createInstance({
// sdkKey,
@@ -152,7 +162,6 @@ export const App: React.FC = () => {
// const prepareClient = () => {
// optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
// setReadyResult(res);
- // setIsSegmentsFetched(true);
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
// });
// };
@@ -168,7 +177,6 @@ export const App: React.FC = () => {
// const prepareClient = () => {
// optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
// setReadyResult(res);
- // setIsSegmentsFetched(true);
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
// });
// };
@@ -181,7 +189,6 @@ export const App: React.FC = () => {
// optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
// setReadyResult(res);
// setFeatureKey('test_feature_1')
- // setIsSegmentsFetched(true);
// setEnableDecision(true);
// });
// };
@@ -194,11 +201,9 @@ export const App: React.FC = () => {
{readyResult?.success && (
<>
-
Bug Bash Output
-
Please open your browser's "Developer tools" (Ctrl-Shift-I) for Console output
-
- {enableDecision && featureKey && }
-
+
Bug Bash
+
Please open your browser's "Developer tools" (Ctrl-Shift-I) for Console, Network, & Application tabs
+
{enableDecision && featureKey && }
>
)}
{readyResult && !readyResult.success && (
@@ -238,4 +243,10 @@ function Decision({ userId, featureKey }: { userId: string; featureKey: string }
);
}
+export type OptimizelyReturnType = {
+ success: boolean;
+ reason?: string;
+ message?: string;
+};
+
export default App;
diff --git a/bug-bash/app/src/App.types.tsx b/bug-bash/app/src/App.types.tsx
deleted file mode 100644
index 6ca0b06f..00000000
--- a/bug-bash/app/src/App.types.tsx
+++ /dev/null
@@ -1,6 +0,0 @@
-export type OptimizelyReturnType = {
- success: boolean;
- reason?: string;
- message?: string;
-};
-
\ No newline at end of file
diff --git a/bug-bash/app/src/index.css b/bug-bash/app/src/index.css
index 207cac5c..9f02e8ad 100644
--- a/bug-bash/app/src/index.css
+++ b/bug-bash/app/src/index.css
@@ -17,7 +17,6 @@
body {
margin: 10px;
display: flex;
- place-items: center;
min-width: 320px;
min-height: 100vh;
}
From dc4485b0cce7cb3e49ca37be3440013d21e90aad Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Fri, 18 Aug 2023 14:13:12 +0000
Subject: [PATCH 33/54] Move Decision; Finish refactor existing tests
---
bug-bash/app/src/App.tsx | 109 ++++++++++++----------------------
bug-bash/app/src/Decision.tsx | 34 +++++++++++
2 files changed, 72 insertions(+), 71 deletions(-)
create mode 100644 bug-bash/app/src/Decision.tsx
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index 341b6620..a5c9159a 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -1,7 +1,9 @@
import React, { useEffect, useState } from 'react';
import { createInstance, OptimizelyProvider, useDecision } from '@optimizely/react-sdk';
-import { OptimizelySegmentOption } from '@optimizely/optimizely-sdk';
+import { OdpOptions } from '@optimizely/optimizely-sdk/dist/shared_types';
+import { OptimizelySegmentOption } from '@optimizely/optimizely-sdk/lib/shared_types';
+import Decision from './Decision';
const sdkKey = import.meta.env.VITE_SDK_KEY as string; // update in .env.local file
const logLevel = 'info'; // adjust as you needed; 'debug' needed later
@@ -119,10 +121,9 @@ export const App: React.FC = () => {
because we have a stored VUID that has segments */
// const [userId] = useState('random-user-id');
// const prepareClient = () => {
- // // not using handleReadyResult here because we want to test the error
// optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
- // setReadyResult(res);
+ // handleReadyResult(res);
// });
// };
@@ -131,67 +132,59 @@ export const App: React.FC = () => {
// const prepareClient = () => {
// optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
- // setReadyResult(res);
+ // handleReadyResult(res);
// });
// };
- /* 10. Testing ODP network error. You should see a status 521 in the Console & Network tabs */
- optimizelyClient = createInstance({
- logLevel,
- sdkKey,
- datafileOptions: {
- urlTemplate: 'https://httpstat.us/521?sdkKey=%s',
- },
- });
- const [userId] = useState('matjaz-user-2');
- const prepareClient = () => {
- optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
- await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
- setReadyResult(res);
- });
- };
+ /* Testing ODP network error. You should see a status 521 in the Console & Network
+ tabs when an ODP function is called.
+
+ Monkey patch XMLHttpRequest's open function to make a call to a "down" ODP endpoint
+ */
+ // const originalOpen = XMLHttpRequest.prototype.open;
+ // XMLHttpRequest.prototype.open = function(method:string, url:string, async:boolean) {
+ // url = url.includes('api.zaius.com') ? 'https://httpstat.us/521' : url;
+ // originalOpen.call(this, method, url, async);
+ // };
+ // const [userId] = useState('matjaz-user-2');
+ // const prepareClient = () => {
+ // optimizelyClient.onReady().then(handleReadyResult);
+ // };
- // 11. segment api timeout error
- // const optimizelyClient = createInstance({
+ /* Simulate segment API timeout. Expect to see error about the audience fetching */
+ // optimizelyClient = createInstance({
// sdkKey,
// odpOptions: {
- // segmentsApiTimeout: 1,
+ // segmentsApiTimeout: 10, // too fast timeout
// },
// });
// const [userId] = useState('matjaz-user-2');
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
- // setReadyResult(res);
- // await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
- // });
+ // optimizelyClient.onReady().then(handleReadyResult);
// };
- // 12. should work fine for proper timeout value
- // const optimizelyClient = createInstance({
+ /* Should work fine for proper timeout value */
+ // optimizelyClient = createInstance({
// sdkKey,
// odpOptions: {
- // segmentsApiTimeout: 100000,
+ // segmentsApiTimeout: 5_000, // reasonable timeout
// },
// });
// const [userId] = useState('matjaz-user-2');
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
- // setReadyResult(res);
- // await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
- // });
+ // optimizelyClient.onReady().then(handleReadyResult);
// };
- // useEffect(prepareClient, []);
- // 13. call decide for a segment user is not a part of hence user should not qualify,
- // later make the user part of the segment and call decide again to check if user qualifies
- // const [userId] = useState('matjaz-user-2');
- // const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
- // setReadyResult(res);
- // setFeatureKey('test_feature_1')
- // setEnableDecision(true);
- // });
- // };
+ /* Call decide for a segment user is not a part of hence user should not qualify,
+ later make the user part of the segment and call decide again to check if user qualifies */
+ const [userId] = useState('matjaz-user-2');
+ const prepareClient = () => {
+ optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
+ setFeatureKey('test_feature_1')
+ setEnableDecision(true);
+ handleReadyResult(res);
+ });
+ };
/* โฌ๏ธ Tests are above this line โฌ๏ธ */
@@ -217,33 +210,7 @@ export const App: React.FC = () => {
);
};
-function Decision({ userId, featureKey }: { userId: string; featureKey: string }) {
- const [decision, clientReady] = useDecision(featureKey, {}, { overrideUserId: userId });
-
- if (!clientReady) {
- return <>>;
- }
-
- const variationKey = decision.variationKey;
-
- if (variationKey === null) {
- console.log(' decision error: ', decision['reasons']);
- }
-
- const sortMethod = decision.variables['sort_method'];
-
- return (
-
- {`Flag ${
- decision.enabled ? 'on' : 'off'
- }. User number ${userId} saw flag variation: ${variationKey} and got products sorted by: ${sortMethod} config variable as part of flag rule: ${
- decision.ruleKey
- }`}
-
+ {`Flag ${
+ decision.enabled ? 'on' : 'off'
+ }. User number ${userId} saw flag variation: ${variationKey} and got products sorted by: ${sortMethod} config variable as part of flag rule: ${
+ decision.ruleKey
+ }`}
+
+ );
+};
+
+export default Decision;
\ No newline at end of file
From 381c42a9b3ba55beabeae4f38553d587a657d3fb Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Fri, 18 Aug 2023 14:58:52 +0000
Subject: [PATCH 34/54] Add more tests based on spreadsheet\
---
bug-bash/app/src/App.tsx | 74 +++++++++++++++++++++++++++++-----------
1 file changed, 54 insertions(+), 20 deletions(-)
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index a5c9159a..0b7f4e20 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -11,6 +11,7 @@ const logLevel = 'info'; // adjust as you needed; 'debug' needed later
const bugBashLog = (message: string) => {
console.log(`%c๐[BUG BASH] - ${message}`, 'color: orange; font-size: 20px;');
};
+
export const App: React.FC = () => {
const [featureKey, setFeatureKey] = useState('some_key');
const [readyResult, setReadyResult] = useState();
@@ -127,19 +128,18 @@ export const App: React.FC = () => {
// });
// };
- /* 9. fetch should return error in the console, for segment fetch */
- // const [userId] = useState('matjaz-user-2');
+ /* Try a different SDK Key that has ODP integratino OFF */
+ // optimizelyClient = createInstance({ sdkKey: 'Dp4dLTSVkoP8VhYkdb4Z4', logLevel: 'debug' });
+ // const [userId] = useState(null);
// const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
- // await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
- // handleReadyResult(res);
- // });
+ // optimizelyClient.onReady().then(handleReadyResult);
// };
/* Testing ODP network error. You should see a status 521 in the Console & Network
tabs when an ODP function is called.
Monkey patch XMLHttpRequest's open function to make a call to a "down" ODP endpoint
+ https://httpstat.us/521 gives a 521 status code but you can choose others to test (https://httpstat.us/ for details)
*/
// const originalOpen = XMLHttpRequest.prototype.open;
// XMLHttpRequest.prototype.open = function(method:string, url:string, async:boolean) {
@@ -155,7 +155,7 @@ export const App: React.FC = () => {
// optimizelyClient = createInstance({
// sdkKey,
// odpOptions: {
- // segmentsApiTimeout: 10, // too fast timeout
+ // segmentsApiTimeout: 10, // too fast timeout 10 or reasonable timeout 5_000
// },
// });
// const [userId] = useState('matjaz-user-2');
@@ -163,11 +163,56 @@ export const App: React.FC = () => {
// optimizelyClient.onReady().then(handleReadyResult);
// };
- /* Should work fine for proper timeout value */
+ /* Call decide for a segment user is not a part of hence user should not qualify.
+ Later make the user part of the segment and call decide again to check if user qualifies
+ */
+ // const [userId] = useState('matjaz-user-2');
+ // const prepareClient = () => {
+ // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
+ // setFeatureKey('test_feature_1'); // flag1 or flag2 in the AAT SDK project then try again
+ // setEnableDecision(true);
+ // handleReadyResult(res);
+ // });
+ // };
+
+ /* Test Promise version of fetchQualifiedSegments */
+ // const [userId] = useState('matjaz-user-2');
+ // const prepareClient = () => {
+ // optimizelyClient.onReady().then((res: OptimizelyReturnType) => {
+ // setFeatureKey('flag2');
+ // setEnableDecision(true);
+ // optimizelyClient.fetchQualifiedSegments().then(() => handleReadyResult(res));
+ // });
+ // };
+
+ /* Cannot test isQualifiedFor since userContext is not exposed (only user)
+ You have been testing a hacky way to view the qualified segments by accessing the private property in
+ handleReadyResult (NOT recommended)
+ */
+
+ /* createUserContext() is done implicity in the React SDK so we cannot test it here */
+
+ /* React SDK Omits the getVuid(). We've been getting it from localStorage.getItem('optimizely-vuid') for browsers */
+
+ /* Test other ODP segments and events settings including Odp disabled
+ disabled?: boolean;
+ segmentsCache?: ICache; // probably too hard to test
+ segmentsCacheSize?: number;
+ segmentsCacheTimeout?: number;
+ segmentsApiTimeout?: number;
+ segmentsRequestHandler?: RequestHandler; // probably too hard to test
+ segmentManager?: IOdpSegmentManager; // probably too hard to test
+ eventFlushInterval?: number;
+ eventBatchSize?: number;
+ eventQueueSize?: number;
+ eventApiTimeout?: number;
+ eventRequestHandler?: RequestHandler; // probably too hard to test
+ eventManager?: IOdpEventManager; // probably too hard to test
+ */
// optimizelyClient = createInstance({
// sdkKey,
// odpOptions: {
- // segmentsApiTimeout: 5_000, // reasonable timeout
+ // segmentsCacheSize: 1,
// },
// });
// const [userId] = useState('matjaz-user-2');
@@ -175,17 +220,6 @@ export const App: React.FC = () => {
// optimizelyClient.onReady().then(handleReadyResult);
// };
- /* Call decide for a segment user is not a part of hence user should not qualify,
- later make the user part of the segment and call decide again to check if user qualifies */
- const [userId] = useState('matjaz-user-2');
- const prepareClient = () => {
- optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
- setFeatureKey('test_feature_1')
- setEnableDecision(true);
- handleReadyResult(res);
- });
- };
-
/* โฌ๏ธ Tests are above this line โฌ๏ธ */
useEffect(prepareClient, []);
From c55cb442da53ca90db83453649ec78a0b593bde3 Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Fri, 18 Aug 2023 15:46:46 +0000
Subject: [PATCH 35/54] Add sendOdpEvent tests
---
bug-bash/app/src/App.tsx | 80 ++++++++++++++++++++++++++++++++++++----
1 file changed, 72 insertions(+), 8 deletions(-)
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index 0b7f4e20..557b7017 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -4,6 +4,7 @@ import { createInstance, OptimizelyProvider, useDecision } from '@optimizely/rea
import { OdpOptions } from '@optimizely/optimizely-sdk/dist/shared_types';
import { OptimizelySegmentOption } from '@optimizely/optimizely-sdk/lib/shared_types';
import Decision from './Decision';
+import { OdpEvent } from '@optimizely/optimizely-sdk/lib/core/odp/odp_event';
const sdkKey = import.meta.env.VITE_SDK_KEY as string; // update in .env.local file
const logLevel = 'info'; // adjust as you needed; 'debug' needed later
@@ -181,7 +182,7 @@ export const App: React.FC = () => {
// optimizelyClient.onReady().then((res: OptimizelyReturnType) => {
// setFeatureKey('flag2');
// setEnableDecision(true);
- // optimizelyClient.fetchQualifiedSegments().then(() => handleReadyResult(res));
+ // optimizelyClient.fetchQualifiedSegments().then(() => handleReadyResult(res));
// });
// };
@@ -189,12 +190,12 @@ export const App: React.FC = () => {
You have been testing a hacky way to view the qualified segments by accessing the private property in
handleReadyResult (NOT recommended)
*/
-
+
/* createUserContext() is done implicity in the React SDK so we cannot test it here */
/* React SDK Omits the getVuid(). We've been getting it from localStorage.getItem('optimizely-vuid') for browsers */
- /* Test other ODP segments and events settings including Odp disabled
+ /* Test other ODP segments settings including Odp disabled
disabled?: boolean;
segmentsCache?: ICache; // probably too hard to test
segmentsCacheSize?: number;
@@ -202,9 +203,63 @@ export const App: React.FC = () => {
segmentsApiTimeout?: number;
segmentsRequestHandler?: RequestHandler; // probably too hard to test
segmentManager?: IOdpSegmentManager; // probably too hard to test
- eventFlushInterval?: number;
- eventBatchSize?: number;
- eventQueueSize?: number;
+ */
+ // optimizelyClient = createInstance({
+ // sdkKey,
+ // odpOptions: {
+ // segmentsCacheSize: 1,
+ // },
+ // });
+ // const [userId] = useState('matjaz-user-2');
+ // const prepareClient = () => {
+ // optimizelyClient.onReady().then(handleReadyResult);
+ // };
+
+ /* Test sending ODP events.
+ View the Network tab and look for zaius.gif calls and inspect the Query String Parameters
+ */
+ // const [userId] = useState('matjaz-user-3');
+ // const prepareClient = () => {
+ // optimizelyClient.onReady().then(() => {
+ // // optimizelyClient.sendOdpEvent(
+ // // 'fullstack', // action
+ // // 'bug_bash', // type
+ // // new Map([['fs_user_id', 'fsUserA']]), // identifiers
+ // // new Map([['test_key', 'test_value']]), // data; test with various data types
+ // // );
+ // // optimizelyClient.sendOdpEvent(''); // error; shouldn't see associated zaius.gif call
+ // // optimizelyClient.sendOdpEvent(null); // error
+ // // optimizelyClient.sendOdpEvent(undefined); // error
+ // });
+ // };
+
+ /* Test when ODP endpoint is down
+ You can ignore OPTIONS or "preflight" requests focusing on xhr GET
+ */
+ // const originalOpen = XMLHttpRequest.prototype.open;
+ // XMLHttpRequest.prototype.open = function(method: string, url: string, async: boolean) {
+ // url =
+ // url.includes('jumbe.zaius.com') && !url.includes('httpstat.us')
+ // ? `https://httpstat.us/521?original_url=${url}`
+ // : url;
+ // originalOpen.call(this, method, url, async);
+ // };
+ // const [userId] = useState('matjaz-user-3');
+ // const prepareClient = () => {
+ // optimizelyClient.onReady().then(() => {
+ // optimizelyClient.sendOdpEvent( // feel free to add the loop from below
+ // 'fullstack',
+ // 'bug_bash',
+ // new Map([['fs_user_id', 'fsUserB']]),
+ // new Map([['test_count', 1]])
+ // );
+ // });
+ // };
+
+ /* Test other ODP events settings
+ eventFlushInterval?: number; // queuing in a browser is not supported
+ eventBatchSize?: number; // queuing in a browser is not supported
+ eventQueueSize?: number; // queuing in a browser is not supported
eventApiTimeout?: number;
eventRequestHandler?: RequestHandler; // probably too hard to test
eventManager?: IOdpEventManager; // probably too hard to test
@@ -212,12 +267,21 @@ export const App: React.FC = () => {
// optimizelyClient = createInstance({
// sdkKey,
// odpOptions: {
- // segmentsCacheSize: 1,
+ // eventFlushInterval: 1,
// },
// });
// const [userId] = useState('matjaz-user-2');
// const prepareClient = () => {
- // optimizelyClient.onReady().then(handleReadyResult);
+ // optimizelyClient.onReady().then(() => {
+ // for (let i = 0; i < 10; i++) {
+ // optimizelyClient.sendOdpEvent(
+ // 'fullstack',
+ // 'bug_bash',
+ // new Map([['fs_user_id', 'fsUserC']]),
+ // new Map([['test_count', i]])
+ // );
+ // }
+ // });
// };
/* โฌ๏ธ Tests are above this line โฌ๏ธ */
From 5a0c9c85fb05af2f278d6ef62a1a86f45d4711bb Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Fri, 18 Aug 2023 16:00:58 +0000
Subject: [PATCH 36/54] Last bits of documentation
---
bug-bash/app/src/App.tsx | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index 557b7017..b2ff0668 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -45,10 +45,10 @@ export const App: React.FC = () => {
/* Open the Developer Tools > Console tab
[BUG BASH ๐] items should show two qualified segments and a viud */
- // const [userId] = useState('matjaz-user-1');
- // const prepareClient = () => {
- // optimizelyClient.onReady().then(handleReadyResult);
- // };
+ const [userId] = useState('matjaz-user-1');
+ const prepareClient = () => {
+ optimizelyClient.onReady().then(handleReadyResult);
+ };
/* The Console tab should now show three qualified segments and the same viud */
// const [userId] = useState('matjaz-user-2');
@@ -165,7 +165,8 @@ export const App: React.FC = () => {
// };
/* Call decide for a segment user is not a part of hence user should not qualify.
- Later make the user part of the segment and call decide again to check if user qualifies
+ Later make the user part of the segment and call decide again to check if user
+ Look for results in the HTML page instead of the developer tools
*/
// const [userId] = useState('matjaz-user-2');
// const prepareClient = () => {
@@ -284,6 +285,8 @@ export const App: React.FC = () => {
// });
// };
+ /* You should be seeing `client_initialized` & 'identified' implied events in the Network tab throughout your testing */
+
/* โฌ๏ธ Tests are above this line โฌ๏ธ */
useEffect(prepareClient, []);
From 659e93605d8fb5a1cc4c7b425d214fe91edda9ab Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Tue, 22 Aug 2023 19:40:16 +0000
Subject: [PATCH 37/54] Update to use js sdk 5.0.0-beta4
---
package.json | 2 +-
yarn.lock | 43 ++++++++++---------------------------------
2 files changed, 11 insertions(+), 34 deletions(-)
diff --git a/package.json b/package.json
index ed875297..0f30ad1b 100644
--- a/package.json
+++ b/package.json
@@ -35,7 +35,7 @@
"access": "public"
},
"dependencies": {
- "@optimizely/optimizely-sdk": "^5.0.0-beta2",
+ "@optimizely/optimizely-sdk": "^5.0.0-beta4",
"hoist-non-react-statics": "^3.3.0",
"prop-types": "^15.6.2",
"utility-types": "^2.1.0 || ^3.0.0"
diff --git a/yarn.lock b/yarn.lock
index 9cc64334..0a88d26a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -535,38 +535,15 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"
-"@optimizely/js-sdk-datafile-manager@^0.9.5":
- version "0.9.5"
- resolved "https://registry.yarnpkg.com/@optimizely/js-sdk-datafile-manager/-/js-sdk-datafile-manager-0.9.5.tgz#c1fa25a4bbdabe97929c72895ca2a48e28047a34"
- integrity sha512-O4ujr1nBBAQBtx8YoKNpzzaEZgsE+aU4dxubT17ePqv/YVUWE+JOY21tSRrqZy/BlbbyzL+ElT8hrGB5ZzVoIQ==
+"@optimizely/optimizely-sdk@^5.0.0-beta4":
+ version "5.0.0-beta4"
+ resolved "https://registry.yarnpkg.com/@optimizely/optimizely-sdk/-/optimizely-sdk-5.0.0-beta4.tgz#0e7a670f79a59227eb57d96c9c431d1b24b5a76d"
+ integrity sha512-NFWjNEp0ruHLU75kkMDT4cJwrXXA5SUeut+8Fhda/FgXLuOiuVYLxKDMuB74SaXIFprxcZjRUnaSj9NcsJK0nQ==
dependencies:
- "@optimizely/js-sdk-logging" "^0.3.1"
- "@optimizely/js-sdk-utils" "^0.4.0"
- decompress-response "^4.2.1"
-
-"@optimizely/js-sdk-logging@^0.3.1":
- version "0.3.1"
- resolved "https://registry.npmjs.org/@optimizely/js-sdk-logging/-/js-sdk-logging-0.3.1.tgz"
- integrity sha512-K71Jf283FP0E4oXehcXTTM3gvgHZHr7FUrIsw//0mdJlotHJT4Nss4hE0CWPbBxO7LJAtwNnO+VIA/YOcO4vHg==
- dependencies:
- "@optimizely/js-sdk-utils" "^0.4.0"
-
-"@optimizely/js-sdk-utils@^0.4.0":
- version "0.4.0"
- resolved "https://registry.npmjs.org/@optimizely/js-sdk-utils/-/js-sdk-utils-0.4.0.tgz"
- integrity sha512-QG2oytnITW+VKTJK+l0RxjaS5VrA6W+AZMzpeg4LCB4Rn4BEKtF+EcW/5S1fBDLAviGq/0TLpkjM3DlFkJ9/Gw==
- dependencies:
- uuid "^3.3.2"
-
-"@optimizely/optimizely-sdk@^5.0.0-beta2":
- version "5.0.0-beta2"
- resolved "https://registry.yarnpkg.com/@optimizely/optimizely-sdk/-/optimizely-sdk-5.0.0-beta2.tgz#83eb7ea3fb94ad6e75263c1493f219d3cfff0595"
- integrity sha512-UnA5Nk1ZbmpsJoHt2uizJ+Rb0qx6Jrt2+g9rPguzbkr1HMFDiK1apod8+9NVzB98SroXSA+dHTlBc+OAVp7m4w==
- dependencies:
- "@optimizely/js-sdk-datafile-manager" "^0.9.5"
decompress-response "^4.2.1"
json-schema "^0.4.0"
murmurhash "^2.0.1"
+ ua-parser-js "^1.0.35"
uuid "^8.3.2"
"@rollup/plugin-commonjs@^16.0.0":
@@ -4675,6 +4652,11 @@ typescript@^4.7.4:
resolved "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz"
integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==
+ua-parser-js@^1.0.35:
+ version "1.0.35"
+ resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.35.tgz#c4ef44343bc3db0a3cbefdf21822f1b1fc1ab011"
+ integrity sha512-fKnGuqmTBnIE+/KXSzCn4db8RTigUzw1AN0DmdU6hJovUTbYJKyqj+8Mt1c4VfRDnOVJnENmfYkIPZ946UrSAA==
+
uglify-js@^3.4.9:
version "3.16.3"
resolved "https://registry.npmjs.org/uglify-js/-/uglify-js-3.16.3.tgz"
@@ -4743,11 +4725,6 @@ use@^3.1.0:
resolved "https://registry.npmjs.org/utility-types/-/utility-types-3.10.0.tgz"
integrity sha512-O11mqxmi7wMKCo6HKFt5AhO4BwY3VV68YU07tgxfz8zJTIxr4BpsezN49Ffwy9j3ZpwwJp4fkRwjRzq3uWE6Rg==
-uuid@^3.3.2:
- version "3.4.0"
- resolved "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz"
- integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
-
uuid@^8.3.0, uuid@^8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
From 8d91b301c22edbe56553bc5933cc868c0254f30e Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Tue, 22 Aug 2023 19:40:53 +0000
Subject: [PATCH 38/54] WIP test updates
---
bug-bash/app/src/App.tsx | 60 +++++++++++++++++++++++-----------------
bug-bash/setup.sh | 2 +-
2 files changed, 35 insertions(+), 27 deletions(-)
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index b2ff0668..483b14bb 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -6,11 +6,11 @@ import { OptimizelySegmentOption } from '@optimizely/optimizely-sdk/lib/shared_t
import Decision from './Decision';
import { OdpEvent } from '@optimizely/optimizely-sdk/lib/core/odp/odp_event';
-const sdkKey = import.meta.env.VITE_SDK_KEY as string; // update in .env.local file
-const logLevel = 'info'; // adjust as you needed; 'debug' needed later
+const sdkKey = import.meta.env.VITE_SDK_KEY as string; // ๐กupdate in .env.local file
+const logLevel = 'debug';
const bugBashLog = (message: string) => {
- console.log(`%c๐[BUG BASH] - ${message}`, 'color: orange; font-size: 20px;');
+ console.log(`%c๐[BUG BASH] - ${message}`, 'color: orange; font-size: 20px;');
};
export const App: React.FC = () => {
@@ -44,25 +44,32 @@ export const App: React.FC = () => {
/* โฌ๏ธ Tests are below this line โฌ๏ธ */
/* Open the Developer Tools > Console tab
- [BUG BASH ๐] items should show two qualified segments and a viud */
- const [userId] = useState('matjaz-user-1');
- const prepareClient = () => {
- optimizelyClient.onReady().then(handleReadyResult);
- };
+ [BUG BASH] items should show 2 qualified segments and a viud */
+ // const [userId] = useState('matjaz-user-1');
+ // const prepareClient = () => {
+ // optimizelyClient.onReady().then(handleReadyResult);
+ // };
- /* The Console tab should now show three qualified segments and the same viud */
- // const [userId] = useState('matjaz-user-2');
+ /* After a few minutes from the above test, fill in the VUID as the userid.
+ The Console tab should now show the same qualified segments and previous userid.
+ The Network graphql POST calls should have passed `query {customer(vuid : "vuid_f22c526c1e93406f82294d41e6a")`
+ instead of `fs_user_id`
+
+ Try deleting the vuid by going to Application tab > Local Storage (left pane) > http://127.0.0.1:5173/ entry then
+ delete the optimizely-vuid entry in the middle pane then refresh the page
+ */
+ // const [userId] = useState('vuid_f22c526c1e93406f82294d41e6a');
// const prepareClient = () => {
// optimizelyClient.onReady().then(handleReadyResult);
// };
- /* The Console tab should now show no qualified segments and the same vuid */
+ /* The Console tab should show empty qualified segments and the same vuid */
// const [userId] = useState('matjaz-user-3');
// const prepareClient = () => {
// optimizelyClient.onReady().then(handleReadyResult);
// };
- /* The Console tab should show no qualified segments and the same vuid */
+ /* The Console tab should not show qualified segments and USER_NOT_READY error since React requires userId for usercontext */
// const [userId] = useState(null);
// const prepareClient = () => {
// optimizelyClient.onReady().then(handleReadyResult);
@@ -77,30 +84,31 @@ export const App: React.FC = () => {
// optimizelyClient.onReady().then(handleReadyResult);
// };
- /* In the Network tab, there should be 1 graphql POST calls since we're using the cache */
+ /* In the Network tab, Clear the network output using the ๐ซ button.
+ Make a small change to this file, then look for the number of graphql POST calls.*/
// const [userId] = useState('matjaz-user-3');
// const prepareClient = () => {
// optimizelyClient.onReady().then(handleReadyResult);
// };
// useEffect(() => {
// (async () => {
- // if (readyResult?.success) {
+ // if (readyResult?.success) {
// await optimizelyClient.fetchQualifiedSegments();
// await optimizelyClient.fetchQualifiedSegments();
// }
// })();
// }, [readyResult?.success]);
- /* Now the Network tab should show 2 identical graphql POSTs since we're resetting the cache */
- // const [userId] = useState('matjaz-user-3');
+ /* Now the Network tab should show 2 identical graphql POSTs since we're resetting the cache */
+ // const [userId] = useState('matjaz-user-3');
// const prepareClient = () => {
// optimizelyClient.onReady().then(handleReadyResult);
// };
// useEffect(() => {
// (async () => {
// if (readyResult?.success) {
- // await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.RESET_CACHE]);
- // await optimizelyClient.fetchQualifiedSegments();
+ // await optimizelyClient.fetchQualifiedSegments();
+ // await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.RESET_CACHE]);
// }
// })();
// }, [readyResult?.success]);
@@ -113,21 +121,21 @@ export const App: React.FC = () => {
// useEffect(() => {
// (async () => {
// if (readyResult?.success) {
+ // await optimizelyClient.fetchQualifiedSegments();
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
- // await optimizelyClient.fetchQualifiedSegments();
// }
// })();
// }, [readyResult?.success]);
/* There should be an error for the first call to fetchQualifiedSegments the second call should work fine
because we have a stored VUID that has segments */
- // const [userId] = useState('random-user-id');
- // const prepareClient = () => {
- // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
- // await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
- // handleReadyResult(res);
- // });
- // };
+ const [userId] = useState('random-user-id');
+ const prepareClient = () => {
+ optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
+ await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
+ handleReadyResult(res);
+ });
+ };
/* Try a different SDK Key that has ODP integratino OFF */
// optimizelyClient = createInstance({ sdkKey: 'Dp4dLTSVkoP8VhYkdb4Z4', logLevel: 'debug' });
diff --git a/bug-bash/setup.sh b/bug-bash/setup.sh
index 71f04b2d..7a6012bf 100644
--- a/bug-bash/setup.sh
+++ b/bug-bash/setup.sh
@@ -11,7 +11,7 @@ npm install --save --silent ../../
# Prompt for SDK key
echo
-echo "\033[1;38;2;0;55;255mPlease enter your SDK key: \033[0m\c"
+echo "\033[1;38;2;0;55;255mPlease enter your SDK key (use TbrfRLeKvLyWGusqANoeR for AAT): \033[0m\c"
read sdk_key
# Check if .env.local file exists and contains SDK_KEY entry
From 1f26f392a6715d65c1bd8e1eb359db613e973b7a Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Tue, 22 Aug 2023 19:56:52 +0000
Subject: [PATCH 39/54] Update path to logging
due to re-organized JS SDK
---
src/Provider.tsx | 4 ++--
src/autoUpdate.ts | 4 ++--
src/hooks.ts | 4 ++--
src/logOnlyEventDispatcher.spec.ts | 4 ++--
src/logOnlyEventDispatcher.ts | 4 ++--
5 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/src/Provider.tsx b/src/Provider.tsx
index b26485de..593c90b1 100644
--- a/src/Provider.tsx
+++ b/src/Provider.tsx
@@ -1,5 +1,5 @@
/**
- * Copyright 2022, Optimizely
+ * Copyright 2022-2023 Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
*/
import * as React from 'react';
import { UserAttributes } from '@optimizely/optimizely-sdk';
-import { getLogger } from '@optimizely/js-sdk-logging';
+import { getLogger } from '@optimizely/optimizely-sdk/dist/modules/logging';
import { OptimizelyContextProvider } from './Context';
import { ReactSDKClient } from './client';
diff --git a/src/autoUpdate.ts b/src/autoUpdate.ts
index 31954da5..f7a87735 100644
--- a/src/autoUpdate.ts
+++ b/src/autoUpdate.ts
@@ -1,5 +1,5 @@
/**
- * Copyright 2020, Optimizely
+ * Copyright 2020, 2023 Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { enums } from '@optimizely/optimizely-sdk';
-import { LoggerFacade } from '@optimizely/js-sdk-logging';
+import { LoggerFacade } from '@optimizely/optimizely-sdk/dist/modules/logging';
import { ReactSDKClient } from './client';
diff --git a/src/hooks.ts b/src/hooks.ts
index 50b82424..60a8d4df 100644
--- a/src/hooks.ts
+++ b/src/hooks.ts
@@ -1,5 +1,5 @@
/**
- * Copyright 2018-2019, 2022, Optimizely
+ * Copyright 2018-2019, 2022-2023 Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
import { useCallback, useContext, useEffect, useState, useRef } from 'react';
import { UserAttributes, OptimizelyDecideOption } from '@optimizely/optimizely-sdk';
-import { getLogger, LoggerFacade } from '@optimizely/js-sdk-logging';
+import { getLogger, LoggerFacade } from '@optimizely/optimizely-sdk/dist/modules/logging';
import { setupAutoUpdateListeners } from './autoUpdate';
import { ReactSDKClient, VariableValuesObject, OnReadyResult } from './client';
diff --git a/src/logOnlyEventDispatcher.spec.ts b/src/logOnlyEventDispatcher.spec.ts
index b07d3540..85a6b9c8 100644
--- a/src/logOnlyEventDispatcher.spec.ts
+++ b/src/logOnlyEventDispatcher.spec.ts
@@ -1,9 +1,9 @@
-jest.mock('@optimizely/js-sdk-logging', () => ({
+jest.mock('@optimizely/optimizely-sdk/dist/modules/logging', () => ({
getLogger: jest.fn().mockReturnValue({ debug: jest.fn() }),
}));
import logOnlyEventDispatcher from './logOnlyEventDispatcher';
-import * as logging from '@optimizely/js-sdk-logging';
+import * as logging from '@optimizely/optimizely-sdk/dist/modules/logging';
const logger = logging.getLogger('ReactSDK');
diff --git a/src/logOnlyEventDispatcher.ts b/src/logOnlyEventDispatcher.ts
index b3974226..fb8bf6f4 100644
--- a/src/logOnlyEventDispatcher.ts
+++ b/src/logOnlyEventDispatcher.ts
@@ -1,5 +1,5 @@
/**
- * Copyright 2019, Optimizely
+ * Copyright 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.
@@ -15,7 +15,7 @@
*/
import * as optimizely from '@optimizely/optimizely-sdk';
-import * as logging from '@optimizely/js-sdk-logging';
+import * as logging from '@optimizely/optimizely-sdk/dist/modules/logging';
const logger = logging.getLogger('ReactSDK');
From 4ca21b6d7fc767b51ab8334ae8887c5f249091d6 Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Tue, 22 Aug 2023 19:57:18 +0000
Subject: [PATCH 40/54] Update bug bash to package-lock.json
---
bug-bash/app/package-lock.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bug-bash/app/package-lock.json b/bug-bash/app/package-lock.json
index 10b2143a..1062013e 100644
--- a/bug-bash/app/package-lock.json
+++ b/bug-bash/app/package-lock.json
@@ -30,7 +30,7 @@
"version": "2.9.2",
"license": "Apache-2.0",
"dependencies": {
- "@optimizely/optimizely-sdk": "^5.0.0-beta2",
+ "@optimizely/optimizely-sdk": "^5.0.0-beta4",
"hoist-non-react-statics": "^3.3.0",
"prop-types": "^15.6.2",
"utility-types": "^2.1.0 || ^3.0.0"
From 9f4c00c0d7b037d43d928a266e7c0175ecf2c894 Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Tue, 22 Aug 2023 20:36:26 +0000
Subject: [PATCH 41/54] =?UTF-8?q?Add=20@types/uuid=20=F0=9F=A4=94?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package.json | 1 +
yarn.lock | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/package.json b/package.json
index 0f30ad1b..a5b36e70 100644
--- a/package.json
+++ b/package.json
@@ -36,6 +36,7 @@
},
"dependencies": {
"@optimizely/optimizely-sdk": "^5.0.0-beta4",
+ "@types/uuid": "^9.0.2",
"hoist-non-react-statics": "^3.3.0",
"prop-types": "^15.6.2",
"utility-types": "^2.1.0 || ^3.0.0"
diff --git a/yarn.lock b/yarn.lock
index 0a88d26a..ab36133d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -808,6 +808,11 @@
dependencies:
"@types/jest" "*"
+"@types/uuid@^9.0.2":
+ version "9.0.2"
+ resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.2.tgz#ede1d1b1e451548d44919dc226253e32a6952c4b"
+ integrity sha512-kNnC1GFBLuhImSnV7w4njQkUiJi0ZXUycu1rUaouPqiKlXkh77JKgdRnTAp1x5eBwcIwbtI+3otwzuIDEuDoxQ==
+
"@types/yargs-parser@*":
version "21.0.0"
resolved "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.0.tgz"
From ec875cdfed070599ca2e8365db27127edb149e6e Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Tue, 22 Aug 2023 20:36:59 +0000
Subject: [PATCH 42/54] Use /lib/ instead of /dist/ from JS SDK
---
src/Provider.tsx | 2 +-
src/autoUpdate.ts | 2 +-
src/hooks.ts | 2 +-
src/logOnlyEventDispatcher.ts | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/Provider.tsx b/src/Provider.tsx
index 593c90b1..cf416ce6 100644
--- a/src/Provider.tsx
+++ b/src/Provider.tsx
@@ -15,7 +15,7 @@
*/
import * as React from 'react';
import { UserAttributes } from '@optimizely/optimizely-sdk';
-import { getLogger } from '@optimizely/optimizely-sdk/dist/modules/logging';
+import { getLogger } from '@optimizely/optimizely-sdk/lib/modules/logging';
import { OptimizelyContextProvider } from './Context';
import { ReactSDKClient } from './client';
diff --git a/src/autoUpdate.ts b/src/autoUpdate.ts
index f7a87735..7484aeff 100644
--- a/src/autoUpdate.ts
+++ b/src/autoUpdate.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { enums } from '@optimizely/optimizely-sdk';
-import { LoggerFacade } from '@optimizely/optimizely-sdk/dist/modules/logging';
+import { LoggerFacade } from '@optimizely/optimizely-sdk/lib/modules/logging';
import { ReactSDKClient } from './client';
diff --git a/src/hooks.ts b/src/hooks.ts
index 60a8d4df..05c6d85b 100644
--- a/src/hooks.ts
+++ b/src/hooks.ts
@@ -16,7 +16,7 @@
import { useCallback, useContext, useEffect, useState, useRef } from 'react';
import { UserAttributes, OptimizelyDecideOption } from '@optimizely/optimizely-sdk';
-import { getLogger, LoggerFacade } from '@optimizely/optimizely-sdk/dist/modules/logging';
+import { getLogger, LoggerFacade } from '@optimizely/optimizely-sdk/lib/modules/logging';
import { setupAutoUpdateListeners } from './autoUpdate';
import { ReactSDKClient, VariableValuesObject, OnReadyResult } from './client';
diff --git a/src/logOnlyEventDispatcher.ts b/src/logOnlyEventDispatcher.ts
index fb8bf6f4..b3ad347f 100644
--- a/src/logOnlyEventDispatcher.ts
+++ b/src/logOnlyEventDispatcher.ts
@@ -15,7 +15,7 @@
*/
import * as optimizely from '@optimizely/optimizely-sdk';
-import * as logging from '@optimizely/optimizely-sdk/dist/modules/logging';
+import * as logging from '@optimizely/optimizely-sdk/lib/modules/logging';
const logger = logging.getLogger('ReactSDK');
From 03f4779c4a95e42957505acca5e13fb8350d887a Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Tue, 22 Aug 2023 20:50:38 +0000
Subject: [PATCH 43/54] Reset for other bashers
---
bug-bash/app/src/App.tsx | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index 483b14bb..0eb9c443 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -45,10 +45,10 @@ export const App: React.FC = () => {
/* Open the Developer Tools > Console tab
[BUG BASH] items should show 2 qualified segments and a viud */
- // const [userId] = useState('matjaz-user-1');
- // const prepareClient = () => {
- // optimizelyClient.onReady().then(handleReadyResult);
- // };
+ const [userId] = useState('matjaz-user-1');
+ const prepareClient = () => {
+ optimizelyClient.onReady().then(handleReadyResult);
+ };
/* After a few minutes from the above test, fill in the VUID as the userid.
The Console tab should now show the same qualified segments and previous userid.
@@ -129,13 +129,13 @@ export const App: React.FC = () => {
/* There should be an error for the first call to fetchQualifiedSegments the second call should work fine
because we have a stored VUID that has segments */
- const [userId] = useState('random-user-id');
- const prepareClient = () => {
- optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
- await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
- handleReadyResult(res);
- });
- };
+ // const [userId] = useState('random-user-id');
+ // const prepareClient = () => {
+ // optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
+ // await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
+ // handleReadyResult(res);
+ // });
+ // };
/* Try a different SDK Key that has ODP integratino OFF */
// optimizelyClient = createInstance({ sdkKey: 'Dp4dLTSVkoP8VhYkdb4Z4', logLevel: 'debug' });
From 47460efed4a9f466f37c342e74cb1285b5be4eef Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Wed, 23 Aug 2023 19:48:33 +0000
Subject: [PATCH 44/54] Add more documentation
---
bug-bash/app/src/App.tsx | 36 ++++++++++++++++++++++--------------
1 file changed, 22 insertions(+), 14 deletions(-)
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index 0eb9c443..84543c39 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -129,7 +129,7 @@ export const App: React.FC = () => {
/* There should be an error for the first call to fetchQualifiedSegments the second call should work fine
because we have a stored VUID that has segments */
- // const [userId] = useState('random-user-id');
+ // const [userId] = useState('random-user-change-me-every-time');
// const prepareClient = () => {
// optimizelyClient.onReady().then(async (res: OptimizelyReturnType) => {
// await optimizelyClient.fetchQualifiedSegments([OptimizelySegmentOption.IGNORE_CACHE]);
@@ -137,7 +137,7 @@ export const App: React.FC = () => {
// });
// };
- /* Try a different SDK Key that has ODP integratino OFF */
+ /* Try a different SDK Key that has ODP integration OFF. You'll need to refresh your page*/
// optimizelyClient = createInstance({ sdkKey: 'Dp4dLTSVkoP8VhYkdb4Z4', logLevel: 'debug' });
// const [userId] = useState(null);
// const prepareClient = () => {
@@ -149,18 +149,19 @@ export const App: React.FC = () => {
Monkey patch XMLHttpRequest's open function to make a call to a "down" ODP endpoint
https://httpstat.us/521 gives a 521 status code but you can choose others to test (https://httpstat.us/ for details)
+ Use https://httpstat.us/408?sleep=20000 to have the connection timeout after 20 seconds
*/
// const originalOpen = XMLHttpRequest.prototype.open;
// XMLHttpRequest.prototype.open = function(method:string, url:string, async:boolean) {
- // url = url.includes('api.zaius.com') ? 'https://httpstat.us/521' : url;
+ // url = url.includes('api.zaius.com') ? 'https://httpstat.us/521' : url;
// originalOpen.call(this, method, url, async);
// };
// const [userId] = useState('matjaz-user-2');
// const prepareClient = () => {
// optimizelyClient.onReady().then(handleReadyResult);
- // };
+ // };
- /* Simulate segment API timeout. Expect to see error about the audience fetching */
+ /* Simulate segment API timeout. Expect to see error about the audience fetching too fast then update to a reasonable timeout*/
// optimizelyClient = createInstance({
// sdkKey,
// odpOptions: {
@@ -174,7 +175,7 @@ export const App: React.FC = () => {
/* Call decide for a segment user is not a part of hence user should not qualify.
Later make the user part of the segment and call decide again to check if user
- Look for results in the HTML page instead of the developer tools
+ Look for results in the HTML page or filter your Console output for DECISION_SERVICE
*/
// const [userId] = useState('matjaz-user-2');
// const prepareClient = () => {
@@ -202,7 +203,8 @@ export const App: React.FC = () => {
/* createUserContext() is done implicity in the React SDK so we cannot test it here */
- /* React SDK Omits the getVuid(). We've been getting it from localStorage.getItem('optimizely-vuid') for browsers */
+ /* React SDK Omits the getVuid(). We've been getting it from localStorage.getItem('optimizely-vuid') for browsers
+ otherwise it's not available for non-browser contexts (react native uses asyncstorage)*/
/* Test other ODP segments settings including Odp disabled
disabled?: boolean;
@@ -212,6 +214,8 @@ export const App: React.FC = () => {
segmentsApiTimeout?: number;
segmentsRequestHandler?: RequestHandler; // probably too hard to test
segmentManager?: IOdpSegmentManager; // probably too hard to test
+
+ You'll be looking at the Console tab; filter to "cache"
*/
// optimizelyClient = createInstance({
// sdkKey,
@@ -226,16 +230,18 @@ export const App: React.FC = () => {
/* Test sending ODP events.
View the Network tab and look for zaius.gif calls and inspect the Query String Parameters
+ Also review the Console tab
*/
// const [userId] = useState('matjaz-user-3');
// const prepareClient = () => {
// optimizelyClient.onReady().then(() => {
- // // optimizelyClient.sendOdpEvent(
- // // 'fullstack', // action
- // // 'bug_bash', // type
- // // new Map([['fs_user_id', 'fsUserA']]), // identifiers
- // // new Map([['test_key', 'test_value']]), // data; test with various data types
- // // );
+ // /* Uncomment each of the following individually to test scenarios of ODP event data*/
+ // optimizelyClient.sendOdpEvent(
+ // 'fullstack', // action
+ // 'bug_bash', // type
+ // new Map([['fs_user_id', 'fsUserA']]), // identifiers; feel free to remove the data from here `new Map()` or edit the key-values
+ // new Map([['test_key', 'test_value']]), // data; test with various data types
+ // );
// // optimizelyClient.sendOdpEvent(''); // error; shouldn't see associated zaius.gif call
// // optimizelyClient.sendOdpEvent(null); // error
// // optimizelyClient.sendOdpEvent(undefined); // error
@@ -266,6 +272,7 @@ export const App: React.FC = () => {
// };
/* Test other ODP events settings
+ disabled?: boolean
eventFlushInterval?: number; // queuing in a browser is not supported
eventBatchSize?: number; // queuing in a browser is not supported
eventQueueSize?: number; // queuing in a browser is not supported
@@ -276,7 +283,8 @@ export const App: React.FC = () => {
// optimizelyClient = createInstance({
// sdkKey,
// odpOptions: {
- // eventFlushInterval: 1,
+ // disabled: true,
+ // eventFlushInterval: 10,
// },
// });
// const [userId] = useState('matjaz-user-2');
From 04dc93f25d0d36c74808b2262d44264e2ddde3b7 Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Fri, 25 Aug 2023 14:39:14 +0000
Subject: [PATCH 45/54] Upgrade vulnerable tough-cookie to v4.1.3
---
package.json | 1 +
yarn.lock | 33 +++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/package.json b/package.json
index a5b36e70..0245fc48 100644
--- a/package.json
+++ b/package.json
@@ -39,6 +39,7 @@
"@types/uuid": "^9.0.2",
"hoist-non-react-statics": "^3.3.0",
"prop-types": "^15.6.2",
+ "tough-cookie": "4.1.3",
"utility-types": "^2.1.0 || ^3.0.0"
},
"peerDependencies": {
diff --git a/yarn.lock b/yarn.lock
index ab36133d..99ab0b9d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3835,6 +3835,11 @@ punycode@^2.1.0, punycode@^2.1.1:
resolved "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz"
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
+querystringify@^2.1.1:
+ version "2.2.0"
+ resolved "https://registry.yarnpkg.com/querystringify/-/querystringify-2.2.0.tgz#3345941b4153cb9d082d8eee4cda2016a9aef7f6"
+ integrity sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==
+
react-dom@^18.2.0:
version "18.2.0"
resolved "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz"
@@ -3944,6 +3949,11 @@ require-main-filename@^2.0.0:
resolved "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz"
integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==
+requires-port@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
+ integrity sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==
+
resolve-cwd@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/resolve-cwd/-/resolve-cwd-3.0.0.tgz"
@@ -4563,6 +4573,16 @@ to-regex@^3.0.1, to-regex@^3.0.2:
regex-not "^1.0.2"
safe-regex "^1.1.0"
+tough-cookie@4.1.3:
+ version "4.1.3"
+ resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-4.1.3.tgz#97b9adb0728b42280aa3d814b6b999b2ff0318bf"
+ integrity sha512-aX/y5pVRkfRnfmuX+OdbSdXvPe6ieKX/G2s7e98f4poJHnqH3281gDPm/metm6E/WRamfx7WC4HUqkWHfQHprw==
+ dependencies:
+ psl "^1.1.33"
+ punycode "^2.1.1"
+ universalify "^0.2.0"
+ url-parse "^1.5.3"
+
tough-cookie@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz"
@@ -4692,6 +4712,11 @@ universalify@^0.1.0, universalify@^0.1.2:
resolved "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz"
integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==
+universalify@^0.2.0:
+ version "0.2.0"
+ resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.2.0.tgz#6451760566fa857534745ab1dde952d1b1761be0"
+ integrity sha512-CJ1QgKmNg3CwvAv/kOFmtnEN05f0D/cn9QntgNOQlQF9dgvVTHj3t+8JPdjqawCHk7V/KA+fbUqzZ9XWhcqPUg==
+
unset-value@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/unset-value/-/unset-value-1.0.0.tgz"
@@ -4720,6 +4745,14 @@ urix@^0.1.0:
resolved "https://registry.npmjs.org/urix/-/urix-0.1.0.tgz"
integrity sha512-Am1ousAhSLBeB9cG/7k7r2R0zj50uDRlZHPGbazid5s9rlF1F/QKYObEKSIunSjIOkJZqwRRLpvewjEkM7pSqg==
+url-parse@^1.5.3:
+ version "1.5.10"
+ resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.10.tgz#9d3c2f736c1d75dd3bd2be507dcc111f1e2ea9c1"
+ integrity sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==
+ dependencies:
+ querystringify "^2.1.1"
+ requires-port "^1.0.0"
+
use@^3.1.0:
version "3.1.1"
resolved "https://registry.npmjs.org/use/-/use-3.1.1.tgz"
From 07b779e1e071773ebdf230b2b8aeaa83ca243864 Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Fri, 25 Aug 2023 20:34:44 +0000
Subject: [PATCH 46/54] Add "repository" field to package.json
Thanks @iamstarkov
---
package.json | 1 +
1 file changed, 1 insertion(+)
diff --git a/package.json b/package.json
index 0245fc48..d613364b 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,7 @@
"version": "2.9.2",
"description": "React SDK for Optimizely Feature Experimentation, Optimizely Full Stack (legacy), and Optimizely Rollouts",
"homepage": "https://github.com/optimizely/react-sdk",
+ "repository": "https://github.com/optimizely/react-sdk",
"license": "Apache-2.0",
"module": "dist/react-sdk.es.js",
"types": "dist/index.d.ts",
From c997ba25cab4d637d4e8b669fafbde12a7846964 Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Mon, 28 Aug 2023 15:52:19 +0000
Subject: [PATCH 47/54] Add `useContext` documentation from...
@raphaeleidus in #165
---
README.md | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/README.md b/README.md
index 9b072593..78f3f523 100644
--- a/README.md
+++ b/README.md
@@ -286,6 +286,44 @@ const WrappedMyComponent = withOptimizely(MyComp);
**_Note:_** The `optimizely` client object provided via `withOptimizely` is automatically associated with the `user` prop passed to the ancestor `OptimizelyProvider` - the `id` and `attributes` from that `user` object will be automatically forwarded to all appropriate SDK method calls. So, there is no need to pass the `userId` or `attributes` arguments when calling methods of the `optimizely` client object, unless you wish to use _different_ `userId` or `attributes` than those given to `OptimizelyProvider`.
+## `useContext`
+
+Any component under the `` can access the Optimizely `ReactSDKClient` via the `OptimizelyContext` with `useContext`.
+
+_arguments_
+- `OptimizelyContext : React.Context` The Optimizely context initialized in a parent component (or App).
+
+_returns_
+- Wrapped object:
+ - `optimizely : ReactSDKClient` The client object which was passed to the `OptimizelyProvider`
+ - `isServerSide : boolean` Value that was passed to the `OptimizelyProvider`
+ - `timeout : number | undefined` The timeout which was passed to the `OptimizelyProvider`
+
+### Example
+
+```jsx
+import React, { useContext } from 'react';
+import { OptimizelyContext } from '@optimizely/react-sdk';
+
+function MyComponent() {
+ const { optimizely, isServerSide, timeout } = useContext(OptimizelyContext);
+ const decision = optimizely.decide('my-feature');
+ const onClick = () => {
+ optimizely.track('signup-clicked');
+ // rest of your click handling code
+ };
+ return (
+ <>
+ { decision.enabled &&
- {`Flag ${
- decision.enabled ? 'on' : 'off'
- }. User number ${userId} saw flag variation: ${variationKey} and got products sorted by: ${sortMethod} config variable as part of flag rule: ${
- decision.ruleKey
- }`}
-
+ <>
+
+ {`Flag ${
+ decision.enabled ? 'on' : 'off'
+ }. User id '${userId}' saw flag variation '${variationKey}' and got products sorted by '${sortMethod}' config variable as part of flag rule '${
+ decision.ruleKey
+ }'`}
+
{`Flag ${
decision.enabled ? 'on' : 'off'
- }. User id '${userId}' saw flag variation '${variationKey}' and got products sorted by '${sortMethod}' config variable as part of flag rule '${
+ }. User id '${userId}' saw flag variation '${decision.variationKey}' and got products sorted by '${sortMethod}' config variable as part of flag rule '${
decision.ruleKey
}'`}
From 4cd67ed562989b846c9286328e47dc2dc1752b58 Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Fri, 1 Sep 2023 19:09:47 +0000
Subject: [PATCH 53/54] Upgrade to JS SDK 5.0.0-beta5
---
package.json | 2 +-
yarn.lock | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/package.json b/package.json
index d613364b..92de8453 100644
--- a/package.json
+++ b/package.json
@@ -36,7 +36,7 @@
"access": "public"
},
"dependencies": {
- "@optimizely/optimizely-sdk": "^5.0.0-beta4",
+ "@optimizely/optimizely-sdk": "5.0.0-beta5",
"@types/uuid": "^9.0.2",
"hoist-non-react-statics": "^3.3.0",
"prop-types": "^15.6.2",
diff --git a/yarn.lock b/yarn.lock
index 99ab0b9d..fc16a08a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -535,10 +535,10 @@
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"
-"@optimizely/optimizely-sdk@^5.0.0-beta4":
- version "5.0.0-beta4"
- resolved "https://registry.yarnpkg.com/@optimizely/optimizely-sdk/-/optimizely-sdk-5.0.0-beta4.tgz#0e7a670f79a59227eb57d96c9c431d1b24b5a76d"
- integrity sha512-NFWjNEp0ruHLU75kkMDT4cJwrXXA5SUeut+8Fhda/FgXLuOiuVYLxKDMuB74SaXIFprxcZjRUnaSj9NcsJK0nQ==
+"@optimizely/optimizely-sdk@5.0.0-beta5":
+ version "5.0.0-beta5"
+ resolved "https://registry.yarnpkg.com/@optimizely/optimizely-sdk/-/optimizely-sdk-5.0.0-beta5.tgz#67ac961be3d1269d2774ec758659d42a3e763e38"
+ integrity sha512-xQ1Lv306d9xQoK/vr0o4Wpn53gJNVUeJVi8N90NinDYjtFPsXasdWEFNXNN+qH678VmdpBsPPKLg/5olLoFrKg==
dependencies:
decompress-response "^4.2.1"
json-schema "^0.4.0"
From 3a958b8cae5c9628f369a612b22aa176d018ef94 Mon Sep 17 00:00:00 2001
From: Mike Chu
Date: Fri, 1 Sep 2023 19:09:58 +0000
Subject: [PATCH 54/54] Fix references to remove /lib
---
bug-bash/app/src/App.tsx | 28 +++++++++++++---------------
src/Provider.tsx | 2 +-
src/autoUpdate.ts | 2 +-
src/hooks.ts | 3 ++-
src/logOnlyEventDispatcher.ts | 2 +-
5 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/bug-bash/app/src/App.tsx b/bug-bash/app/src/App.tsx
index 7bc7b40e..0d15b825 100644
--- a/bug-bash/app/src/App.tsx
+++ b/bug-bash/app/src/App.tsx
@@ -1,10 +1,8 @@
import React, { useEffect, useState } from 'react';
import { createInstance, OptimizelyProvider, useDecision } from '@optimizely/react-sdk';
-import { OdpOptions } from '@optimizely/optimizely-sdk/dist/shared_types';
-import { OptimizelySegmentOption } from '@optimizely/optimizely-sdk/lib/shared_types';
+import { OptimizelySegmentOption } from '@optimizely/optimizely-sdk';
import Decision from './Decision';
-import { OdpEvent } from '@optimizely/optimizely-sdk/lib/core/odp/odp_event';
const sdkKey = import.meta.env.VITE_SDK_KEY as string; // ๐กupdate in .env.local file
const logLevel = 'debug';
@@ -45,10 +43,10 @@ export const App: React.FC = () => {
/* Open the Developer Tools > Console tab
[BUG BASH] items should show 2 qualified segments and a viud */
- // const [userId, setUserId] = useState('matjaz-user-1');
- // const prepareClient = () => {
- // optimizelyClient.onReady().then(handleReadyResult);
- // };
+ const [userId, setUserId] = useState('matjaz-user-1');
+ const prepareClient = () => {
+ optimizelyClient.onReady().then(handleReadyResult);
+ };
/* After a few minutes from the above test, fill in the VUID as the userid.
The Console tab should now show the same qualified segments and previous userid.
@@ -199,14 +197,14 @@ export const App: React.FC = () => {
/* Test changing a user that is enabled matjaz-user-1 to a disabled matjaz-user-3
Look for a button on the HTML.
*/
- const [userId, setUserId] = useState('matjaz-user-1');
- const prepareClient = () => {
- optimizelyClient.onReady().then((res: OptimizelyReturnType) => {
- setFeatureKey('flag2');
- setEnableDecision(true);
- optimizelyClient.fetchQualifiedSegments().then(() => handleReadyResult(res));
- });
- };
+ // const [userId, setUserId] = useState('matjaz-user-1');
+ // const prepareClient = () => {
+ // optimizelyClient.onReady().then((res: OptimizelyReturnType) => {
+ // setFeatureKey('flag2');
+ // setEnableDecision(true);
+ // optimizelyClient.fetchQualifiedSegments().then(() => handleReadyResult(res));
+ // });
+ // };
/* Cannot test isQualifiedFor since userContext is not exposed (only user)
You have been testing a hacky way to view the qualified segments by accessing the private property in
diff --git a/src/Provider.tsx b/src/Provider.tsx
index cf416ce6..3c0f6fe8 100644
--- a/src/Provider.tsx
+++ b/src/Provider.tsx
@@ -15,7 +15,7 @@
*/
import * as React from 'react';
import { UserAttributes } from '@optimizely/optimizely-sdk';
-import { getLogger } from '@optimizely/optimizely-sdk/lib/modules/logging';
+import { getLogger } from '@optimizely/optimizely-sdk';
import { OptimizelyContextProvider } from './Context';
import { ReactSDKClient } from './client';
diff --git a/src/autoUpdate.ts b/src/autoUpdate.ts
index 7484aeff..21dfa5e2 100644
--- a/src/autoUpdate.ts
+++ b/src/autoUpdate.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
import { enums } from '@optimizely/optimizely-sdk';
-import { LoggerFacade } from '@optimizely/optimizely-sdk/lib/modules/logging';
import { ReactSDKClient } from './client';
+import { LoggerFacade } from '@optimizely/optimizely-sdk/dist/modules/logging';
interface AutoUpdate {
(
diff --git a/src/hooks.ts b/src/hooks.ts
index 05c6d85b..4647259f 100644
--- a/src/hooks.ts
+++ b/src/hooks.ts
@@ -16,7 +16,8 @@
import { useCallback, useContext, useEffect, useState, useRef } from 'react';
import { UserAttributes, OptimizelyDecideOption } from '@optimizely/optimizely-sdk';
-import { getLogger, LoggerFacade } from '@optimizely/optimizely-sdk/lib/modules/logging';
+import { getLogger } from '@optimizely/optimizely-sdk';
+import { LoggerFacade } from '@optimizely/optimizely-sdk/dist/modules/logging';
import { setupAutoUpdateListeners } from './autoUpdate';
import { ReactSDKClient, VariableValuesObject, OnReadyResult } from './client';
diff --git a/src/logOnlyEventDispatcher.ts b/src/logOnlyEventDispatcher.ts
index b3ad347f..4525aca5 100644
--- a/src/logOnlyEventDispatcher.ts
+++ b/src/logOnlyEventDispatcher.ts
@@ -15,7 +15,7 @@
*/
import * as optimizely from '@optimizely/optimizely-sdk';
-import * as logging from '@optimizely/optimizely-sdk/lib/modules/logging';
+import * as logging from '@optimizely/optimizely-sdk';
const logger = logging.getLogger('ReactSDK');