posthog-node 5.51.1 → 5.51.3

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.
@@ -27,19 +27,13 @@ __webpack_require__.d(__webpack_exports__, {
27
27
  matchProperty: ()=>matchProperty,
28
28
  parseSemver: ()=>parseSemver,
29
29
  ClientError: ()=>ClientError,
30
- relativeDateParseForFeatureFlagMatching: ()=>relativeDateParseForFeatureFlagMatching,
31
- InconclusiveMatchError: ()=>InconclusiveMatchError,
30
+ relativeDateParseForFeatureFlagMatching: ()=>core_namespaceObject.relativeDateParseForFeatureFlagMatching,
31
+ InconclusiveMatchError: ()=>core_namespaceObject.InconclusiveMatchError,
32
32
  FeatureFlagsPoller: ()=>FeatureFlagsPoller,
33
33
  RequiresServerEvaluation: ()=>RequiresServerEvaluation
34
34
  });
35
35
  const core_namespaceObject = require("@posthog/core");
36
- const external_crypto_js_namespaceObject = require("./crypto.js");
37
36
  const SIXTY_SECONDS = 60000;
38
- const LONG_SCALE = 0xfffffffffffffff;
39
- const NULL_VALUES_ALLOWED_OPERATORS = [
40
- 'is_not',
41
- 'is_set'
42
- ];
43
37
  class ClientError extends Error {
44
38
  constructor(message){
45
39
  super();
@@ -54,12 +48,6 @@ function setCustomErrorPrototype(error, constructor) {
54
48
  Error.captureStackTrace(error, constructor);
55
49
  Object.setPrototypeOf(error, constructor.prototype);
56
50
  }
57
- class InconclusiveMatchError extends Error {
58
- constructor(message){
59
- super(message);
60
- setCustomErrorPrototype(this, InconclusiveMatchError);
61
- }
62
- }
63
51
  class RequiresServerEvaluation extends Error {
64
52
  constructor(message){
65
53
  super(message);
@@ -120,7 +108,7 @@ class FeatureFlagsPoller {
120
108
  response = result.value;
121
109
  this.logMsgIfDebug(()=>console.debug(`Successfully computed flag locally: ${key} -> ${response}`));
122
110
  } catch (e) {
123
- if (e instanceof RequiresServerEvaluation || e instanceof InconclusiveMatchError) this.logMsgIfDebug(()=>console.debug(`${e.name} when computing flag locally: ${key}: ${e.message}`));
111
+ if (e instanceof RequiresServerEvaluation || e instanceof core_namespaceObject.InconclusiveMatchError) this.logMsgIfDebug(()=>console.debug(`${e.name} when computing flag locally: ${key}: ${e.message}`));
124
112
  else if (e instanceof Error) this.onError?.(new Error(`Error computing flag locally: ${key}: ${e}`));
125
113
  }
126
114
  }
@@ -142,7 +130,7 @@ class FeatureFlagsPoller {
142
130
  response[flag.key] = matchValue;
143
131
  if (matchPayload) payloads[flag.key] = matchPayload;
144
132
  } catch (e) {
145
- if (e instanceof RequiresServerEvaluation || e instanceof InconclusiveMatchError) this.logMsgIfDebug(()=>console.debug(`${e.name} when computing flag locally: ${flag.key}: ${e.message}`));
133
+ if (e instanceof RequiresServerEvaluation || e instanceof core_namespaceObject.InconclusiveMatchError) this.logMsgIfDebug(()=>console.debug(`${e.name} when computing flag locally: ${flag.key}: ${e.message}`));
146
134
  else if (e instanceof Error) this.onError?.(new Error(`Error computing flag locally: ${flag.key}: ${e}`));
147
135
  fallbackToFlags = true;
148
136
  }
@@ -171,14 +159,14 @@ class FeatureFlagsPoller {
171
159
  async computeFlagValueLocally(flag, evaluationContext) {
172
160
  const { distinctId, groups, personProperties, groupProperties } = evaluationContext;
173
161
  if (!flag.active) return false;
174
- if (flag.ensure_experience_continuity) throw new InconclusiveMatchError('Flag has experience continuity enabled');
162
+ if (flag.ensure_experience_continuity) throw new core_namespaceObject.InconclusiveMatchError('Flag has experience continuity enabled');
175
163
  const flagFilters = flag.filters || {};
176
164
  const aggregation_group_type_index = flagFilters.aggregation_group_type_index;
177
165
  if (void 0 != aggregation_group_type_index) {
178
166
  const groupName = this.groupTypeMapping[String(aggregation_group_type_index)];
179
167
  if (!groupName) {
180
168
  this.logMsgIfDebug(()=>console.warn(`[FEATURE FLAGS] Unknown group type index ${aggregation_group_type_index} for feature flag ${flag.key}`));
181
- throw new InconclusiveMatchError('Flag has unknown group type index');
169
+ throw new core_namespaceObject.InconclusiveMatchError('Flag has unknown group type index');
182
170
  }
183
171
  if (!(groupName in groups)) {
184
172
  this.logMsgIfDebug(()=>console.warn(`[FEATURE FLAGS] Can't compute group feature flag: ${flag.key} without group names passed in`));
@@ -192,7 +180,7 @@ class FeatureFlagsPoller {
192
180
  const bucketingValue = this.getBucketingValueForFlag(flag, distinctId, personProperties);
193
181
  if (void 0 === bucketingValue) {
194
182
  this.logMsgIfDebug(()=>console.warn(`[FEATURE FLAGS] Can't compute feature flag: ${flag.key} without $device_id, falling back to server evaluation`));
195
- throw new InconclusiveMatchError(`Can't compute feature flag: ${flag.key} without $device_id`);
183
+ throw new core_namespaceObject.InconclusiveMatchError(`Can't compute feature flag: ${flag.key} without $device_id`);
196
184
  }
197
185
  return await this.matchFeatureFlagProperties(flag, bucketingValue, personProperties, evaluationContext);
198
186
  }
@@ -207,28 +195,16 @@ class FeatureFlagsPoller {
207
195
  return distinctId;
208
196
  }
209
197
  getFeatureFlagPayload(key, flagValue) {
210
- let payload = null;
211
- if (false !== flagValue && null != flagValue) {
212
- if ('boolean' == typeof flagValue) payload = this.featureFlagsByKey?.[key]?.filters?.payloads?.[flagValue.toString()] || null;
213
- else if ('string' == typeof flagValue) payload = this.featureFlagsByKey?.[key]?.filters?.payloads?.[flagValue] || null;
214
- if (null != payload) {
215
- if ('object' == typeof payload) return payload;
216
- if ('string' == typeof payload) try {
217
- return JSON.parse(payload);
218
- } catch {}
219
- return payload;
220
- }
221
- }
222
- return null;
198
+ return (0, core_namespaceObject.resolveFeatureFlagPayload)(this.featureFlagsByKey?.[key]?.filters?.payloads, flagValue);
223
199
  }
224
200
  async evaluateFlagDependency(property, properties, evaluationContext) {
225
201
  const { evaluationCache } = evaluationContext;
226
202
  const targetFlagKey = property.key;
227
- if (!this.featureFlagsByKey) throw new InconclusiveMatchError('Feature flags not available for dependency evaluation');
228
- if (!('dependency_chain' in property)) throw new InconclusiveMatchError(`Flag dependency property for '${targetFlagKey}' is missing required 'dependency_chain' field`);
203
+ if (!this.featureFlagsByKey) throw new core_namespaceObject.InconclusiveMatchError('Feature flags not available for dependency evaluation');
204
+ if (!('dependency_chain' in property)) throw new core_namespaceObject.InconclusiveMatchError(`Flag dependency property for '${targetFlagKey}' is missing required 'dependency_chain' field`);
229
205
  const dependencyChain = property.dependency_chain;
230
- if (!Array.isArray(dependencyChain)) throw new InconclusiveMatchError(`Flag dependency property for '${targetFlagKey}' has an invalid 'dependency_chain' (expected array, got ${typeof dependencyChain})`);
231
- if (0 === dependencyChain.length) throw new InconclusiveMatchError(`Circular dependency detected for flag '${targetFlagKey}' (empty dependency chain)`);
206
+ if (!Array.isArray(dependencyChain)) throw new core_namespaceObject.InconclusiveMatchError(`Flag dependency property for '${targetFlagKey}' has an invalid 'dependency_chain' (expected array, got ${typeof dependencyChain})`);
207
+ if (0 === dependencyChain.length) throw new core_namespaceObject.InconclusiveMatchError(`Circular dependency detected for flag '${targetFlagKey}' (empty dependency chain)`);
232
208
  for (const depFlagKey of dependencyChain){
233
209
  if (!(depFlagKey in evaluationCache)) {
234
210
  const depFlag = this.featureFlagsByKey[depFlagKey];
@@ -236,13 +212,13 @@ class FeatureFlagsPoller {
236
212
  const depResult = await this.computeFlagValueLocally(depFlag, evaluationContext);
237
213
  evaluationCache[depFlagKey] = depResult;
238
214
  } catch (error) {
239
- throw new InconclusiveMatchError(`Error evaluating flag dependency '${depFlagKey}' for flag '${targetFlagKey}': ${error}`);
215
+ throw new core_namespaceObject.InconclusiveMatchError(`Error evaluating flag dependency '${depFlagKey}' for flag '${targetFlagKey}': ${error}`);
240
216
  }
241
217
  else evaluationCache[depFlagKey] = false;
242
- else throw new InconclusiveMatchError(`Missing flag dependency '${depFlagKey}' for flag '${targetFlagKey}'`);
218
+ else throw new core_namespaceObject.InconclusiveMatchError(`Missing flag dependency '${depFlagKey}' for flag '${targetFlagKey}'`);
243
219
  }
244
220
  const cachedResult = evaluationCache[depFlagKey];
245
- if (null == cachedResult) throw new InconclusiveMatchError(`Dependency '${depFlagKey}' could not be evaluated`);
221
+ if (null == cachedResult) throw new core_namespaceObject.InconclusiveMatchError(`Dependency '${depFlagKey}' could not be evaluated`);
246
222
  }
247
223
  const targetFlagValue = evaluationCache[targetFlagKey];
248
224
  return this.flagEvaluatesToExpectedValue(property.value, targetFlagValue);
@@ -286,14 +262,17 @@ class FeatureFlagsPoller {
286
262
  result = variantOverride && flagVariants.some((variant)=>variant.key === variantOverride) ? variantOverride : await this.getMatchingVariant(flag, effectiveBucketingValue) || true;
287
263
  break;
288
264
  }
289
- if (earlyExitEnabled && 'out_of_rollout_bound' === matchResult) return false;
265
+ if (earlyExitEnabled && 'out_of_rollout_bound' === matchResult) {
266
+ if (isInconclusive) break;
267
+ return false;
268
+ }
290
269
  } catch (e) {
291
270
  if (e instanceof RequiresServerEvaluation) throw e;
292
- if (e instanceof InconclusiveMatchError) isInconclusive = true;
271
+ if (e instanceof core_namespaceObject.InconclusiveMatchError) isInconclusive = true;
293
272
  else throw e;
294
273
  }
295
274
  if (void 0 !== result) return result;
296
- if (isInconclusive) throw new InconclusiveMatchError("Can't determine if feature flag is enabled or not with given properties");
275
+ if (isInconclusive) throw new core_namespaceObject.InconclusiveMatchError("Can't determine if feature flag is enabled or not with given properties");
297
276
  return false;
298
277
  }
299
278
  async isConditionMatch(flag, bucketingValue, condition, properties, evaluationContext) {
@@ -313,30 +292,14 @@ class FeatureFlagsPoller {
313
292
  }
314
293
  if (void 0 == rolloutPercentage) return 'match';
315
294
  }
316
- if (void 0 != rolloutPercentage && await _hash(flag.key, bucketingValue) > rolloutPercentage / 100.0) return 'out_of_rollout_bound';
295
+ if (void 0 != rolloutPercentage && await (0, core_namespaceObject.getFeatureFlagHash)(flag.key, bucketingValue) > rolloutPercentage / 100.0) return 'out_of_rollout_bound';
317
296
  return 'match';
318
297
  }
319
298
  async getMatchingVariant(flag, bucketingValue) {
320
- const hashValue = await _hash(flag.key, bucketingValue, 'variant');
321
- const matchingVariant = this.variantLookupTable(flag).find((variant)=>hashValue >= variant.valueMin && hashValue < variant.valueMax);
322
- if (matchingVariant) return matchingVariant.key;
299
+ return (0, core_namespaceObject.getFeatureFlagVariant)(flag.key, bucketingValue, flag.filters?.multivariate?.variants || []);
323
300
  }
324
301
  variantLookupTable(flag) {
325
- const lookupTable = [];
326
- let valueMin = 0;
327
- let valueMax = 0;
328
- const flagFilters = flag.filters || {};
329
- const multivariates = flagFilters.multivariate?.variants || [];
330
- multivariates.forEach((variant)=>{
331
- valueMax = valueMin + variant.rollout_percentage / 100.0;
332
- lookupTable.push({
333
- valueMin,
334
- valueMax,
335
- key: variant.key
336
- });
337
- valueMin = valueMax;
338
- });
339
- return lookupTable;
302
+ return (0, core_namespaceObject.getFeatureFlagVariantLookupTable)(flag.filters?.multivariate?.variants || []);
340
303
  }
341
304
  updateFlagState(flagData) {
342
305
  this.featureFlags = flagData.flags;
@@ -540,134 +503,13 @@ class FeatureFlagsPoller {
540
503
  }
541
504
  }
542
505
  }
543
- async function _hash(key, bucketingValue, salt = '') {
544
- const hashString = await (0, external_crypto_js_namespaceObject.hashSHA1)(`${key}.${bucketingValue}${salt}`);
545
- return parseInt(hashString.slice(0, 15), 16) / LONG_SCALE;
546
- }
547
506
  function matchProperty(property, propertyValues, warnFunction) {
548
- const key = property.key;
549
- const value = property.value;
550
- const operator = property.operator || 'exact';
551
- if (key in propertyValues) {
552
- if ('is_not_set' === operator) return false;
553
- } else {
554
- if ('is_not_set' === operator) return true;
555
- throw new InconclusiveMatchError(`Property ${key} not found in propertyValues`);
556
- }
557
- const overrideValue = propertyValues[key];
558
- if (null == overrideValue && !NULL_VALUES_ALLOWED_OPERATORS.includes(operator)) {
559
- if (warnFunction) warnFunction(`Property ${key} cannot have a value of null/undefined with the ${operator} operator`);
560
- return false;
561
- }
562
- function computeExactMatch(value, overrideValue) {
563
- if (Array.isArray(value)) return value.map((val)=>String(val).toLowerCase()).includes(String(overrideValue).toLowerCase());
564
- return String(value).toLowerCase() === String(overrideValue).toLowerCase();
565
- }
566
- function compare(lhs, rhs, operator) {
567
- if ('gt' === operator) return lhs > rhs;
568
- if ('gte' === operator) return lhs >= rhs;
569
- if ('lt' === operator) return lhs < rhs;
570
- if ('lte' === operator) return lhs <= rhs;
571
- throw new Error(`Invalid operator: ${operator}`);
572
- }
573
- switch(operator){
574
- case 'exact':
575
- return computeExactMatch(value, overrideValue);
576
- case 'is_not':
577
- return !computeExactMatch(value, overrideValue);
578
- case 'is_set':
579
- return key in propertyValues;
580
- case 'icontains':
581
- return String(overrideValue).toLowerCase().includes(String(value).toLowerCase());
582
- case 'not_icontains':
583
- return !String(overrideValue).toLowerCase().includes(String(value).toLowerCase());
584
- case 'starts_with':
585
- return String(overrideValue).toLowerCase().startsWith(String(value).toLowerCase());
586
- case 'not_starts_with':
587
- return !String(overrideValue).toLowerCase().startsWith(String(value).toLowerCase());
588
- case 'ends_with':
589
- return String(overrideValue).toLowerCase().endsWith(String(value).toLowerCase());
590
- case 'not_ends_with':
591
- return !String(overrideValue).toLowerCase().endsWith(String(value).toLowerCase());
592
- case 'regex':
593
- return isValidRegex(String(value)) && null !== String(overrideValue).match(String(value));
594
- case 'not_regex':
595
- return isValidRegex(String(value)) && null === String(overrideValue).match(String(value));
596
- case 'gt':
597
- case 'gte':
598
- case 'lt':
599
- case 'lte':
600
- {
601
- const parsedValue = 'number' == typeof value ? value : parseFloat(String(value));
602
- let parsedOverride;
603
- parsedOverride = 'number' == typeof overrideValue ? overrideValue : null != overrideValue ? parseFloat(String(overrideValue)) : NaN;
604
- if (Number.isFinite(parsedValue) && Number.isFinite(parsedOverride)) return compare(parsedOverride, parsedValue, operator);
605
- return compare(String(overrideValue), String(value), operator);
606
- }
607
- case 'is_date_after':
608
- case 'is_date_before':
609
- {
610
- if ('boolean' == typeof value) throw new InconclusiveMatchError("Date operations cannot be performed on boolean values");
611
- let parsedDate = relativeDateParseForFeatureFlagMatching(String(value));
612
- if (null == parsedDate) parsedDate = convertToDateTime(value);
613
- if (null == parsedDate) throw new InconclusiveMatchError(`Invalid date: ${value}`);
614
- const overrideDate = convertToDateTime(overrideValue);
615
- if ([
616
- 'is_date_before'
617
- ].includes(operator)) return overrideDate < parsedDate;
618
- return overrideDate > parsedDate;
619
- }
620
- case 'semver_eq':
621
- {
622
- const cmp = compareSemverTuples(parseSemver(String(overrideValue)), parseSemver(String(value)));
623
- return 0 === cmp;
624
- }
625
- case 'semver_neq':
626
- {
627
- const cmp = compareSemverTuples(parseSemver(String(overrideValue)), parseSemver(String(value)));
628
- return 0 !== cmp;
629
- }
630
- case 'semver_gt':
631
- {
632
- const cmp = compareSemverTuples(parseSemver(String(overrideValue)), parseSemver(String(value)));
633
- return cmp > 0;
634
- }
635
- case 'semver_gte':
636
- {
637
- const cmp = compareSemverTuples(parseSemver(String(overrideValue)), parseSemver(String(value)));
638
- return cmp >= 0;
639
- }
640
- case 'semver_lt':
641
- {
642
- const cmp = compareSemverTuples(parseSemver(String(overrideValue)), parseSemver(String(value)));
643
- return cmp < 0;
644
- }
645
- case 'semver_lte':
646
- {
647
- const cmp = compareSemverTuples(parseSemver(String(overrideValue)), parseSemver(String(value)));
648
- return cmp <= 0;
649
- }
650
- case 'semver_tilde':
651
- {
652
- const overrideParsed = parseSemver(String(overrideValue));
653
- const { lower, upper } = computeTildeBounds(String(value));
654
- return compareSemverTuples(overrideParsed, lower) >= 0 && compareSemverTuples(overrideParsed, upper) < 0;
655
- }
656
- case 'semver_caret':
657
- {
658
- const overrideParsed = parseSemver(String(overrideValue));
659
- const { lower, upper } = computeCaretBounds(String(value));
660
- return compareSemverTuples(overrideParsed, lower) >= 0 && compareSemverTuples(overrideParsed, upper) < 0;
661
- }
662
- case 'semver_wildcard':
663
- {
664
- const overrideParsed = parseSemver(String(overrideValue));
665
- const { lower, upper } = computeWildcardBounds(String(value));
666
- return compareSemverTuples(overrideParsed, lower) >= 0 && compareSemverTuples(overrideParsed, upper) < 0;
667
- }
668
- default:
669
- throw new InconclusiveMatchError(`Unknown operator: ${operator}`);
670
- }
507
+ return (0, core_namespaceObject.matchFeatureFlagProperty)(property, propertyValues, {
508
+ warnFunction
509
+ });
510
+ }
511
+ function parseSemver(value) {
512
+ return (0, core_namespaceObject.parseFeatureFlagSemver)(value, 'strict');
671
513
  }
672
514
  function checkCohortExists(cohortId, cohortProperties) {
673
515
  if (!(cohortId in cohortProperties)) throw new RequiresServerEvaluation(`cohort ${cohortId} not found in local cohorts - likely a static cohort that requires server evaluation`);
@@ -692,19 +534,19 @@ async function matchPropertyGroup(propertyGroup, propertyValues, cohortPropertie
692
534
  } else if (matches) return true;
693
535
  } catch (err) {
694
536
  if (err instanceof RequiresServerEvaluation) throw err;
695
- if (err instanceof InconclusiveMatchError) {
537
+ if (err instanceof core_namespaceObject.InconclusiveMatchError) {
696
538
  if (debugMode) console.debug(`Failed to compute property ${prop} locally: ${err}`);
697
539
  errorMatchingLocally = true;
698
540
  } else throw err;
699
541
  }
700
- if (errorMatchingLocally) throw new InconclusiveMatchError("Can't match cohort without a given cohort property value");
542
+ if (errorMatchingLocally) throw new core_namespaceObject.InconclusiveMatchError("Can't match cohort without a given cohort property value");
701
543
  return 'AND' === propertyGroupType;
702
544
  }
703
545
  for (const prop of properties)try {
704
546
  let matches;
705
547
  if ('cohort' === prop.type) matches = await matchCohort(prop, propertyValues, cohortProperties, debugMode, flagDependencyEvaluator);
706
548
  else if ('flag' === prop.type) {
707
- if (!flagDependencyEvaluator) throw new InconclusiveMatchError(`Flag dependency '${prop.key || 'unknown'}' cannot be evaluated without a flag dependency evaluator`);
549
+ if (!flagDependencyEvaluator) throw new core_namespaceObject.InconclusiveMatchError(`Flag dependency '${prop.key || 'unknown'}' cannot be evaluated without a flag dependency evaluator`);
708
550
  matches = await flagDependencyEvaluator(prop);
709
551
  } else matches = matchProperty(prop, propertyValues);
710
552
  const negation = prop.negation || false;
@@ -717,170 +559,14 @@ async function matchPropertyGroup(propertyGroup, propertyValues, cohortPropertie
717
559
  }
718
560
  } catch (err) {
719
561
  if (err instanceof RequiresServerEvaluation) throw err;
720
- if (err instanceof InconclusiveMatchError) {
562
+ if (err instanceof core_namespaceObject.InconclusiveMatchError) {
721
563
  if (debugMode) console.debug(`Failed to compute property ${prop} locally: ${err}`);
722
564
  errorMatchingLocally = true;
723
565
  } else throw err;
724
566
  }
725
- if (errorMatchingLocally) throw new InconclusiveMatchError("can't match cohort without a given cohort property value");
567
+ if (errorMatchingLocally) throw new core_namespaceObject.InconclusiveMatchError("can't match cohort without a given cohort property value");
726
568
  return 'AND' === propertyGroupType;
727
569
  }
728
- function isValidRegex(regex) {
729
- try {
730
- new RegExp(regex);
731
- return true;
732
- } catch (err) {
733
- return false;
734
- }
735
- }
736
- function parseSemverNumericIdentifier(part, raw) {
737
- if (!/^\d+$/.test(part)) throw new InconclusiveMatchError(`Invalid semver: ${raw}`);
738
- if (part.length > 1 && '0' === part[0]) throw new InconclusiveMatchError(`Invalid semver: ${raw}`);
739
- return parseInt(part, 10);
740
- }
741
- function parseSemver(value) {
742
- const text = String(value).trim().replace(/^[vV]/, '');
743
- const baseVersion = text.split('-')[0].split('+')[0];
744
- if (!baseVersion || baseVersion.startsWith('.')) throw new InconclusiveMatchError(`Invalid semver: ${value}`);
745
- const parts = baseVersion.split('.');
746
- const parsePart = (part)=>{
747
- if (void 0 === part || '' === part) return 0;
748
- return parseSemverNumericIdentifier(part, value);
749
- };
750
- const major = parsePart(parts[0]);
751
- const minor = parsePart(parts[1]);
752
- const patch = parsePart(parts[2]);
753
- return [
754
- major,
755
- minor,
756
- patch
757
- ];
758
- }
759
- function compareSemverTuples(a, b) {
760
- for(let i = 0; i < 3; i++){
761
- if (a[i] < b[i]) return -1;
762
- if (a[i] > b[i]) return 1;
763
- }
764
- return 0;
765
- }
766
- function computeTildeBounds(value) {
767
- const parsed = parseSemver(value);
768
- const lower = [
769
- parsed[0],
770
- parsed[1],
771
- parsed[2]
772
- ];
773
- const upper = [
774
- parsed[0],
775
- parsed[1] + 1,
776
- 0
777
- ];
778
- return {
779
- lower,
780
- upper
781
- };
782
- }
783
- function computeCaretBounds(value) {
784
- const parsed = parseSemver(value);
785
- const [major, minor, patch] = parsed;
786
- const lower = [
787
- major,
788
- minor,
789
- patch
790
- ];
791
- let upper;
792
- upper = major > 0 ? [
793
- major + 1,
794
- 0,
795
- 0
796
- ] : minor > 0 ? [
797
- 0,
798
- minor + 1,
799
- 0
800
- ] : [
801
- 0,
802
- 0,
803
- patch + 1
804
- ];
805
- return {
806
- lower,
807
- upper
808
- };
809
- }
810
- function computeWildcardBounds(value) {
811
- const text = String(value).trim().replace(/^[vV]/, '');
812
- const cleanedText = text.replace(/\.\*$/, '').replace(/\*$/, '');
813
- if (!cleanedText) throw new InconclusiveMatchError(`Invalid wildcard semver: ${value}`);
814
- const parts = cleanedText.split('.');
815
- const parseWildcardPart = (part)=>{
816
- try {
817
- return parseSemverNumericIdentifier(part, value);
818
- } catch {
819
- throw new InconclusiveMatchError(`Invalid wildcard semver: ${value}`);
820
- }
821
- };
822
- const major = parseWildcardPart(parts[0]);
823
- let lower;
824
- let upper;
825
- if (1 === parts.length) {
826
- lower = [
827
- major,
828
- 0,
829
- 0
830
- ];
831
- upper = [
832
- major + 1,
833
- 0,
834
- 0
835
- ];
836
- } else {
837
- const minor = parseWildcardPart(parts[1]);
838
- lower = [
839
- major,
840
- minor,
841
- 0
842
- ];
843
- upper = [
844
- major,
845
- minor + 1,
846
- 0
847
- ];
848
- }
849
- return {
850
- lower,
851
- upper
852
- };
853
- }
854
- function convertToDateTime(value) {
855
- if (value instanceof Date) return value;
856
- if ('string' == typeof value || 'number' == typeof value) {
857
- const date = new Date(value);
858
- if (!isNaN(date.valueOf())) return date;
859
- throw new InconclusiveMatchError(`${value} is in an invalid date format`);
860
- }
861
- throw new InconclusiveMatchError(`The date provided ${value} must be a string, number, or date object`);
862
- }
863
- function relativeDateParseForFeatureFlagMatching(value) {
864
- const regex = /^-?(?<number>[0-9]+)(?<interval>[a-z])$/;
865
- const match = value.match(regex);
866
- const parsedDt = new Date(new Date().toISOString());
867
- if (!match) return null;
868
- {
869
- if (!match.groups) return null;
870
- const number = parseInt(match.groups['number']);
871
- if (number >= 10000) return null;
872
- const interval = match.groups['interval'];
873
- if ('h' == interval) parsedDt.setUTCHours(parsedDt.getUTCHours() - number);
874
- else if ('d' == interval) parsedDt.setUTCDate(parsedDt.getUTCDate() - number);
875
- else if ('w' == interval) parsedDt.setUTCDate(parsedDt.getUTCDate() - 7 * number);
876
- else if ('m' == interval) parsedDt.setUTCMonth(parsedDt.getUTCMonth() - number);
877
- else {
878
- if ('y' != interval) return null;
879
- parsedDt.setUTCFullYear(parsedDt.getUTCFullYear() - number);
880
- }
881
- return parsedDt;
882
- }
883
- }
884
570
  exports.ClientError = __webpack_exports__.ClientError;
885
571
  exports.FeatureFlagsPoller = __webpack_exports__.FeatureFlagsPoller;
886
572
  exports.InconclusiveMatchError = __webpack_exports__.InconclusiveMatchError;