@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,91 @@
1
+ {
2
+ "name": "clauses inside a segment group use AND",
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": "US",
82
+ "plan": "free",
83
+ "email": "a@example.com"
84
+ }
85
+ },
86
+ "expected": {
87
+ "variantKey": "off",
88
+ "value": false,
89
+ "reason": "FALLTHROUGH"
90
+ }
91
+ }
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "segment clause values use OR",
3
+ "bundle": {
4
+ "fmt": 1,
5
+ "envId": "env_test",
6
+ "version": 7,
7
+ "publishedAt": 1700000000000,
8
+ "revoked": false,
9
+ "segments": {
10
+ "staff": [
11
+ {
12
+ "clauses": [
13
+ {
14
+ "attr": "role",
15
+ "op": "eq",
16
+ "values": ["staff"],
17
+ "negate": false
18
+ }
19
+ ]
20
+ }
21
+ ],
22
+ "paid": [
23
+ {
24
+ "clauses": [
25
+ {
26
+ "attr": "plan",
27
+ "op": "eq",
28
+ "values": ["pro"],
29
+ "negate": false
30
+ }
31
+ ]
32
+ }
33
+ ]
34
+ },
35
+ "flags": {
36
+ "test-flag": {
37
+ "type": "boolean",
38
+ "version": 3,
39
+ "salt": "0123456789abcdef",
40
+ "on": true,
41
+ "variants": [
42
+ {
43
+ "key": "off",
44
+ "value": false
45
+ },
46
+ {
47
+ "key": "on",
48
+ "value": true
49
+ }
50
+ ],
51
+ "offVariant": 0,
52
+ "fallthrough": {
53
+ "variant": 0
54
+ },
55
+ "rules": [
56
+ {
57
+ "id": "rule-1",
58
+ "clauses": [
59
+ {
60
+ "attr": "",
61
+ "op": "segment",
62
+ "values": ["staff", "paid"],
63
+ "negate": false
64
+ }
65
+ ],
66
+ "serve": {
67
+ "variant": 1
68
+ }
69
+ }
70
+ ]
71
+ }
72
+ }
73
+ },
74
+ "context": {
75
+ "key": "u",
76
+ "attributes": {
77
+ "role": "customer",
78
+ "plan": "pro"
79
+ }
80
+ },
81
+ "expected": {
82
+ "variantKey": "on",
83
+ "value": true,
84
+ "reason": "RULE_MATCH:rule-1"
85
+ }
86
+ }
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "missing segment is a false clause",
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": "rule-1",
33
+ "clauses": [
34
+ {
35
+ "attr": "",
36
+ "op": "segment",
37
+ "values": ["missing"],
38
+ "negate": false
39
+ }
40
+ ],
41
+ "serve": {
42
+ "variant": 1
43
+ }
44
+ }
45
+ ]
46
+ }
47
+ }
48
+ },
49
+ "context": {
50
+ "key": "u",
51
+ "attributes": {}
52
+ },
53
+ "expected": {
54
+ "variantKey": "off",
55
+ "value": false,
56
+ "reason": "FALLTHROUGH"
57
+ }
58
+ }
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "segment cycles fail closed",
3
+ "bundle": {
4
+ "fmt": 1,
5
+ "envId": "env_test",
6
+ "version": 7,
7
+ "publishedAt": 1700000000000,
8
+ "revoked": false,
9
+ "segments": {
10
+ "a": [
11
+ {
12
+ "clauses": [
13
+ {
14
+ "attr": "",
15
+ "op": "segment",
16
+ "values": ["b"],
17
+ "negate": false
18
+ }
19
+ ]
20
+ }
21
+ ],
22
+ "b": [
23
+ {
24
+ "clauses": [
25
+ {
26
+ "attr": "",
27
+ "op": "segment",
28
+ "values": ["a"],
29
+ "negate": false
30
+ }
31
+ ]
32
+ }
33
+ ]
34
+ },
35
+ "flags": {
36
+ "test-flag": {
37
+ "type": "boolean",
38
+ "version": 3,
39
+ "salt": "0123456789abcdef",
40
+ "on": true,
41
+ "variants": [
42
+ {
43
+ "key": "off",
44
+ "value": false
45
+ },
46
+ {
47
+ "key": "on",
48
+ "value": true
49
+ }
50
+ ],
51
+ "offVariant": 0,
52
+ "fallthrough": {
53
+ "variant": 0
54
+ },
55
+ "rules": [
56
+ {
57
+ "id": "rule-1",
58
+ "clauses": [
59
+ {
60
+ "attr": "",
61
+ "op": "segment",
62
+ "values": ["a"],
63
+ "negate": false
64
+ }
65
+ ],
66
+ "serve": {
67
+ "variant": 1
68
+ }
69
+ }
70
+ ]
71
+ }
72
+ }
73
+ },
74
+ "context": {
75
+ "key": "u",
76
+ "attributes": {}
77
+ },
78
+ "expected": {
79
+ "variantKey": "off",
80
+ "value": false,
81
+ "reason": "FALLTHROUGH"
82
+ }
83
+ }
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "negated matching segment does not match",
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": true
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": "off",
70
+ "value": false,
71
+ "reason": "FALLTHROUGH"
72
+ }
73
+ }
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "nested segments can match",
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
+ "nested": [
23
+ {
24
+ "clauses": [
25
+ {
26
+ "attr": "",
27
+ "op": "segment",
28
+ "values": ["paid"],
29
+ "negate": false
30
+ }
31
+ ]
32
+ }
33
+ ]
34
+ },
35
+ "flags": {
36
+ "test-flag": {
37
+ "type": "boolean",
38
+ "version": 3,
39
+ "salt": "0123456789abcdef",
40
+ "on": true,
41
+ "variants": [
42
+ {
43
+ "key": "off",
44
+ "value": false
45
+ },
46
+ {
47
+ "key": "on",
48
+ "value": true
49
+ }
50
+ ],
51
+ "offVariant": 0,
52
+ "fallthrough": {
53
+ "variant": 0
54
+ },
55
+ "rules": [
56
+ {
57
+ "id": "rule-1",
58
+ "clauses": [
59
+ {
60
+ "attr": "",
61
+ "op": "segment",
62
+ "values": ["nested"],
63
+ "negate": false
64
+ }
65
+ ],
66
+ "serve": {
67
+ "variant": 1
68
+ }
69
+ }
70
+ ]
71
+ }
72
+ }
73
+ },
74
+ "context": {
75
+ "key": "u",
76
+ "attributes": {
77
+ "plan": "pro"
78
+ }
79
+ },
80
+ "expected": {
81
+ "variantKey": "on",
82
+ "value": true,
83
+ "reason": "RULE_MATCH:rule-1"
84
+ }
85
+ }
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "a valid segment group can match after another group errors",
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": "missing",
15
+ "op": "eq",
16
+ "values": ["x"],
17
+ "negate": false
18
+ }
19
+ ]
20
+ },
21
+ {
22
+ "clauses": [
23
+ {
24
+ "attr": "email",
25
+ "op": "endsWith",
26
+ "values": ["@flagwire.dev"],
27
+ "negate": false
28
+ }
29
+ ]
30
+ }
31
+ ]
32
+ },
33
+ "flags": {
34
+ "test-flag": {
35
+ "type": "boolean",
36
+ "version": 3,
37
+ "salt": "0123456789abcdef",
38
+ "on": true,
39
+ "variants": [
40
+ {
41
+ "key": "off",
42
+ "value": false
43
+ },
44
+ {
45
+ "key": "on",
46
+ "value": true
47
+ }
48
+ ],
49
+ "offVariant": 0,
50
+ "fallthrough": {
51
+ "variant": 0
52
+ },
53
+ "rules": [
54
+ {
55
+ "id": "rule-1",
56
+ "clauses": [
57
+ {
58
+ "attr": "",
59
+ "op": "segment",
60
+ "values": ["target"],
61
+ "negate": false
62
+ }
63
+ ],
64
+ "serve": {
65
+ "variant": 1
66
+ }
67
+ }
68
+ ]
69
+ }
70
+ }
71
+ },
72
+ "context": {
73
+ "key": "u",
74
+ "attributes": {
75
+ "email": "a@flagwire.dev"
76
+ }
77
+ },
78
+ "expected": {
79
+ "variantKey": "on",
80
+ "value": true,
81
+ "reason": "RULE_MATCH:rule-1"
82
+ }
83
+ }
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "a valid segment value can match after a missing segment",
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": ["missing", "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,48 @@
1
+ [
2
+ { "input": "", "seed": 0, "expectedUint32": 0 },
3
+ { "input": "a", "seed": 0, "expectedUint32": 1009084850 },
4
+ { "input": "ab", "seed": 0, "expectedUint32": 2613040991 },
5
+ { "input": "abc", "seed": 0, "expectedUint32": 3017643002 },
6
+ { "input": "abcd", "seed": 0, "expectedUint32": 1139631978 },
7
+ { "input": "abcde", "seed": 0, "expectedUint32": 3902511862 },
8
+ { "input": "abcdef", "seed": 0, "expectedUint32": 1635893381 },
9
+ { "input": "abcdefg", "seed": 0, "expectedUint32": 2285673222 },
10
+ { "input": "abcdefgh", "seed": 0, "expectedUint32": 1239272644 },
11
+ { "input": "hello", "seed": 0, "expectedUint32": 613153351 },
12
+ { "input": "Hello", "seed": 0, "expectedUint32": 316307400 },
13
+ { "input": "hello world", "seed": 0, "expectedUint32": 1586663183 },
14
+ {
15
+ "input": "The quick brown fox jumps over the lazy dog",
16
+ "seed": 0,
17
+ "expectedUint32": 776992547
18
+ },
19
+ {
20
+ "input": "0123456789abcdef0123456789abcdef",
21
+ "seed": 0,
22
+ "expectedUint32": 3007520238
23
+ },
24
+ {
25
+ "input": "0123456789abcdef0123456789abcdef0",
26
+ "seed": 0,
27
+ "expectedUint32": 787549363
28
+ },
29
+ { "input": "flagwire", "seed": 0, "expectedUint32": 119348820 },
30
+ {
31
+ "input": "user-123:new-checkout:0123456789abcdef",
32
+ "seed": 0,
33
+ "expectedUint32": 956233461
34
+ },
35
+ { "input": "with spaces", "seed": 0, "expectedUint32": 2515971982 },
36
+ { "input": "line\nbreak", "seed": 0, "expectedUint32": 3441254551 },
37
+ { "input": "null\u0000byte", "seed": 0, "expectedUint32": 298535477 },
38
+ { "input": "café", "seed": 0, "expectedUint32": 605818632 },
39
+ { "input": "é", "seed": 0, "expectedUint32": 269551495 },
40
+ { "input": "é", "seed": 0, "expectedUint32": 2670895720 },
41
+ { "input": "你好", "seed": 0, "expectedUint32": 337357348 },
42
+ { "input": "こんにちは", "seed": 0, "expectedUint32": 757219804 },
43
+ { "input": "مرحبا", "seed": 0, "expectedUint32": 1840427645 },
44
+ { "input": "🚀", "seed": 0, "expectedUint32": 2137479269 },
45
+ { "input": "🏳️‍🌈", "seed": 0, "expectedUint32": 2046586608 },
46
+ { "input": "emoji-😀-end", "seed": 0, "expectedUint32": 3021407503 },
47
+ { "input": "Grüße 世界 🌍", "seed": 0, "expectedUint32": 1637837346 }
48
+ ]