posthog-node 4.0.1 → 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,3 +1,12 @@
1
+ # Next
2
+
3
+ # 4.1.1 - 2024-08-20
4
+
5
+ 1. Local evaluation returns correct results on `undefined/null` values
6
+ # 4.1.0 - 2024-08-14
7
+
8
+ 1. chore: change host to new address.
9
+ 2. chore: bump axios to 1.7.4 (fixes [CVE-2024-39338](https://github.com/advisories/GHSA-8hc4-vh64-cxmj))
1
10
 
2
11
  # 4.0.1 - 2024-04-25
3
12
 
@@ -27,7 +36,6 @@
27
36
  1. Fixed an issue where `shutdown` would potentially exit early if a flush was already in progress
28
37
  2. Fixes some typos in types
29
38
 
30
-
31
39
  # 4.0.0-beta.3 - 2024-03-13
32
40
 
33
41
  1. Sets `User-Agent` headers with SDK name and version for RN
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.0.1";
7
+ var version = "4.1.1";
8
8
 
9
9
  var PostHogPersistedProperty;
10
10
  (function (PostHogPersistedProperty) {
@@ -960,7 +960,7 @@ class PostHogCoreStateless {
960
960
  this._isInitialized = false;
961
961
  assert(apiKey, "You must pass your PostHog project's api key.");
962
962
  this.apiKey = apiKey;
963
- this.host = removeTrailingSlash(options?.host || 'https://app.posthog.com');
963
+ this.host = removeTrailingSlash(options?.host || 'https://us.i.posthog.com');
964
964
  this.flushAt = options?.flushAt ? Math.max(options?.flushAt, 1) : 20;
965
965
  this.maxBatchSize = Math.max(this.flushAt, options?.maxBatchSize ?? 100);
966
966
  this.maxQueueSize = Math.max(this.flushAt, options?.maxQueueSize ?? 1000);
@@ -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());
@@ -2523,7 +2540,7 @@ class PostHogSentryIntegration {
2523
2540
  this.organization = organization;
2524
2541
  this.prefix = prefix;
2525
2542
  this.name = 'posthog-node';
2526
- this.posthogHost = posthog.options.host ?? 'https://app.posthog.com';
2543
+ this.posthogHost = posthog.options.host ?? 'https://us.i.posthog.com';
2527
2544
  }
2528
2545
 
2529
2546
  setupOnce(addGlobalEventProcessor, getCurrentHub) {