Skip to content

Commit

Permalink
refactor: Standardise example apps (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickybondarenko authored Aug 20, 2024
1 parent 82c4f7d commit 8d44347
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ examples/*/build
examples/*/.next
examples/*/out
examples/*/*.log*
examples/*/.env*
examples/*/*.tsbuildinfo
examples/*/next-env.d.ts
examples/.env

# logs
npm-debug.log*
Expand Down
2 changes: 1 addition & 1 deletion examples/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@spotify-confidence/sdk": "workspace:*"
},
"scripts": {
"dev": "node src/index.js"
"dev": "node --env-file=../.env src/index.js"
},
"private": true
}
7 changes: 5 additions & 2 deletions examples/node/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Confidence } from '@spotify-confidence/sdk';

if (!process.env.CLIENT_SECRET) {
console.log('CLIENT_SECRET is not set inb .env');
}
const confidence = Confidence.create({
clientSecret: 'RxDVTrXvc6op1XxiQ4OaR31dKbJ39aYV',
clientSecret: process.env.CLIENT_SECRET,
fetchImplementation: fetch,
timeout: 1000,
logger: console,
Expand All @@ -11,7 +14,7 @@ main();
async function main() {
confidence.subscribe(state => console.log('state:', state));
confidence.setContext({ targeting_key: 'user-a' });
const fe = confidence.evaluateFlag('web-sdk-e2e-flag.int', 0);
const fe = confidence.evaluateFlag('tutorial-feature.title', 'Default');

console.log(fe);

Expand Down
7 changes: 5 additions & 2 deletions examples/nodeCJS/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const { OpenFeature } = require('@openfeature/server-sdk');

if (!process.env.CLIENT_SECRET) {
console.log('CLIENT_SECRET is not set inb .env');
}
main();

async function main() {
const { createConfidenceServerProvider } = await import('@spotify-confidence/openfeature-server-provider');

const provider = createConfidenceServerProvider({
clientSecret: 'RxDVTrXvc6op1XxiQ4OaR31dKbJ39aYV',
clientSecret: process.env.CLIENT_SECRET,
region: 'eu',
fetchImplementation: fetch,
timeout: 1000,
Expand All @@ -17,7 +20,7 @@ async function main() {
const client = OpenFeature.getClient();

client
.getBooleanValue('web-sdk-e2e-flag.bool', false, {
.getStringValue('tutorial-feature.title', 'Default', {
targetingKey: `user-${Math.random()}`,
})
.then(result => {
Expand Down
1 change: 1 addition & 0 deletions examples/react18/.env
9 changes: 7 additions & 2 deletions examples/react18/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ const handleFailRequestsOnChange = (e: React.ChangeEvent<HTMLInputElement>) => {
state.failRequests = e.target.checked;
};

if (!process.env.REACT_APP_CLIENT_SECRET) {
console.error('REACT_APP_CLIENT_SECRET not set in .env');
process.exit(1);
}

const confidence = Confidence.create({
clientSecret: 'RxDVTrXvc6op1XxiQ4OaR31dKbJ39aYV',
clientSecret: process.env.REACT_APP_CLIENT_SECRET,
environment: 'client',
timeout: 3000,
logger: console,
Expand Down Expand Up @@ -89,7 +94,7 @@ function Level({ name, children }: { name: string; children?: React.ReactNode })

function Flags() {
const confidence = useConfidence();
const flagData = JSON.stringify(confidence.useEvaluateFlag('web-sdk-e2e-flag.str', 'default'), null, ' ');
const flagData = JSON.stringify(confidence.useEvaluateFlag('tutorial-feature.title', 'Default'), null, ' ');
// const flagData = useDeferredValue(confidence.useFlag('web-sdk-e2e-flag.str', 'default'));
return (
<fieldset>
Expand Down

0 comments on commit 8d44347

Please sign in to comment.