posthog-js-lite 2.0.0-alpha4 → 2.0.0

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.d.ts CHANGED
@@ -5,13 +5,19 @@ declare type PosthogCoreOptions = {
5
5
  enable?: boolean;
6
6
  sendFeatureFlagEvent?: boolean;
7
7
  preloadFeatureFlags?: boolean;
8
- decidePollInterval?: number;
8
+ bootstrap?: {
9
+ distinctId?: string;
10
+ isIdentifiedId?: boolean;
11
+ featureFlags?: Record<string, boolean | string>;
12
+ };
9
13
  fetchRetryCount?: number;
10
14
  fetchRetryDelay?: number;
15
+ requestTimeout?: number;
11
16
  sessionExpirationTimeSeconds?: number;
12
17
  captureMode?: 'json' | 'form';
13
18
  };
14
19
  declare enum PostHogPersistedProperty {
20
+ AnonymousId = "anonymous_id",
15
21
  DistinctId = "distinct_id",
16
22
  Props = "props",
17
23
  FeatureFlags = "feature_flags",
@@ -19,7 +25,9 @@ declare enum PostHogPersistedProperty {
19
25
  Queue = "queue",
20
26
  OptedOut = "opted_out",
21
27
  SessionId = "session_id",
22
- SessionLastTimestamp = "session_timestamp"
28
+ SessionLastTimestamp = "session_timestamp",
29
+ PersonProperties = "person_properties",
30
+ GroupProperties = "group_properties"
23
31
  }
24
32
  declare type PostHogFetchOptions = {
25
33
  method: 'GET' | 'POST' | 'PUT' | 'PATCH';
@@ -28,11 +36,13 @@ declare type PostHogFetchOptions = {
28
36
  headers: {
29
37
  [key: string]: string;
30
38
  };
31
- body: string;
39
+ body?: string;
40
+ signal?: AbortSignal;
32
41
  };
33
42
  declare type PostHogFetchResponse = {
34
43
  status: number;
35
44
  text: () => Promise<string>;
45
+ json: () => Promise<any>;
36
46
  };
37
47
  declare type PostHogEventProperties = {
38
48
  [key: string]: any;
@@ -80,9 +90,10 @@ declare class SimpleEventEmitter {
80
90
 
81
91
  declare abstract class PostHogCore {
82
92
  private apiKey;
83
- private host;
93
+ host: string;
84
94
  private flushAt;
85
95
  private flushInterval;
96
+ private requestTimeout;
86
97
  private captureMode;
87
98
  private sendFeatureFlagEvent;
88
99
  private flagCallReported;
@@ -90,8 +101,6 @@ declare abstract class PostHogCore {
90
101
  protected _events: SimpleEventEmitter;
91
102
  protected _flushTimer?: any;
92
103
  protected _decideResponsePromise?: Promise<PostHogDecideResponse>;
93
- protected _decideTimer?: any;
94
- protected _decidePollInterval: number;
95
104
  protected _retryOptions: RetriableOptions;
96
105
  protected _sessionExpirationTimeSeconds: number;
97
106
  abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
@@ -103,18 +112,21 @@ declare abstract class PostHogCore {
103
112
  private _optoutOverride;
104
113
  constructor(apiKey: string, options?: PosthogCoreOptions);
105
114
  protected getCommonEventProperties(): any;
115
+ protected setupBootstrap(options?: Partial<PosthogCoreOptions>): void;
106
116
  private get props();
107
117
  private set props(value);
118
+ private clearProps;
108
119
  private _props;
109
120
  get optedOut(): boolean;
110
121
  optIn(): void;
111
122
  optOut(): void;
112
123
  on(event: string, cb: (...args: any[]) => void): () => void;
113
- reset(): void;
124
+ reset(propertiesToKeep?: PostHogPersistedProperty[]): void;
114
125
  debug(enabled?: boolean): void;
115
126
  private buildPayload;
116
127
  getSessionId(): string | undefined;
117
128
  resetSessionId(): void;
129
+ getAnonymousId(): string;
118
130
  getDistinctId(): string;
119
131
  register(properties: {
120
132
  [key: string]: any;
@@ -126,7 +138,7 @@ declare abstract class PostHogCore {
126
138
  identify(distinctId?: string, properties?: PostHogEventProperties): this;
127
139
  capture(event: string, properties?: {
128
140
  [key: string]: any;
129
- }): this;
141
+ }, forceSendFeatureFlags?: boolean): this;
130
142
  alias(alias: string): this;
131
143
  autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties): this;
132
144
  /***
@@ -137,17 +149,31 @@ declare abstract class PostHogCore {
137
149
  }): this;
138
150
  group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties): this;
139
151
  groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties): this;
152
+ /***
153
+ * PROPERTIES
154
+ ***/
155
+ personProperties(properties: {
156
+ [type: string]: string;
157
+ }): this;
158
+ groupProperties(properties: {
159
+ [type: string]: Record<string, string>;
160
+ }): this;
140
161
  /***
141
162
  *** FEATURE FLAGS
142
163
  ***/
143
164
  private decideAsync;
144
165
  private _decideAsync;
145
- getFeatureFlag(key: string, defaultResult?: string | boolean): boolean | string | undefined;
166
+ private setKnownFeatureFlags;
167
+ getFeatureFlag(key: string): boolean | string | undefined;
146
168
  getFeatureFlags(): PostHogDecideResponse['featureFlags'] | undefined;
147
- isFeatureEnabled(key: string, defaultResult?: boolean): boolean;
148
- reloadFeatureFlagsAsync(): Promise<PostHogDecideResponse['featureFlags']>;
169
+ isFeatureEnabled(key: string): boolean | undefined;
170
+ reloadFeatureFlagsAsync(sendAnonDistinctId?: boolean): Promise<PostHogDecideResponse['featureFlags']>;
149
171
  onFeatureFlags(cb: (flags: PostHogDecideResponse['featureFlags']) => void): () => void;
172
+ onFeatureFlag(key: string, cb: (value: string | boolean) => void): () => void;
150
173
  overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): void;
174
+ _sendFeatureFlags(event: string, properties?: {
175
+ [key: string]: any;
176
+ }): void;
151
177
  /***
152
178
  *** QUEUEING AND FLUSHING
153
179
  ***/
@@ -159,10 +185,12 @@ declare abstract class PostHogCore {
159
185
  shutdown(): void;
160
186
  }
161
187
 
162
- interface PostHogOptions extends PosthogCoreOptions {
188
+ declare type PostHogOptions = {
163
189
  autocapture?: boolean;
190
+ persistence?: 'localStorage' | 'sessionStorage' | 'cookie' | 'memory';
164
191
  persistence_name?: string;
165
- }
192
+ } & PosthogCoreOptions;
193
+
166
194
  declare class PostHog extends PostHogCore {
167
195
  private _storage;
168
196
  private _storageCache;
@@ -177,4 +205,4 @@ declare class PostHog extends PostHogCore {
177
205
  getCommonEventProperties(): any;
178
206
  }
179
207
 
180
- export { PostHog, PostHogOptions, PostHog as default };
208
+ export { PostHog, PostHog as default };