Skip to content

Commit

Permalink
feat: add feature_enabled to variant response (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunogois authored Nov 15, 2023
1 parent e49fc90 commit 51d50d7
Show file tree
Hide file tree
Showing 8 changed files with 594 additions and 954 deletions.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"singleQuote": false,
"semi": true,
"trailingComma": "es5"
}
2 changes: 1 addition & 1 deletion example/.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ UNLEASH_SERVER_API_TOKEN=test-server:default.8a090f30679be7254af997864d66b86e44d
# NEXT_PUBLIC_UNLEASH_FRONTEND_URL=https://app.unleash-hosted.com/demo/api/frontend
# or: UNLEASH_FRONTEND_URL=https://app.unleash-hosted.com/demo/api/frontend

NEXT_PUBLIC_UNLEASH_FRONTEND_API_TOKEN=demo-app:default.a901bd337765b46cfcf80d630c4c550e84845e840569b8f61e4c497d
NEXT_PUBLIC_UNLEASH_FRONTEND_API_TOKEN=default:default.26d592049f821f731f94047e7d760252f431697e2153b26f7eaba014
# or: UNLEASH_FRONTEND_API_TOKEN=demo-app:default.a901bd337765b46cfcf80d630c4c550e84845e840569b8f61e4c497d

NEXT_PUBLIC_UNLEASH_APP_NAME=nextjs-example
Expand Down
2 changes: 1 addition & 1 deletion example/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function Page() {
</Link>
</li>
<li>
<Link href="/ssr">
<Link href="/ssg">
Pages router, SSG &ndash; Static Site Generation
</Link>
</li>
Expand Down
8 changes: 4 additions & 4 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@types/react": "18.2.33",
"@types/react-dom": "18.2.14",
"@types/semver": "7.5.4",
"@unleash/client-specification": "5.0.2",
"@unleash/client-specification": "5.1.0",
"@vitest/coverage-c8": "^0.33.0",
"@vitest/coverage-v8": "^0.34.6",
"eslint-config-custom": "workspace:*",
Expand All @@ -51,12 +51,12 @@
"dependencies": {
"@commander-js/extra-typings": "11.1.0",
"@next/env": "14.0.0",
"@unleash/proxy-client-react": "4.0.3",
"@unleash/proxy-client-react": "4.1.0",
"commander": "11.1.0",
"murmurhash3js": "3.0.1",
"semver": "7.5.4",
"unleash-client": "5.0.0",
"unleash-proxy-client": "3.1.0"
"unleash-client": "5.1.0",
"unleash-proxy-client": "3.2.0"
},
"peerDependencies": {
"next": ">=12",
Expand Down
5 changes: 3 additions & 2 deletions lib/src/core/variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function getDefaultVariant(): Variant {
return {
name: "disabled",
enabled: false,
feature_enabled: false,
};
}

Expand Down Expand Up @@ -54,8 +55,8 @@ function findOverride(
): VariantDefinition | undefined {
return variants
.filter((variant) => variant.overrides)
.find((variant) =>
variant.overrides?.some(overrideMatchesContext(context))
.find(
(variant) => variant.overrides?.some(overrideMatchesContext(context))
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/evaluateFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const evaluateFlags = (
.map((feature) => ({
name: feature.name,
enabled: feature.enabled,
variant: feature.variant,
variant: { ...feature.variant, feature_enabled: feature.enabled },
impressionData: feature.impressionData,
}));

Expand Down
2 changes: 2 additions & 0 deletions lib/src/flagsClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe("flagsClient", () => {
expect(client.getVariant("foo")).toEqual({
name: "A",
enabled: true,
feature_enabled: true,
payload: {
type: "string",
value: "FOO",
Expand All @@ -64,6 +65,7 @@ describe("flagsClient", () => {
expect(client.getVariant("bar")).toEqual({
name: "disabled",
enabled: false,
feature_enabled: true,
});
});
});
Loading

0 comments on commit 51d50d7

Please sign in to comment.