Skip to content

Commit

Permalink
feat: add helpers to retrieve a list of all feature flags / remote co… (
Browse files Browse the repository at this point in the history
  • Loading branch information
cstrnt authored Mar 18, 2024
1 parent add0fbf commit ed7d158
Show file tree
Hide file tree
Showing 23 changed files with 323 additions and 16 deletions.
7 changes: 7 additions & 0 deletions apps/angular-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# angular-example

## 0.0.17

### Patch Changes

- @tryabby/angular@2.0.7
- @tryabby/devtools@5.0.0

## 0.0.16

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/angular-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-example",
"version": "0.0.16",
"version": "0.0.17",
"private": true,
"scripts": {
"ng": "ng",
Expand Down
24 changes: 24 additions & 0 deletions apps/docs/pages/reference/nextjs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ The name of the flag, needs to be one of the defined flags.

The value of the flag _Type: `boolean`_

#### useFeatureFlags

`useFeatureFlags` is a React hook that is used to access all existing feature flags.

##### Parameters

The name of the flag, needs to be one of the defined flags.

##### Return Value

An Array of all feature flags. Includes the name and the value. The value will be a boolean.

#### useRemoteConfig

`useRemotConfig` is a React hook that is used to access the value of a Remote Configuration variable.
Expand All @@ -123,6 +135,18 @@ The name of the Remote Configuration variable, which needs to be one of the keys

The current value of the Remote Configuration variable. The type will be according to the specified type in the `abby.config.ts`

#### useRemoteConfigVariables

`useRemoteConfigVariables` is a React hook that is used to access all existing Remote Configuration variables.

##### Parameters

None

##### Return Value

An Array of all remote config variables. Includes the name and the value. The type will be according to the specified type in the `abby.config.ts`

#### AbbyProvider

A react component to wrap your application.
Expand Down
26 changes: 25 additions & 1 deletion apps/docs/pages/reference/react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,21 @@ The name of the flag, needs to be one of the defined flags.

The value of the flag _Type: `boolean`_

#### useFeatureFlags

`useFeatureFlags` is a React hook that is used to access all existing feature flags.

##### Parameters

The name of the flag, needs to be one of the defined flags.

##### Return Value

An Array of all feature flags. Includes the name and the value. The value will be a boolean.

#### useRemoteConfig

`useRemotConfig` is a React hook that is used to access the value of a Remote Configuration variable.
`useRemoteConfig` is a React hook that is used to access the value of a Remote Configuration variable.

##### Parameters

Expand All @@ -123,6 +135,18 @@ The name of the Remote Configuration variable, which needs to be one of the keys

The current value of the Remote Configuration variable. The type will be according to the specified type in the `abby.config.ts`

#### useRemoteConfigVariables

`useRemoteConfigVariables` is a React hook that is used to access all existing Remote Configuration variables.

##### Parameters

None

##### Return Value

An Array of all remote config variables. Includes the name and the value. The type will be according to the specified type in the `abby.config.ts`

#### AbbyProvider

A react component to wrap your application.
Expand Down
9 changes: 9 additions & 0 deletions apps/web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# web

## 0.2.35

### Patch Changes

- Updated dependencies
- @tryabby/core@5.2.0
- @tryabby/next@5.1.0
- @tryabby/devtools@5.0.0

## 0.2.34

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "web",
"version": "0.2.34",
"version": "0.2.35",
"private": true,
"scripts": {
"build": "next build",
Expand Down
7 changes: 7 additions & 0 deletions packages/angular/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @tryabby/angular

## 2.0.7

### Patch Changes

- Updated dependencies
- @tryabby/core@5.2.0

## 2.0.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tryabby/angular",
"version": "2.0.6",
"version": "2.0.7",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
6 changes: 6 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @tryabby/core

## 5.2.0

### Minor Changes

- add helper to retrieve all flags/config variables

## 5.1.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tryabby/core",
"version": "5.1.4",
"version": "5.2.0",
"description": "",
"main": "dist/index.js",
"files": [
Expand Down
25 changes: 24 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
ABBY_WINDOW_KEY,
} from "./shared/";
import { HttpService } from "./shared";
import { F } from "ts-toolbelt";
import { F, O } from "ts-toolbelt";
import { getWeightedRandomVariant } from "./mathHelpers";
import { parseCookies } from "./helpers";

Expand Down Expand Up @@ -581,4 +581,27 @@ export class Abby<
}
return stringifyRemoteConfigValue(value);
}

/**
* Retruns an Array of all flags with their name and value
*/
getFeatureFlags() {
return (Object.keys(this.#data.flags) as Array<FlagName>).map((flagName) => ({
name: flagName,
value: this.getFeatureFlag(flagName),
}));
}

/**
* Retruns an Array of all remote config variables with their name and value
*/
getRemoteConfigVariables() {
return (Object.keys(this.#data.remoteConfig) as Array<RemoteConfigName>).map((configName) => ({
name: configName,
value: this.getRemoteConfig(configName),
})) as Array<{
name: RemoteConfigName;
value: RemoteConfigValueStringToType<RemoteConfig[RemoteConfigName]>;
}>;
}
}
66 changes: 66 additions & 0 deletions packages/core/tests/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,72 @@ describe("Abby", () => {

expect(abby.getRemoteConfig("remoteConfig1")).toBe("bar");
});

it("returns the correct list of all flags", () => {
const flagInit = [
{
name: "a",
value: true,
},
{
name: "b",
value: true,
},
{
name: "c",
value: false,
},
];
const abby = new Abby({
environments: ["test"],
currentEnvironment: "test",
projectId: "",
flags: ["a", "b", "c"],
});

abby.init({
flags: flagInit,
tests: [],
remoteConfig: [],
});
expect(abby.getFeatureFlags()).toEqual(flagInit);
});

it("returns the correct list of all remote config variables", () => {
const configInit = [
{
name: "a",
value: "test",
},
{
name: "b",
value: 123,
},
{
name: "c",
value: { a: true },
},
];
const abby = new Abby({
environments: ["test"],
currentEnvironment: "test",
projectId: "",
remoteConfig: {
a: "String",
b: "Number",
c: "JSON",
},
});

abby.init({
flags: [],
tests: [],
remoteConfig: configInit,
});
expect(abby.getRemoteConfigVariables()).toEqual(configInit);

const d = abby.getRemoteConfigVariables();
});
});

describe("Math helpers", () => {
Expand Down
11 changes: 11 additions & 0 deletions packages/next/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @tryabby/next

## 5.1.0

### Minor Changes

- add helper to retrieve all flags/config variables

### Patch Changes

- Updated dependencies
- @tryabby/react@5.1.0

## 5.0.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tryabby/next",
"version": "5.0.6",
"version": "5.1.0",
"description": "",
"main": "dist/index.js",
"files": [
Expand Down
16 changes: 10 additions & 6 deletions packages/next/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export function createAbby<
__abby__,
getVariants,
withDevtools,
useFeatureFlags,
useRemoteConfigVariables,
} = baseCreateAbby<FlagName, TestName, Tests, RemoteConfig, RemoteConfigName, ConfigType>(config);

const abbyApiHandler =
Expand Down Expand Up @@ -78,6 +80,8 @@ export function createAbby<
withAbby: withAbby(config as AbbyConfig<FlagName, Tests>, __abby__),
getFeatureFlagValue,
useRemoteConfig,
useFeatureFlags,
useRemoteConfigVariables,
getRemoteConfig,
__abby__,
getVariants,
Expand All @@ -101,8 +105,8 @@ export function createAbby<
ResponseType extends NextResponse | NextApiResponse = RequestType extends NextRequest
? NextResponse
: RequestType extends NextApiRequest
? NextApiResponse
: never,
? NextApiResponse
: never,
>(
name: T,
req?: RequestType,
Expand All @@ -111,8 +115,8 @@ export function createAbby<
Lookup extends undefined
? TestVariant
: TestVariant extends keyof Lookup
? Lookup[TestVariant]
: never,
? Lookup[TestVariant]
: never,
RequestType extends NextRequest | NextApiRequest ? (res: ResponseType) => void : () => void,
] {
const cookies = getIsomorphicCookies(req);
Expand Down Expand Up @@ -170,8 +174,8 @@ export function createAbby<
ResponseType extends NextResponse | NextApiResponse = RequestType extends NextRequest
? NextResponse
: RequestType extends NextApiRequest
? NextApiResponse
: never,
? NextApiResponse
: never,
>(
name: T,
req?: RequestType
Expand Down
7 changes: 7 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @tryabby/node

## 5.1.5

### Patch Changes

- Updated dependencies
- @tryabby/core@5.2.0

## 5.1.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tryabby/node",
"version": "5.1.4",
"version": "5.1.5",
"description": "",
"main": "dist/index.js",
"files": [
Expand Down
11 changes: 11 additions & 0 deletions packages/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @tryabby/react

## 5.1.0

### Minor Changes

- add helper to retrieve all flags/config variables

### Patch Changes

- Updated dependencies
- @tryabby/core@5.2.0

## 5.0.6

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tryabby/react",
"version": "5.0.6",
"version": "5.1.0",
"description": "",
"main": "dist/index.js",
"files": [
Expand Down
Loading

0 comments on commit ed7d158

Please sign in to comment.