posthog-node 4.0.0-beta.2 → 4.0.0-beta.3
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 +11 -7
- package/lib/index.cjs.js +23 -14
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.esm.js +23 -14
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +3 -0
- package/lib/posthog-node/src/feature-flags.d.ts +7 -1
- package/package.json +1 -1
- package/src/feature-flags.ts +5 -2
- package/src/posthog-node.ts +2 -1
|
@@ -78,6 +78,9 @@ export declare abstract class PostHogCoreStateless {
|
|
|
78
78
|
*/
|
|
79
79
|
private flushBackground;
|
|
80
80
|
flush(): Promise<any[]>;
|
|
81
|
+
protected getCustomHeaders(): {
|
|
82
|
+
[key: string]: string;
|
|
83
|
+
};
|
|
81
84
|
private _flush;
|
|
82
85
|
private fetchWithRetry;
|
|
83
86
|
shutdown(shutdownTimeoutMs?: number): Promise<void>;
|
|
@@ -15,6 +15,9 @@ declare type FeatureFlagsPollerOptions = {
|
|
|
15
15
|
timeout?: number;
|
|
16
16
|
fetch?: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>;
|
|
17
17
|
onError?: (error: Error) => void;
|
|
18
|
+
customHeaders?: {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
};
|
|
18
21
|
};
|
|
19
22
|
declare class FeatureFlagsPoller {
|
|
20
23
|
pollingInterval: number;
|
|
@@ -31,7 +34,10 @@ declare class FeatureFlagsPoller {
|
|
|
31
34
|
fetch: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>;
|
|
32
35
|
debugMode: boolean;
|
|
33
36
|
onError?: (error: Error) => void;
|
|
34
|
-
|
|
37
|
+
customHeaders?: {
|
|
38
|
+
[key: string]: string;
|
|
39
|
+
};
|
|
40
|
+
constructor({ pollingInterval, personalApiKey, projectApiKey, timeout, host, customHeaders, ...options }: FeatureFlagsPollerOptions);
|
|
35
41
|
debug(enabled?: boolean): void;
|
|
36
42
|
getFeatureFlag(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<string | boolean | undefined>;
|
|
37
43
|
computeFeatureFlagPayloadLocally(key: string, matchValue: string | boolean): Promise<JsonType | undefined>;
|
package/package.json
CHANGED
package/src/feature-flags.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'rusha'
|
|
2
2
|
import { FeatureFlagCondition, FlagProperty, PostHogFeatureFlag, PropertyGroup } from './types'
|
|
3
|
-
import { version } from '../package.json'
|
|
4
3
|
import { JsonType, PostHogFetchOptions, PostHogFetchResponse } from 'posthog-core/src'
|
|
5
4
|
import { safeSetTimeout } from 'posthog-core/src/utils'
|
|
6
5
|
import fetch from './fetch'
|
|
@@ -38,6 +37,7 @@ type FeatureFlagsPollerOptions = {
|
|
|
38
37
|
timeout?: number
|
|
39
38
|
fetch?: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>
|
|
40
39
|
onError?: (error: Error) => void
|
|
40
|
+
customHeaders?: { [key: string]: string }
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
class FeatureFlagsPoller {
|
|
@@ -55,6 +55,7 @@ class FeatureFlagsPoller {
|
|
|
55
55
|
fetch: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>
|
|
56
56
|
debugMode: boolean = false
|
|
57
57
|
onError?: (error: Error) => void
|
|
58
|
+
customHeaders?: { [key: string]: string }
|
|
58
59
|
|
|
59
60
|
constructor({
|
|
60
61
|
pollingInterval,
|
|
@@ -62,6 +63,7 @@ class FeatureFlagsPoller {
|
|
|
62
63
|
projectApiKey,
|
|
63
64
|
timeout,
|
|
64
65
|
host,
|
|
66
|
+
customHeaders,
|
|
65
67
|
...options
|
|
66
68
|
}: FeatureFlagsPollerOptions) {
|
|
67
69
|
this.pollingInterval = pollingInterval
|
|
@@ -78,6 +80,7 @@ class FeatureFlagsPoller {
|
|
|
78
80
|
// NOTE: as any is required here as the AbortSignal typing is slightly misaligned but works just fine
|
|
79
81
|
this.fetch = options.fetch || fetch
|
|
80
82
|
this.onError = options.onError
|
|
83
|
+
this.customHeaders = customHeaders
|
|
81
84
|
|
|
82
85
|
void this.loadFeatureFlags()
|
|
83
86
|
}
|
|
@@ -413,9 +416,9 @@ class FeatureFlagsPoller {
|
|
|
413
416
|
const options: PostHogFetchOptions = {
|
|
414
417
|
method: 'GET',
|
|
415
418
|
headers: {
|
|
419
|
+
...this.customHeaders,
|
|
416
420
|
'Content-Type': 'application/json',
|
|
417
421
|
Authorization: `Bearer ${this.personalApiKey}`,
|
|
418
|
-
'user-agent': `posthog-node/${version}`,
|
|
419
422
|
},
|
|
420
423
|
}
|
|
421
424
|
|
package/src/posthog-node.ts
CHANGED
|
@@ -58,6 +58,7 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
58
58
|
onError: (err: Error) => {
|
|
59
59
|
this._events.emit('error', err)
|
|
60
60
|
},
|
|
61
|
+
customHeaders: this.getCustomHeaders(),
|
|
61
62
|
})
|
|
62
63
|
}
|
|
63
64
|
this.distinctIdHasSentFlagCalls = {}
|
|
@@ -83,7 +84,7 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
83
84
|
return version
|
|
84
85
|
}
|
|
85
86
|
getCustomUserAgent(): string {
|
|
86
|
-
return
|
|
87
|
+
return `${this.getLibraryId()}/${this.getLibraryVersion()}`
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
enable(): Promise<void> {
|