posthog-node 4.3.2 → 4.4.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,13 @@
1
1
  # Next
2
2
 
3
+ # 4.4.1 - 2025-01-21
4
+
5
+ - Add option privacyMode to remove input and output from LLM Observability
6
+
7
+ # 4.4.0 - 2025-01-15
8
+
9
+ Switch from rusha to native (node:crypto) sha1 implementation
10
+
3
11
  # 4.3.2 - 2024-12-11
4
12
 
5
13
  1. REVERT: Fix bug where this SDK incorrectly sent `$feature_flag_called` events with null values when using `getFeatureFlagPayload`.
@@ -0,0 +1,70 @@
1
+ // @ts-check
2
+
3
+ import { bench, run, summary } from "mitata";
4
+ import { createHash } from "node:crypto"
5
+ import pkg from 'rusha';
6
+ const { createHash: createHashRusha } = pkg;
7
+
8
+ // eslint-disable-next-line
9
+ const LONG_SCALE = 0xfffffffffffffff
10
+
11
+ // from https://github.com/PostHog/posthog-js-lite/blob/2baa794708d78d5d10940817c3768e47abe2da99/posthog-node/src/feature-flags.ts#L460-L465
12
+ function _hashRusha(key, distinctId, salt = '') {
13
+ // rusha is a fast sha1 implementation in pure javascript
14
+ const sha1Hash = createHashRusha()
15
+ sha1Hash.update(`${key}.${distinctId}${salt}`)
16
+ return parseInt(sha1Hash.digest('hex').slice(0, 15), 16) / LONG_SCALE
17
+ }
18
+
19
+ function _hash(key, distinctId, salt = '') {
20
+ const sha1Hash = createHash("sha1")
21
+ sha1Hash.update(`${key}.${distinctId}${salt}`)
22
+ return parseInt(sha1Hash.digest('hex').slice(0, 15), 16) / LONG_SCALE
23
+ }
24
+
25
+ summary(() => {
26
+ bench("_hash with rusha", () => {
27
+ _hashRusha("test", "user_id")
28
+ });
29
+
30
+ bench("_hash with native", () => {
31
+ _hash("test", "user_id")
32
+ });
33
+ });
34
+
35
+ await run();
36
+
37
+
38
+ // !NODE
39
+ // node benchmarks/rusha-vs-native.mjs
40
+ // clk: ~3.99 GHz
41
+ // cpu: AMD Ryzen 7 7700 8-Core Processor
42
+ // runtime: node 22.11.0 (x64-linux)
43
+
44
+ // benchmark avg (min … max) p75 p99 (min … top 1%)
45
+ // ------------------------------------------- -------------------------------
46
+ // _hash with rusha 12.10 µs/iter 7.25 µs █
47
+ // (4.66 µs … 1.27 ms) 116.62 µs █▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
48
+ // _hash with native 547.04 ns/iter 435.45 ns █
49
+ // (370.08 ns … 3.61 µs) 3.58 µs █▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
50
+
51
+ // summary
52
+ // _hash with native
53
+ // 22.12x faster than _hash with rusha
54
+
55
+ // !BUN
56
+ // bun benchmarks/rusha-vs-native.mjs
57
+ // clk: ~5.04 GHz
58
+ // cpu: AMD Ryzen 7 7700 8-Core Processor
59
+ // runtime: bun 1.1.37 (x64-linux)
60
+
61
+ // benchmark avg (min … max) p75 p99 (min … top 1%)
62
+ // ------------------------------------------- -------------------------------
63
+ // _hash with rusha 10.00 µs/iter 4.96 µs █
64
+ // (2.60 µs … 2.78 ms) 45.85 µs ▂█▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
65
+ // _hash with native 471.82 ns/iter 420.00 ns █
66
+ // (370.00 ns … 949.79 µs) 1.99 µs █▆▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
67
+
68
+ // summary
69
+ // _hash with native
70
+ // 21.19x faster than _hash with rusha
package/lib/index.cjs.js CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var rusha = require('rusha');
5
+ var node_crypto = require('node:crypto');
6
6
 
7
- var version = "4.3.2";
7
+ var version = "4.4.1";
8
8
 
9
9
  var PostHogPersistedProperty;
10
10
  (function (PostHogPersistedProperty) {
@@ -13,6 +13,8 @@ var PostHogPersistedProperty;
13
13
  PostHogPersistedProperty["Props"] = "props";
14
14
  PostHogPersistedProperty["FeatureFlags"] = "feature_flags";
15
15
  PostHogPersistedProperty["FeatureFlagPayloads"] = "feature_flag_payloads";
16
+ PostHogPersistedProperty["BootstrapFeatureFlags"] = "bootstrap_feature_flags";
17
+ PostHogPersistedProperty["BootstrapFeatureFlagPayloads"] = "bootstrap_feature_flag_payloads";
16
18
  PostHogPersistedProperty["OverrideFeatureFlags"] = "override_feature_flags";
17
19
  PostHogPersistedProperty["Queue"] = "queue";
18
20
  PostHogPersistedProperty["OptedOut"] = "opted_out";
@@ -23,6 +25,7 @@ var PostHogPersistedProperty;
23
25
  PostHogPersistedProperty["InstalledAppBuild"] = "installed_app_build";
24
26
  PostHogPersistedProperty["InstalledAppVersion"] = "installed_app_version";
25
27
  PostHogPersistedProperty["SessionReplay"] = "session_replay";
28
+ PostHogPersistedProperty["DecideEndpointWasHit"] = "decide_endpoint_was_hit";
26
29
  })(PostHogPersistedProperty || (PostHogPersistedProperty = {}));
27
30
 
28
31
  function assert(truthyValue, message) {
@@ -66,6 +69,9 @@ function safeSetTimeout(fn, timeout) {
66
69
  // We unref if available to prevent Node.js hanging on exit
67
70
  t?.unref && t?.unref();
68
71
  return t;
72
+ }
73
+ function getFetch() {
74
+ return typeof fetch !== 'undefined' ? fetch : typeof global.fetch !== 'undefined' ? global.fetch : undefined;
69
75
  }
70
76
 
71
77
  // Copyright (c) 2013 Pieroxy <pieroxy@pieroxy.net>
@@ -1428,10 +1434,7 @@ class PostHogMemoryStorage {
1428
1434
  * This is currently solved by using the global fetch if available instead.
1429
1435
  * See https://github.com/PostHog/posthog-js-lite/issues/127 for more info
1430
1436
  */
1431
- let _fetch =
1432
- // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
1433
- // @ts-ignore
1434
- typeof fetch !== 'undefined' ? fetch : typeof global.fetch !== 'undefined' ? global.fetch : undefined;
1437
+ let _fetch = getFetch();
1435
1438
  if (!_fetch) {
1436
1439
  // eslint-disable-next-line @typescript-eslint/no-var-requires
1437
1440
  const axios = require('axios');
@@ -1786,8 +1789,7 @@ class FeatureFlagsPoller {
1786
1789
  // # uniformly distributed between 0 and 1, so if we want to show this feature to 20% of traffic
1787
1790
  // # we can do _hash(key, distinct_id) < 0.2
1788
1791
  function _hash(key, distinctId, salt = '') {
1789
- // rusha is a fast sha1 implementation in pure javascript
1790
- const sha1Hash = rusha.createHash();
1792
+ const sha1Hash = node_crypto.createHash('sha1');
1791
1793
  sha1Hash.update(`${key}.${distinctId}${salt}`);
1792
1794
  return parseInt(sha1Hash.digest('hex').slice(0, 15), 16) / LONG_SCALE;
1793
1795
  }