posthog-node 4.13.0 → 5.0.0-alpha.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,13 @@
1
+ # 5.0.0-alpha.1 - 2025-04-29
2
+
3
+ ## Breaking changes
4
+
5
+ 1. feat: migrate to native fetch, Node 18+ required
6
+
7
+ # 4.14.0 - 2025-04-24
8
+
9
+ 1. feat: Add super properties as a concept to the Node SDK
10
+
1
11
  # 4.13.0 - 2025-04-21
2
12
 
3
13
  1. feat: Add method to wait for local evaluation feature flag definitions to be loaded
package/lib/index.cjs.js CHANGED
@@ -22,7 +22,7 @@ function _interopNamespace(e) {
22
22
  return Object.freeze(n);
23
23
  }
24
24
 
25
- var version = "4.13.0";
25
+ var version = "5.0.0-alpha.1";
26
26
 
27
27
  var PostHogPersistedProperty;
28
28
  (function (PostHogPersistedProperty) {
@@ -326,9 +326,6 @@ function safeSetTimeout(fn, timeout) {
326
326
  t?.unref && t?.unref();
327
327
  return t;
328
328
  }
329
- function getFetch() {
330
- return typeof fetch !== 'undefined' ? fetch : typeof global.fetch !== 'undefined' ? global.fetch : undefined;
331
- }
332
329
  // FNV-1a hash function
333
330
  // https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
334
331
  // I know, I know, I'm rolling my own hash function, but I didn't want to take on
@@ -1595,6 +1592,30 @@ class PostHogCoreStateless {
1595
1592
  }
1596
1593
  return newSurveys ?? [];
1597
1594
  }
1595
+ get props() {
1596
+ if (!this._props) {
1597
+ this._props = this.getPersistedProperty(PostHogPersistedProperty.Props);
1598
+ }
1599
+ return this._props || {};
1600
+ }
1601
+ set props(val) {
1602
+ this._props = val;
1603
+ }
1604
+ async register(properties) {
1605
+ this.wrap(() => {
1606
+ this.props = {
1607
+ ...this.props,
1608
+ ...properties,
1609
+ };
1610
+ this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
1611
+ });
1612
+ }
1613
+ async unregister(property) {
1614
+ this.wrap(() => {
1615
+ delete this.props[property];
1616
+ this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
1617
+ });
1618
+ }
1598
1619
  /***
1599
1620
  *** QUEUEING AND FLUSHING
1600
1621
  ***/
@@ -1812,38 +1833,6 @@ class PostHogMemoryStorage {
1812
1833
  }
1813
1834
  }
1814
1835
 
1815
- /**
1816
- * Fetch wrapper
1817
- *
1818
- * We want to polyfill fetch when not available with axios but use it when it is.
1819
- * NOTE: The current version of Axios has an issue when in non-node environments like Clouflare Workers.
1820
- * This is currently solved by using the global fetch if available instead.
1821
- * See https://github.com/PostHog/posthog-js-lite/issues/127 for more info
1822
- */
1823
- let _fetch = getFetch();
1824
- if (!_fetch) {
1825
- // eslint-disable-next-line @typescript-eslint/no-var-requires
1826
- const axios = require('axios');
1827
- _fetch = async (url, options) => {
1828
- const res = await axios.request({
1829
- url,
1830
- headers: options.headers,
1831
- method: options.method.toLowerCase(),
1832
- data: options.body,
1833
- signal: options.signal,
1834
- // fetch only throws on network errors, not on HTTP errors
1835
- validateStatus: () => true
1836
- });
1837
- return {
1838
- status: res.status,
1839
- text: async () => res.data,
1840
- json: async () => res.data
1841
- };
1842
- };
1843
- }
1844
- // NOTE: We have to export this as default, even though we prefer named exports as we are relying on detecting "fetch" in the global scope
1845
- var fetch$1 = _fetch;
1846
-
1847
1836
  /**
1848
1837
  * A lazy value that is only computed when needed. Inspired by C#'s Lazy<T> class.
1849
1838
  */
@@ -1985,7 +1974,7 @@ class FeatureFlagsPoller {
1985
1974
  this.projectApiKey = projectApiKey;
1986
1975
  this.host = host;
1987
1976
  this.poller = undefined;
1988
- this.fetch = options.fetch || fetch$1;
1977
+ this.fetch = options.fetch || fetch;
1989
1978
  this.onError = options.onError;
1990
1979
  this.customHeaders = customHeaders;
1991
1980
  this.onLoad = options.onLoad;
@@ -3570,7 +3559,7 @@ class PostHog extends PostHogCoreStateless {
3570
3559
  return this._memoryStorage.setProperty(key, value);
3571
3560
  }
3572
3561
  fetch(url, options) {
3573
- return this.options.fetch ? this.options.fetch(url, options) : fetch$1(url, options);
3562
+ return this.options.fetch ? this.options.fetch(url, options) : fetch(url, options);
3574
3563
  }
3575
3564
  getLibraryId() {
3576
3565
  return 'posthog-node';