posthog-node 2.0.0-alpha3 → 2.0.0-alpha6
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.cjs.js +40 -13
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.esm.js +40 -13
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/eventemitter.d.ts +2 -2
- package/lib/posthog-core/src/index.d.ts +4 -1
- package/lib/posthog-core/src/storage-memory.d.ts +6 -0
- package/lib/posthog-node/src/posthog-node.d.ts +3 -1
- package/package.json +1 -1
- package/src/posthog-node.ts +15 -8
package/src/posthog-node.ts
CHANGED
|
@@ -7,12 +7,15 @@ import {
|
|
|
7
7
|
PostHogFetchResponse,
|
|
8
8
|
PostHogPersistedProperty,
|
|
9
9
|
} from '../../posthog-core/src'
|
|
10
|
+
import { PostHogMemoryStorage } from '../../posthog-core/src/storage-memory'
|
|
10
11
|
import { EventMessageV1, GroupIdentifyMessage, IdentifyMessageV1, PostHogNodeV1 } from './types'
|
|
11
12
|
|
|
12
|
-
export type PostHogOptions = PosthogCoreOptions
|
|
13
|
+
export type PostHogOptions = PosthogCoreOptions & {
|
|
14
|
+
persistence?: 'memory'
|
|
15
|
+
}
|
|
13
16
|
|
|
14
17
|
class PostHog extends PostHogCore {
|
|
15
|
-
private _memoryStorage
|
|
18
|
+
private _memoryStorage = new PostHogMemoryStorage()
|
|
16
19
|
|
|
17
20
|
constructor(apiKey: string, options: PostHogOptions = {}) {
|
|
18
21
|
options.captureMode = options?.captureMode || 'json'
|
|
@@ -22,11 +25,11 @@ class PostHog extends PostHogCore {
|
|
|
22
25
|
}
|
|
23
26
|
|
|
24
27
|
getPersistedProperty(key: PostHogPersistedProperty): any | undefined {
|
|
25
|
-
return this._memoryStorage
|
|
28
|
+
return this._memoryStorage.getProperty(key)
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
setPersistedProperty(key: PostHogPersistedProperty, value: any | null): void {
|
|
29
|
-
this._memoryStorage
|
|
32
|
+
return this._memoryStorage.setProperty(key, value)
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
getSessionId(): string | undefined {
|
|
@@ -59,10 +62,14 @@ export class PostHogGlobal implements PostHogNodeV1 {
|
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
private reInit(distinctId: string): void {
|
|
62
|
-
//
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
65
|
+
// Certain properties we want to persist
|
|
66
|
+
const propertiesToKeep = [PostHogPersistedProperty.Queue, PostHogPersistedProperty.OptedOut]
|
|
67
|
+
|
|
68
|
+
for (const key in PostHogPersistedProperty) {
|
|
69
|
+
if (!propertiesToKeep.includes(key as any)) {
|
|
70
|
+
this._sharedClient.setPersistedProperty((PostHogPersistedProperty as any)[key], null)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
66
73
|
this._sharedClient.setPersistedProperty(PostHogPersistedProperty.DistinctId, distinctId)
|
|
67
74
|
}
|
|
68
75
|
|