posthog-node 4.1.0 → 4.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Next
2
2
 
3
+ # 4.1.1 - 2024-08-20
4
+
5
+ 1. Local evaluation returns correct results on `undefined/null` values
3
6
  # 4.1.0 - 2024-08-14
4
7
 
5
8
  1. chore: change host to new address.
package/lib/index.cjs.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var rusha = require('rusha');
6
6
 
7
- var version = "4.1.0";
7
+ var version = "4.1.1";
8
8
 
9
9
  var PostHogPersistedProperty;
10
10
  (function (PostHogPersistedProperty) {
@@ -1434,6 +1434,7 @@ if (!_fetch) {
1434
1434
  var fetch$1 = _fetch;
1435
1435
 
1436
1436
  const LONG_SCALE = 0xfffffffffffffff;
1437
+ const NULL_VALUES_ALLOWED_OPERATORS = ['is_not'];
1437
1438
 
1438
1439
  class ClientError extends Error {
1439
1440
  constructor(message) {
@@ -1680,6 +1681,12 @@ class FeatureFlagsPoller {
1680
1681
  isConditionMatch(flag, distinctId, condition, properties) {
1681
1682
  const rolloutPercentage = condition.rollout_percentage;
1682
1683
 
1684
+ const warnFunction = msg => {
1685
+ if (this.debugMode) {
1686
+ console.warn(msg);
1687
+ }
1688
+ };
1689
+
1683
1690
  if ((condition.properties || []).length > 0) {
1684
1691
  for (const prop of condition.properties) {
1685
1692
  const propertyType = prop.type;
@@ -1688,7 +1695,7 @@ class FeatureFlagsPoller {
1688
1695
  if (propertyType === 'cohort') {
1689
1696
  matches = matchCohort(prop, properties, this.cohorts, this.debugMode);
1690
1697
  } else {
1691
- matches = matchProperty(prop, properties);
1698
+ matches = matchProperty(prop, properties, warnFunction);
1692
1699
  }
1693
1700
 
1694
1701
  if (!matches) {
@@ -1830,7 +1837,7 @@ function _hash(key, distinctId, salt = '') {
1830
1837
  return parseInt(sha1Hash.digest('hex').slice(0, 15), 16) / LONG_SCALE;
1831
1838
  }
1832
1839
 
1833
- function matchProperty(property, propertyValues) {
1840
+ function matchProperty(property, propertyValues, warnFunction) {
1834
1841
  const key = property.key;
1835
1842
  const value = property.value;
1836
1843
  const operator = property.operator || 'exact';
@@ -1843,6 +1850,16 @@ function matchProperty(property, propertyValues) {
1843
1850
 
1844
1851
  const overrideValue = propertyValues[key];
1845
1852
 
1853
+ if (overrideValue == null && !NULL_VALUES_ALLOWED_OPERATORS.includes(operator)) {
1854
+ // if the value is null, just fail the feature flag comparison
1855
+ // this isn't an InconclusiveMatchError because the property value was provided.
1856
+ if (warnFunction) {
1857
+ warnFunction(`Property ${key} cannot have a value of null/undefined with the ${operator} operator`);
1858
+ }
1859
+
1860
+ return false;
1861
+ }
1862
+
1846
1863
  function computeExactMatch(value, overrideValue) {
1847
1864
  if (Array.isArray(value)) {
1848
1865
  return value.map(val => String(val).toLowerCase()).includes(String(overrideValue).toLowerCase());