posthog-node 4.5.2 → 4.7.0

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
@@ -446,6 +446,7 @@ declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
446
446
  sendFeatureFlagEvents?: boolean;
447
447
  disableGeoip?: boolean;
448
448
  }): Promise<JsonType | undefined>;
449
+ getRemoteConfigPayload(flagKey: string): Promise<JsonType | undefined>;
449
450
  isFeatureEnabled(key: string, distinctId: string, options?: {
450
451
  groups?: Record<string, string>;
451
452
  personProperties?: Record<string, string>;
package/lib/index.esm.js CHANGED
@@ -3,7 +3,7 @@ import { createReadStream } from 'node:fs';
3
3
  import { createInterface } from 'node:readline';
4
4
  import { posix, dirname, sep } from 'node:path';
5
5
 
6
- var version = "4.5.2";
6
+ var version = "4.7.0";
7
7
 
8
8
  var PostHogPersistedProperty;
9
9
  (function (PostHogPersistedProperty) {
@@ -1755,16 +1755,19 @@ class FeatureFlagsPoller {
1755
1755
  }
1756
1756
  }
1757
1757
  }
1758
- async _requestFeatureFlagDefinitions() {
1759
- const url = `${this.host}/api/feature_flag/local_evaluation?token=${this.projectApiKey}&send_cohorts`;
1760
- const options = {
1761
- method: 'GET',
1758
+ getPersonalApiKeyRequestOptions(method = 'GET') {
1759
+ return {
1760
+ method,
1762
1761
  headers: {
1763
1762
  ...this.customHeaders,
1764
1763
  'Content-Type': 'application/json',
1765
1764
  Authorization: `Bearer ${this.personalApiKey}`
1766
1765
  }
1767
1766
  };
1767
+ }
1768
+ async _requestFeatureFlagDefinitions() {
1769
+ const url = `${this.host}/api/feature_flag/local_evaluation?token=${this.projectApiKey}&send_cohorts`;
1770
+ const options = this.getPersonalApiKeyRequestOptions();
1768
1771
  let abortTimeout = null;
1769
1772
  if (this.timeout && typeof this.timeout === 'number') {
1770
1773
  const controller = new AbortController();
@@ -1782,6 +1785,23 @@ class FeatureFlagsPoller {
1782
1785
  stopPoller() {
1783
1786
  clearTimeout(this.poller);
1784
1787
  }
1788
+ _requestRemoteConfigPayload(flagKey) {
1789
+ const url = `${this.host}/api/projects/@current/feature_flags/${flagKey}/remote_config/`;
1790
+ const options = this.getPersonalApiKeyRequestOptions();
1791
+ let abortTimeout = null;
1792
+ if (this.timeout && typeof this.timeout === 'number') {
1793
+ const controller = new AbortController();
1794
+ abortTimeout = safeSetTimeout(() => {
1795
+ controller.abort();
1796
+ }, this.timeout);
1797
+ options.signal = controller.signal;
1798
+ }
1799
+ try {
1800
+ return this.fetch(url, options);
1801
+ } finally {
1802
+ clearTimeout(abortTimeout);
1803
+ }
1804
+ }
1785
1805
  }
1786
1806
  // # This function takes a distinct_id and a feature flag key and returns a float between 0 and 1.
1787
1807
  // # Given the same distinct_id and key, it'll always return the same float. These floats are
@@ -3155,6 +3175,9 @@ class PostHog extends PostHogCoreStateless {
3155
3175
  }
3156
3176
  return response;
3157
3177
  }
3178
+ async getRemoteConfigPayload(flagKey) {
3179
+ return (await this.featureFlagsPoller?._requestRemoteConfigPayload(flagKey))?.json();
3180
+ }
3158
3181
  async isFeatureEnabled(key, distinctId, options) {
3159
3182
  const feat = await this.getFeatureFlag(key, distinctId, options);
3160
3183
  if (feat === undefined) {