posthog-js-lite 2.0.0-alpha5 → 2.0.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 +3 -0
- package/README.md +68 -0
- package/lib/index.cjs.js +269 -85
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +55 -12
- package/lib/index.esm.js +269 -85
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +33 -9
- package/lib/posthog-core/src/types.d.ts +26 -3
- package/lib/posthog-core/src/utils.d.ts +0 -1
- package/lib/posthog-web/src/storage.d.ts +1 -5
- package/package.json +2 -2
- package/src/posthog-web.ts +5 -1
- package/src/storage.ts +18 -9
package/lib/index.d.ts
CHANGED
|
@@ -5,21 +5,31 @@ declare type PosthogCoreOptions = {
|
|
|
5
5
|
enable?: boolean;
|
|
6
6
|
sendFeatureFlagEvent?: boolean;
|
|
7
7
|
preloadFeatureFlags?: boolean;
|
|
8
|
-
|
|
8
|
+
bootstrap?: {
|
|
9
|
+
distinctId?: string;
|
|
10
|
+
isIdentifiedId?: boolean;
|
|
11
|
+
featureFlags?: Record<string, boolean | string>;
|
|
12
|
+
featureFlagPayloads?: Record<string, JsonType>;
|
|
13
|
+
};
|
|
9
14
|
fetchRetryCount?: number;
|
|
10
15
|
fetchRetryDelay?: number;
|
|
16
|
+
requestTimeout?: number;
|
|
11
17
|
sessionExpirationTimeSeconds?: number;
|
|
12
18
|
captureMode?: 'json' | 'form';
|
|
13
19
|
};
|
|
14
20
|
declare enum PostHogPersistedProperty {
|
|
21
|
+
AnonymousId = "anonymous_id",
|
|
15
22
|
DistinctId = "distinct_id",
|
|
16
23
|
Props = "props",
|
|
17
24
|
FeatureFlags = "feature_flags",
|
|
25
|
+
FeatureFlagPayloads = "feature_flag_payloads",
|
|
18
26
|
OverrideFeatureFlags = "override_feature_flags",
|
|
19
27
|
Queue = "queue",
|
|
20
28
|
OptedOut = "opted_out",
|
|
21
29
|
SessionId = "session_id",
|
|
22
|
-
SessionLastTimestamp = "session_timestamp"
|
|
30
|
+
SessionLastTimestamp = "session_timestamp",
|
|
31
|
+
PersonProperties = "person_properties",
|
|
32
|
+
GroupProperties = "group_properties"
|
|
23
33
|
}
|
|
24
34
|
declare type PostHogFetchOptions = {
|
|
25
35
|
method: 'GET' | 'POST' | 'PUT' | 'PATCH';
|
|
@@ -28,11 +38,13 @@ declare type PostHogFetchOptions = {
|
|
|
28
38
|
headers: {
|
|
29
39
|
[key: string]: string;
|
|
30
40
|
};
|
|
31
|
-
body
|
|
41
|
+
body?: string;
|
|
42
|
+
signal?: AbortSignal;
|
|
32
43
|
};
|
|
33
44
|
declare type PostHogFetchResponse = {
|
|
34
45
|
status: number;
|
|
35
46
|
text: () => Promise<string>;
|
|
47
|
+
json: () => Promise<any>;
|
|
36
48
|
};
|
|
37
49
|
declare type PostHogEventProperties = {
|
|
38
50
|
[key: string]: any;
|
|
@@ -60,8 +72,15 @@ declare type PostHogDecideResponse = {
|
|
|
60
72
|
featureFlags: {
|
|
61
73
|
[key: string]: string | boolean;
|
|
62
74
|
};
|
|
75
|
+
featureFlagPayloads: {
|
|
76
|
+
[key: string]: JsonType;
|
|
77
|
+
};
|
|
78
|
+
errorsWhileComputingFlags: boolean;
|
|
63
79
|
sessionRecording: boolean;
|
|
64
|
-
};
|
|
80
|
+
};
|
|
81
|
+
declare type JsonType = string | number | boolean | null | {
|
|
82
|
+
[key: string]: JsonType;
|
|
83
|
+
} | Array<JsonType>;
|
|
65
84
|
|
|
66
85
|
interface RetriableOptions {
|
|
67
86
|
retryCount?: number;
|
|
@@ -80,9 +99,10 @@ declare class SimpleEventEmitter {
|
|
|
80
99
|
|
|
81
100
|
declare abstract class PostHogCore {
|
|
82
101
|
private apiKey;
|
|
83
|
-
|
|
102
|
+
host: string;
|
|
84
103
|
private flushAt;
|
|
85
104
|
private flushInterval;
|
|
105
|
+
private requestTimeout;
|
|
86
106
|
private captureMode;
|
|
87
107
|
private sendFeatureFlagEvent;
|
|
88
108
|
private flagCallReported;
|
|
@@ -90,8 +110,6 @@ declare abstract class PostHogCore {
|
|
|
90
110
|
protected _events: SimpleEventEmitter;
|
|
91
111
|
protected _flushTimer?: any;
|
|
92
112
|
protected _decideResponsePromise?: Promise<PostHogDecideResponse>;
|
|
93
|
-
protected _decideTimer?: any;
|
|
94
|
-
protected _decidePollInterval: number;
|
|
95
113
|
protected _retryOptions: RetriableOptions;
|
|
96
114
|
protected _sessionExpirationTimeSeconds: number;
|
|
97
115
|
abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
|
|
@@ -103,18 +121,21 @@ declare abstract class PostHogCore {
|
|
|
103
121
|
private _optoutOverride;
|
|
104
122
|
constructor(apiKey: string, options?: PosthogCoreOptions);
|
|
105
123
|
protected getCommonEventProperties(): any;
|
|
124
|
+
protected setupBootstrap(options?: Partial<PosthogCoreOptions>): void;
|
|
106
125
|
private get props();
|
|
107
126
|
private set props(value);
|
|
127
|
+
private clearProps;
|
|
108
128
|
private _props;
|
|
109
129
|
get optedOut(): boolean;
|
|
110
130
|
optIn(): void;
|
|
111
131
|
optOut(): void;
|
|
112
132
|
on(event: string, cb: (...args: any[]) => void): () => void;
|
|
113
|
-
reset(): void;
|
|
133
|
+
reset(propertiesToKeep?: PostHogPersistedProperty[]): void;
|
|
114
134
|
debug(enabled?: boolean): void;
|
|
115
135
|
private buildPayload;
|
|
116
136
|
getSessionId(): string | undefined;
|
|
117
137
|
resetSessionId(): void;
|
|
138
|
+
getAnonymousId(): string;
|
|
118
139
|
getDistinctId(): string;
|
|
119
140
|
register(properties: {
|
|
120
141
|
[key: string]: any;
|
|
@@ -126,7 +147,7 @@ declare abstract class PostHogCore {
|
|
|
126
147
|
identify(distinctId?: string, properties?: PostHogEventProperties): this;
|
|
127
148
|
capture(event: string, properties?: {
|
|
128
149
|
[key: string]: any;
|
|
129
|
-
}): this;
|
|
150
|
+
}, forceSendFeatureFlags?: boolean): this;
|
|
130
151
|
alias(alias: string): this;
|
|
131
152
|
autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties): this;
|
|
132
153
|
/***
|
|
@@ -137,17 +158,39 @@ declare abstract class PostHogCore {
|
|
|
137
158
|
}): this;
|
|
138
159
|
group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties): this;
|
|
139
160
|
groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties): this;
|
|
161
|
+
/***
|
|
162
|
+
* PROPERTIES
|
|
163
|
+
***/
|
|
164
|
+
personProperties(properties: {
|
|
165
|
+
[type: string]: string;
|
|
166
|
+
}): this;
|
|
167
|
+
groupProperties(properties: {
|
|
168
|
+
[type: string]: Record<string, string>;
|
|
169
|
+
}): this;
|
|
140
170
|
/***
|
|
141
171
|
*** FEATURE FLAGS
|
|
142
172
|
***/
|
|
143
173
|
private decideAsync;
|
|
144
174
|
private _decideAsync;
|
|
145
|
-
|
|
175
|
+
private setKnownFeatureFlags;
|
|
176
|
+
private setKnownFeatureFlagPayloads;
|
|
177
|
+
getFeatureFlag(key: string): boolean | string | undefined;
|
|
178
|
+
getFeatureFlagPayload(key: string): JsonType | undefined;
|
|
179
|
+
getFeatureFlagPayloads(): PostHogDecideResponse['featureFlagPayloads'] | undefined;
|
|
180
|
+
_parsePayload(response: any): any;
|
|
146
181
|
getFeatureFlags(): PostHogDecideResponse['featureFlags'] | undefined;
|
|
147
|
-
|
|
148
|
-
|
|
182
|
+
getFeatureFlagsAndPayloads(): {
|
|
183
|
+
flags: PostHogDecideResponse['featureFlags'] | undefined;
|
|
184
|
+
payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
|
|
185
|
+
};
|
|
186
|
+
isFeatureEnabled(key: string): boolean | undefined;
|
|
187
|
+
reloadFeatureFlagsAsync(sendAnonDistinctId?: boolean): Promise<PostHogDecideResponse['featureFlags']>;
|
|
149
188
|
onFeatureFlags(cb: (flags: PostHogDecideResponse['featureFlags']) => void): () => void;
|
|
189
|
+
onFeatureFlag(key: string, cb: (value: string | boolean) => void): () => void;
|
|
150
190
|
overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): void;
|
|
191
|
+
_sendFeatureFlags(event: string, properties?: {
|
|
192
|
+
[key: string]: any;
|
|
193
|
+
}): void;
|
|
151
194
|
/***
|
|
152
195
|
*** QUEUEING AND FLUSHING
|
|
153
196
|
***/
|