Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
evaluateFlag,
evaluateRolloutStep,
evaluateRolloutSteps,
} from "../engine";
import type { FeatureFlagInputSchema, FlagEvaluationInput } from "../schema";
} from "../engine.ts";
import type { FeatureFlagInputSchema, FlagEvaluationInput } from "../types.ts";

function createMockInput(
overrides?: Partial<FlagEvaluationInput>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, test } from "vitest";
import { evaluateFlag } from "../engine";
import type { FlagEvaluationInput } from "../schema";
import { evaluateFlag } from "../engine.ts";
import type { FlagEvaluationInput } from "../types.ts";

/**
* Helper to create properly structured evaluation input
Expand Down
2 changes: 1 addition & 1 deletion src/engine.ts → engine/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
FeatureFlagInputSchema,
FlagEvaluationInput,
FlagResultSchema,
} from "./schema";
} from "./types";

jexl.addTransform("split", (val, char) => val.split(char));
jexl.addTransform("lower", (val) => val.toLowerCase());
Expand Down
2 changes: 2 additions & 0 deletions engine/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./engine";
export * from "./types";
34 changes: 34 additions & 0 deletions engine/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@flaggly/engine",
"version": "0.2.0",
"description": "Flaggly feature flag evaluation engine",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"files": [
"dist",
"README.md"
],
"keywords": [
"feature-flags",
"engine",
"typescript",
"cloudflare"
],
"author": "butttons",
"license": "MIT",
"dependencies": {
"jexl": "^2.3.0"
},
"repository": {
"type": "git",
"url": "https://github.com/butttons/flaggly"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
}
}
}
20 changes: 20 additions & 0 deletions engine/tsconfig.engine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": false,
"outDir": "../../dist/engine",
"rootDir": "../",
"strict": true,
"strictNullChecks": false,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"types": []
},
"include": ["./**/*.ts"],
"exclude": ["**/*.test.ts", "**/*.spec.ts", "node_modules"]
}
98 changes: 98 additions & 0 deletions engine/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
export type RolloutStep = {
start: string;
percentage?: number;
segment?: string;
};

export type FeatureFlagVariation = {
id: string;
label?: string;
weight: number;
payload?: unknown;
};

export type FeatureFlagInputSchema =
| {
id: string;
label?: string;
description?: string;
enabled: boolean;
type: "boolean";
rules: string[];
segments: string[];
rollout: number;
rollouts: RolloutStep[];
isTrackable: boolean;
}
| {
id: string;
label?: string;
description?: string;
enabled: boolean;
type: "payload";
payload: unknown;
rules: string[];
segments: string[];
rollout: number;
rollouts: RolloutStep[];
isTrackable: boolean;
}
| {
id: string;
label?: string;
description?: string;
enabled: boolean;
type: "variant";
variations: FeatureFlagVariation[];
rules: string[];
segments: string[];
rollout: number;
rollouts: RolloutStep[];
isTrackable: boolean;
};

export type FlagEvaluationInput = {
user?: unknown;
id?: string;
request: {
headers: Record<string, string>;
};
page: {
url?: string | null;
};
geo: {
country?: string;
isEUCountry?: boolean;
continent?: string;
city?: string;
postalCode?: string;
latitude?: string;
longitude?: string;
timezone?: string;
region?: string;
regionCode?: string;
metroCode?: string;
};
};

export type FlagResultSchema =
| {
type: "boolean";
result: boolean;
isEval: boolean;
}
| {
type: "payload";
result: unknown;
isEval: boolean;
}
| {
type: "variant";
result: unknown;
isEval: boolean;
};

export type AppData = {
flags: Record<string, FeatureFlagInputSchema>;
segments: Record<string, string>;
};
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
"test": "vitest",
"test:run": "vitest run",
"build:sdk": "tsup sdk/index.ts --dts --format esm,cjs --tsconfig sdk/tsconfig.sdk.json --out-dir sdk/dist",
"sandbox:sdk": "tsx sdk/sandbox.ts"
"sandbox:sdk": "tsx sdk/sandbox.ts",
"build:engine": "tsup engine/index.ts --dts --format esm,cjs --tsconfig engine/tsconfig.engine.json --out-dir engine/dist"
},
"dependencies": {
"hono": "^4.9.9",
"jexl": "^2.3.0",
"zod": "^4.1.11"
"zod": "^4.1.11",
"@flaggly/engine": "workspace:*"
},
"devDependencies": {
"@types/jexl": "^2.3.4",
Expand Down
54 changes: 54 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading