@voltro/plugin-flags 0.85.0 → 0.86.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.
@@ -1,11 +1,11 @@
1
1
  # Third-Party Notices — @voltro/plugin-flags
2
2
 
3
- This package depends on the open-source software listed below. Each is the
3
+ This package uses the open-source software listed below. Each is the
4
4
  property of its respective copyright holders and is used under the terms of
5
5
  its license. This file is provided for attribution; it grants no rights in
6
6
  @voltro/plugin-flags itself, which is proprietary (see LICENSE).
7
7
 
8
- Generated from the resolved runtime dependency closure (11 packages).
8
+ Generated from the resolved runtime dependency closure (10 packages).
9
9
 
10
10
  ---
11
11
 
@@ -177,34 +177,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
177
177
  SOFTWARE.
178
178
  ```
179
179
 
180
- ## layerr@3.0.0
181
-
182
- License: MIT
183
-
184
- ```
185
- MIT License
186
-
187
- Copyright (c) 2020 Perry Mitchell
188
-
189
- Permission is hereby granted, free of charge, to any person obtaining a copy
190
- of this software and associated documentation files (the "Software"), to deal
191
- in the Software without restriction, including without limitation the rights
192
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
193
- copies of the Software, and to permit persons to whom the Software is
194
- furnished to do so, subject to the following conditions:
195
-
196
- The above copyright notice and this permission notice shall be included in all
197
- copies or substantial portions of the Software.
198
-
199
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
200
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
201
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
202
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
203
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
204
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
205
- SOFTWARE.
206
- ```
207
-
208
180
  ## typeid-js@1.2.0
209
181
 
210
182
  License: Apache-2.0
@@ -413,14 +385,14 @@ Apache License
413
385
  limitations under the License.
414
386
  ```
415
387
 
416
- ## ulidx@2.4.1
388
+ ## ulid@3.0.2
417
389
 
418
390
  License: MIT
419
391
 
420
392
  ```
421
- MIT License
393
+ The MIT License (MIT)
422
394
 
423
- Copyright (c) 2021 Perry Mitchell
395
+ Copyright (c) 2017 Alizain Feerasta
424
396
 
425
397
  Permission is hereby granted, free of charge, to any person obtaining a copy
426
398
  of this software and associated documentation files (the "Software"), to deal
@@ -76,4 +76,4 @@ var n = (e) => typeof e == "object" && !!e && e._voltroTypedFlag === !0, r = (e)
76
76
  };
77
77
  };
78
78
  //#endregion
79
- export { a as i, o as n, n as r, i as t };
79
+ export { i as defineFlag, o as gateOverride, n as isTypedFlag, a as typedValueOf };
@@ -0,0 +1,81 @@
1
+ //#region src/evaluate.ts
2
+ var e = (e) => typeof e == "boolean" ? { enabled: e } : e, t = (e, t) => {
3
+ let n = 2166136261, r = `${e}:${t}`;
4
+ for (let e = 0; e < r.length; e++) n ^= r.charCodeAt(e), n = Math.imul(n, 16777619);
5
+ return n >>> 0;
6
+ }, n = (e, n) => t(e, n) % 100, r = (e, n) => t(`${e}:variant`, n) % 1e4, i = (e, t) => {
7
+ if (e.subjectIds && !(t.id != null && e.subjectIds.includes(t.id)) || e.tenantIds && !(t.tenantId != null && e.tenantIds.includes(t.tenantId)) || e.subjectTypes && !(t.type != null && e.subjectTypes.includes(t.type))) return !1;
8
+ if (e.metadata) {
9
+ let n = t.metadata ?? {};
10
+ for (let [t, r] of Object.entries(e.metadata)) if (String(n[t]) !== r) return !1;
11
+ }
12
+ return !0;
13
+ }, a = (e) => typeof e == "number" ? e : Date.parse(e), o = (e, t) => (e.rolloutBy === "tenant" ? t.tenantId : t.id) ?? "anon", s = (e, t) => {
14
+ if (e.activateAt != null && t < a(e.activateAt) || e.deactivateAt != null && t >= a(e.deactivateAt)) return { active: !1 };
15
+ if (e.ramp) {
16
+ let { from: n, to: r, startAt: i, endAt: o } = e.ramp, s = a(i), c = a(o);
17
+ if (t <= s) return {
18
+ active: !0,
19
+ rollout: n
20
+ };
21
+ if (t >= c || c <= s) return {
22
+ active: !0,
23
+ rollout: r
24
+ };
25
+ let l = (t - s) / (c - s);
26
+ return {
27
+ active: !0,
28
+ rollout: n + (r - n) * l
29
+ };
30
+ }
31
+ return { active: !0 };
32
+ }, c = (t, n, r, i = Date.now()) => {
33
+ let a = e(n);
34
+ return l(t, a, r, i) ? !a.variants?.length || a.offVariant == null || d(t, a, r).name !== a.offVariant : !1;
35
+ }, l = (e, t, r, a) => {
36
+ if (t.enabled === !1) return !1;
37
+ let c;
38
+ if (t.schedule) {
39
+ let e = s(t.schedule, a);
40
+ if (!e.active) return !1;
41
+ c = e.rollout;
42
+ }
43
+ if (t.targeting && t.targeting.length > 0 && !t.targeting.some((e) => i(e, r))) return !1;
44
+ let l = c ?? t.rollout ?? 100;
45
+ if (l < 100 && l > 0) {
46
+ if (!(n(e, o(t, r)) < l)) return !1;
47
+ } else if (l <= 0) return !1;
48
+ return !0;
49
+ }, u = (e) => {
50
+ let t = e.reduce((e, t) => e + (t.weight ?? 1), 0) || e.length, n = 0;
51
+ return e.map((r, i) => (n += r.weight ?? 1, i === e.length - 1 ? 1e4 : Math.round(n / t * 1e4)));
52
+ }, d = (e, t, n) => {
53
+ let i = t.variants ?? [];
54
+ if (i.length === 0) throw Error(`flag "${e}" has no variants`);
55
+ let a = r(e, o(t, n)), s = u(i);
56
+ for (let e = 0; e < i.length; e++) if (a < s[e]) return i[e];
57
+ return i[i.length - 1];
58
+ }, f = (t, n, r, i = Date.now()) => {
59
+ let a = e(n), o = l(t, a, r, i);
60
+ if (!a.variants || a.variants.length === 0) return {
61
+ name: o ? "on" : "off",
62
+ value: o,
63
+ enabled: o
64
+ };
65
+ let s = d(t, a, r);
66
+ return {
67
+ name: s.name,
68
+ value: s.value,
69
+ enabled: o && s.name !== a.offVariant
70
+ };
71
+ }, p = (e, t, n = Date.now()) => {
72
+ let r = {};
73
+ for (let [i, a] of Object.entries(e)) r[i] = c(i, a, t, n);
74
+ return r;
75
+ }, m = (e, t, n = Date.now()) => {
76
+ let r = {};
77
+ for (let [i, a] of Object.entries(e)) r[i] = f(i, a, t, n);
78
+ return r;
79
+ };
80
+ //#endregion
81
+ export { p as evaluateAll, m as evaluateAllVariants, c as evaluateFlag, s as evaluateSchedule, f as evaluateVariant, d as resolveVariant, e as toDefinition };
@@ -0,0 +1,48 @@
1
+ //#region src/experimentLink.ts
2
+ var e = (e, t) => {
3
+ let n = new Map(t.map((e) => [e.name, e])), r = [];
4
+ for (let t of e) {
5
+ let e = t.experiment;
6
+ if (e === void 0) continue;
7
+ let i = n.get(e);
8
+ if (i === void 0) {
9
+ r.push({
10
+ flag: t.key,
11
+ experiment: e,
12
+ problem: `no experiment named ${JSON.stringify(e)} was passed to flagsPlugin({ experiments }). Pass the defineExperiment() definitions the app declares, or drop the \`experiment\` link.`
13
+ });
14
+ continue;
15
+ }
16
+ (i.variantFrom === void 0 || i.variantFrom === null) && r.push({
17
+ flag: t.key,
18
+ experiment: e,
19
+ problem: `the experiment assigns its own arms (\`subject\` mode), so it would measure a split this flag never served — the two bucketings are independent hashes. Persist the served arm (\`flagVariant(ctx, ${JSON.stringify(t.key)})\`) on the watched table and declare the experiment with \`variantFrom: <that column>\`.`
20
+ }), typeof i.holdout == "number" && i.holdout > 0 && r.push({
21
+ flag: t.key,
22
+ experiment: e,
23
+ problem: `holdout ${i.holdout} is carved at ASSIGNMENT, and this flag does the assigning — the experiment can never place a row there. Declare the holdout as a flag variant instead.`
24
+ });
25
+ let a = new Set(t.variants.map((e) => e.name)), o = new Set(i.variants.map((e) => e.name));
26
+ if (a.size === 0) r.push({
27
+ flag: t.key,
28
+ experiment: e,
29
+ problem: "the flag declares no variants, so it serves one value to everyone and there is nothing to compare."
30
+ });
31
+ else {
32
+ let n = [...a].filter((e) => !o.has(e)), i = [...o].filter((e) => !a.has(e));
33
+ (n.length > 0 || i.length > 0) && r.push({
34
+ flag: t.key,
35
+ experiment: e,
36
+ problem: `the arms disagree — ${n.length > 0 ? `served by the flag but not declared by the experiment: ${n.join(", ")}` : ""}${n.length > 0 && i.length > 0 ? "; " : ""}${i.length > 0 ? `declared by the experiment but never served: ${i.join(", ")}` : ""}. A row assigned to an arm the experiment does not declare is EXCLUDED, so the mismatch shows up as an empty arm rather than an error.`
37
+ });
38
+ }
39
+ }
40
+ return r;
41
+ }, t = (t, n) => {
42
+ let r = e(t, n);
43
+ if (r.length === 0) return;
44
+ let i = r.map((e) => ` · flag "${e.flag}" → experiment "${e.experiment}": ${e.problem}`);
45
+ throw Error(`@voltro/plugin-flags: ${r.length} flag→experiment link problem(s):\n${i.join("\n")}`);
46
+ };
47
+ //#endregion
48
+ export { t as assertFlagExperimentLinks, e as checkFlagExperimentLinks };