@flag-engine/core 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/getEligibleStrategy.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/types.d.ts +40 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -2
- package/rollup.config.mjs +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getEligibleStrategy.d.ts","sourceRoot":"","sources":["../src/getEligibleStrategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getEligibleStrategy.d.ts","sourceRoot":"","sources":["../src/getEligibleStrategy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAM/E;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAChC,OAAO,IAAI,EAAE,EACb,mBAAmB,iBAAiB,EACpC,QAAO,MAAU,KAChB,OAsKF,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAC9B,YAAY,iBAAiB,EAC7B,mBAAmB,iBAAiB,KACnC,QAAQ,GAAG,SAIb,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("murmurhash-js");const
|
|
1
|
+
"use strict";var e=require("semver"),t=require("murmurhash-js");const r=e=>"string"==typeof e,n=(t,s,a=0)=>!(a>10)&&(0===t.length||t.every((t=>{if("inSegment"in t)return n(t.inSegment.rules,s,a+1);switch(t.operator){case"equals":return-1!==t.value.indexOf(s[t.field]);case"not_equals":return-1===t.value.indexOf(s[t.field]);case"greater_than":{const e=s[t.field];return"number"==typeof e&&e>t.value}case"less_than":{const e=s[t.field];return"number"==typeof e&&e<t.value}case"contains":{const e=s[t.field];return!!r(e)&&t.value.some((t=>e.includes(t)))}case"not_contains":{const e=s[t.field];return!r(e)||t.value.every((t=>!e.includes(t)))}case"starts_with":{const e=s[t.field];return!!r(e)&&t.value.some((t=>e.startsWith(t)))}case"ends_with":{const e=s[t.field];return!!r(e)&&t.value.some((t=>e.endsWith(t)))}case"regex":{const e=s[t.field];if(!r(e))return!1;try{return new RegExp(t.value).test(e)}catch{return!1}}case"greater_than_or_equal":{const e=s[t.field];return"number"==typeof e&&e>=t.value}case"less_than_or_equal":{const e=s[t.field];return"number"==typeof e&&e<=t.value}case"date_before":{const e=s[t.field];if(!r(e))return!1;const n=new Date(e),a=new Date(t.value);return!isNaN(n.getTime())&&!isNaN(a.getTime())&&n<a}case"date_after":{const e=s[t.field];if(!r(e))return!1;const n=new Date(e),a=new Date(t.value);return!isNaN(n.getTime())&&!isNaN(a.getTime())&&n>a}case"is_set":return void 0!==s[t.field]&&null!==s[t.field];case"is_not_set":return void 0===s[t.field]||null===s[t.field];case"modulo":{const e=s[t.field];if("number"!=typeof e)return!1;const r=e%t.value.divisor;return!isNaN(r)&&r===t.value.remainder}case"semver_equal":{const n=s[t.field];return!!r(n)&&(!(!e.valid(n)||!e.valid(t.value))&&e.eq(n,t.value))}case"semver_greater_than":{const n=s[t.field];return!!r(n)&&(!(!e.valid(n)||!e.valid(t.value))&&e.gt(n,t.value))}case"semver_less_than":{const n=s[t.field];return!!r(n)&&(!(!e.valid(n)||!e.valid(t.value))&&e.lt(n,t.value))}default:return!1}}))),s=2**32,a=(e,r)=>{if(0===e.strategies.length)return!0;const a=((e,t)=>e.strategies.find((e=>n(e.rules,t))))(e,r);if(!a)return!1;if(0===a.variants.length)return!0;const u=((e,r)=>{const n=[...e.variants].sort(((e,t)=>e.percent-t.percent)),a=`${e.name}-${r}`,u=t.murmur3(a)/s*100;let i=0;for(const e of n)if(i+=e.percent,u<i)return e;return!1})(a,r.__id);return!1!==u&&u.name};exports.createFlagEngine=e=>({createUserContext:t=>((e,t)=>{let r=t;return{evaluateAll:()=>{const t={};for(const n of e)t[n.key]="enabled"===n.status&&a(n,r);return t},evaluate:t=>{const n=e.find((e=>e.key===t));return!!n&&"enabled"===n.status&&a(n,r)},setUserConfiguration:e=>{r=e}}})(e,t)});
|
package/dist/index.d.ts
CHANGED
|
@@ -13,5 +13,5 @@ import { EvaluationMachine, FlagsConfiguration } from "./types";
|
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
export declare const createFlagEngine: (flagsConfig: FlagsConfiguration) => EvaluationMachine;
|
|
16
|
-
export type { ConditionOperator, EvaluationMachine, FlagConfiguration, FlagDict, FlagStatus, FlagsConfiguration, Rule, RuleValuePrimitive, Segment, Strategy, UserConfiguration, UserContextFlagEvaluation, Variant, } from "./types";
|
|
16
|
+
export type { ConditionOperator, DateComparisonRule, DateString, EqualityRule, EvaluationMachine, ExistenceRule, FlagConfiguration, FlagDict, FlagStatus, FlagsConfiguration, ModuloRule, NumericComparisonRule, RegexRule, Rule, RuleValuePrimitive, Segment, SegmentRule, SemVerRule, Strategy, StringMatchRule, UserConfiguration, UserContextFlagEvaluation, Variant, } from "./types";
|
|
17
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EAEjB,kBAAkB,EAGnB,MAAM,SAAS,CAAC;AAoCjB;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,GAC3B,aAAa,kBAAkB,KAC9B,iBAKF,CAAC;AAEF,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,QAAQ,EACR,UAAU,EACV,kBAAkB,EAClB,IAAI,EACJ,kBAAkB,EAClB,OAAO,EACP,QAAQ,EACR,iBAAiB,EACjB,yBAAyB,EACzB,OAAO,GACR,MAAM,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EAEjB,kBAAkB,EAGnB,MAAM,SAAS,CAAC;AAoCjB;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,GAC3B,aAAa,kBAAkB,KAC9B,iBAKF,CAAC;AAEF,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,QAAQ,EACR,UAAU,EACV,kBAAkB,EAClB,UAAU,EACV,qBAAqB,EACrB,SAAS,EACT,IAAI,EACJ,kBAAkB,EAClB,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,EACR,eAAe,EACf,iBAAiB,EACjB,yBAAyB,EACzB,OAAO,GACR,MAAM,SAAS,CAAC"}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{valid as e,lt as t,gt as r,eq as n}from"semver";import{murmur3 as s}from"murmurhash-js";const a=e=>"string"==typeof e,u=(s,i,l=0)=>!(l>10)&&(0===s.length||s.every((s=>{if("inSegment"in s)return u(s.inSegment.rules,i,l+1);switch(s.operator){case"equals":return-1!==s.value.indexOf(i[s.field]);case"not_equals":return-1===s.value.indexOf(i[s.field]);case"greater_than":{const e=i[s.field];return"number"==typeof e&&e>s.value}case"less_than":{const e=i[s.field];return"number"==typeof e&&e<s.value}case"contains":{const e=i[s.field];return!!a(e)&&s.value.some((t=>e.includes(t)))}case"not_contains":{const e=i[s.field];return!a(e)||s.value.every((t=>!e.includes(t)))}case"starts_with":{const e=i[s.field];return!!a(e)&&s.value.some((t=>e.startsWith(t)))}case"ends_with":{const e=i[s.field];return!!a(e)&&s.value.some((t=>e.endsWith(t)))}case"regex":{const e=i[s.field];if(!a(e))return!1;try{return new RegExp(s.value).test(e)}catch{return!1}}case"greater_than_or_equal":{const e=i[s.field];return"number"==typeof e&&e>=s.value}case"less_than_or_equal":{const e=i[s.field];return"number"==typeof e&&e<=s.value}case"date_before":{const e=i[s.field];if(!a(e))return!1;const t=new Date(e),r=new Date(s.value);return!isNaN(t.getTime())&&!isNaN(r.getTime())&&t<r}case"date_after":{const e=i[s.field];if(!a(e))return!1;const t=new Date(e),r=new Date(s.value);return!isNaN(t.getTime())&&!isNaN(r.getTime())&&t>r}case"is_set":return void 0!==i[s.field]&&null!==i[s.field];case"is_not_set":return void 0===i[s.field]||null===i[s.field];case"modulo":{const e=i[s.field];if("number"!=typeof e)return!1;const t=e%s.value.divisor;return!isNaN(t)&&t===s.value.remainder}case"semver_equal":{const t=i[s.field];return!!a(t)&&(!(!e(t)||!e(s.value))&&n(t,s.value))}case"semver_greater_than":{const t=i[s.field];return!!a(t)&&(!(!e(t)||!e(s.value))&&r(t,s.value))}case"semver_less_than":{const r=i[s.field];return!!a(r)&&(!(!e(r)||!e(s.value))&&t(r,s.value))}default:return!1}}))),i=2**32,l=(e,t)=>{if(0===e.strategies.length)return!0;const r=((e,t)=>e.strategies.find((e=>u(e.rules,t))))(e,t);if(!r)return!1;if(0===r.variants.length)return!0;const n=((e,t)=>{const r=[...e.variants].sort(((e,t)=>e.percent-t.percent)),n=`${e.name}-${t}`,a=s(n)/i*100;let u=0;for(const e of r)if(u+=e.percent,a<u)return e;return!1})(r,t.__id);return!1!==n&&n.name},o=e=>({createUserContext:t=>((e,t)=>{let r=t;return{evaluateAll:()=>{const t={};for(const n of e)t[n.key]="enabled"===n.status&&l(n,r);return t},evaluate:t=>{const n=e.find((e=>e.key===t));return!!n&&"enabled"===n.status&&l(n,r)},setUserConfiguration:e=>{r=e}}})(e,t)});export{o as createFlagEngine};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,21 +1,54 @@
|
|
|
1
1
|
export type FlagStatus = "enabled" | "disabled";
|
|
2
|
-
|
|
2
|
+
/** ISO 8601 date string (e.g., "2025-01-15T00:00:00Z") */
|
|
3
|
+
export type DateString = string;
|
|
4
|
+
export type ConditionOperator = "equals" | "not_equals" | "contains" | "not_contains" | "starts_with" | "ends_with" | "regex" | "greater_than" | "less_than" | "greater_than_or_equal" | "less_than_or_equal" | "date_before" | "date_after" | "is_set" | "is_not_set" | "modulo" | "semver_equal" | "semver_greater_than" | "semver_less_than";
|
|
3
5
|
export type RuleValuePrimitive = object | null | undefined | string | number | boolean | Date;
|
|
4
|
-
export type
|
|
6
|
+
export type EqualityRule = {
|
|
5
7
|
field: string;
|
|
6
8
|
operator: "equals" | "not_equals";
|
|
7
9
|
value: Array<RuleValuePrimitive>;
|
|
8
|
-
}
|
|
10
|
+
};
|
|
11
|
+
export type StringMatchRule = {
|
|
9
12
|
field: string;
|
|
10
|
-
operator: "contains" | "not_contains";
|
|
13
|
+
operator: "contains" | "not_contains" | "starts_with" | "ends_with";
|
|
11
14
|
value: Array<string>;
|
|
12
|
-
}
|
|
15
|
+
};
|
|
16
|
+
export type RegexRule = {
|
|
17
|
+
field: string;
|
|
18
|
+
operator: "regex";
|
|
19
|
+
value: string;
|
|
20
|
+
};
|
|
21
|
+
export type NumericComparisonRule = {
|
|
13
22
|
field: string;
|
|
14
|
-
operator: "greater_than" | "less_than";
|
|
23
|
+
operator: "greater_than" | "less_than" | "greater_than_or_equal" | "less_than_or_equal";
|
|
15
24
|
value: number;
|
|
16
|
-
}
|
|
25
|
+
};
|
|
26
|
+
export type DateComparisonRule = {
|
|
27
|
+
field: string;
|
|
28
|
+
operator: "date_before" | "date_after";
|
|
29
|
+
value: DateString;
|
|
30
|
+
};
|
|
31
|
+
export type ExistenceRule = {
|
|
32
|
+
field: string;
|
|
33
|
+
operator: "is_set" | "is_not_set";
|
|
34
|
+
};
|
|
35
|
+
export type ModuloRule = {
|
|
36
|
+
field: string;
|
|
37
|
+
operator: "modulo";
|
|
38
|
+
value: {
|
|
39
|
+
divisor: number;
|
|
40
|
+
remainder: number;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export type SemVerRule = {
|
|
44
|
+
field: string;
|
|
45
|
+
operator: "semver_equal" | "semver_greater_than" | "semver_less_than";
|
|
46
|
+
value: string;
|
|
47
|
+
};
|
|
48
|
+
export type SegmentRule = {
|
|
17
49
|
inSegment: Segment;
|
|
18
50
|
};
|
|
51
|
+
export type Rule = EqualityRule | StringMatchRule | RegexRule | NumericComparisonRule | DateComparisonRule | ExistenceRule | ModuloRule | SemVerRule | SegmentRule;
|
|
19
52
|
export type Segment = {
|
|
20
53
|
name: string;
|
|
21
54
|
rules: Array<Rule>;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,UAAU,CAAC;AAEhD,0DAA0D;AAC1D,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC,MAAM,MAAM,iBAAiB,GACzB,QAAQ,GACR,YAAY,GACZ,UAAU,GACV,cAAc,GACd,aAAa,GACb,WAAW,GACX,OAAO,GACP,cAAc,GACd,WAAW,GACX,uBAAuB,GACvB,oBAAoB,GACpB,aAAa,GACb,YAAY,GACZ,QAAQ,GACR,YAAY,GACZ,QAAQ,GACR,cAAc,GACd,qBAAqB,GACrB,kBAAkB,CAAC;AAEvB,MAAM,MAAM,kBAAkB,GAC1B,MAAM,GACN,IAAI,GACJ,SAAS,GACT,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,CAAC;AAET,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,QAAQ,GAAG,YAAY,CAAC;IAClC,KAAK,EAAE,KAAK,CAAC,kBAAkB,CAAC,CA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CAAC;CAChC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flag-engine/core",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"description": "Feature flags evaluation engine, runtime agnostic",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs.js",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"@rollup/plugin-typescript": "^12.1.3",
|
|
34
34
|
"@types/eslint__js": "^9.14.0",
|
|
35
35
|
"@types/murmurhash-js": "^1.0.6",
|
|
36
|
+
"@types/semver": "^7.7.1",
|
|
36
37
|
"@vitest/coverage-v8": "3.2.4",
|
|
37
38
|
"bundlesize": "^0.18.2",
|
|
38
39
|
"eslint": "^9.29.0",
|
|
@@ -45,7 +46,8 @@
|
|
|
45
46
|
"vitest": "^3.2.4"
|
|
46
47
|
},
|
|
47
48
|
"dependencies": {
|
|
48
|
-
"murmurhash-js": "^1.0.0"
|
|
49
|
+
"murmurhash-js": "^1.0.0",
|
|
50
|
+
"semver": "^7.7.4"
|
|
49
51
|
},
|
|
50
52
|
"bundlesize": [
|
|
51
53
|
{
|
package/rollup.config.mjs
CHANGED
|
@@ -2,8 +2,8 @@ import typescript from "@rollup/plugin-typescript";
|
|
|
2
2
|
import terser from "@rollup/plugin-terser";
|
|
3
3
|
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
4
4
|
|
|
5
|
-
const external = ["murmurhash-js"];
|
|
6
|
-
const globals = { "murmurhash-js": "murmurhash-js" };
|
|
5
|
+
const external = ["murmurhash-js", "semver"];
|
|
6
|
+
const globals = { "murmurhash-js": "murmurhash-js", "semver": "semver" };
|
|
7
7
|
|
|
8
8
|
export default () => {
|
|
9
9
|
return {
|