@featurevisor/sdk 2.19.0 → 2.21.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.
- package/CHANGELOG.md +19 -0
- package/coverage/clover.xml +12 -11
- package/coverage/coverage-final.json +1 -1
- package/coverage/lcov-report/bucketer.ts.html +1 -1
- package/coverage/lcov-report/child.ts.html +1 -1
- package/coverage/lcov-report/conditions.ts.html +34 -13
- package/coverage/lcov-report/datafileReader.ts.html +1 -1
- package/coverage/lcov-report/emitter.ts.html +1 -1
- package/coverage/lcov-report/evaluate.ts.html +1 -1
- package/coverage/lcov-report/events.ts.html +1 -1
- package/coverage/lcov-report/helpers.ts.html +1 -1
- package/coverage/lcov-report/hooks.ts.html +1 -1
- package/coverage/lcov-report/index.html +14 -14
- package/coverage/lcov-report/instance.ts.html +1 -1
- package/coverage/lcov-report/logger.ts.html +1 -1
- package/coverage/lcov.info +18 -14
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.gz +0 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/conditions.ts +12 -5
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
<div class='clearfix'>
|
|
24
24
|
|
|
25
25
|
<div class='fl pad1y space-right2'>
|
|
26
|
-
<span class="strong">98.
|
|
26
|
+
<span class="strong">98.64% </span>
|
|
27
27
|
<span class="quiet">Statements</span>
|
|
28
|
-
<span class='fraction'>
|
|
28
|
+
<span class='fraction'>73/74</span>
|
|
29
29
|
</div>
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
<div class='fl pad1y space-right2'>
|
|
33
|
-
<span class="strong">
|
|
33
|
+
<span class="strong">92.5% </span>
|
|
34
34
|
<span class="quiet">Branches</span>
|
|
35
|
-
<span class='fraction'>74/
|
|
35
|
+
<span class='fraction'>74/80</span>
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
38
|
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
<div class='fl pad1y space-right2'>
|
|
47
|
-
<span class="strong">98.
|
|
47
|
+
<span class="strong">98.63% </span>
|
|
48
48
|
<span class="quiet">Lines</span>
|
|
49
|
-
<span class='fraction'>
|
|
49
|
+
<span class='fraction'>72/73</span>
|
|
50
50
|
</div>
|
|
51
51
|
|
|
52
52
|
|
|
@@ -173,7 +173,14 @@
|
|
|
173
173
|
<a name='L108'></a><a href='#L108'>108</a>
|
|
174
174
|
<a name='L109'></a><a href='#L109'>109</a>
|
|
175
175
|
<a name='L110'></a><a href='#L110'>110</a>
|
|
176
|
-
<a name='L111'></a><a href='#L111'>111</a
|
|
176
|
+
<a name='L111'></a><a href='#L111'>111</a>
|
|
177
|
+
<a name='L112'></a><a href='#L112'>112</a>
|
|
178
|
+
<a name='L113'></a><a href='#L113'>113</a>
|
|
179
|
+
<a name='L114'></a><a href='#L114'>114</a>
|
|
180
|
+
<a name='L115'></a><a href='#L115'>115</a>
|
|
181
|
+
<a name='L116'></a><a href='#L116'>116</a>
|
|
182
|
+
<a name='L117'></a><a href='#L117'>117</a>
|
|
183
|
+
<a name='L118'></a><a href='#L118'>118</a></td><td class="line-coverage quiet"><span class="cline-any cline-neutral"> </span>
|
|
177
184
|
<span class="cline-any cline-neutral"> </span>
|
|
178
185
|
<span class="cline-any cline-neutral"> </span>
|
|
179
186
|
<span class="cline-any cline-yes">6x</span>
|
|
@@ -272,6 +279,13 @@
|
|
|
272
279
|
<span class="cline-any cline-yes">6x</span>
|
|
273
280
|
<span class="cline-any cline-yes">6x</span>
|
|
274
281
|
<span class="cline-any cline-neutral"> </span>
|
|
282
|
+
<span class="cline-any cline-neutral"> </span>
|
|
283
|
+
<span class="cline-any cline-neutral"> </span>
|
|
284
|
+
<span class="cline-any cline-neutral"> </span>
|
|
285
|
+
<span class="cline-any cline-neutral"> </span>
|
|
286
|
+
<span class="cline-any cline-neutral"> </span>
|
|
287
|
+
<span class="cline-any cline-neutral"> </span>
|
|
288
|
+
<span class="cline-any cline-yes">4x</span>
|
|
275
289
|
<span class="cline-any cline-yes">4x</span>
|
|
276
290
|
<span class="cline-any cline-neutral"> </span>
|
|
277
291
|
<span class="cline-any cline-yes">4x</span>
|
|
@@ -380,14 +394,21 @@ export function conditionIsMatched(
|
|
|
380
394
|
return typeof contextValueFromPath !== "undefined";
|
|
381
395
|
} else if (operator === "notExists") {
|
|
382
396
|
return typeof contextValueFromPath === "undefined";
|
|
383
|
-
} else if (
|
|
384
|
-
|
|
385
|
-
|
|
397
|
+
} else if (
|
|
398
|
+
Array.isArray(contextValueFromPath) &&
|
|
399
|
+
(typeof value === "string" ||
|
|
400
|
+
<span class="branch-2 cbranch-no" title="branch not covered" > typeof value === "number" </span>||
|
|
401
|
+
<span class="branch-3 cbranch-no" title="branch not covered" > typeof value === "boolean" </span>||
|
|
402
|
+
<span class="branch-4 cbranch-no" title="branch not covered" > value === null)</span>
|
|
403
|
+
) {
|
|
404
|
+
// includes / notIncludes (where context value is an array of primitive values)
|
|
405
|
+
const valueInContext = contextValueFromPath as Array<string | number | boolean | null>;
|
|
406
|
+
const primitiveValue = value as string | number | boolean | null;
|
|
386
407
|
|
|
387
408
|
if (operator === "includes") {
|
|
388
|
-
return valueInContext.indexOf(
|
|
409
|
+
return valueInContext.indexOf(primitiveValue) > -1;
|
|
389
410
|
} else if (operator === "notIncludes") {
|
|
390
|
-
return valueInContext.indexOf(
|
|
411
|
+
return valueInContext.indexOf(primitiveValue) === -1;
|
|
391
412
|
}
|
|
392
413
|
}
|
|
393
414
|
|
|
@@ -400,7 +421,7 @@ export function conditionIsMatched(
|
|
|
400
421
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
401
422
|
Code coverage generated by
|
|
402
423
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
403
|
-
at 2026-03-
|
|
424
|
+
at 2026-03-29T22:16:29.925Z
|
|
404
425
|
</div>
|
|
405
426
|
<script src="prettify.js"></script>
|
|
406
427
|
<script>
|
|
@@ -1048,7 +1048,7 @@ export class DatafileReader {
|
|
|
1048
1048
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
1049
1049
|
Code coverage generated by
|
|
1050
1050
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
1051
|
-
at 2026-03-
|
|
1051
|
+
at 2026-03-29T22:16:29.925Z
|
|
1052
1052
|
</div>
|
|
1053
1053
|
<script src="prettify.js"></script>
|
|
1054
1054
|
<script>
|
|
@@ -247,7 +247,7 @@ export class Emitter {
|
|
|
247
247
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
248
248
|
Code coverage generated by
|
|
249
249
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
250
|
-
at 2026-03-
|
|
250
|
+
at 2026-03-29T22:16:29.925Z
|
|
251
251
|
</div>
|
|
252
252
|
<script src="prettify.js"></script>
|
|
253
253
|
<script>
|
|
@@ -2842,7 +2842,7 @@ export function evaluate(options: EvaluateOptions): Evaluation {
|
|
|
2842
2842
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
2843
2843
|
Code coverage generated by
|
|
2844
2844
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
2845
|
-
at 2026-03-
|
|
2845
|
+
at 2026-03-29T22:16:29.925Z
|
|
2846
2846
|
</div>
|
|
2847
2847
|
<script src="prettify.js"></script>
|
|
2848
2848
|
<script>
|
|
@@ -319,7 +319,7 @@ export function getParamsForDatafileSetEvent(
|
|
|
319
319
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
320
320
|
Code coverage generated by
|
|
321
321
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
322
|
-
at 2026-03-
|
|
322
|
+
at 2026-03-29T22:16:29.925Z
|
|
323
323
|
</div>
|
|
324
324
|
<script src="prettify.js"></script>
|
|
325
325
|
<script>
|
|
@@ -154,7 +154,7 @@ export function getValueByType(value: ValueType, fieldType: FieldType): ValueTyp
|
|
|
154
154
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
155
155
|
Code coverage generated by
|
|
156
156
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
157
|
-
at 2026-03-
|
|
157
|
+
at 2026-03-29T22:16:29.925Z
|
|
158
158
|
</div>
|
|
159
159
|
<script src="prettify.js"></script>
|
|
160
160
|
<script>
|
|
@@ -337,7 +337,7 @@ export class HooksManager {
|
|
|
337
337
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
338
338
|
Code coverage generated by
|
|
339
339
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
340
|
-
at 2026-03-
|
|
340
|
+
at 2026-03-29T22:16:29.925Z
|
|
341
341
|
</div>
|
|
342
342
|
<script src="prettify.js"></script>
|
|
343
343
|
<script>
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
<div class='clearfix'>
|
|
24
24
|
|
|
25
25
|
<div class='fl pad1y space-right2'>
|
|
26
|
-
<span class="strong">91.
|
|
26
|
+
<span class="strong">91.41% </span>
|
|
27
27
|
<span class="quiet">Statements</span>
|
|
28
|
-
<span class='fraction'>
|
|
28
|
+
<span class='fraction'>660/722</span>
|
|
29
29
|
</div>
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
<div class='fl pad1y space-right2'>
|
|
33
|
-
<span class="strong">
|
|
33
|
+
<span class="strong">84.84% </span>
|
|
34
34
|
<span class="quiet">Branches</span>
|
|
35
|
-
<span class='fraction'>403/
|
|
35
|
+
<span class='fraction'>403/475</span>
|
|
36
36
|
</div>
|
|
37
37
|
|
|
38
38
|
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
<div class='fl pad1y space-right2'>
|
|
47
|
-
<span class="strong">91.
|
|
47
|
+
<span class="strong">91.54% </span>
|
|
48
48
|
<span class="quiet">Lines</span>
|
|
49
|
-
<span class='fraction'>
|
|
49
|
+
<span class='fraction'>650/710</span>
|
|
50
50
|
</div>
|
|
51
51
|
|
|
52
52
|
|
|
@@ -110,17 +110,17 @@
|
|
|
110
110
|
|
|
111
111
|
<tr>
|
|
112
112
|
<td class="file high" data-value="conditions.ts"><a href="conditions.ts.html">conditions.ts</a></td>
|
|
113
|
-
<td data-value="98.
|
|
113
|
+
<td data-value="98.64" class="pic high">
|
|
114
114
|
<div class="chart"><div class="cover-fill" style="width: 98%"></div><div class="cover-empty" style="width: 2%"></div></div>
|
|
115
115
|
</td>
|
|
116
|
-
<td data-value="98.
|
|
117
|
-
<td data-value="
|
|
118
|
-
<td data-value="
|
|
119
|
-
<td data-value="
|
|
116
|
+
<td data-value="98.64" class="pct high">98.64%</td>
|
|
117
|
+
<td data-value="74" class="abs high">73/74</td>
|
|
118
|
+
<td data-value="92.5" class="pct high">92.5%</td>
|
|
119
|
+
<td data-value="80" class="abs high">74/80</td>
|
|
120
120
|
<td data-value="100" class="pct high">100%</td>
|
|
121
121
|
<td data-value="3" class="abs high">3/3</td>
|
|
122
|
-
<td data-value="98.
|
|
123
|
-
<td data-value="
|
|
122
|
+
<td data-value="98.63" class="pct high">98.63%</td>
|
|
123
|
+
<td data-value="73" class="abs high">72/73</td>
|
|
124
124
|
</tr>
|
|
125
125
|
|
|
126
126
|
<tr>
|
|
@@ -251,7 +251,7 @@
|
|
|
251
251
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
252
252
|
Code coverage generated by
|
|
253
253
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
254
|
-
at 2026-03-
|
|
254
|
+
at 2026-03-29T22:16:29.925Z
|
|
255
255
|
</div>
|
|
256
256
|
<script src="prettify.js"></script>
|
|
257
257
|
<script>
|
|
@@ -1402,7 +1402,7 @@ export function createInstance(options: InstanceOptions = <span class="branch-0
|
|
|
1402
1402
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
1403
1403
|
Code coverage generated by
|
|
1404
1404
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
1405
|
-
at 2026-03-
|
|
1405
|
+
at 2026-03-29T22:16:29.925Z
|
|
1406
1406
|
</div>
|
|
1407
1407
|
<script src="prettify.js"></script>
|
|
1408
1408
|
<script>
|
|
@@ -340,7 +340,7 @@ export function createLogger(options: CreateLoggerOptions = {}): Logger {
|
|
|
340
340
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
341
341
|
Code coverage generated by
|
|
342
342
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
343
|
-
at 2026-03-
|
|
343
|
+
at 2026-03-29T22:16:29.925Z
|
|
344
344
|
</div>
|
|
345
345
|
<script src="prettify.js"></script>
|
|
346
346
|
<script>
|
package/coverage/lcov.info
CHANGED
|
@@ -249,14 +249,15 @@ DA:95,6
|
|
|
249
249
|
DA:96,12
|
|
250
250
|
DA:97,6
|
|
251
251
|
DA:98,6
|
|
252
|
-
DA:
|
|
253
|
-
DA:
|
|
254
|
-
DA:
|
|
255
|
-
DA:
|
|
256
|
-
DA:
|
|
257
|
-
DA:
|
|
258
|
-
|
|
259
|
-
|
|
252
|
+
DA:106,4
|
|
253
|
+
DA:107,4
|
|
254
|
+
DA:109,4
|
|
255
|
+
DA:110,2
|
|
256
|
+
DA:111,2
|
|
257
|
+
DA:112,2
|
|
258
|
+
DA:116,2
|
|
259
|
+
LF:73
|
|
260
|
+
LH:72
|
|
260
261
|
BRDA:7,0,0,992
|
|
261
262
|
BRDA:11,1,0,22
|
|
262
263
|
BRDA:11,1,1,2
|
|
@@ -329,12 +330,15 @@ BRDA:94,35,1,12
|
|
|
329
330
|
BRDA:96,36,0,6
|
|
330
331
|
BRDA:96,36,1,6
|
|
331
332
|
BRDA:98,37,0,4
|
|
332
|
-
BRDA:
|
|
333
|
-
BRDA:
|
|
334
|
-
BRDA:
|
|
335
|
-
BRDA:
|
|
336
|
-
BRDA:
|
|
337
|
-
|
|
333
|
+
BRDA:99,38,0,6
|
|
334
|
+
BRDA:99,38,1,4
|
|
335
|
+
BRDA:99,38,2,0
|
|
336
|
+
BRDA:99,38,3,0
|
|
337
|
+
BRDA:99,38,4,0
|
|
338
|
+
BRDA:109,39,0,2
|
|
339
|
+
BRDA:109,39,1,2
|
|
340
|
+
BRDA:111,40,0,2
|
|
341
|
+
BRF:80
|
|
338
342
|
BRH:74
|
|
339
343
|
end_of_record
|
|
340
344
|
TN:
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.FeaturevisorSDK=t():e.FeaturevisorSDK=t()}(this,(()=>(()=>{"use strict";var e={481(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.MAX_BUCKETED_NUMBER=void 0,t.getBucketedNumber=function(e){var r=(0,i.MurmurHashV3)(e,1)/n;return Math.floor(r*t.MAX_BUCKETED_NUMBER)},t.getBucketKey=function(e){var t,r,i=e.featureKey,n=e.bucketBy,o=e.context,s=e.logger;if("string"==typeof n)t="plain",r=[n];else if(Array.isArray(n))t="and",r=n;else{if("object"!=typeof n||!Array.isArray(n.or))throw s.error("invalid bucketBy",{featureKey:i,bucketBy:n}),new Error("invalid bucketBy");t="or",r=n.or}var u=[];return r.forEach((function(e){var r=(0,a.getValueFromContext)(o,e);void 0!==r&&("plain"===t||"and"===t||0===u.length)&&u.push(r)})),u.push(i),u.join(".")};var a=r(186),i=r(400),n=Math.pow(2,32);t.MAX_BUCKETED_NUMBER=1e5},608(e,t,r){var a=this&&this.__assign||function(){return a=Object.assign||function(e){for(var t,r=1,a=arguments.length;r<a;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},a.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.FeaturevisorChildInstance=void 0;var i=r(40),n=r(985),o=function(){function e(e){this.parent=e.parent,this.context=e.context,this.sticky=e.sticky||{},this.emitter=new i.Emitter}return e.prototype.on=function(e,t){return"context_set"===e||"sticky_set"===e?this.emitter.on(e,t):this.parent.on(e,t)},e.prototype.close=function(){this.emitter.clearAll()},e.prototype.setContext=function(e,t){void 0===t&&(t=!1),this.context=t?e:a(a({},this.context),e),this.emitter.trigger("context_set",{context:this.context,replaced:t})},e.prototype.getContext=function(e){return this.parent.getContext(a(a({},this.context),e))},e.prototype.setSticky=function(e,t){void 0===t&&(t=!1);var r=this.sticky||{};this.sticky=a(t?{}:a({},this.sticky),e);var i=(0,n.getParamsForStickySetEvent)(r,this.sticky,t);this.emitter.trigger("sticky_set",i)},e.prototype.isEnabled=function(e,t,r){return void 0===t&&(t={}),void 0===r&&(r={}),this.parent.isEnabled(e,a(a({},this.context),t),a({sticky:this.sticky},r))},e.prototype.getVariation=function(e,t,r){return void 0===t&&(t={}),void 0===r&&(r={}),this.parent.getVariation(e,a(a({},this.context),t),a({sticky:this.sticky},r))},e.prototype.getVariable=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariable(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableBoolean=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableBoolean(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableString=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableString(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableInteger=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableInteger(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableDouble=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableDouble(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableArray=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableArray(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableObject=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableObject(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableJSON=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableJSON(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getAllEvaluations=function(e,t,r){return void 0===e&&(e={}),void 0===t&&(t=[]),void 0===r&&(r={}),this.parent.getAllEvaluations(a(a({},this.context),e),t,a({sticky:this.sticky},r))},e}();t.FeaturevisorChildInstance=o},108(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.compareVersions=t.compareSegments=t.validateAndParse=t.semver=void 0,t.semver=/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,t.validateAndParse=function(e){if("string"!=typeof e)throw new TypeError("Invalid argument expected string");var r=e.match(t.semver);if(!r)throw new Error("Invalid argument not valid semver ('".concat(e,"' received)"));return r.shift(),r};var r=function(e){return"*"===e||"x"===e||"X"===e},a=function(e){var t=parseInt(e,10);return isNaN(t)?e:t},i=function(e,t){if(r(e)||r(t))return 0;var i=function(e,t){return typeof e!=typeof t?[String(e),String(t)]:[e,t]}(a(e),a(t)),n=i[0],o=i[1];return n>o?1:n<o?-1:0};t.compareSegments=function(e,t){for(var r=0;r<Math.max(e.length,t.length);r++){var a=i(e[r]||"0",t[r]||"0");if(0!==a)return a}return 0},t.compareVersions=function(e,r){var a=(0,t.validateAndParse)(e),i=(0,t.validateAndParse)(r),n=a.pop(),o=i.pop(),s=(0,t.compareSegments)(a,i);return 0!==s?s:n&&o?(0,t.compareSegments)(n.split("."),o.split(".")):n||o?n?-1:1:0}},186(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.getValueFromContext=i,t.conditionIsMatched=function(e,t,r){var n=e.attribute,o=e.operator,s=e.value,u=e.regexFlags,l=i(t,n);if("equals"===o)return l===s;if("notEquals"===o)return l!==s;if("before"===o||"after"===o){var c=(d=l)instanceof Date?d:new Date(d),f=s instanceof Date?s:new Date(s);return"before"===o?c<f:c>f}if(!Array.isArray(s)||-1===["string","number"].indexOf(typeof l)&&null!==l)if("string"==typeof l&&"string"==typeof s){if(d=l,"contains"===o)return-1!==d.indexOf(s);if("notContains"===o)return-1===d.indexOf(s);if("startsWith"===o)return d.startsWith(s);if("endsWith"===o)return d.endsWith(s);if("semverEquals"===o)return 0===(0,a.compareVersions)(d,s);if("semverNotEquals"===o)return 0!==(0,a.compareVersions)(d,s);if("semverGreaterThan"===o)return 1===(0,a.compareVersions)(d,s);if("semverGreaterThanOrEquals"===o)return(0,a.compareVersions)(d,s)>=0;if("semverLessThan"===o)return-1===(0,a.compareVersions)(d,s);if("semverLessThanOrEquals"===o)return(0,a.compareVersions)(d,s)<=0;if("matches"===o)return r(s,u||"").test(d);if("notMatches"===o)return!r(s,u||"").test(d)}else if("number"==typeof l&&"number"==typeof s){if(d=l,"greaterThan"===o)return d>s;if("greaterThanOrEquals"===o)return d>=s;if("lessThan"===o)return d<s;if("lessThanOrEquals"===o)return d<=s}else{if("exists"===o)return void 0!==l;if("notExists"===o)return void 0===l;if(Array.isArray(l)&&"string"==typeof s){if(d=l,"includes"===o)return d.indexOf(s)>-1;if("notIncludes"===o)return-1===d.indexOf(s)}}else{var d=l;if("in"===o)return-1!==s.indexOf(d);if("notIn"===o)return-1===s.indexOf(d)}return!1};var a=r(108);function i(e,t){return-1===t.indexOf(".")?e[t]:t.split(".").reduce((function(e,t){return e?e[t]:void 0}),e)}},649(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.DatafileReader=void 0;var a=r(186),i=function(){function e(e){var t=e.datafile,r=e.logger;this.logger=r,this.schemaVersion=t.schemaVersion,this.revision=t.revision,this.segments=t.segments,this.features=t.features,this.regexCache={}}return e.prototype.getRevision=function(){return this.revision},e.prototype.getSchemaVersion=function(){return this.schemaVersion},e.prototype.getSegment=function(e){var t=this.segments[e];if(t)return t.conditions=this.parseConditionsIfStringified(t.conditions),t},e.prototype.getFeatureKeys=function(){return Object.keys(this.features)},e.prototype.getFeature=function(e){return this.features[e]},e.prototype.getVariableKeys=function(e){var t=this.getFeature(e);return t?Object.keys(t.variablesSchema||{}):[]},e.prototype.hasVariations=function(e){var t=this.getFeature(e);return!!t&&Array.isArray(t.variations)&&t.variations.length>0},e.prototype.getRegex=function(e,t){var r=t||"",a="".concat(e,"-").concat(r);if(this.regexCache[a])return this.regexCache[a];var i=new RegExp(e,r);return this.regexCache[a]=i,i},e.prototype.allConditionsAreMatched=function(e,t){var r=this;if("string"==typeof e)return"*"===e;if("attribute"in e)try{return(0,a.conditionIsMatched)(e,t,(function(e,t){return r.getRegex(e,t)}))}catch(r){return this.logger.warn(r.message,{error:r,details:{condition:e,context:t}}),!1}return"and"in e&&Array.isArray(e.and)?e.and.every((function(e){return r.allConditionsAreMatched(e,t)})):"or"in e&&Array.isArray(e.or)?e.or.some((function(e){return r.allConditionsAreMatched(e,t)})):"not"in e&&Array.isArray(e.not)?e.not.every((function(){return!1===r.allConditionsAreMatched({and:e.not},t)})):!!Array.isArray(e)&&e.every((function(e){return r.allConditionsAreMatched(e,t)}))},e.prototype.segmentIsMatched=function(e,t){return this.allConditionsAreMatched(e.conditions,t)},e.prototype.allSegmentsAreMatched=function(e,t){var r=this;if("*"===e)return!0;if("string"==typeof e){var a=this.getSegment(e);return!!a&&this.segmentIsMatched(a,t)}if("object"==typeof e){if("and"in e&&Array.isArray(e.and))return e.and.every((function(e){return r.allSegmentsAreMatched(e,t)}));if("or"in e&&Array.isArray(e.or))return e.or.some((function(e){return r.allSegmentsAreMatched(e,t)}));if("not"in e&&Array.isArray(e.not))return e.not.every((function(e){return!1===r.allSegmentsAreMatched(e,t)}))}return!!Array.isArray(e)&&e.every((function(e){return r.allSegmentsAreMatched(e,t)}))},e.prototype.getMatchedTraffic=function(e,t){var r=this;return e.find((function(e){return!!r.allSegmentsAreMatched(r.parseSegmentsIfStringified(e.segments),t)}))},e.prototype.getMatchedAllocation=function(e,t){if(e.allocation)for(var r=0,a=e.allocation;r<a.length;r++){var i=a[r],n=i.range,o=n[0],s=n[1];if(i.range&&o<=t&&s>=t)return i}},e.prototype.getMatchedForce=function(e,t){var r={force:void 0,forceIndex:void 0},a="string"==typeof e?this.getFeature(e):e;if(!a||!a.force)return r;for(var i=0;i<a.force.length;i++){var n=a.force[i];if(n.conditions&&this.allConditionsAreMatched(this.parseConditionsIfStringified(n.conditions),t)){r.force=n,r.forceIndex=i;break}if(n.segments&&this.allSegmentsAreMatched(this.parseSegmentsIfStringified(n.segments),t)){r.force=n,r.forceIndex=i;break}}return r},e.prototype.parseConditionsIfStringified=function(e){if("string"!=typeof e)return e;if("*"===e)return e;try{return JSON.parse(e)}catch(t){return this.logger.error("Error parsing conditions",{error:t,details:{conditions:e}}),e}},e.prototype.parseSegmentsIfStringified=function(e){return"string"==typeof e&&(e.startsWith("{")||e.startsWith("["))?JSON.parse(e):e},e}();t.DatafileReader=i},40(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.Emitter=void 0;var r=function(){function e(){this.listeners={}}return e.prototype.on=function(e,t){this.listeners[e]||(this.listeners[e]=[]);var r=this.listeners[e];r.push(t);var a=!0;return function(){if(a){a=!1;var e=r.indexOf(t);-1!==e&&r.splice(e,1)}}},e.prototype.trigger=function(e,t){void 0===t&&(t={});var r=this.listeners[e];r&&r.forEach((function(e){try{e(t)}catch(e){console.error(e)}}))},e.prototype.clearAll=function(){this.listeners={}},e}();t.Emitter=r},335(e,t,r){var a=this&&this.__assign||function(){return a=Object.assign||function(e){for(var t,r=1,a=arguments.length;r<a;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},a.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.EvaluationReason=void 0,t.evaluateWithHooks=function(e){try{for(var t=e.hooksManager,r=t.getAll(),a=e,n=0,s=t.getAll();n<s.length;n++)(f=s[n]).before&&(a=f.before(a));var u=o(a);void 0!==a.defaultVariationValue&&"variation"===u.type&&void 0===u.variationValue&&(u.variationValue=a.defaultVariationValue),void 0!==a.defaultVariableValue&&"variable"===u.type&&void 0===u.variableValue&&(u.variableValue=a.defaultVariableValue);for(var l=0,c=r;l<c.length;l++){var f;(f=c[l]).after&&(u=f.after(u,a))}return u}catch(t){var d=e.type,v=e.featureKey,y=e.variableKey,g=e.logger;return u={type:d,featureKey:v,variableKey:y,reason:i.ERROR,error:t},g.error("error during evaluation",u),u}},t.evaluate=o;var i,n=r(481);function o(e){var t,r=e.type,s=e.featureKey,u=e.variableKey,l=e.context,c=e.logger,f=e.datafileReader,d=e.sticky,v=e.hooksManager.getAll();try{if("flag"!==r&&!1===o(a(a({},e),{type:"flag"})).enabled){t={type:r,featureKey:s,reason:i.DISABLED};var y=f.getFeature(s);if("variable"===r&&y&&u&&y.variablesSchema&&y.variablesSchema[u]){var g=y.variablesSchema[u];void 0!==g.disabledValue?t={type:r,featureKey:s,reason:i.VARIABLE_DISABLED,variableKey:u,variableValue:g.disabledValue,variableSchema:g,enabled:!1}:g.useDefaultWhenDisabled&&(t={type:r,featureKey:s,reason:i.VARIABLE_DEFAULT,variableKey:u,variableValue:g.defaultValue,variableSchema:g,enabled:!1})}return"variation"===r&&y&&y.disabledVariationValue&&(t={type:r,featureKey:s,reason:i.VARIATION_DISABLED,variationValue:y.disabledVariationValue,enabled:!1}),c.debug("feature is disabled",t),t}if(d&&d[s]){if("flag"===r&&void 0!==d[s].enabled)return t={type:r,featureKey:s,reason:i.STICKY,sticky:d[s],enabled:d[s].enabled},c.debug("using sticky enabled",t),t;if("variation"===r){var h=d[s].variation;if(void 0!==h)return t={type:r,featureKey:s,reason:i.STICKY,variationValue:h},c.debug("using sticky variation",t),t}if(u){var p=d[s].variables;if(p){var b=p[u];if(void 0!==b)return t={type:r,featureKey:s,reason:i.STICKY,variableKey:u,variableValue:b},c.debug("using sticky variable",t),t}}}var V="string"==typeof s?f.getFeature(s):s;if(!V)return t={type:r,featureKey:s,reason:i.FEATURE_NOT_FOUND},c.warn("feature not found",t),t;"flag"===r&&V.deprecated&&c.warn("feature is deprecated",{featureKey:s});var k=void 0;if(u){if(V.variablesSchema&&V.variablesSchema[u]&&(k=V.variablesSchema[u]),!k)return t={type:r,featureKey:s,reason:i.VARIABLE_NOT_FOUND,variableKey:u},c.warn("variable schema not found",t),t;k.deprecated&&c.warn("variable is deprecated",{featureKey:s,variableKey:u})}if("variation"===r&&(!V.variations||0===V.variations.length))return t={type:r,featureKey:s,reason:i.NO_VARIATIONS},c.warn("no variations",t),t;var m=f.getMatchedForce(V,l),A=m.force,K=m.forceIndex;if(A){if("flag"===r&&void 0!==A.enabled)return t={type:r,featureKey:s,reason:i.FORCED,forceIndex:K,force:A,enabled:A.enabled},c.debug("forced enabled found",t),t;if("variation"===r&&A.variation&&V.variations&&(B=V.variations.find((function(e){return e.value===A.variation}))))return t={type:r,featureKey:s,reason:i.FORCED,forceIndex:K,force:A,variation:B},c.debug("forced variation found",t),t;if(u&&A.variables&&void 0!==A.variables[u])return t={type:r,featureKey:s,reason:i.FORCED,forceIndex:K,force:A,variableKey:u,variableSchema:k,variableValue:A.variables[u]},c.debug("forced variable",t),t}if("flag"===r&&V.required&&V.required.length>0){var O=V.required.every((function(t){var r,i;if("string"==typeof t?r=t:(r=t.key,i=t.variation),!o(a(a({},e),{type:"flag",featureKey:r})).enabled)return!1;if(void 0!==i){var n=o(a(a({},e),{type:"variation",featureKey:r})),s=void 0;return n.variationValue?s=n.variationValue:n.variation&&(s=n.variation.value),s===i}return!0}));if(!O)return t={type:r,featureKey:s,reason:i.REQUIRED,required:V.required,enabled:O},c.debug("required features not enabled",t),t}for(var x=(0,n.getBucketKey)({featureKey:s,bucketBy:V.bucketBy,context:l,logger:c}),E=0,_=v;E<_.length;E++)(L=_[E]).bucketKey&&(x=L.bucketKey({featureKey:s,context:l,bucketBy:V.bucketBy,bucketKey:x}));for(var S,R,I=(0,n.getBucketedNumber)(x),M=0,D=v;M<D.length;M++){var L;(L=D[M]).bucketValue&&(I=L.bucketValue({featureKey:s,bucketKey:x,context:l,bucketValue:I}))}if("flag"!==r?(S=f.getMatchedTraffic(V.traffic,l))&&(R=f.getMatchedAllocation(S,I)):S=f.getMatchedTraffic(V.traffic,l),S){if(0===S.percentage)return t={type:r,featureKey:s,reason:i.RULE,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,enabled:!1},c.debug("matched rule with 0 percentage",t),t;if("flag"===r){if(V.ranges&&V.ranges.length>0)return V.ranges.find((function(e){return I>=e[0]&&I<e[1]}))?(t={type:r,featureKey:s,reason:i.ALLOCATED,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,enabled:void 0===S.enabled||S.enabled},c.debug("matched",t),t):(t={type:r,featureKey:s,reason:i.OUT_OF_RANGE,bucketKey:x,bucketValue:I,enabled:!1},c.debug("not matched",t),t);if(void 0!==S.enabled)return t={type:r,featureKey:s,reason:i.RULE,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,enabled:S.enabled},c.debug("override from rule",t),t;if(I<=S.percentage)return t={type:r,featureKey:s,reason:i.RULE,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,enabled:!0},c.debug("matched traffic",t),t}if("variation"===r&&V.variations){if(S.variation&&(B=V.variations.find((function(e){return e.value===S.variation}))))return t={type:r,featureKey:s,reason:i.RULE,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,variation:B},c.debug("override from rule",t),t;if(R&&R.variation&&(B=V.variations.find((function(e){return e.value===R.variation}))))return t={type:r,featureKey:s,reason:i.ALLOCATED,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,variation:B},c.debug("allocated variation",t),t}}if("variable"===r&&u){if(S){if(S.variableOverrides&&S.variableOverrides[u]&&-1!==(w=(C=S.variableOverrides[u]).findIndex((function(e){return e.conditions?f.allConditionsAreMatched("string"==typeof e.conditions&&"*"!==e.conditions?JSON.parse(e.conditions):e.conditions,l):!!e.segments&&f.allSegmentsAreMatched(f.parseSegmentsIfStringified(e.segments),l)})))){var T=C[w];return t={type:r,featureKey:s,reason:i.VARIABLE_OVERRIDE_RULE,bucketKey:x,bucketValue:I,ruleKey:null==S?void 0:S.key,traffic:S,variableKey:u,variableSchema:k,variableValue:T.value,variableOverrideIndex:w},c.debug("variable override from rule",t),t}if(S.variables&&void 0!==S.variables[u])return t={type:r,featureKey:s,reason:i.RULE,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,variableKey:u,variableSchema:k,variableValue:S.variables[u]},c.debug("override from rule",t),t}var F;if(A&&A.variation?F=A.variation:S&&S.variation?F=S.variation:R&&R.variation&&(F=R.variation),F&&Array.isArray(V.variations)){var B,C,w;if((B=V.variations.find((function(e){return e.value===F})))&&B.variableOverrides&&B.variableOverrides[u]&&-1!==(w=(C=B.variableOverrides[u]).findIndex((function(e){return e.conditions?f.allConditionsAreMatched("string"==typeof e.conditions&&"*"!==e.conditions?JSON.parse(e.conditions):e.conditions,l):!!e.segments&&f.allSegmentsAreMatched(f.parseSegmentsIfStringified(e.segments),l)}))))return T=C[w],t={type:r,featureKey:s,reason:i.VARIABLE_OVERRIDE_VARIATION,bucketKey:x,bucketValue:I,ruleKey:null==S?void 0:S.key,traffic:S,variableKey:u,variableSchema:k,variableValue:T.value,variableOverrideIndex:w},c.debug("variable override from variation",t),t;if(B&&B.variables&&void 0!==B.variables[u])return t={type:r,featureKey:s,reason:i.ALLOCATED,bucketKey:x,bucketValue:I,ruleKey:null==S?void 0:S.key,traffic:S,variableKey:u,variableSchema:k,variableValue:B.variables[u]},c.debug("allocated variable",t),t}}return"variation"===r?(t={type:r,featureKey:s,reason:i.NO_MATCH,bucketKey:x,bucketValue:I},c.debug("no matched variation",t),t):"variable"===r?k?(t={type:r,featureKey:s,reason:i.VARIABLE_DEFAULT,bucketKey:x,bucketValue:I,variableKey:u,variableSchema:k,variableValue:k.defaultValue},c.debug("using default value",t),t):(t={type:r,featureKey:s,reason:i.VARIABLE_NOT_FOUND,variableKey:u,bucketKey:x,bucketValue:I},c.debug("variable not found",t),t):(t={type:r,featureKey:s,reason:i.NO_MATCH,bucketKey:x,bucketValue:I,enabled:!1},c.debug("nothing matched",t),t)}catch(e){return t={type:r,featureKey:s,variableKey:u,reason:i.ERROR,error:e},c.error("error",t),t}}!function(e){e.FEATURE_NOT_FOUND="feature_not_found",e.DISABLED="disabled",e.REQUIRED="required",e.OUT_OF_RANGE="out_of_range",e.NO_VARIATIONS="no_variations",e.VARIATION_DISABLED="variation_disabled",e.VARIABLE_NOT_FOUND="variable_not_found",e.VARIABLE_DEFAULT="variable_default",e.VARIABLE_DISABLED="variable_disabled",e.VARIABLE_OVERRIDE_VARIATION="variable_override_variation",e.VARIABLE_OVERRIDE_RULE="variable_override_rule",e.NO_MATCH="no_match",e.FORCED="forced",e.STICKY="sticky",e.RULE="rule",e.ALLOCATED="allocated",e.ERROR="error"}(i||(t.EvaluationReason=i={}))},985(e,t){var r=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var a,i=0,n=t.length;i<n;i++)!a&&i in t||(a||(a=Array.prototype.slice.call(t,0,i)),a[i]=t[i]);return e.concat(a||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.getParamsForStickySetEvent=function(e,t,a){void 0===e&&(e={}),void 0===t&&(t={});var i=Object.keys(e),n=Object.keys(t),o=r(r([],i,!0),n,!0);return{features:o.filter((function(e,t){return o.indexOf(e)===t})),replaced:a}},t.getParamsForDatafileSetEvent=function(e,t){for(var a=e.getRevision(),i=e.getFeatureKeys(),n=t.getRevision(),o=t.getFeatureKeys(),s=[],u=[],l=[],c=0,f=i;c<f.length;c++){var d=f[c];if(-1!==o.indexOf(d)){var v=e.getFeature(d),y=t.getFeature(d);(null==v?void 0:v.hash)!==(null==y?void 0:y.hash)&&u.push(d)}else s.push(d)}for(var g=0,h=o;g<h.length;g++){var p=h[g];-1===i.indexOf(p)&&l.push(p)}return{revision:n,previousRevision:a,revisionChanged:a!==n,features:r(r(r([],s,!0),u,!0),l,!0).filter((function(e,t,r){return r.indexOf(e)===t}))}}},943(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.getValueByType=function(e,t){if(void 0===e)return null;switch(t){case"string":return"string"==typeof e?e:null;case"integer":return parseInt(e,10);case"double":return parseFloat(e);case"boolean":return!0===e;case"array":return Array.isArray(e)?e:null;case"object":return"object"==typeof e?e:null;default:return e}}},438(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.HooksManager=void 0;var r=function(){function e(e){var t=this;this.hooks=[],this.logger=e.logger,e.hooks&&e.hooks.forEach((function(e){t.add(e)}))}return e.prototype.add=function(e){var t=this;if(!this.hooks.some((function(t){return t.name===e.name})))return this.hooks.push(e),function(){t.remove(e.name)};this.logger.error('Hook with name "'.concat(e.name,'" already exists.'),{name:e.name,hook:e})},e.prototype.remove=function(e){this.hooks=this.hooks.filter((function(t){return t.name!==e}))},e.prototype.getAll=function(){return this.hooks},e}();t.HooksManager=r},166(e,t,r){var a=this&&this.__createBinding||(Object.create?function(e,t,r,a){void 0===a&&(a=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,a,i)}:function(e,t,r,a){void 0===a&&(a=r),e[a]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||a(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),i(r(481),t),i(r(247),t),i(r(584),t),i(r(186),t),i(r(335),t),i(r(649),t),i(r(608),t)},247(e,t,r){var a=this&&this.__assign||function(){return a=Object.assign||function(e){for(var t,r=1,a=arguments.length;r<a;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},a.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.FeaturevisorInstance=void 0,t.createInstance=function(e){return void 0===e&&(e={}),new v(e)};var i=r(584),n=r(438),o=r(40),s=r(649),u=r(335),l=r(608),c=r(985),f=r(943),d={schemaVersion:"2",revision:"unknown",segments:{},features:{}},v=function(){function e(e){this.context={},this.context=e.context||{},this.logger=e.logger||(0,i.createLogger)({level:e.logLevel||i.Logger.defaultLevel}),this.hooksManager=new n.HooksManager({hooks:e.hooks||[],logger:this.logger}),this.emitter=new o.Emitter,this.sticky=e.sticky,this.datafileReader=new s.DatafileReader({datafile:d,logger:this.logger}),e.datafile&&(this.datafileReader=new s.DatafileReader({datafile:"string"==typeof e.datafile?JSON.parse(e.datafile):e.datafile,logger:this.logger})),this.logger.info("Featurevisor SDK initialized")}return e.prototype.setLogLevel=function(e){this.logger.setLevel(e)},e.prototype.setDatafile=function(e){try{var t=new s.DatafileReader({datafile:"string"==typeof e?JSON.parse(e):e,logger:this.logger}),r=(0,c.getParamsForDatafileSetEvent)(this.datafileReader,t);this.datafileReader=t,this.logger.info("datafile set",r),this.emitter.trigger("datafile_set",r)}catch(e){this.logger.error("could not parse datafile",{error:e})}},e.prototype.setSticky=function(e,t){void 0===t&&(t=!1);var r=this.sticky||{};this.sticky=a(t?{}:a({},this.sticky),e);var i=(0,c.getParamsForStickySetEvent)(r,this.sticky,t);this.logger.info("sticky features set",i),this.emitter.trigger("sticky_set",i)},e.prototype.getRevision=function(){return this.datafileReader.getRevision()},e.prototype.getFeature=function(e){return this.datafileReader.getFeature(e)},e.prototype.addHook=function(e){return this.hooksManager.add(e)},e.prototype.on=function(e,t){return this.emitter.on(e,t)},e.prototype.close=function(){this.emitter.clearAll()},e.prototype.setContext=function(e,t){void 0===t&&(t=!1),this.context=t?e:a(a({},this.context),e),this.emitter.trigger("context_set",{context:this.context,replaced:t}),this.logger.debug(t?"context replaced":"context updated",{context:this.context,replaced:t})},e.prototype.getContext=function(e){return e?a(a({},this.context),e):this.context},e.prototype.spawn=function(e,t){return void 0===e&&(e={}),void 0===t&&(t={}),new l.FeaturevisorChildInstance({parent:this,context:this.getContext(e),sticky:t.sticky})},e.prototype.getEvaluationDependencies=function(e,t){return void 0===t&&(t={}),{context:this.getContext(e),logger:this.logger,hooksManager:this.hooksManager,datafileReader:this.datafileReader,sticky:t.sticky?a(a({},this.sticky),t.sticky):this.sticky,defaultVariationValue:t.defaultVariationValue,defaultVariableValue:t.defaultVariableValue}},e.prototype.evaluateFlag=function(e,t,r){return void 0===t&&(t={}),void 0===r&&(r={}),(0,u.evaluateWithHooks)(a(a({},this.getEvaluationDependencies(t,r)),{type:"flag",featureKey:e}))},e.prototype.isEnabled=function(e,t,r){void 0===t&&(t={}),void 0===r&&(r={});try{return!0===this.evaluateFlag(e,t,r).enabled}catch(t){return this.logger.error("isEnabled",{featureKey:e,error:t}),!1}},e.prototype.evaluateVariation=function(e,t,r){return void 0===t&&(t={}),void 0===r&&(r={}),(0,u.evaluateWithHooks)(a(a({},this.getEvaluationDependencies(t,r)),{type:"variation",featureKey:e}))},e.prototype.getVariation=function(e,t,r){void 0===t&&(t={}),void 0===r&&(r={});try{var a=this.evaluateVariation(e,t,r);return void 0!==a.variationValue?a.variationValue:a.variation?a.variation.value:null}catch(t){return this.logger.error("getVariation",{featureKey:e,error:t}),null}},e.prototype.evaluateVariable=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),(0,u.evaluateWithHooks)(a(a({},this.getEvaluationDependencies(r,i)),{type:"variable",featureKey:e,variableKey:t}))},e.prototype.getVariable=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});try{var i=this.evaluateVariable(e,t,r,a);return void 0!==i.variableValue?i.variableSchema&&"json"===i.variableSchema.type&&"string"==typeof i.variableValue?JSON.parse(i.variableValue):i.variableValue:null}catch(r){return this.logger.error("getVariable",{featureKey:e,variableKey:t,error:r}),null}},e.prototype.getVariableBoolean=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"boolean")},e.prototype.getVariableString=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"string")},e.prototype.getVariableInteger=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"integer")},e.prototype.getVariableDouble=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"double")},e.prototype.getVariableArray=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"array")},e.prototype.getVariableObject=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"object")},e.prototype.getVariableJSON=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"json")},e.prototype.getAllEvaluations=function(e,t,r){void 0===e&&(e={}),void 0===t&&(t=[]),void 0===r&&(r={});for(var a={},i=0,n=t.length>0?t:this.datafileReader.getFeatureKeys();i<n.length;i++){var o=n[i],s={enabled:this.isEnabled(o,e,r)};if(this.datafileReader.hasVariations(o)){var u=this.getVariation(o,e,r);u&&(s.variation=u)}var l=this.datafileReader.getVariableKeys(o);if(l.length>0){s.variables={};for(var c=0,f=l;c<f.length;c++){var d=f[c];s.variables[d]=this.getVariable(o,d,e,r)}}a[o]=s}return a},e}();t.FeaturevisorInstance=v},584(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.Logger=t.defaultLogHandler=t.loggerPrefix=void 0,t.createLogger=function(e){return void 0===e&&(e={}),new r(e)},t.loggerPrefix="[Featurevisor]",t.defaultLogHandler=function(e,r,a){void 0===a&&(a={});var i="log";"info"===e?i="info":"warn"===e?i="warn":"error"===e&&(i="error"),console[i](t.loggerPrefix,r,a)};var r=function(){function e(r){this.level=r.level||e.defaultLevel,this.handle=r.handler||t.defaultLogHandler}return e.prototype.setLevel=function(e){this.level=e},e.prototype.log=function(t,r,a){e.allLevels.indexOf(this.level)>=e.allLevels.indexOf(t)&&this.handle(t,r,a)},e.prototype.debug=function(e,t){this.log("debug",e,t)},e.prototype.info=function(e,t){this.log("info",e,t)},e.prototype.warn=function(e,t){this.log("warn",e,t)},e.prototype.error=function(e,t){this.log("error",e,t)},e.allLevels=["fatal","error","warn","info","debug"],e.defaultLevel="info",e}();t.Logger=r},400(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.MurmurHashV3=function(e,t){var r,a,i,n,o,s,u,l,c;for("string"==typeof e&&(r=e,e=(new TextEncoder).encode(r)),a=3&e.length,i=e.length-a,n=t,s=3432918353,u=461845907,c=0;c<i;)l=255&e[c]|(255&e[++c])<<8|(255&e[++c])<<16|(255&e[++c])<<24,++c,n=27492+(65535&(o=5*(65535&(n=(n^=l=(65535&(l=(l=(65535&l)*s+(((l>>>16)*s&65535)<<16)&4294967295)<<15|l>>>17))*u+(((l>>>16)*u&65535)<<16)&4294967295)<<13|n>>>19))+((5*(n>>>16)&65535)<<16)&4294967295))+((58964+(o>>>16)&65535)<<16);switch(l=0,a){case 3:l^=(255&e[c+2])<<16;case 2:l^=(255&e[c+1])<<8;case 1:n^=l=(65535&(l=(l=(65535&(l^=255&e[c]))*s+(((l>>>16)*s&65535)<<16)&4294967295)<<15|l>>>17))*u+(((l>>>16)*u&65535)<<16)&4294967295}return n^=e.length,n=2246822507*(65535&(n^=n>>>16))+((2246822507*(n>>>16)&65535)<<16)&4294967295,n=3266489909*(65535&(n^=n>>>13))+((3266489909*(n>>>16)&65535)<<16)&4294967295,(n^=n>>>16)>>>0}}},t={};return function r(a){var i=t[a];if(void 0!==i)return i.exports;var n=t[a]={exports:{}};return e[a].call(n.exports,n,n.exports,r),n.exports}(166)})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.FeaturevisorSDK=t():e.FeaturevisorSDK=t()}(this,(()=>(()=>{"use strict";var e={481(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.MAX_BUCKETED_NUMBER=void 0,t.getBucketedNumber=function(e){var r=(0,i.MurmurHashV3)(e,1)/n;return Math.floor(r*t.MAX_BUCKETED_NUMBER)},t.getBucketKey=function(e){var t,r,i=e.featureKey,n=e.bucketBy,o=e.context,s=e.logger;if("string"==typeof n)t="plain",r=[n];else if(Array.isArray(n))t="and",r=n;else{if("object"!=typeof n||!Array.isArray(n.or))throw s.error("invalid bucketBy",{featureKey:i,bucketBy:n}),new Error("invalid bucketBy");t="or",r=n.or}var u=[];return r.forEach((function(e){var r=(0,a.getValueFromContext)(o,e);void 0!==r&&("plain"===t||"and"===t||0===u.length)&&u.push(r)})),u.push(i),u.join(".")};var a=r(186),i=r(400),n=Math.pow(2,32);t.MAX_BUCKETED_NUMBER=1e5},608(e,t,r){var a=this&&this.__assign||function(){return a=Object.assign||function(e){for(var t,r=1,a=arguments.length;r<a;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},a.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.FeaturevisorChildInstance=void 0;var i=r(40),n=r(985),o=function(){function e(e){this.parent=e.parent,this.context=e.context,this.sticky=e.sticky||{},this.emitter=new i.Emitter}return e.prototype.on=function(e,t){return"context_set"===e||"sticky_set"===e?this.emitter.on(e,t):this.parent.on(e,t)},e.prototype.close=function(){this.emitter.clearAll()},e.prototype.setContext=function(e,t){void 0===t&&(t=!1),this.context=t?e:a(a({},this.context),e),this.emitter.trigger("context_set",{context:this.context,replaced:t})},e.prototype.getContext=function(e){return this.parent.getContext(a(a({},this.context),e))},e.prototype.setSticky=function(e,t){void 0===t&&(t=!1);var r=this.sticky||{};this.sticky=a(t?{}:a({},this.sticky),e);var i=(0,n.getParamsForStickySetEvent)(r,this.sticky,t);this.emitter.trigger("sticky_set",i)},e.prototype.isEnabled=function(e,t,r){return void 0===t&&(t={}),void 0===r&&(r={}),this.parent.isEnabled(e,a(a({},this.context),t),a({sticky:this.sticky},r))},e.prototype.getVariation=function(e,t,r){return void 0===t&&(t={}),void 0===r&&(r={}),this.parent.getVariation(e,a(a({},this.context),t),a({sticky:this.sticky},r))},e.prototype.getVariable=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariable(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableBoolean=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableBoolean(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableString=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableString(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableInteger=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableInteger(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableDouble=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableDouble(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableArray=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableArray(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableObject=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableObject(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getVariableJSON=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),this.parent.getVariableJSON(e,t,a(a({},this.context),r),a({sticky:this.sticky},i))},e.prototype.getAllEvaluations=function(e,t,r){return void 0===e&&(e={}),void 0===t&&(t=[]),void 0===r&&(r={}),this.parent.getAllEvaluations(a(a({},this.context),e),t,a({sticky:this.sticky},r))},e}();t.FeaturevisorChildInstance=o},108(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.compareVersions=t.compareSegments=t.validateAndParse=t.semver=void 0,t.semver=/^[v^~<>=]*?(\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+)(?:\.([x*]|\d+))?(?:-([\da-z\-]+(?:\.[\da-z\-]+)*))?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i,t.validateAndParse=function(e){if("string"!=typeof e)throw new TypeError("Invalid argument expected string");var r=e.match(t.semver);if(!r)throw new Error("Invalid argument not valid semver ('".concat(e,"' received)"));return r.shift(),r};var r=function(e){return"*"===e||"x"===e||"X"===e},a=function(e){var t=parseInt(e,10);return isNaN(t)?e:t},i=function(e,t){if(r(e)||r(t))return 0;var i=function(e,t){return typeof e!=typeof t?[String(e),String(t)]:[e,t]}(a(e),a(t)),n=i[0],o=i[1];return n>o?1:n<o?-1:0};t.compareSegments=function(e,t){for(var r=0;r<Math.max(e.length,t.length);r++){var a=i(e[r]||"0",t[r]||"0");if(0!==a)return a}return 0},t.compareVersions=function(e,r){var a=(0,t.validateAndParse)(e),i=(0,t.validateAndParse)(r),n=a.pop(),o=i.pop(),s=(0,t.compareSegments)(a,i);return 0!==s?s:n&&o?(0,t.compareSegments)(n.split("."),o.split(".")):n||o?n?-1:1:0}},186(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.getValueFromContext=i,t.conditionIsMatched=function(e,t,r){var n=e.attribute,o=e.operator,s=e.value,u=e.regexFlags,l=i(t,n);if("equals"===o)return l===s;if("notEquals"===o)return l!==s;if("before"===o||"after"===o){var c=(v=l)instanceof Date?v:new Date(v),f=s instanceof Date?s:new Date(s);return"before"===o?c<f:c>f}if(!Array.isArray(s)||-1===["string","number"].indexOf(typeof l)&&null!==l)if("string"==typeof l&&"string"==typeof s){if(v=l,"contains"===o)return-1!==v.indexOf(s);if("notContains"===o)return-1===v.indexOf(s);if("startsWith"===o)return v.startsWith(s);if("endsWith"===o)return v.endsWith(s);if("semverEquals"===o)return 0===(0,a.compareVersions)(v,s);if("semverNotEquals"===o)return 0!==(0,a.compareVersions)(v,s);if("semverGreaterThan"===o)return 1===(0,a.compareVersions)(v,s);if("semverGreaterThanOrEquals"===o)return(0,a.compareVersions)(v,s)>=0;if("semverLessThan"===o)return-1===(0,a.compareVersions)(v,s);if("semverLessThanOrEquals"===o)return(0,a.compareVersions)(v,s)<=0;if("matches"===o)return r(s,u||"").test(v);if("notMatches"===o)return!r(s,u||"").test(v)}else if("number"==typeof l&&"number"==typeof s){if(v=l,"greaterThan"===o)return v>s;if("greaterThanOrEquals"===o)return v>=s;if("lessThan"===o)return v<s;if("lessThanOrEquals"===o)return v<=s}else{if("exists"===o)return void 0!==l;if("notExists"===o)return void 0===l;if(Array.isArray(l)&&("string"==typeof s||"number"==typeof s||"boolean"==typeof s||null===s)){v=l;var d=s;if("includes"===o)return v.indexOf(d)>-1;if("notIncludes"===o)return-1===v.indexOf(d)}}else{var v=l;if("in"===o)return-1!==s.indexOf(v);if("notIn"===o)return-1===s.indexOf(v)}return!1};var a=r(108);function i(e,t){return-1===t.indexOf(".")?e[t]:t.split(".").reduce((function(e,t){return e?e[t]:void 0}),e)}},649(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.DatafileReader=void 0;var a=r(186),i=function(){function e(e){var t=e.datafile,r=e.logger;this.logger=r,this.schemaVersion=t.schemaVersion,this.revision=t.revision,this.segments=t.segments,this.features=t.features,this.regexCache={}}return e.prototype.getRevision=function(){return this.revision},e.prototype.getSchemaVersion=function(){return this.schemaVersion},e.prototype.getSegment=function(e){var t=this.segments[e];if(t)return t.conditions=this.parseConditionsIfStringified(t.conditions),t},e.prototype.getFeatureKeys=function(){return Object.keys(this.features)},e.prototype.getFeature=function(e){return this.features[e]},e.prototype.getVariableKeys=function(e){var t=this.getFeature(e);return t?Object.keys(t.variablesSchema||{}):[]},e.prototype.hasVariations=function(e){var t=this.getFeature(e);return!!t&&Array.isArray(t.variations)&&t.variations.length>0},e.prototype.getRegex=function(e,t){var r=t||"",a="".concat(e,"-").concat(r);if(this.regexCache[a])return this.regexCache[a];var i=new RegExp(e,r);return this.regexCache[a]=i,i},e.prototype.allConditionsAreMatched=function(e,t){var r=this;if("string"==typeof e)return"*"===e;if("attribute"in e)try{return(0,a.conditionIsMatched)(e,t,(function(e,t){return r.getRegex(e,t)}))}catch(r){return this.logger.warn(r.message,{error:r,details:{condition:e,context:t}}),!1}return"and"in e&&Array.isArray(e.and)?e.and.every((function(e){return r.allConditionsAreMatched(e,t)})):"or"in e&&Array.isArray(e.or)?e.or.some((function(e){return r.allConditionsAreMatched(e,t)})):"not"in e&&Array.isArray(e.not)?e.not.every((function(){return!1===r.allConditionsAreMatched({and:e.not},t)})):!!Array.isArray(e)&&e.every((function(e){return r.allConditionsAreMatched(e,t)}))},e.prototype.segmentIsMatched=function(e,t){return this.allConditionsAreMatched(e.conditions,t)},e.prototype.allSegmentsAreMatched=function(e,t){var r=this;if("*"===e)return!0;if("string"==typeof e){var a=this.getSegment(e);return!!a&&this.segmentIsMatched(a,t)}if("object"==typeof e){if("and"in e&&Array.isArray(e.and))return e.and.every((function(e){return r.allSegmentsAreMatched(e,t)}));if("or"in e&&Array.isArray(e.or))return e.or.some((function(e){return r.allSegmentsAreMatched(e,t)}));if("not"in e&&Array.isArray(e.not))return e.not.every((function(e){return!1===r.allSegmentsAreMatched(e,t)}))}return!!Array.isArray(e)&&e.every((function(e){return r.allSegmentsAreMatched(e,t)}))},e.prototype.getMatchedTraffic=function(e,t){var r=this;return e.find((function(e){return!!r.allSegmentsAreMatched(r.parseSegmentsIfStringified(e.segments),t)}))},e.prototype.getMatchedAllocation=function(e,t){if(e.allocation)for(var r=0,a=e.allocation;r<a.length;r++){var i=a[r],n=i.range,o=n[0],s=n[1];if(i.range&&o<=t&&s>=t)return i}},e.prototype.getMatchedForce=function(e,t){var r={force:void 0,forceIndex:void 0},a="string"==typeof e?this.getFeature(e):e;if(!a||!a.force)return r;for(var i=0;i<a.force.length;i++){var n=a.force[i];if(n.conditions&&this.allConditionsAreMatched(this.parseConditionsIfStringified(n.conditions),t)){r.force=n,r.forceIndex=i;break}if(n.segments&&this.allSegmentsAreMatched(this.parseSegmentsIfStringified(n.segments),t)){r.force=n,r.forceIndex=i;break}}return r},e.prototype.parseConditionsIfStringified=function(e){if("string"!=typeof e)return e;if("*"===e)return e;try{return JSON.parse(e)}catch(t){return this.logger.error("Error parsing conditions",{error:t,details:{conditions:e}}),e}},e.prototype.parseSegmentsIfStringified=function(e){return"string"==typeof e&&(e.startsWith("{")||e.startsWith("["))?JSON.parse(e):e},e}();t.DatafileReader=i},40(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.Emitter=void 0;var r=function(){function e(){this.listeners={}}return e.prototype.on=function(e,t){this.listeners[e]||(this.listeners[e]=[]);var r=this.listeners[e];r.push(t);var a=!0;return function(){if(a){a=!1;var e=r.indexOf(t);-1!==e&&r.splice(e,1)}}},e.prototype.trigger=function(e,t){void 0===t&&(t={});var r=this.listeners[e];r&&r.forEach((function(e){try{e(t)}catch(e){console.error(e)}}))},e.prototype.clearAll=function(){this.listeners={}},e}();t.Emitter=r},335(e,t,r){var a=this&&this.__assign||function(){return a=Object.assign||function(e){for(var t,r=1,a=arguments.length;r<a;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},a.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.EvaluationReason=void 0,t.evaluateWithHooks=function(e){try{for(var t=e.hooksManager,r=t.getAll(),a=e,n=0,s=t.getAll();n<s.length;n++)(f=s[n]).before&&(a=f.before(a));var u=o(a);void 0!==a.defaultVariationValue&&"variation"===u.type&&void 0===u.variationValue&&(u.variationValue=a.defaultVariationValue),void 0!==a.defaultVariableValue&&"variable"===u.type&&void 0===u.variableValue&&(u.variableValue=a.defaultVariableValue);for(var l=0,c=r;l<c.length;l++){var f;(f=c[l]).after&&(u=f.after(u,a))}return u}catch(t){var d=e.type,v=e.featureKey,y=e.variableKey,g=e.logger;return u={type:d,featureKey:v,variableKey:y,reason:i.ERROR,error:t},g.error("error during evaluation",u),u}},t.evaluate=o;var i,n=r(481);function o(e){var t,r=e.type,s=e.featureKey,u=e.variableKey,l=e.context,c=e.logger,f=e.datafileReader,d=e.sticky,v=e.hooksManager.getAll();try{if("flag"!==r&&!1===o(a(a({},e),{type:"flag"})).enabled){t={type:r,featureKey:s,reason:i.DISABLED};var y=f.getFeature(s);if("variable"===r&&y&&u&&y.variablesSchema&&y.variablesSchema[u]){var g=y.variablesSchema[u];void 0!==g.disabledValue?t={type:r,featureKey:s,reason:i.VARIABLE_DISABLED,variableKey:u,variableValue:g.disabledValue,variableSchema:g,enabled:!1}:g.useDefaultWhenDisabled&&(t={type:r,featureKey:s,reason:i.VARIABLE_DEFAULT,variableKey:u,variableValue:g.defaultValue,variableSchema:g,enabled:!1})}return"variation"===r&&y&&y.disabledVariationValue&&(t={type:r,featureKey:s,reason:i.VARIATION_DISABLED,variationValue:y.disabledVariationValue,enabled:!1}),c.debug("feature is disabled",t),t}if(d&&d[s]){if("flag"===r&&void 0!==d[s].enabled)return t={type:r,featureKey:s,reason:i.STICKY,sticky:d[s],enabled:d[s].enabled},c.debug("using sticky enabled",t),t;if("variation"===r){var h=d[s].variation;if(void 0!==h)return t={type:r,featureKey:s,reason:i.STICKY,variationValue:h},c.debug("using sticky variation",t),t}if(u){var p=d[s].variables;if(p){var b=p[u];if(void 0!==b)return t={type:r,featureKey:s,reason:i.STICKY,variableKey:u,variableValue:b},c.debug("using sticky variable",t),t}}}var V="string"==typeof s?f.getFeature(s):s;if(!V)return t={type:r,featureKey:s,reason:i.FEATURE_NOT_FOUND},c.warn("feature not found",t),t;"flag"===r&&V.deprecated&&c.warn("feature is deprecated",{featureKey:s});var k=void 0;if(u){if(V.variablesSchema&&V.variablesSchema[u]&&(k=V.variablesSchema[u]),!k)return t={type:r,featureKey:s,reason:i.VARIABLE_NOT_FOUND,variableKey:u},c.warn("variable schema not found",t),t;k.deprecated&&c.warn("variable is deprecated",{featureKey:s,variableKey:u})}if("variation"===r&&(!V.variations||0===V.variations.length))return t={type:r,featureKey:s,reason:i.NO_VARIATIONS},c.warn("no variations",t),t;var m=f.getMatchedForce(V,l),A=m.force,K=m.forceIndex;if(A){if("flag"===r&&void 0!==A.enabled)return t={type:r,featureKey:s,reason:i.FORCED,forceIndex:K,force:A,enabled:A.enabled},c.debug("forced enabled found",t),t;if("variation"===r&&A.variation&&V.variations&&(B=V.variations.find((function(e){return e.value===A.variation}))))return t={type:r,featureKey:s,reason:i.FORCED,forceIndex:K,force:A,variation:B},c.debug("forced variation found",t),t;if(u&&A.variables&&void 0!==A.variables[u])return t={type:r,featureKey:s,reason:i.FORCED,forceIndex:K,force:A,variableKey:u,variableSchema:k,variableValue:A.variables[u]},c.debug("forced variable",t),t}if("flag"===r&&V.required&&V.required.length>0){var O=V.required.every((function(t){var r,i;if("string"==typeof t?r=t:(r=t.key,i=t.variation),!o(a(a({},e),{type:"flag",featureKey:r})).enabled)return!1;if(void 0!==i){var n=o(a(a({},e),{type:"variation",featureKey:r})),s=void 0;return n.variationValue?s=n.variationValue:n.variation&&(s=n.variation.value),s===i}return!0}));if(!O)return t={type:r,featureKey:s,reason:i.REQUIRED,required:V.required,enabled:O},c.debug("required features not enabled",t),t}for(var x=(0,n.getBucketKey)({featureKey:s,bucketBy:V.bucketBy,context:l,logger:c}),E=0,_=v;E<_.length;E++)(L=_[E]).bucketKey&&(x=L.bucketKey({featureKey:s,context:l,bucketBy:V.bucketBy,bucketKey:x}));for(var S,R,I=(0,n.getBucketedNumber)(x),M=0,D=v;M<D.length;M++){var L;(L=D[M]).bucketValue&&(I=L.bucketValue({featureKey:s,bucketKey:x,context:l,bucketValue:I}))}if("flag"!==r?(S=f.getMatchedTraffic(V.traffic,l))&&(R=f.getMatchedAllocation(S,I)):S=f.getMatchedTraffic(V.traffic,l),S){if(0===S.percentage)return t={type:r,featureKey:s,reason:i.RULE,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,enabled:!1},c.debug("matched rule with 0 percentage",t),t;if("flag"===r){if(V.ranges&&V.ranges.length>0)return V.ranges.find((function(e){return I>=e[0]&&I<e[1]}))?(t={type:r,featureKey:s,reason:i.ALLOCATED,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,enabled:void 0===S.enabled||S.enabled},c.debug("matched",t),t):(t={type:r,featureKey:s,reason:i.OUT_OF_RANGE,bucketKey:x,bucketValue:I,enabled:!1},c.debug("not matched",t),t);if(void 0!==S.enabled)return t={type:r,featureKey:s,reason:i.RULE,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,enabled:S.enabled},c.debug("override from rule",t),t;if(I<=S.percentage)return t={type:r,featureKey:s,reason:i.RULE,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,enabled:!0},c.debug("matched traffic",t),t}if("variation"===r&&V.variations){if(S.variation&&(B=V.variations.find((function(e){return e.value===S.variation}))))return t={type:r,featureKey:s,reason:i.RULE,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,variation:B},c.debug("override from rule",t),t;if(R&&R.variation&&(B=V.variations.find((function(e){return e.value===R.variation}))))return t={type:r,featureKey:s,reason:i.ALLOCATED,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,variation:B},c.debug("allocated variation",t),t}}if("variable"===r&&u){if(S){if(S.variableOverrides&&S.variableOverrides[u]&&-1!==(w=(C=S.variableOverrides[u]).findIndex((function(e){return e.conditions?f.allConditionsAreMatched("string"==typeof e.conditions&&"*"!==e.conditions?JSON.parse(e.conditions):e.conditions,l):!!e.segments&&f.allSegmentsAreMatched(f.parseSegmentsIfStringified(e.segments),l)})))){var T=C[w];return t={type:r,featureKey:s,reason:i.VARIABLE_OVERRIDE_RULE,bucketKey:x,bucketValue:I,ruleKey:null==S?void 0:S.key,traffic:S,variableKey:u,variableSchema:k,variableValue:T.value,variableOverrideIndex:w},c.debug("variable override from rule",t),t}if(S.variables&&void 0!==S.variables[u])return t={type:r,featureKey:s,reason:i.RULE,bucketKey:x,bucketValue:I,ruleKey:S.key,traffic:S,variableKey:u,variableSchema:k,variableValue:S.variables[u]},c.debug("override from rule",t),t}var F;if(A&&A.variation?F=A.variation:S&&S.variation?F=S.variation:R&&R.variation&&(F=R.variation),F&&Array.isArray(V.variations)){var B,C,w;if((B=V.variations.find((function(e){return e.value===F})))&&B.variableOverrides&&B.variableOverrides[u]&&-1!==(w=(C=B.variableOverrides[u]).findIndex((function(e){return e.conditions?f.allConditionsAreMatched("string"==typeof e.conditions&&"*"!==e.conditions?JSON.parse(e.conditions):e.conditions,l):!!e.segments&&f.allSegmentsAreMatched(f.parseSegmentsIfStringified(e.segments),l)}))))return T=C[w],t={type:r,featureKey:s,reason:i.VARIABLE_OVERRIDE_VARIATION,bucketKey:x,bucketValue:I,ruleKey:null==S?void 0:S.key,traffic:S,variableKey:u,variableSchema:k,variableValue:T.value,variableOverrideIndex:w},c.debug("variable override from variation",t),t;if(B&&B.variables&&void 0!==B.variables[u])return t={type:r,featureKey:s,reason:i.ALLOCATED,bucketKey:x,bucketValue:I,ruleKey:null==S?void 0:S.key,traffic:S,variableKey:u,variableSchema:k,variableValue:B.variables[u]},c.debug("allocated variable",t),t}}return"variation"===r?(t={type:r,featureKey:s,reason:i.NO_MATCH,bucketKey:x,bucketValue:I},c.debug("no matched variation",t),t):"variable"===r?k?(t={type:r,featureKey:s,reason:i.VARIABLE_DEFAULT,bucketKey:x,bucketValue:I,variableKey:u,variableSchema:k,variableValue:k.defaultValue},c.debug("using default value",t),t):(t={type:r,featureKey:s,reason:i.VARIABLE_NOT_FOUND,variableKey:u,bucketKey:x,bucketValue:I},c.debug("variable not found",t),t):(t={type:r,featureKey:s,reason:i.NO_MATCH,bucketKey:x,bucketValue:I,enabled:!1},c.debug("nothing matched",t),t)}catch(e){return t={type:r,featureKey:s,variableKey:u,reason:i.ERROR,error:e},c.error("error",t),t}}!function(e){e.FEATURE_NOT_FOUND="feature_not_found",e.DISABLED="disabled",e.REQUIRED="required",e.OUT_OF_RANGE="out_of_range",e.NO_VARIATIONS="no_variations",e.VARIATION_DISABLED="variation_disabled",e.VARIABLE_NOT_FOUND="variable_not_found",e.VARIABLE_DEFAULT="variable_default",e.VARIABLE_DISABLED="variable_disabled",e.VARIABLE_OVERRIDE_VARIATION="variable_override_variation",e.VARIABLE_OVERRIDE_RULE="variable_override_rule",e.NO_MATCH="no_match",e.FORCED="forced",e.STICKY="sticky",e.RULE="rule",e.ALLOCATED="allocated",e.ERROR="error"}(i||(t.EvaluationReason=i={}))},985(e,t){var r=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var a,i=0,n=t.length;i<n;i++)!a&&i in t||(a||(a=Array.prototype.slice.call(t,0,i)),a[i]=t[i]);return e.concat(a||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.getParamsForStickySetEvent=function(e,t,a){void 0===e&&(e={}),void 0===t&&(t={});var i=Object.keys(e),n=Object.keys(t),o=r(r([],i,!0),n,!0);return{features:o.filter((function(e,t){return o.indexOf(e)===t})),replaced:a}},t.getParamsForDatafileSetEvent=function(e,t){for(var a=e.getRevision(),i=e.getFeatureKeys(),n=t.getRevision(),o=t.getFeatureKeys(),s=[],u=[],l=[],c=0,f=i;c<f.length;c++){var d=f[c];if(-1!==o.indexOf(d)){var v=e.getFeature(d),y=t.getFeature(d);(null==v?void 0:v.hash)!==(null==y?void 0:y.hash)&&u.push(d)}else s.push(d)}for(var g=0,h=o;g<h.length;g++){var p=h[g];-1===i.indexOf(p)&&l.push(p)}return{revision:n,previousRevision:a,revisionChanged:a!==n,features:r(r(r([],s,!0),u,!0),l,!0).filter((function(e,t,r){return r.indexOf(e)===t}))}}},943(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.getValueByType=function(e,t){if(void 0===e)return null;switch(t){case"string":return"string"==typeof e?e:null;case"integer":return parseInt(e,10);case"double":return parseFloat(e);case"boolean":return!0===e;case"array":return Array.isArray(e)?e:null;case"object":return"object"==typeof e?e:null;default:return e}}},438(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.HooksManager=void 0;var r=function(){function e(e){var t=this;this.hooks=[],this.logger=e.logger,e.hooks&&e.hooks.forEach((function(e){t.add(e)}))}return e.prototype.add=function(e){var t=this;if(!this.hooks.some((function(t){return t.name===e.name})))return this.hooks.push(e),function(){t.remove(e.name)};this.logger.error('Hook with name "'.concat(e.name,'" already exists.'),{name:e.name,hook:e})},e.prototype.remove=function(e){this.hooks=this.hooks.filter((function(t){return t.name!==e}))},e.prototype.getAll=function(){return this.hooks},e}();t.HooksManager=r},166(e,t,r){var a=this&&this.__createBinding||(Object.create?function(e,t,r,a){void 0===a&&(a=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,a,i)}:function(e,t,r,a){void 0===a&&(a=r),e[a]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||a(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),i(r(481),t),i(r(247),t),i(r(584),t),i(r(186),t),i(r(335),t),i(r(649),t),i(r(608),t)},247(e,t,r){var a=this&&this.__assign||function(){return a=Object.assign||function(e){for(var t,r=1,a=arguments.length;r<a;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},a.apply(this,arguments)};Object.defineProperty(t,"__esModule",{value:!0}),t.FeaturevisorInstance=void 0,t.createInstance=function(e){return void 0===e&&(e={}),new v(e)};var i=r(584),n=r(438),o=r(40),s=r(649),u=r(335),l=r(608),c=r(985),f=r(943),d={schemaVersion:"2",revision:"unknown",segments:{},features:{}},v=function(){function e(e){this.context={},this.context=e.context||{},this.logger=e.logger||(0,i.createLogger)({level:e.logLevel||i.Logger.defaultLevel}),this.hooksManager=new n.HooksManager({hooks:e.hooks||[],logger:this.logger}),this.emitter=new o.Emitter,this.sticky=e.sticky,this.datafileReader=new s.DatafileReader({datafile:d,logger:this.logger}),e.datafile&&(this.datafileReader=new s.DatafileReader({datafile:"string"==typeof e.datafile?JSON.parse(e.datafile):e.datafile,logger:this.logger})),this.logger.info("Featurevisor SDK initialized")}return e.prototype.setLogLevel=function(e){this.logger.setLevel(e)},e.prototype.setDatafile=function(e){try{var t=new s.DatafileReader({datafile:"string"==typeof e?JSON.parse(e):e,logger:this.logger}),r=(0,c.getParamsForDatafileSetEvent)(this.datafileReader,t);this.datafileReader=t,this.logger.info("datafile set",r),this.emitter.trigger("datafile_set",r)}catch(e){this.logger.error("could not parse datafile",{error:e})}},e.prototype.setSticky=function(e,t){void 0===t&&(t=!1);var r=this.sticky||{};this.sticky=a(t?{}:a({},this.sticky),e);var i=(0,c.getParamsForStickySetEvent)(r,this.sticky,t);this.logger.info("sticky features set",i),this.emitter.trigger("sticky_set",i)},e.prototype.getRevision=function(){return this.datafileReader.getRevision()},e.prototype.getFeature=function(e){return this.datafileReader.getFeature(e)},e.prototype.addHook=function(e){return this.hooksManager.add(e)},e.prototype.on=function(e,t){return this.emitter.on(e,t)},e.prototype.close=function(){this.emitter.clearAll()},e.prototype.setContext=function(e,t){void 0===t&&(t=!1),this.context=t?e:a(a({},this.context),e),this.emitter.trigger("context_set",{context:this.context,replaced:t}),this.logger.debug(t?"context replaced":"context updated",{context:this.context,replaced:t})},e.prototype.getContext=function(e){return e?a(a({},this.context),e):this.context},e.prototype.spawn=function(e,t){return void 0===e&&(e={}),void 0===t&&(t={}),new l.FeaturevisorChildInstance({parent:this,context:this.getContext(e),sticky:t.sticky})},e.prototype.getEvaluationDependencies=function(e,t){return void 0===t&&(t={}),{context:this.getContext(e),logger:this.logger,hooksManager:this.hooksManager,datafileReader:this.datafileReader,sticky:t.sticky?a(a({},this.sticky),t.sticky):this.sticky,defaultVariationValue:t.defaultVariationValue,defaultVariableValue:t.defaultVariableValue}},e.prototype.evaluateFlag=function(e,t,r){return void 0===t&&(t={}),void 0===r&&(r={}),(0,u.evaluateWithHooks)(a(a({},this.getEvaluationDependencies(t,r)),{type:"flag",featureKey:e}))},e.prototype.isEnabled=function(e,t,r){void 0===t&&(t={}),void 0===r&&(r={});try{return!0===this.evaluateFlag(e,t,r).enabled}catch(t){return this.logger.error("isEnabled",{featureKey:e,error:t}),!1}},e.prototype.evaluateVariation=function(e,t,r){return void 0===t&&(t={}),void 0===r&&(r={}),(0,u.evaluateWithHooks)(a(a({},this.getEvaluationDependencies(t,r)),{type:"variation",featureKey:e}))},e.prototype.getVariation=function(e,t,r){void 0===t&&(t={}),void 0===r&&(r={});try{var a=this.evaluateVariation(e,t,r);return void 0!==a.variationValue?a.variationValue:a.variation?a.variation.value:null}catch(t){return this.logger.error("getVariation",{featureKey:e,error:t}),null}},e.prototype.evaluateVariable=function(e,t,r,i){return void 0===r&&(r={}),void 0===i&&(i={}),(0,u.evaluateWithHooks)(a(a({},this.getEvaluationDependencies(r,i)),{type:"variable",featureKey:e,variableKey:t}))},e.prototype.getVariable=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});try{var i=this.evaluateVariable(e,t,r,a);return void 0!==i.variableValue?i.variableSchema&&"json"===i.variableSchema.type&&"string"==typeof i.variableValue?JSON.parse(i.variableValue):i.variableValue:null}catch(r){return this.logger.error("getVariable",{featureKey:e,variableKey:t,error:r}),null}},e.prototype.getVariableBoolean=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"boolean")},e.prototype.getVariableString=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"string")},e.prototype.getVariableInteger=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"integer")},e.prototype.getVariableDouble=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"double")},e.prototype.getVariableArray=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"array")},e.prototype.getVariableObject=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"object")},e.prototype.getVariableJSON=function(e,t,r,a){void 0===r&&(r={}),void 0===a&&(a={});var i=this.getVariable(e,t,r,a);return(0,f.getValueByType)(i,"json")},e.prototype.getAllEvaluations=function(e,t,r){void 0===e&&(e={}),void 0===t&&(t=[]),void 0===r&&(r={});for(var a={},i=0,n=t.length>0?t:this.datafileReader.getFeatureKeys();i<n.length;i++){var o=n[i],s={enabled:this.isEnabled(o,e,r)};if(this.datafileReader.hasVariations(o)){var u=this.getVariation(o,e,r);u&&(s.variation=u)}var l=this.datafileReader.getVariableKeys(o);if(l.length>0){s.variables={};for(var c=0,f=l;c<f.length;c++){var d=f[c];s.variables[d]=this.getVariable(o,d,e,r)}}a[o]=s}return a},e}();t.FeaturevisorInstance=v},584(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.Logger=t.defaultLogHandler=t.loggerPrefix=void 0,t.createLogger=function(e){return void 0===e&&(e={}),new r(e)},t.loggerPrefix="[Featurevisor]",t.defaultLogHandler=function(e,r,a){void 0===a&&(a={});var i="log";"info"===e?i="info":"warn"===e?i="warn":"error"===e&&(i="error"),console[i](t.loggerPrefix,r,a)};var r=function(){function e(r){this.level=r.level||e.defaultLevel,this.handle=r.handler||t.defaultLogHandler}return e.prototype.setLevel=function(e){this.level=e},e.prototype.log=function(t,r,a){e.allLevels.indexOf(this.level)>=e.allLevels.indexOf(t)&&this.handle(t,r,a)},e.prototype.debug=function(e,t){this.log("debug",e,t)},e.prototype.info=function(e,t){this.log("info",e,t)},e.prototype.warn=function(e,t){this.log("warn",e,t)},e.prototype.error=function(e,t){this.log("error",e,t)},e.allLevels=["fatal","error","warn","info","debug"],e.defaultLevel="info",e}();t.Logger=r},400(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.MurmurHashV3=function(e,t){var r,a,i,n,o,s,u,l,c;for("string"==typeof e&&(r=e,e=(new TextEncoder).encode(r)),a=3&e.length,i=e.length-a,n=t,s=3432918353,u=461845907,c=0;c<i;)l=255&e[c]|(255&e[++c])<<8|(255&e[++c])<<16|(255&e[++c])<<24,++c,n=27492+(65535&(o=5*(65535&(n=(n^=l=(65535&(l=(l=(65535&l)*s+(((l>>>16)*s&65535)<<16)&4294967295)<<15|l>>>17))*u+(((l>>>16)*u&65535)<<16)&4294967295)<<13|n>>>19))+((5*(n>>>16)&65535)<<16)&4294967295))+((58964+(o>>>16)&65535)<<16);switch(l=0,a){case 3:l^=(255&e[c+2])<<16;case 2:l^=(255&e[c+1])<<8;case 1:n^=l=(65535&(l=(l=(65535&(l^=255&e[c]))*s+(((l>>>16)*s&65535)<<16)&4294967295)<<15|l>>>17))*u+(((l>>>16)*u&65535)<<16)&4294967295}return n^=e.length,n=2246822507*(65535&(n^=n>>>16))+((2246822507*(n>>>16)&65535)<<16)&4294967295,n=3266489909*(65535&(n^=n>>>13))+((3266489909*(n>>>16)&65535)<<16)&4294967295,(n^=n>>>16)>>>0}}},t={};return function r(a){var i=t[a];if(void 0!==i)return i.exports;var n=t[a]={exports:{}};return e[a].call(n.exports,n,n.exports,r),n.exports}(166)})()));
|
|
2
2
|
//# sourceMappingURL=index.js.map
|