Skip to content

Commit

Permalink
feat(core): add fallback values per flag (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
cstrnt authored Sep 11, 2023
1 parent b80054c commit ed5c7ab
Show file tree
Hide file tree
Showing 18 changed files with 112 additions and 11 deletions.
8 changes: 8 additions & 0 deletions apps/angular-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# angular-example

## 0.0.11

### Patch Changes

- Updated dependencies
- @tryabby/angular@2.0.1
- @tryabby/devtools@5.0.0

## 0.0.10

### 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.10",
"version": "0.0.11",
"private": true,
"scripts": {
"ng": "ng",
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.29

### Patch Changes

- Updated dependencies
- @tryabby/core@5.0.1
- @tryabby/next@5.0.1
- @tryabby/devtools@5.0.0

## 0.2.28

### 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.28",
"version": "0.2.29",
"private": true,
"scripts": {
"build": "next build",
Expand Down
8 changes: 8 additions & 0 deletions packages/angular/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @tryabby/angular

## 2.0.1

### Patch Changes

- add fallback values to remote config
- Updated dependencies
- @tryabby/core@5.0.1

## 2.0.0

### Major 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.0",
"version": "2.0.1",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @tryabby/cli

## 1.0.1

### Patch Changes

- add fallback values to remote config

## 1.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tryabby/cli",
"version": "1.0.0",
"version": "1.0.1",
"private": false,
"main": "./dist/index.js",
"bin": {
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.0.1

### Patch Changes

- add fallback values to remote config

## 5.0.0

### Major 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.0.0",
"version": "5.0.1",
"description": "",
"main": "dist/index.js",
"files": [
Expand Down
19 changes: 16 additions & 3 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ type Settings<
devOverrides?: {
[K in keyof RemoteConfig]: RemoteConfigValueStringToType<RemoteConfig[K]>;
};
fallbackValues?: {
[K in keyof RemoteConfig]?: RemoteConfigValueStringToType<RemoteConfig[K]>;
};
};
};

Expand Down Expand Up @@ -85,7 +88,7 @@ export type AbbyConfig<
tests?: Tests;
flags?: FlagName[];
remoteConfig?: RemoteConfig;
settings?: Settings<F.NoInfer<FlagName>>;
settings?: Settings<F.NoInfer<FlagName>, F.NoInfer<RemoteConfigName>, F.NoInfer<RemoteConfig>>;
debug?: boolean;
};

Expand Down Expand Up @@ -336,8 +339,18 @@ export class Abby<
const defaultValue =
this._cfg.settings?.remoteConfig?.defaultValues?.[this._cfg.remoteConfig?.[key]!];

if (storedValue === undefined && defaultValue !== undefined) {
return defaultValue as RemoteConfigValueStringToType<RemoteConfig[RemoteConfigName]>;
if (storedValue === undefined) {
// before we return the default value we check if there is a fallback value set
const fallbackValue = key in (this._cfg.settings?.remoteConfig?.fallbackValues ?? {});
if (fallbackValue) {
return this._cfg.settings?.remoteConfig?.fallbackValues?.[
key
] as RemoteConfigValueStringToType<RemoteConfig[RemoteConfigName]>;
}

if (defaultValue != null) {
return defaultValue as RemoteConfigValueStringToType<RemoteConfig[RemoteConfigName]>;
}
}

this.log(`getRemoteConfig() => storedValue:`, storedValue);
Expand Down
27 changes: 27 additions & 0 deletions packages/core/tests/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,33 @@ describe("Abby", () => {
expect(abby.getRemoteConfig("remoteConfig1")).toBe("asdf");
});

it("uses fallbacks", () => {
const abby = new Abby({
environments: [],
projectId: "",
remoteConfig: {
config1: "String",
config2: "String",
},
settings: {
remoteConfig: {
fallbackValues: {
config1: "fallback1",
},
defaultValues: {
String: "default",
},
},
},
});

abby.init({ flags: [], tests: [], remoteConfig: [] });

expect(abby.getRemoteConfig("config1")).toBe("fallback1");

expect(abby.getRemoteConfig("config2")).toBe("default");
});

it("updates a local variant in dev mode", () => {
process.env.NODE_ENV = "development";

Expand Down
8 changes: 8 additions & 0 deletions packages/next/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @tryabby/next

## 5.0.1

### Patch Changes

- add fallback values to remote config
- Updated dependencies
- @tryabby/react@5.0.1

## 5.0.0

### Major 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.0",
"version": "5.0.1",
"description": "",
"main": "dist/index.js",
"files": [
Expand Down
8 changes: 8 additions & 0 deletions packages/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @tryabby/react

## 5.0.1

### Patch Changes

- add fallback values to remote config
- Updated dependencies
- @tryabby/core@5.0.1

## 5.0.0

### Major 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.0",
"version": "5.0.1",
"description": "",
"main": "dist/index.js",
"files": [
Expand Down
8 changes: 8 additions & 0 deletions packages/svelte/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @tryabby/svelte

## 2.0.1

### Patch Changes

- add fallback values to remote config
- Updated dependencies
- @tryabby/core@5.0.1

## 2.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tryabby/svelte",
"version": "2.0.0",
"version": "2.0.1",
"main": "dist/index.umd.cjs",
"homepage": "https://docs.tryabby.dev",
"type": "module",
Expand Down

1 comment on commit ed5c7ab

@vercel
Copy link

@vercel vercel bot commented on ed5c7ab Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.