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.
- package/CHANGELOG.md +3 -0
- package/lib/index.cjs.js +31 -2
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.esm.js +31 -2
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +1 -0
- package/lib/posthog-node/src/feature-flags.d.ts +2 -0
- package/lib/posthog-node/src/posthog-node.d.ts +1 -0
- package/package.json +1 -1
- package/src/feature-flags.ts +11 -1
- package/src/posthog-node.ts +5 -0
|
@@ -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
package/src/feature-flags.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
package/src/posthog-node.ts
CHANGED
|
@@ -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 })
|