posthog-node 3.2.0 → 3.2.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 +4 -0
- package/lib/index.cjs.js +26 -17
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +26 -17
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-node/src/feature-flags.d.ts +2 -0
- package/package.json +1 -1
- package/src/feature-flags.ts +5 -2
- package/src/posthog-node.ts +3 -0
|
@@ -14,6 +14,7 @@ declare type FeatureFlagsPollerOptions = {
|
|
|
14
14
|
pollingInterval: number;
|
|
15
15
|
timeout?: number;
|
|
16
16
|
fetch?: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>;
|
|
17
|
+
onError?: (error: Error) => void;
|
|
17
18
|
};
|
|
18
19
|
declare class FeatureFlagsPoller {
|
|
19
20
|
pollingInterval: number;
|
|
@@ -29,6 +30,7 @@ declare class FeatureFlagsPoller {
|
|
|
29
30
|
poller?: NodeJS.Timeout;
|
|
30
31
|
fetch: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>;
|
|
31
32
|
debugMode: boolean;
|
|
33
|
+
onError?: (error: Error) => void;
|
|
32
34
|
constructor({ pollingInterval, personalApiKey, projectApiKey, timeout, host, ...options }: FeatureFlagsPollerOptions);
|
|
33
35
|
debug(enabled?: boolean): void;
|
|
34
36
|
getFeatureFlag(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<string | boolean | undefined>;
|
package/package.json
CHANGED
package/src/feature-flags.ts
CHANGED
|
@@ -37,6 +37,7 @@ type FeatureFlagsPollerOptions = {
|
|
|
37
37
|
pollingInterval: number
|
|
38
38
|
timeout?: number
|
|
39
39
|
fetch?: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>
|
|
40
|
+
onError?: (error: Error) => void
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
class FeatureFlagsPoller {
|
|
@@ -53,6 +54,7 @@ class FeatureFlagsPoller {
|
|
|
53
54
|
poller?: NodeJS.Timeout
|
|
54
55
|
fetch: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>
|
|
55
56
|
debugMode: boolean = false
|
|
57
|
+
onError?: (error: Error) => void
|
|
56
58
|
|
|
57
59
|
constructor({
|
|
58
60
|
pollingInterval,
|
|
@@ -75,6 +77,7 @@ class FeatureFlagsPoller {
|
|
|
75
77
|
this.poller = undefined
|
|
76
78
|
// NOTE: as any is required here as the AbortSignal typing is slightly misaligned but works just fine
|
|
77
79
|
this.fetch = options.fetch || fetch
|
|
80
|
+
this.onError = options.onError
|
|
78
81
|
|
|
79
82
|
void this.loadFeatureFlags()
|
|
80
83
|
}
|
|
@@ -177,7 +180,7 @@ class FeatureFlagsPoller {
|
|
|
177
180
|
if (e instanceof InconclusiveMatchError) {
|
|
178
181
|
// do nothing
|
|
179
182
|
} else if (e instanceof Error) {
|
|
180
|
-
|
|
183
|
+
this.onError?.(new Error(`Error computing flag locally: ${flag.key}: ${e}`))
|
|
181
184
|
}
|
|
182
185
|
fallbackToDecide = true
|
|
183
186
|
}
|
|
@@ -395,7 +398,7 @@ class FeatureFlagsPoller {
|
|
|
395
398
|
// if an error that is not an instance of ClientError is thrown
|
|
396
399
|
// we silently ignore the error when reloading feature flags
|
|
397
400
|
if (err instanceof ClientError) {
|
|
398
|
-
|
|
401
|
+
this.onError?.(err)
|
|
399
402
|
}
|
|
400
403
|
}
|
|
401
404
|
}
|
package/src/posthog-node.ts
CHANGED
|
@@ -56,6 +56,9 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
56
56
|
timeout: options.requestTimeout ?? 10000, // 10 seconds
|
|
57
57
|
host: this.host,
|
|
58
58
|
fetch: options.fetch,
|
|
59
|
+
onError: (err: Error) => {
|
|
60
|
+
this._events.emit('error', err)
|
|
61
|
+
},
|
|
59
62
|
})
|
|
60
63
|
}
|
|
61
64
|
this.distinctIdHasSentFlagCalls = {}
|