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/lib/index.d.ts CHANGED
@@ -49,6 +49,8 @@ declare enum PostHogPersistedProperty {
49
49
  Props = "props",
50
50
  FeatureFlags = "feature_flags",
51
51
  FeatureFlagPayloads = "feature_flag_payloads",
52
+ BootstrapFeatureFlags = "bootstrap_feature_flags",
53
+ BootstrapFeatureFlagPayloads = "bootstrap_feature_flag_payloads",
52
54
  OverrideFeatureFlags = "override_feature_flags",
53
55
  Queue = "queue",
54
56
  OptedOut = "opted_out",
@@ -58,7 +60,8 @@ declare enum PostHogPersistedProperty {
58
60
  GroupProperties = "group_properties",
59
61
  InstalledAppBuild = "installed_app_build",
60
62
  InstalledAppVersion = "installed_app_version",
61
- SessionReplay = "session_replay"
63
+ SessionReplay = "session_replay",
64
+ DecideEndpointWasHit = "decide_endpoint_was_hit"
62
65
  }
63
66
  type PostHogFetchOptions = {
64
67
  method: 'GET' | 'POST' | 'PUT' | 'PATCH';
@@ -319,13 +322,25 @@ type PostHogNodeV1 = {
319
322
  }): Promise<string | boolean | undefined>;
320
323
  /**
321
324
  * @description Retrieves payload associated with the specified flag and matched value that is passed in.
322
- * (Expected to be used in conjunction with getFeatureFlag but allows for manual lookup).
323
- * If matchValue isn't passed, getFeatureFlag is called implicitly.
324
- * Will try to evaluate for payload locally first otherwise default to network call if allowed
325
+ *
326
+ * IMPORTANT: The `matchValue` parameter should be the value you previously obtained from `getFeatureFlag()`.
327
+ * If matchValue isn't passed (or is undefined), this method will automatically call `getFeatureFlag()`
328
+ * internally to fetch the flag value, which could result in a network call to the PostHog server if this flag can
329
+ * not be evaluated locally. This means that omitting `matchValue` will potentially:
330
+ * - Bypass local evaluation
331
+ * - Count as an additional flag evaluation against your quota
332
+ * - Impact performance due to the extra network request
333
+ *
334
+ * Example usage:
335
+ * ```js
336
+ * const flagValue = await client.getFeatureFlag('my-flag', distinctId);
337
+ * const payload = await client.getFeatureFlagPayload('my-flag', distinctId, flagValue);
338
+ * ```
325
339
  *
326
340
  * @param key the unique key of your feature flag
327
341
  * @param distinctId the current unique id
328
- * @param matchValue optional- the matched flag string or boolean
342
+ * @param matchValue The flag value previously obtained from calling `getFeatureFlag()`. Can be a string or boolean.
343
+ * To avoid extra network calls, pass this parameter when you can.
329
344
  * @param options: dict with optional parameters below
330
345
  * @param onlyEvaluateLocally optional - whether to only evaluate the flag locally. Defaults to false.
331
346
  *
@@ -360,6 +375,7 @@ type PostHogNodeV1 = {
360
375
  type PostHogOptions = PostHogCoreOptions & {
361
376
  persistence?: 'memory';
362
377
  personalApiKey?: string;
378
+ privacyMode?: boolean;
363
379
  featureFlagsPollingInterval?: number;
364
380
  maxCacheSize?: number;
365
381
  fetch?: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>;
package/lib/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
- import { createHash } from 'rusha';
1
+ import { createHash } from 'node:crypto';
2
2
 
3
- var version = "4.3.2";
3
+ var version = "4.4.1";
4
4
 
5
5
  var PostHogPersistedProperty;
6
6
  (function (PostHogPersistedProperty) {
@@ -9,6 +9,8 @@ var PostHogPersistedProperty;
9
9
  PostHogPersistedProperty["Props"] = "props";
10
10
  PostHogPersistedProperty["FeatureFlags"] = "feature_flags";
11
11
  PostHogPersistedProperty["FeatureFlagPayloads"] = "feature_flag_payloads";
12
+ PostHogPersistedProperty["BootstrapFeatureFlags"] = "bootstrap_feature_flags";
13
+ PostHogPersistedProperty["BootstrapFeatureFlagPayloads"] = "bootstrap_feature_flag_payloads";
12
14
  PostHogPersistedProperty["OverrideFeatureFlags"] = "override_feature_flags";
13
15
  PostHogPersistedProperty["Queue"] = "queue";
14
16
  PostHogPersistedProperty["OptedOut"] = "opted_out";
@@ -19,6 +21,7 @@ var PostHogPersistedProperty;
19
21
  PostHogPersistedProperty["InstalledAppBuild"] = "installed_app_build";
20
22
  PostHogPersistedProperty["InstalledAppVersion"] = "installed_app_version";
21
23
  PostHogPersistedProperty["SessionReplay"] = "session_replay";
24
+ PostHogPersistedProperty["DecideEndpointWasHit"] = "decide_endpoint_was_hit";
22
25
  })(PostHogPersistedProperty || (PostHogPersistedProperty = {}));
23
26
 
24
27
  function assert(truthyValue, message) {
@@ -62,6 +65,9 @@ function safeSetTimeout(fn, timeout) {
62
65
  // We unref if available to prevent Node.js hanging on exit
63
66
  t?.unref && t?.unref();
64
67
  return t;
68
+ }
69
+ function getFetch() {
70
+ return typeof fetch !== 'undefined' ? fetch : typeof global.fetch !== 'undefined' ? global.fetch : undefined;
65
71
  }
66
72
 
67
73
  // Copyright (c) 2013 Pieroxy <pieroxy@pieroxy.net>
@@ -1424,10 +1430,7 @@ class PostHogMemoryStorage {
1424
1430
  * This is currently solved by using the global fetch if available instead.
1425
1431
  * See https://github.com/PostHog/posthog-js-lite/issues/127 for more info
1426
1432
  */
1427
- let _fetch =
1428
- // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
1429
- // @ts-ignore
1430
- typeof fetch !== 'undefined' ? fetch : typeof global.fetch !== 'undefined' ? global.fetch : undefined;
1433
+ let _fetch = getFetch();
1431
1434
  if (!_fetch) {
1432
1435
  // eslint-disable-next-line @typescript-eslint/no-var-requires
1433
1436
  const axios = require('axios');
@@ -1782,8 +1785,7 @@ class FeatureFlagsPoller {
1782
1785
  // # uniformly distributed between 0 and 1, so if we want to show this feature to 20% of traffic
1783
1786
  // # we can do _hash(key, distinct_id) < 0.2
1784
1787
  function _hash(key, distinctId, salt = '') {
1785
- // rusha is a fast sha1 implementation in pure javascript
1786
- const sha1Hash = createHash();
1788
+ const sha1Hash = createHash('sha1');
1787
1789
  sha1Hash.update(`${key}.${distinctId}${salt}`);
1788
1790
  return parseInt(sha1Hash.digest('hex').slice(0, 15), 16) / LONG_SCALE;
1789
1791
  }