@posthog/core 1.59.4 → 1.60.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/featureFlagLocalEvaluation.d.ts +13 -1
- package/dist/featureFlagLocalEvaluation.d.ts.map +1 -1
- package/dist/featureFlagLocalEvaluation.js +194 -37
- package/dist/featureFlagLocalEvaluation.mjs +192 -38
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -7
- package/dist/index.mjs +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/dist/types.mjs +1 -0
- package/package.json +1 -1
- package/src/featureFlagLocalEvaluation.ts +250 -70
- package/src/index.ts +2 -0
- package/src/types.ts +2 -0
|
@@ -21,12 +21,24 @@ export type FeatureFlagVariantLookupEntry = {
|
|
|
21
21
|
valueMax: number;
|
|
22
22
|
key: string;
|
|
23
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Why local evaluation could not resolve a flag. `experience_continuity` and
|
|
26
|
+
* `unsupported_definition` come from the flag's definition, `missing_context` from the
|
|
27
|
+
* evaluation call, and `unresolved_dependency` from a flag the definition depends on.
|
|
28
|
+
*/
|
|
29
|
+
export type UnresolvedFlagReason = 'experience_continuity' | 'unsupported_definition' | 'missing_context' | 'unresolved_dependency';
|
|
24
30
|
export declare class InconclusiveMatchError extends Error {
|
|
25
|
-
|
|
31
|
+
readonly reason: UnresolvedFlagReason;
|
|
32
|
+
constructor(message: string, reason?: UnresolvedFlagReason);
|
|
26
33
|
}
|
|
27
34
|
type SemverTuple = [number, number, number];
|
|
28
35
|
export declare function parseFeatureFlagSemver(value: string, parsingPolicy?: FeatureFlagSemverParsingPolicy): SemverTuple;
|
|
29
36
|
export declare function relativeDateParseForFeatureFlagMatching(value: string): Date | null;
|
|
37
|
+
/**
|
|
38
|
+
* Throws an unsupported_definition error when local evaluation cannot use the filter, whatever
|
|
39
|
+
* the context holds: an unknown operator, or a filter value that the operator cannot parse.
|
|
40
|
+
*/
|
|
41
|
+
export declare function assertFeatureFlagFilterSupported(property: FeatureFlagProperty, options?: Pick<MatchFeatureFlagPropertyOptions, 'semverParsingPolicy'>): void;
|
|
30
42
|
export declare function matchFeatureFlagProperty(property: FeatureFlagProperty, propertyValues: Record<string, any>, options?: MatchFeatureFlagPropertyOptions): boolean;
|
|
31
43
|
export declare function hashSHA1(text: string): Promise<string>;
|
|
32
44
|
export declare function getFeatureFlagHash(key: string, bucketingValue: string, salt?: string, separator?: string): Promise<number>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"featureFlagLocalEvaluation.d.ts","sourceRoot":"","sources":["../src/featureFlagLocalEvaluation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEzD,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAA;AAE/C,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,wBAAwB,CAAA;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,8BAA8B,GAAG,QAAQ,GAAG,mBAAmB,CAAA;AAE3E,MAAM,MAAM,+BAA+B,GAAG;IAC5C,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IACxC,mBAAmB,CAAC,EAAE,8BAA8B,CAAA;IACpD,mGAAmG;IACnG,uBAAuB,CAAC,EAAE,MAAM,CAAA;CACjC,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,kBAAkB,EAAE,MAAM,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,GAAG,EAAE,MAA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7B;AAED,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,GAAG,SAAS,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EAC3E,SAAS,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GAC7C,QAAQ,GAAG,IAAI,CAMjB"}
|
|
@@ -29,6 +29,7 @@ var __webpack_exports__ = {};
|
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
InconclusiveMatchError: ()=>InconclusiveMatchError,
|
|
32
|
+
assertFeatureFlagFilterSupported: ()=>assertFeatureFlagFilterSupported,
|
|
32
33
|
getFeatureFlagHash: ()=>getFeatureFlagHash,
|
|
33
34
|
getFeatureFlagVariant: ()=>getFeatureFlagVariant,
|
|
34
35
|
getFeatureFlagVariantLookupTable: ()=>getFeatureFlagVariantLookupTable,
|
|
@@ -54,12 +55,21 @@ const NULL_VALUES_ALLOWED_OPERATORS = [
|
|
|
54
55
|
];
|
|
55
56
|
const LONG_SCALE = 0xfffffffffffffff;
|
|
56
57
|
class InconclusiveMatchError extends Error {
|
|
57
|
-
constructor(message){
|
|
58
|
+
constructor(message, reason = 'unsupported_definition'){
|
|
58
59
|
super(message);
|
|
59
60
|
this.name = this.constructor.name;
|
|
61
|
+
this.reason = reason;
|
|
60
62
|
Object.setPrototypeOf(this, InconclusiveMatchError.prototype);
|
|
61
63
|
}
|
|
62
64
|
}
|
|
65
|
+
function readContextValue(read) {
|
|
66
|
+
try {
|
|
67
|
+
return read();
|
|
68
|
+
} catch (e) {
|
|
69
|
+
if (e instanceof InconclusiveMatchError) throw new InconclusiveMatchError(e.message, 'missing_context');
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
63
73
|
function isTruthyOrFalsyPropertyValue(value) {
|
|
64
74
|
if ('boolean' == typeof value) return true;
|
|
65
75
|
if ('string' == typeof value) {
|
|
@@ -184,12 +194,96 @@ function exactMatchString(value) {
|
|
|
184
194
|
}
|
|
185
195
|
return serializeJsonValue(value);
|
|
186
196
|
}
|
|
187
|
-
|
|
197
|
+
const LITERAL_ESCAPED_PUNCTUATION = /[\x20-\x2f:;=?@\x5b-\x60\x7b-\x7e]/;
|
|
198
|
+
function getPortableRegexClasses(pattern) {
|
|
199
|
+
const classes = [];
|
|
200
|
+
let classStart = -1;
|
|
201
|
+
let previousToken = '';
|
|
202
|
+
for(let index = 0; index < pattern.length; index++){
|
|
203
|
+
const character = pattern[index];
|
|
204
|
+
if (character.charCodeAt(0) > 0x7f) return null;
|
|
205
|
+
if ('\\' === character) {
|
|
206
|
+
const escaped = pattern[++index];
|
|
207
|
+
if (void 0 === escaped) break;
|
|
208
|
+
if ('x' === escaped) {
|
|
209
|
+
if (!/^[\da-f]{2}$/i.test(pattern.slice(index + 1, index + 3))) return null;
|
|
210
|
+
index += 2;
|
|
211
|
+
} else if (!'dDsSwWbBfnrtv'.includes(escaped) && !LITERAL_ESCAPED_PUNCTUATION.test(escaped)) return null;
|
|
212
|
+
if (-1 === classStart && 'bB'.includes(escaped)) return null;
|
|
213
|
+
previousToken = 'literal';
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
if ('[' === character) {
|
|
217
|
+
if (-1 !== classStart) return null;
|
|
218
|
+
classStart = index;
|
|
219
|
+
} else if (']' === character && -1 !== classStart) {
|
|
220
|
+
const contentStart = classStart + ('^' === pattern[classStart + 1] ? 2 : 1);
|
|
221
|
+
if (index === contentStart) return null;
|
|
222
|
+
classes.push(pattern.slice(classStart, index + 1));
|
|
223
|
+
classStart = -1;
|
|
224
|
+
previousToken = 'literal';
|
|
225
|
+
continue;
|
|
226
|
+
} else if (-1 !== classStart) {
|
|
227
|
+
if ([
|
|
228
|
+
'&&',
|
|
229
|
+
'--',
|
|
230
|
+
'~~'
|
|
231
|
+
].includes(pattern.slice(index, index + 2))) return null;
|
|
232
|
+
continue;
|
|
233
|
+
} else if ('(' === character && '?' === pattern[index + 1]) {
|
|
234
|
+
if (':' !== pattern[index + 2]) return null;
|
|
235
|
+
index += 2;
|
|
236
|
+
} else if ('{' === character) {
|
|
237
|
+
const repetition = /^\{(\d+)(?:,(\d*))?\}/.exec(pattern.slice(index));
|
|
238
|
+
if (!repetition || [
|
|
239
|
+
'',
|
|
240
|
+
'|',
|
|
241
|
+
'('
|
|
242
|
+
].includes(previousToken) || repetition.slice(1).some((count)=>Number(count) > 0xffffffff)) return null;
|
|
243
|
+
} else if ('*+?}'.includes(character) && ('+' === pattern[index + 1] || '{' === pattern[index + 1])) return null;
|
|
244
|
+
if ('*+?{'.includes(character) && [
|
|
245
|
+
'^',
|
|
246
|
+
'$',
|
|
247
|
+
'empty group'
|
|
248
|
+
].includes(previousToken)) return null;
|
|
249
|
+
previousToken = ')' === character && [
|
|
250
|
+
'(',
|
|
251
|
+
'empty group'
|
|
252
|
+
].includes(previousToken) ? 'empty group' : character;
|
|
253
|
+
}
|
|
254
|
+
return classes;
|
|
255
|
+
}
|
|
256
|
+
function regexRequiresServerEvaluation(message) {
|
|
257
|
+
const error = new InconclusiveMatchError(message);
|
|
258
|
+
Object.defineProperty(error, Symbol.for('posthog.requiresServerRegexEvaluation'), {
|
|
259
|
+
value: true
|
|
260
|
+
});
|
|
261
|
+
return error;
|
|
262
|
+
}
|
|
263
|
+
function matchFeatureFlagRegex(pattern, value) {
|
|
264
|
+
if ('' === pattern) return true;
|
|
265
|
+
const characterClasses = getPortableRegexClasses(pattern);
|
|
266
|
+
if (null === characterClasses) throw regexRequiresServerEvaluation('Regex syntax requires server evaluation');
|
|
267
|
+
let regex;
|
|
188
268
|
try {
|
|
189
|
-
new RegExp(
|
|
190
|
-
|
|
269
|
+
regex = new RegExp(pattern);
|
|
270
|
+
} catch (error) {
|
|
271
|
+
if (error instanceof SyntaxError) return null;
|
|
272
|
+
throw regexRequiresServerEvaluation('Regex compilation requires server evaluation');
|
|
273
|
+
}
|
|
274
|
+
for (const characterClass of characterClasses)try {
|
|
275
|
+
new RegExp(characterClass, 'u');
|
|
191
276
|
} catch {
|
|
192
|
-
|
|
277
|
+
throw regexRequiresServerEvaluation('Regex character class syntax requires server evaluation');
|
|
278
|
+
}
|
|
279
|
+
for(let index = 0; index < value.length; index++){
|
|
280
|
+
const character = value[index];
|
|
281
|
+
if (character.charCodeAt(0) > 0x7f || '\r' === character) throw regexRequiresServerEvaluation('Regex matching for Unicode or carriage returns requires server evaluation');
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
return regex.test(value);
|
|
285
|
+
} catch {
|
|
286
|
+
throw regexRequiresServerEvaluation('Regex execution requires server evaluation');
|
|
193
287
|
}
|
|
194
288
|
}
|
|
195
289
|
function asciiLowercase(value) {
|
|
@@ -330,7 +424,69 @@ function relativeDateParseForFeatureFlagMatching(value) {
|
|
|
330
424
|
}
|
|
331
425
|
return parsedDt;
|
|
332
426
|
}
|
|
427
|
+
function parseDateFilter(value) {
|
|
428
|
+
if ('boolean' == typeof value) throw new InconclusiveMatchError('Date operations cannot be performed on boolean values');
|
|
429
|
+
return relativeDateParseForFeatureFlagMatching(String(value)) ?? convertToDateTime(value);
|
|
430
|
+
}
|
|
431
|
+
function assertFeatureFlagFilterSupported(property, options = {}) {
|
|
432
|
+
const value = property.value;
|
|
433
|
+
const parsingPolicy = options.semverParsingPolicy ?? 'strict';
|
|
434
|
+
switch(property.operator || 'exact'){
|
|
435
|
+
case 'exact':
|
|
436
|
+
case 'is_not':
|
|
437
|
+
for (const item of Array.isArray(value) ? value : [
|
|
438
|
+
value
|
|
439
|
+
])exactMatchString(item);
|
|
440
|
+
return;
|
|
441
|
+
case 'is_set':
|
|
442
|
+
case 'is_not_set':
|
|
443
|
+
case 'icontains':
|
|
444
|
+
case 'not_icontains':
|
|
445
|
+
case 'starts_with':
|
|
446
|
+
case 'not_starts_with':
|
|
447
|
+
case 'ends_with':
|
|
448
|
+
case 'not_ends_with':
|
|
449
|
+
case 'regex':
|
|
450
|
+
case 'not_regex':
|
|
451
|
+
case 'gt':
|
|
452
|
+
case 'gte':
|
|
453
|
+
case 'lt':
|
|
454
|
+
case 'lte':
|
|
455
|
+
return;
|
|
456
|
+
case 'is_date_after':
|
|
457
|
+
case 'is_date_before':
|
|
458
|
+
parseDateFilter(value);
|
|
459
|
+
return;
|
|
460
|
+
case 'semver_eq':
|
|
461
|
+
case 'semver_neq':
|
|
462
|
+
case 'semver_gt':
|
|
463
|
+
case 'semver_gte':
|
|
464
|
+
case 'semver_lt':
|
|
465
|
+
case 'semver_lte':
|
|
466
|
+
parseFeatureFlagSemver(String(value), parsingPolicy);
|
|
467
|
+
return;
|
|
468
|
+
case 'semver_tilde':
|
|
469
|
+
computeTildeBounds(String(value), parsingPolicy);
|
|
470
|
+
return;
|
|
471
|
+
case 'semver_caret':
|
|
472
|
+
computeCaretBounds(String(value), parsingPolicy);
|
|
473
|
+
return;
|
|
474
|
+
case 'semver_wildcard':
|
|
475
|
+
computeWildcardBounds(String(value), parsingPolicy);
|
|
476
|
+
return;
|
|
477
|
+
default:
|
|
478
|
+
throw new InconclusiveMatchError(`Unknown operator: ${property.operator}`);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
333
481
|
function matchFeatureFlagProperty(property, propertyValues, options = {}) {
|
|
482
|
+
try {
|
|
483
|
+
return matchPropertyValue(property, propertyValues, options);
|
|
484
|
+
} catch (e) {
|
|
485
|
+
if (e instanceof InconclusiveMatchError && 'missing_context' === e.reason) assertFeatureFlagFilterSupported(property, options);
|
|
486
|
+
throw e;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function matchPropertyValue(property, propertyValues, options) {
|
|
334
490
|
const key = property.key;
|
|
335
491
|
const value = property.value;
|
|
336
492
|
const operator = property.operator || 'exact';
|
|
@@ -339,7 +495,7 @@ function matchFeatureFlagProperty(property, propertyValues, options = {}) {
|
|
|
339
495
|
if (hasProperty) {
|
|
340
496
|
if ('is_not_set' === operator) return false;
|
|
341
497
|
else if ('is_set' === operator) return true;
|
|
342
|
-
} else throw new InconclusiveMatchError(`Property ${key} not found in propertyValues
|
|
498
|
+
} else throw new InconclusiveMatchError(`Property ${key} not found in propertyValues`, 'missing_context');
|
|
343
499
|
const overrideValue = propertyValues[key];
|
|
344
500
|
if (void 0 === overrideValue) {
|
|
345
501
|
options.warnFunction?.(`Property ${key} cannot have a value of undefined with the ${operator} operator`);
|
|
@@ -351,18 +507,19 @@ function matchFeatureFlagProperty(property, propertyValues, options = {}) {
|
|
|
351
507
|
}
|
|
352
508
|
const computeExactMatch = (target, actual)=>{
|
|
353
509
|
if (2 !== options.propertyMatchingVersion && isTruthyOrFalsyPropertyValue(target) || Array.isArray(target) && 0 === target.length) {
|
|
354
|
-
assertJsonRepresentable(actual);
|
|
510
|
+
readContextValue(()=>assertJsonRepresentable(actual));
|
|
355
511
|
return isTruthyPropertyValue(target) === isTruthyPropertyValue(actual);
|
|
356
512
|
}
|
|
357
513
|
if (2 === options.propertyMatchingVersion && 'number' == typeof actual && isTruthyOrFalsyPropertyValue(target)) {
|
|
358
|
-
assertJsonRepresentable(actual);
|
|
514
|
+
readContextValue(()=>assertJsonRepresentable(actual));
|
|
359
515
|
return false;
|
|
360
516
|
}
|
|
361
517
|
if (Array.isArray(target)) {
|
|
362
|
-
const actualString = exactMatchString(actual).toLowerCase();
|
|
518
|
+
const actualString = readContextValue(()=>exactMatchString(actual)).toLowerCase();
|
|
363
519
|
return target.some((item)=>exactMatchString(item).toLowerCase() === actualString);
|
|
364
520
|
}
|
|
365
|
-
|
|
521
|
+
const targetString = exactMatchString(target).toLowerCase();
|
|
522
|
+
return targetString === readContextValue(()=>exactMatchString(actual)).toLowerCase();
|
|
366
523
|
};
|
|
367
524
|
const compare = (lhs, rhs, comparisonOperator)=>{
|
|
368
525
|
if ('gt' === comparisonOperator) return lhs > rhs;
|
|
@@ -371,6 +528,15 @@ function matchFeatureFlagProperty(property, propertyValues, options = {}) {
|
|
|
371
528
|
if ('lte' === comparisonOperator) return lhs <= rhs;
|
|
372
529
|
throw new Error(`Invalid operator: ${comparisonOperator}`);
|
|
373
530
|
};
|
|
531
|
+
const parseContextSemver = ()=>readContextValue(()=>parseFeatureFlagSemver(String(overrideValue), parsingPolicy));
|
|
532
|
+
const compareContextSemverToFilter = ()=>{
|
|
533
|
+
const filterParsed = parseFeatureFlagSemver(String(value), parsingPolicy);
|
|
534
|
+
return compareSemverTuples(parseContextSemver(), filterParsed);
|
|
535
|
+
};
|
|
536
|
+
const isContextSemverWithin = ({ lower, upper })=>{
|
|
537
|
+
const overrideParsed = parseContextSemver();
|
|
538
|
+
return compareSemverTuples(overrideParsed, lower) >= 0 && compareSemverTuples(overrideParsed, upper) < 0;
|
|
539
|
+
};
|
|
374
540
|
switch(operator){
|
|
375
541
|
case 'exact':
|
|
376
542
|
return computeExactMatch(value, overrideValue);
|
|
@@ -391,9 +557,12 @@ function matchFeatureFlagProperty(property, propertyValues, options = {}) {
|
|
|
391
557
|
case 'not_ends_with':
|
|
392
558
|
return !asciiLowercase(overrideValue).endsWith(asciiLowercase(value));
|
|
393
559
|
case 'regex':
|
|
394
|
-
return isValidRegex(String(value)) && null !== String(overrideValue).match(String(value));
|
|
395
560
|
case 'not_regex':
|
|
396
|
-
|
|
561
|
+
{
|
|
562
|
+
const matched = matchFeatureFlagRegex(String(value), String(overrideValue));
|
|
563
|
+
if (null === matched) return false;
|
|
564
|
+
return 'regex' === operator ? matched : !matched;
|
|
565
|
+
}
|
|
397
566
|
case 'gt':
|
|
398
567
|
case 'gte':
|
|
399
568
|
case 'lt':
|
|
@@ -407,42 +576,28 @@ function matchFeatureFlagProperty(property, propertyValues, options = {}) {
|
|
|
407
576
|
case 'is_date_after':
|
|
408
577
|
case 'is_date_before':
|
|
409
578
|
{
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
if (null == parsedDate) parsedDate = convertToDateTime(value);
|
|
413
|
-
const overrideDate = convertToDateTime(overrideValue);
|
|
579
|
+
const parsedDate = parseDateFilter(value);
|
|
580
|
+
const overrideDate = readContextValue(()=>convertToDateTime(overrideValue));
|
|
414
581
|
return 'is_date_before' === operator ? overrideDate < parsedDate : overrideDate > parsedDate;
|
|
415
582
|
}
|
|
416
583
|
case 'semver_eq':
|
|
417
|
-
return 0 ===
|
|
584
|
+
return 0 === compareContextSemverToFilter();
|
|
418
585
|
case 'semver_neq':
|
|
419
|
-
return 0 !==
|
|
586
|
+
return 0 !== compareContextSemverToFilter();
|
|
420
587
|
case 'semver_gt':
|
|
421
|
-
return
|
|
588
|
+
return compareContextSemverToFilter() > 0;
|
|
422
589
|
case 'semver_gte':
|
|
423
|
-
return
|
|
590
|
+
return compareContextSemverToFilter() >= 0;
|
|
424
591
|
case 'semver_lt':
|
|
425
|
-
return
|
|
592
|
+
return compareContextSemverToFilter() < 0;
|
|
426
593
|
case 'semver_lte':
|
|
427
|
-
return
|
|
594
|
+
return compareContextSemverToFilter() <= 0;
|
|
428
595
|
case 'semver_tilde':
|
|
429
|
-
|
|
430
|
-
const overrideParsed = parseFeatureFlagSemver(String(overrideValue), parsingPolicy);
|
|
431
|
-
const { lower, upper } = computeTildeBounds(String(value), parsingPolicy);
|
|
432
|
-
return compareSemverTuples(overrideParsed, lower) >= 0 && compareSemverTuples(overrideParsed, upper) < 0;
|
|
433
|
-
}
|
|
596
|
+
return isContextSemverWithin(computeTildeBounds(String(value), parsingPolicy));
|
|
434
597
|
case 'semver_caret':
|
|
435
|
-
|
|
436
|
-
const overrideParsed = parseFeatureFlagSemver(String(overrideValue), parsingPolicy);
|
|
437
|
-
const { lower, upper } = computeCaretBounds(String(value), parsingPolicy);
|
|
438
|
-
return compareSemverTuples(overrideParsed, lower) >= 0 && compareSemverTuples(overrideParsed, upper) < 0;
|
|
439
|
-
}
|
|
598
|
+
return isContextSemverWithin(computeCaretBounds(String(value), parsingPolicy));
|
|
440
599
|
case 'semver_wildcard':
|
|
441
|
-
|
|
442
|
-
const overrideParsed = parseFeatureFlagSemver(String(overrideValue), parsingPolicy);
|
|
443
|
-
const { lower, upper } = computeWildcardBounds(String(value), parsingPolicy);
|
|
444
|
-
return compareSemverTuples(overrideParsed, lower) >= 0 && compareSemverTuples(overrideParsed, upper) < 0;
|
|
445
|
-
}
|
|
600
|
+
return isContextSemverWithin(computeWildcardBounds(String(value), parsingPolicy));
|
|
446
601
|
default:
|
|
447
602
|
throw new InconclusiveMatchError(`Unknown operator: ${operator}`);
|
|
448
603
|
}
|
|
@@ -493,6 +648,7 @@ function resolveFeatureFlagPayload(payloads, flagValue) {
|
|
|
493
648
|
return null == payload ? null : (0, external_featureFlagUtils_js_namespaceObject.parsePayload)(payload);
|
|
494
649
|
}
|
|
495
650
|
exports.InconclusiveMatchError = __webpack_exports__.InconclusiveMatchError;
|
|
651
|
+
exports.assertFeatureFlagFilterSupported = __webpack_exports__.assertFeatureFlagFilterSupported;
|
|
496
652
|
exports.getFeatureFlagHash = __webpack_exports__.getFeatureFlagHash;
|
|
497
653
|
exports.getFeatureFlagVariant = __webpack_exports__.getFeatureFlagVariant;
|
|
498
654
|
exports.getFeatureFlagVariantLookupTable = __webpack_exports__.getFeatureFlagVariantLookupTable;
|
|
@@ -504,6 +660,7 @@ exports.relativeDateParseForFeatureFlagMatching = __webpack_exports__.relativeDa
|
|
|
504
660
|
exports.resolveFeatureFlagPayload = __webpack_exports__.resolveFeatureFlagPayload;
|
|
505
661
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
506
662
|
"InconclusiveMatchError",
|
|
663
|
+
"assertFeatureFlagFilterSupported",
|
|
507
664
|
"getFeatureFlagHash",
|
|
508
665
|
"getFeatureFlagVariant",
|
|
509
666
|
"getFeatureFlagVariantLookupTable",
|