posthog-node 2.5.3 → 2.5.4

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.
@@ -11,6 +11,7 @@ export declare abstract class PostHogCoreStateless {
11
11
  private requestTimeout;
12
12
  private captureMode;
13
13
  private removeDebugCallback?;
14
+ private debugMode;
14
15
  private pendingPromises;
15
16
  private _optoutOverride;
16
17
  protected _events: SimpleEventEmitter;
@@ -27,7 +27,9 @@ declare class FeatureFlagsPoller {
27
27
  host: FeatureFlagsPollerOptions['host'];
28
28
  poller?: NodeJS.Timeout;
29
29
  fetch: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>;
30
+ debugMode: boolean;
30
31
  constructor({ pollingInterval, personalApiKey, projectApiKey, timeout, host, ...options }: FeatureFlagsPollerOptions);
32
+ debug(enabled?: boolean): void;
31
33
  getFeatureFlag(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<string | boolean | undefined>;
32
34
  computeFeatureFlagPayloadLocally(key: string, matchValue: string | boolean): Promise<JsonType | undefined>;
33
35
  getAllFlagsAndPayloads(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<{
@@ -23,6 +23,7 @@ export declare class PostHog extends PostHogCoreStateless implements PostHogNode
23
23
  getCustomUserAgent(): string;
24
24
  enable(): void;
25
25
  disable(): void;
26
+ debug(enabled?: boolean): void;
26
27
  capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp }: EventMessageV1): void;
27
28
  identify({ distinctId, properties }: IdentifyMessageV1): void;
28
29
  alias(data: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthog-node",
3
- "version": "2.5.3",
3
+ "version": "2.5.4",
4
4
  "description": "PostHog Node.js integration",
5
5
  "repository": "PostHog/posthog-node",
6
6
  "scripts": {
@@ -51,6 +51,7 @@ class FeatureFlagsPoller {
51
51
  host: FeatureFlagsPollerOptions['host']
52
52
  poller?: NodeJS.Timeout
53
53
  fetch: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>
54
+ debugMode: boolean = false
54
55
 
55
56
  constructor({
56
57
  pollingInterval,
@@ -76,6 +77,10 @@ class FeatureFlagsPoller {
76
77
  void this.loadFeatureFlags()
77
78
  }
78
79
 
80
+ debug(enabled: boolean = true): void {
81
+ this.debugMode = enabled
82
+ }
83
+
79
84
  async getFeatureFlag(
80
85
  key: string,
81
86
  distinctId: string,
@@ -102,9 +107,14 @@ class FeatureFlagsPoller {
102
107
  if (featureFlag !== undefined) {
103
108
  try {
104
109
  response = this.computeFlagLocally(featureFlag, distinctId, groups, personProperties, groupProperties)
110
+ if (this.debugMode) {
111
+ console.debug(`Successfully computed flag locally: ${key} -> ${response}`)
112
+ }
105
113
  } catch (e) {
106
114
  if (e instanceof InconclusiveMatchError) {
107
- console.error(`InconclusiveMatchError when computing flag locally: ${key}: ${e}`)
115
+ if (this.debugMode) {
116
+ console.debug(`InconclusiveMatchError when computing flag locally: ${key}: ${e}`)
117
+ }
108
118
  } else if (e instanceof Error) {
109
119
  console.error(`Error computing flag locally: ${key}: ${e}`)
110
120
  }
@@ -92,6 +92,11 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
92
92
  return super.optOut()
93
93
  }
94
94
 
95
+ debug(enabled: boolean = true): void {
96
+ super.debug(enabled)
97
+ this.featureFlagsPoller?.debug(enabled)
98
+ }
99
+
95
100
  capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp }: EventMessageV1): void {
96
101
  const _capture = (props: EventMessageV1['properties']): void => {
97
102
  super.captureStateless(distinctId, event, props, { timestamp })