@flagwire/evaluate 0.1.0

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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -0
  3. package/dist/index.d.ts +20 -0
  4. package/dist/index.js +1 -0
  5. package/package.json +42 -0
  6. package/vectors/.gitkeep +1 -0
  7. package/vectors/bucketing.json +86 -0
  8. package/vectors/eval/fail-safe-01.json +42 -0
  9. package/vectors/eval/fail-safe-02.json +42 -0
  10. package/vectors/eval/fail-safe-03.json +20 -0
  11. package/vectors/eval/fail-safe-04.json +42 -0
  12. package/vectors/eval/fail-safe-05.json +42 -0
  13. package/vectors/eval/fail-safe-06.json +60 -0
  14. package/vectors/eval/fail-safe-07.json +42 -0
  15. package/vectors/eval/fail-safe-08.json +57 -0
  16. package/vectors/eval/operators-01.json +60 -0
  17. package/vectors/eval/operators-02.json +60 -0
  18. package/vectors/eval/operators-03.json +60 -0
  19. package/vectors/eval/operators-04.json +60 -0
  20. package/vectors/eval/operators-05.json +60 -0
  21. package/vectors/eval/operators-06.json +60 -0
  22. package/vectors/eval/operators-07.json +60 -0
  23. package/vectors/eval/operators-08.json +60 -0
  24. package/vectors/eval/operators-09.json +60 -0
  25. package/vectors/eval/operators-10.json +60 -0
  26. package/vectors/eval/operators-11.json +60 -0
  27. package/vectors/eval/operators-12.json +60 -0
  28. package/vectors/eval/operators-13.json +60 -0
  29. package/vectors/eval/operators-14.json +60 -0
  30. package/vectors/eval/operators-15.json +60 -0
  31. package/vectors/eval/operators-16.json +60 -0
  32. package/vectors/eval/operators-17.json +60 -0
  33. package/vectors/eval/operators-18.json +60 -0
  34. package/vectors/eval/operators-19.json +58 -0
  35. package/vectors/eval/operators-20.json +60 -0
  36. package/vectors/eval/operators-21.json +67 -0
  37. package/vectors/eval/operators-22.json +74 -0
  38. package/vectors/eval/operators-23.json +60 -0
  39. package/vectors/eval/operators-24.json +60 -0
  40. package/vectors/eval/rollouts-01.json +53 -0
  41. package/vectors/eval/rollouts-02.json +53 -0
  42. package/vectors/eval/rollouts-03.json +53 -0
  43. package/vectors/eval/rollouts-04.json +53 -0
  44. package/vectors/eval/rollouts-05.json +53 -0
  45. package/vectors/eval/rollouts-06.json +71 -0
  46. package/vectors/eval/rollouts-07.json +71 -0
  47. package/vectors/eval/rollouts-08.json +49 -0
  48. package/vectors/eval/segments-01.json +73 -0
  49. package/vectors/eval/segments-02.json +91 -0
  50. package/vectors/eval/segments-03.json +91 -0
  51. package/vectors/eval/segments-04.json +86 -0
  52. package/vectors/eval/segments-05.json +58 -0
  53. package/vectors/eval/segments-06.json +83 -0
  54. package/vectors/eval/segments-07.json +73 -0
  55. package/vectors/eval/segments-08.json +85 -0
  56. package/vectors/eval/segments-09.json +83 -0
  57. package/vectors/eval/segments-10.json +73 -0
  58. package/vectors/murmur3.json +48 -0
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "fallthrough rollout selects first range",
3
+ "bundle": {
4
+ "fmt": 1,
5
+ "envId": "env_test",
6
+ "version": 7,
7
+ "publishedAt": 1700000000000,
8
+ "revoked": false,
9
+ "segments": {},
10
+ "flags": {
11
+ "test-flag": {
12
+ "type": "boolean",
13
+ "version": 3,
14
+ "salt": "0123456789abcdef",
15
+ "on": true,
16
+ "variants": [
17
+ {
18
+ "key": "off",
19
+ "value": false
20
+ },
21
+ {
22
+ "key": "on",
23
+ "value": true
24
+ }
25
+ ],
26
+ "offVariant": 0,
27
+ "fallthrough": {
28
+ "rollout": {
29
+ "variations": [
30
+ {
31
+ "variant": 1,
32
+ "weight": 50000
33
+ },
34
+ {
35
+ "variant": 0,
36
+ "weight": 50000
37
+ }
38
+ ]
39
+ }
40
+ },
41
+ "rules": []
42
+ }
43
+ }
44
+ },
45
+ "context": {
46
+ "key": "user-1"
47
+ },
48
+ "expected": {
49
+ "variantKey": "on",
50
+ "value": true,
51
+ "reason": "FALLTHROUGH"
52
+ }
53
+ }
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "fallthrough rollout selects second range",
3
+ "bundle": {
4
+ "fmt": 1,
5
+ "envId": "env_test",
6
+ "version": 7,
7
+ "publishedAt": 1700000000000,
8
+ "revoked": false,
9
+ "segments": {},
10
+ "flags": {
11
+ "test-flag": {
12
+ "type": "boolean",
13
+ "version": 3,
14
+ "salt": "0123456789abcdef",
15
+ "on": true,
16
+ "variants": [
17
+ {
18
+ "key": "off",
19
+ "value": false
20
+ },
21
+ {
22
+ "key": "on",
23
+ "value": true
24
+ }
25
+ ],
26
+ "offVariant": 0,
27
+ "fallthrough": {
28
+ "rollout": {
29
+ "variations": [
30
+ {
31
+ "variant": 1,
32
+ "weight": 50000
33
+ },
34
+ {
35
+ "variant": 0,
36
+ "weight": 50000
37
+ }
38
+ ]
39
+ }
40
+ },
41
+ "rules": []
42
+ }
43
+ }
44
+ },
45
+ "context": {
46
+ "key": "same-user"
47
+ },
48
+ "expected": {
49
+ "variantKey": "off",
50
+ "value": false,
51
+ "reason": "FALLTHROUGH"
52
+ }
53
+ }
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "rollout is deterministic for unicode keys",
3
+ "bundle": {
4
+ "fmt": 1,
5
+ "envId": "env_test",
6
+ "version": 7,
7
+ "publishedAt": 1700000000000,
8
+ "revoked": false,
9
+ "segments": {},
10
+ "flags": {
11
+ "test-flag": {
12
+ "type": "boolean",
13
+ "version": 3,
14
+ "salt": "0123456789abcdef",
15
+ "on": true,
16
+ "variants": [
17
+ {
18
+ "key": "off",
19
+ "value": false
20
+ },
21
+ {
22
+ "key": "on",
23
+ "value": true
24
+ }
25
+ ],
26
+ "offVariant": 0,
27
+ "fallthrough": {
28
+ "rollout": {
29
+ "variations": [
30
+ {
31
+ "variant": 1,
32
+ "weight": 50000
33
+ },
34
+ {
35
+ "variant": 0,
36
+ "weight": 50000
37
+ }
38
+ ]
39
+ }
40
+ },
41
+ "rules": []
42
+ }
43
+ }
44
+ },
45
+ "context": {
46
+ "key": "🚀"
47
+ },
48
+ "expected": {
49
+ "variantKey": "on",
50
+ "value": true,
51
+ "reason": "FALLTHROUGH"
52
+ }
53
+ }
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "zero-weight variation is never selected",
3
+ "bundle": {
4
+ "fmt": 1,
5
+ "envId": "env_test",
6
+ "version": 7,
7
+ "publishedAt": 1700000000000,
8
+ "revoked": false,
9
+ "segments": {},
10
+ "flags": {
11
+ "test-flag": {
12
+ "type": "boolean",
13
+ "version": 3,
14
+ "salt": "0123456789abcdef",
15
+ "on": true,
16
+ "variants": [
17
+ {
18
+ "key": "off",
19
+ "value": false
20
+ },
21
+ {
22
+ "key": "on",
23
+ "value": true
24
+ }
25
+ ],
26
+ "offVariant": 0,
27
+ "fallthrough": {
28
+ "rollout": {
29
+ "variations": [
30
+ {
31
+ "variant": 1,
32
+ "weight": 0
33
+ },
34
+ {
35
+ "variant": 0,
36
+ "weight": 100000
37
+ }
38
+ ]
39
+ }
40
+ },
41
+ "rules": []
42
+ }
43
+ }
44
+ },
45
+ "context": {
46
+ "key": "user-1"
47
+ },
48
+ "expected": {
49
+ "variantKey": "off",
50
+ "value": false,
51
+ "reason": "FALLTHROUGH"
52
+ }
53
+ }
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "missing rollout context key serves off",
3
+ "bundle": {
4
+ "fmt": 1,
5
+ "envId": "env_test",
6
+ "version": 7,
7
+ "publishedAt": 1700000000000,
8
+ "revoked": false,
9
+ "segments": {},
10
+ "flags": {
11
+ "test-flag": {
12
+ "type": "boolean",
13
+ "version": 3,
14
+ "salt": "0123456789abcdef",
15
+ "on": true,
16
+ "variants": [
17
+ {
18
+ "key": "off",
19
+ "value": false
20
+ },
21
+ {
22
+ "key": "on",
23
+ "value": true
24
+ }
25
+ ],
26
+ "offVariant": 0,
27
+ "fallthrough": {
28
+ "rollout": {
29
+ "variations": [
30
+ {
31
+ "variant": 1,
32
+ "weight": 50000
33
+ },
34
+ {
35
+ "variant": 0,
36
+ "weight": 50000
37
+ }
38
+ ]
39
+ }
40
+ },
41
+ "rules": []
42
+ }
43
+ }
44
+ },
45
+ "context": {
46
+ "key": ""
47
+ },
48
+ "expected": {
49
+ "variantKey": "off",
50
+ "value": false,
51
+ "reason": "ERROR_MISSING_KEY"
52
+ }
53
+ }
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "matching rule preserves reason through rollout",
3
+ "bundle": {
4
+ "fmt": 1,
5
+ "envId": "env_test",
6
+ "version": 7,
7
+ "publishedAt": 1700000000000,
8
+ "revoked": false,
9
+ "segments": {},
10
+ "flags": {
11
+ "test-flag": {
12
+ "type": "boolean",
13
+ "version": 3,
14
+ "salt": "0123456789abcdef",
15
+ "on": true,
16
+ "variants": [
17
+ {
18
+ "key": "off",
19
+ "value": false
20
+ },
21
+ {
22
+ "key": "on",
23
+ "value": true
24
+ }
25
+ ],
26
+ "offVariant": 0,
27
+ "fallthrough": {
28
+ "variant": 0
29
+ },
30
+ "rules": [
31
+ {
32
+ "id": "rollout-rule",
33
+ "clauses": [
34
+ {
35
+ "attr": "plan",
36
+ "op": "eq",
37
+ "values": ["pro"],
38
+ "negate": false
39
+ }
40
+ ],
41
+ "serve": {
42
+ "rollout": {
43
+ "variations": [
44
+ {
45
+ "variant": 1,
46
+ "weight": 50000
47
+ },
48
+ {
49
+ "variant": 0,
50
+ "weight": 50000
51
+ }
52
+ ]
53
+ }
54
+ }
55
+ }
56
+ ]
57
+ }
58
+ }
59
+ },
60
+ "context": {
61
+ "key": "user-1",
62
+ "attributes": {
63
+ "plan": "pro"
64
+ }
65
+ },
66
+ "expected": {
67
+ "variantKey": "on",
68
+ "value": true,
69
+ "reason": "RULE_MATCH:rollout-rule"
70
+ }
71
+ }
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "rule rollout with missing key serves off",
3
+ "bundle": {
4
+ "fmt": 1,
5
+ "envId": "env_test",
6
+ "version": 7,
7
+ "publishedAt": 1700000000000,
8
+ "revoked": false,
9
+ "segments": {},
10
+ "flags": {
11
+ "test-flag": {
12
+ "type": "boolean",
13
+ "version": 3,
14
+ "salt": "0123456789abcdef",
15
+ "on": true,
16
+ "variants": [
17
+ {
18
+ "key": "off",
19
+ "value": false
20
+ },
21
+ {
22
+ "key": "on",
23
+ "value": true
24
+ }
25
+ ],
26
+ "offVariant": 0,
27
+ "fallthrough": {
28
+ "variant": 0
29
+ },
30
+ "rules": [
31
+ {
32
+ "id": "rollout-rule",
33
+ "clauses": [
34
+ {
35
+ "attr": "plan",
36
+ "op": "eq",
37
+ "values": ["pro"],
38
+ "negate": false
39
+ }
40
+ ],
41
+ "serve": {
42
+ "rollout": {
43
+ "variations": [
44
+ {
45
+ "variant": 1,
46
+ "weight": 50000
47
+ },
48
+ {
49
+ "variant": 0,
50
+ "weight": 50000
51
+ }
52
+ ]
53
+ }
54
+ }
55
+ }
56
+ ]
57
+ }
58
+ }
59
+ },
60
+ "context": {
61
+ "key": "",
62
+ "attributes": {
63
+ "plan": "pro"
64
+ }
65
+ },
66
+ "expected": {
67
+ "variantKey": "off",
68
+ "value": false,
69
+ "reason": "ERROR_MISSING_KEY"
70
+ }
71
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "full allocation selects its only variant",
3
+ "bundle": {
4
+ "fmt": 1,
5
+ "envId": "env_test",
6
+ "version": 7,
7
+ "publishedAt": 1700000000000,
8
+ "revoked": false,
9
+ "segments": {},
10
+ "flags": {
11
+ "test-flag": {
12
+ "type": "boolean",
13
+ "version": 3,
14
+ "salt": "0123456789abcdef",
15
+ "on": true,
16
+ "variants": [
17
+ {
18
+ "key": "off",
19
+ "value": false
20
+ },
21
+ {
22
+ "key": "on",
23
+ "value": true
24
+ }
25
+ ],
26
+ "offVariant": 0,
27
+ "fallthrough": {
28
+ "rollout": {
29
+ "variations": [
30
+ {
31
+ "variant": 1,
32
+ "weight": 100000
33
+ }
34
+ ]
35
+ }
36
+ },
37
+ "rules": []
38
+ }
39
+ }
40
+ },
41
+ "context": {
42
+ "key": "any-user"
43
+ },
44
+ "expected": {
45
+ "variantKey": "on",
46
+ "value": true,
47
+ "reason": "FALLTHROUGH"
48
+ }
49
+ }
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "segment matches one complete group",
3
+ "bundle": {
4
+ "fmt": 1,
5
+ "envId": "env_test",
6
+ "version": 7,
7
+ "publishedAt": 1700000000000,
8
+ "revoked": false,
9
+ "segments": {
10
+ "paid": [
11
+ {
12
+ "clauses": [
13
+ {
14
+ "attr": "plan",
15
+ "op": "eq",
16
+ "values": ["pro"],
17
+ "negate": false
18
+ }
19
+ ]
20
+ }
21
+ ]
22
+ },
23
+ "flags": {
24
+ "test-flag": {
25
+ "type": "boolean",
26
+ "version": 3,
27
+ "salt": "0123456789abcdef",
28
+ "on": true,
29
+ "variants": [
30
+ {
31
+ "key": "off",
32
+ "value": false
33
+ },
34
+ {
35
+ "key": "on",
36
+ "value": true
37
+ }
38
+ ],
39
+ "offVariant": 0,
40
+ "fallthrough": {
41
+ "variant": 0
42
+ },
43
+ "rules": [
44
+ {
45
+ "id": "rule-1",
46
+ "clauses": [
47
+ {
48
+ "attr": "",
49
+ "op": "segment",
50
+ "values": ["paid"],
51
+ "negate": false
52
+ }
53
+ ],
54
+ "serve": {
55
+ "variant": 1
56
+ }
57
+ }
58
+ ]
59
+ }
60
+ }
61
+ },
62
+ "context": {
63
+ "key": "u",
64
+ "attributes": {
65
+ "plan": "pro"
66
+ }
67
+ },
68
+ "expected": {
69
+ "variantKey": "on",
70
+ "value": true,
71
+ "reason": "RULE_MATCH:rule-1"
72
+ }
73
+ }
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "segment groups use OR",
3
+ "bundle": {
4
+ "fmt": 1,
5
+ "envId": "env_test",
6
+ "version": 7,
7
+ "publishedAt": 1700000000000,
8
+ "revoked": false,
9
+ "segments": {
10
+ "target": [
11
+ {
12
+ "clauses": [
13
+ {
14
+ "attr": "country",
15
+ "op": "eq",
16
+ "values": ["US"],
17
+ "negate": false
18
+ },
19
+ {
20
+ "attr": "plan",
21
+ "op": "eq",
22
+ "values": ["pro"],
23
+ "negate": false
24
+ }
25
+ ]
26
+ },
27
+ {
28
+ "clauses": [
29
+ {
30
+ "attr": "email",
31
+ "op": "endsWith",
32
+ "values": ["@flagwire.dev"],
33
+ "negate": false
34
+ }
35
+ ]
36
+ }
37
+ ]
38
+ },
39
+ "flags": {
40
+ "test-flag": {
41
+ "type": "boolean",
42
+ "version": 3,
43
+ "salt": "0123456789abcdef",
44
+ "on": true,
45
+ "variants": [
46
+ {
47
+ "key": "off",
48
+ "value": false
49
+ },
50
+ {
51
+ "key": "on",
52
+ "value": true
53
+ }
54
+ ],
55
+ "offVariant": 0,
56
+ "fallthrough": {
57
+ "variant": 0
58
+ },
59
+ "rules": [
60
+ {
61
+ "id": "rule-1",
62
+ "clauses": [
63
+ {
64
+ "attr": "",
65
+ "op": "segment",
66
+ "values": ["target"],
67
+ "negate": false
68
+ }
69
+ ],
70
+ "serve": {
71
+ "variant": 1
72
+ }
73
+ }
74
+ ]
75
+ }
76
+ }
77
+ },
78
+ "context": {
79
+ "key": "u",
80
+ "attributes": {
81
+ "country": "IN",
82
+ "plan": "free",
83
+ "email": "a@flagwire.dev"
84
+ }
85
+ },
86
+ "expected": {
87
+ "variantKey": "on",
88
+ "value": true,
89
+ "reason": "RULE_MATCH:rule-1"
90
+ }
91
+ }