posthog-js-lite 2.2.0 → 2.3.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
@@ -16,6 +16,7 @@ declare type PosthogCoreOptions = {
16
16
  requestTimeout?: number;
17
17
  sessionExpirationTimeSeconds?: number;
18
18
  captureMode?: 'json' | 'form';
19
+ disableGeoip?: boolean;
19
20
  };
20
21
  declare enum PostHogPersistedProperty {
21
22
  AnonymousId = "anonymous_id",
@@ -43,6 +44,7 @@ declare type PostHogFetchOptions = {
43
44
  };
44
45
  declare type PosthogCaptureOptions = {
45
46
  timestamp?: Date;
47
+ disableGeoip?: boolean;
46
48
  };
47
49
  declare type PostHogFetchResponse = {
48
50
  status: number;
@@ -88,7 +90,7 @@ declare type JsonType = string | number | boolean | null | {
88
90
  interface RetriableOptions {
89
91
  retryCount?: number;
90
92
  retryDelay?: number;
91
- retryCheck?: (err: any) => true;
93
+ retryCheck?: (err: any) => boolean;
92
94
  }
93
95
 
94
96
  declare class SimpleEventEmitter {
@@ -100,42 +102,87 @@ declare class SimpleEventEmitter {
100
102
  emit(event: string, payload: any): void;
101
103
  }
102
104
 
103
- declare abstract class PostHogCore {
105
+ declare abstract class PostHogCoreStateless {
104
106
  private apiKey;
105
107
  host: string;
106
108
  private flushAt;
107
109
  private flushInterval;
108
110
  private requestTimeout;
109
111
  private captureMode;
110
- private sendFeatureFlagEvent;
111
- private flagCallReported;
112
112
  private removeDebugCallback?;
113
+ private debugMode;
114
+ private pendingPromises;
115
+ private disableGeoip;
116
+ private _optoutOverride;
113
117
  protected _events: SimpleEventEmitter;
114
118
  protected _flushTimer?: any;
115
- protected _decideResponsePromise?: Promise<PostHogDecideResponse>;
116
119
  protected _retryOptions: RetriableOptions;
117
- protected _sessionExpirationTimeSeconds: number;
118
120
  abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
119
121
  abstract getLibraryId(): string;
120
122
  abstract getLibraryVersion(): string;
121
123
  abstract getCustomUserAgent(): string | void;
122
124
  abstract getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
123
125
  abstract setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
124
- private _optoutOverride;
125
126
  constructor(apiKey: string, options?: PosthogCoreOptions);
126
127
  protected getCommonEventProperties(): any;
128
+ get optedOut(): boolean;
129
+ optIn(): void;
130
+ optOut(): void;
131
+ on(event: string, cb: (...args: any[]) => void): () => void;
132
+ debug(enabled?: boolean): void;
133
+ private buildPayload;
134
+ /***
135
+ *** TRACKING
136
+ ***/
137
+ protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
138
+ protected captureStateless(distinctId: string, event: string, properties?: {
139
+ [key: string]: any;
140
+ }, options?: PosthogCaptureOptions): this;
141
+ protected aliasStateless(alias: string, distinctId: string, properties?: {
142
+ [key: string]: any;
143
+ }, options?: PosthogCaptureOptions): this;
144
+ /***
145
+ *** GROUPS
146
+ ***/
147
+ protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): this;
148
+ /***
149
+ *** FEATURE FLAGS
150
+ ***/
151
+ protected getDecide(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, extraPayload?: Record<string, any>): Promise<PostHogDecideResponse | undefined>;
152
+ protected getFeatureFlagStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<boolean | string | undefined>;
153
+ protected getFeatureFlagPayloadStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<JsonType | undefined>;
154
+ protected getFeatureFlagPayloadsStateless(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<PostHogDecideResponse['featureFlagPayloads'] | undefined>;
155
+ protected _parsePayload(response: any): any;
156
+ protected getFeatureFlagsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<PostHogDecideResponse['featureFlags'] | undefined>;
157
+ protected getFeatureFlagsAndPayloadsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>, disableGeoip?: boolean): Promise<{
158
+ flags: PostHogDecideResponse['featureFlags'] | undefined;
159
+ payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
160
+ }>;
161
+ /***
162
+ *** QUEUEING AND FLUSHING
163
+ ***/
164
+ protected enqueue(type: string, _message: any, options?: PosthogCaptureOptions): void;
165
+ flushAsync(): Promise<any>;
166
+ flush(callback?: (err?: any, data?: any) => void): void;
167
+ private fetchWithRetry;
168
+ shutdownAsync(): Promise<void>;
169
+ shutdown(): void;
170
+ }
171
+ declare abstract class PostHogCore extends PostHogCoreStateless {
172
+ private sendFeatureFlagEvent;
173
+ private flagCallReported;
174
+ protected _decideResponsePromise?: Promise<PostHogDecideResponse | undefined>;
175
+ protected _sessionExpirationTimeSeconds: number;
176
+ constructor(apiKey: string, options?: PosthogCoreOptions);
127
177
  protected setupBootstrap(options?: Partial<PosthogCoreOptions>): void;
128
178
  private get props();
129
179
  private set props(value);
130
180
  private clearProps;
131
181
  private _props;
132
- get optedOut(): boolean;
133
- optIn(): void;
134
- optOut(): void;
135
182
  on(event: string, cb: (...args: any[]) => void): () => void;
136
183
  reset(propertiesToKeep?: PostHogPersistedProperty[]): void;
137
- debug(enabled?: boolean): void;
138
- private buildPayload;
184
+ protected getCommonEventProperties(): any;
185
+ private enrichProperties;
139
186
  getSessionId(): string | undefined;
140
187
  resetSessionId(): void;
141
188
  getAnonymousId(): string;
@@ -180,26 +227,17 @@ declare abstract class PostHogCore {
180
227
  getFeatureFlag(key: string): boolean | string | undefined;
181
228
  getFeatureFlagPayload(key: string): JsonType | undefined;
182
229
  getFeatureFlagPayloads(): PostHogDecideResponse['featureFlagPayloads'] | undefined;
183
- _parsePayload(response: any): any;
184
230
  getFeatureFlags(): PostHogDecideResponse['featureFlags'] | undefined;
185
231
  getFeatureFlagsAndPayloads(): {
186
232
  flags: PostHogDecideResponse['featureFlags'] | undefined;
187
233
  payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
188
234
  };
189
235
  isFeatureEnabled(key: string): boolean | undefined;
190
- reloadFeatureFlagsAsync(sendAnonDistinctId?: boolean): Promise<PostHogDecideResponse['featureFlags']>;
236
+ reloadFeatureFlags(cb?: (err?: Error, flags?: PostHogDecideResponse['featureFlags']) => void): void;
237
+ reloadFeatureFlagsAsync(sendAnonDistinctId?: boolean): Promise<PostHogDecideResponse['featureFlags'] | undefined>;
191
238
  onFeatureFlags(cb: (flags: PostHogDecideResponse['featureFlags']) => void): () => void;
192
239
  onFeatureFlag(key: string, cb: (value: string | boolean) => void): () => void;
193
240
  overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): void;
194
- /***
195
- *** QUEUEING AND FLUSHING
196
- ***/
197
- private enqueue;
198
- flushAsync(): Promise<any>;
199
- flush(callback?: (err?: any, data?: any) => void): void;
200
- private fetchWithRetry;
201
- shutdownAsync(): Promise<void>;
202
- shutdown(): void;
203
241
  }
204
242
 
205
243
  declare type PostHogOptions = {