Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bright-jars-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vercel/flags-core": minor
---

Support object/JSON flag values in addition to boolean, string, and number
8 changes: 8 additions & 0 deletions packages/vercel-flags-core/src/black-box.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2879,6 +2879,10 @@ describe('Controller (black-box)', () => {
environments: { production: 0 },
variants: [42],
},
jsonFlag: {
environments: { production: 0 },
variants: [{ color: 'red', size: 12 }],
},
},
});

Expand All @@ -2893,6 +2897,10 @@ describe('Controller (black-box)', () => {
expect((await client.evaluate('boolFlag')).value).toBe(true);
expect((await client.evaluate('stringFlag')).value).toBe('hello');
expect((await client.evaluate('numberFlag')).value).toBe(42);
expect((await client.evaluate('jsonFlag')).value).toEqual({
color: 'red',
size: 12,
});
});

it('should call internalReportValue when projectId exists', async () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/vercel-flags-core/src/index.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ export {
type EvaluationParams,
type EvaluationResult,
type FlagsClient,
type JsonArray,
type JsonObject,
type JsonValue,
type Packed,
type PollingOptions,
ResolutionReason as Reason,
type StreamOptions,
type Value,
} from './types';
14 changes: 11 additions & 3 deletions packages/vercel-flags-core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { ControllerInstance } from './controller-fns';

/**
* Options for stream connection behavior
*/
Expand Down Expand Up @@ -249,7 +247,17 @@ export type FlagKey = string;
export type VariantId = string;
export type EnvironmentKey = string;
export type SegmentId = string;
export type Value = string | number | boolean;
export type JsonObject = { [key: string]: JsonValue };
export type JsonArray = JsonValue[];
export type JsonValue =
| string
| number
| boolean
| null
| JsonObject
| JsonArray;

export type Value = string | number | boolean | JsonObject | JsonArray;

export enum ResolutionReason {
PAUSED = 'paused',
Expand Down
Loading