posthog-js-lite 2.1.0 → 2.2.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/lib/index.d.ts CHANGED
@@ -41,6 +41,9 @@ declare type PostHogFetchOptions = {
41
41
  body?: string;
42
42
  signal?: AbortSignal;
43
43
  };
44
+ declare type PosthogCaptureOptions = {
45
+ timestamp?: Date;
46
+ };
44
47
  declare type PostHogFetchResponse = {
45
48
  status: number;
46
49
  text: () => Promise<string>;
@@ -97,42 +100,84 @@ declare class SimpleEventEmitter {
97
100
  emit(event: string, payload: any): void;
98
101
  }
99
102
 
100
- declare abstract class PostHogCore {
103
+ declare abstract class PostHogCoreStateless {
101
104
  private apiKey;
102
105
  host: string;
103
106
  private flushAt;
104
107
  private flushInterval;
105
108
  private requestTimeout;
106
109
  private captureMode;
107
- private sendFeatureFlagEvent;
108
- private flagCallReported;
109
110
  private removeDebugCallback?;
111
+ private _optoutOverride;
110
112
  protected _events: SimpleEventEmitter;
111
113
  protected _flushTimer?: any;
112
- protected _decideResponsePromise?: Promise<PostHogDecideResponse>;
113
114
  protected _retryOptions: RetriableOptions;
114
- protected _sessionExpirationTimeSeconds: number;
115
115
  abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
116
116
  abstract getLibraryId(): string;
117
117
  abstract getLibraryVersion(): string;
118
118
  abstract getCustomUserAgent(): string | void;
119
119
  abstract getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
120
120
  abstract setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
121
- private _optoutOverride;
122
121
  constructor(apiKey: string, options?: PosthogCoreOptions);
123
122
  protected getCommonEventProperties(): any;
123
+ get optedOut(): boolean;
124
+ optIn(): void;
125
+ optOut(): void;
126
+ on(event: string, cb: (...args: any[]) => void): () => void;
127
+ debug(enabled?: boolean): void;
128
+ private buildPayload;
129
+ /***
130
+ *** TRACKING
131
+ ***/
132
+ protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
133
+ protected captureStateless(distinctId: string, event: string, properties?: {
134
+ [key: string]: any;
135
+ }, options?: PosthogCaptureOptions): this;
136
+ protected aliasStateless(alias: string, distinctId: string, properties?: {
137
+ [key: string]: any;
138
+ }): this;
139
+ /***
140
+ *** GROUPS
141
+ ***/
142
+ protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): this;
143
+ /***
144
+ *** FEATURE FLAGS
145
+ ***/
146
+ 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>;
147
+ protected getFeatureFlagStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<boolean | string | undefined>;
148
+ protected getFeatureFlagPayloadStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<JsonType | undefined>;
149
+ protected getFeatureFlagPayloadsStateless(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<PostHogDecideResponse['featureFlagPayloads'] | undefined>;
150
+ protected _parsePayload(response: any): any;
151
+ protected getFeatureFlagsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<PostHogDecideResponse['featureFlags'] | undefined>;
152
+ protected getFeatureFlagsAndPayloadsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<{
153
+ flags: PostHogDecideResponse['featureFlags'] | undefined;
154
+ payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
155
+ }>;
156
+ /***
157
+ *** QUEUEING AND FLUSHING
158
+ ***/
159
+ protected enqueue(type: string, _message: any, options?: PosthogCaptureOptions): void;
160
+ flushAsync(): Promise<any>;
161
+ flush(callback?: (err?: any, data?: any) => void): void;
162
+ private fetchWithRetry;
163
+ shutdownAsync(): Promise<void>;
164
+ shutdown(): void;
165
+ }
166
+ declare abstract class PostHogCore extends PostHogCoreStateless {
167
+ private sendFeatureFlagEvent;
168
+ private flagCallReported;
169
+ protected _decideResponsePromise?: Promise<PostHogDecideResponse | undefined>;
170
+ protected _sessionExpirationTimeSeconds: number;
171
+ constructor(apiKey: string, options?: PosthogCoreOptions);
124
172
  protected setupBootstrap(options?: Partial<PosthogCoreOptions>): void;
125
173
  private get props();
126
174
  private set props(value);
127
175
  private clearProps;
128
176
  private _props;
129
- get optedOut(): boolean;
130
- optIn(): void;
131
- optOut(): void;
132
177
  on(event: string, cb: (...args: any[]) => void): () => void;
133
178
  reset(propertiesToKeep?: PostHogPersistedProperty[]): void;
134
- debug(enabled?: boolean): void;
135
- private buildPayload;
179
+ protected getCommonEventProperties(): any;
180
+ private enrichProperties;
136
181
  getSessionId(): string | undefined;
137
182
  resetSessionId(): void;
138
183
  getAnonymousId(): string;
@@ -144,20 +189,20 @@ declare abstract class PostHogCore {
144
189
  /***
145
190
  *** TRACKING
146
191
  ***/
147
- identify(distinctId?: string, properties?: PostHogEventProperties): this;
192
+ identify(distinctId?: string, properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
148
193
  capture(event: string, properties?: {
149
194
  [key: string]: any;
150
- }, forceSendFeatureFlags?: boolean): this;
195
+ }, options?: PosthogCaptureOptions): this;
151
196
  alias(alias: string): this;
152
- autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties): this;
197
+ autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
153
198
  /***
154
199
  *** GROUPS
155
200
  ***/
156
201
  groups(groups: {
157
202
  [type: string]: string | number;
158
203
  }): this;
159
- group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties): this;
160
- groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties): this;
204
+ group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
205
+ groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
161
206
  /***
162
207
  * PROPERTIES
163
208
  ***/
@@ -177,29 +222,17 @@ declare abstract class PostHogCore {
177
222
  getFeatureFlag(key: string): boolean | string | undefined;
178
223
  getFeatureFlagPayload(key: string): JsonType | undefined;
179
224
  getFeatureFlagPayloads(): PostHogDecideResponse['featureFlagPayloads'] | undefined;
180
- _parsePayload(response: any): any;
181
225
  getFeatureFlags(): PostHogDecideResponse['featureFlags'] | undefined;
182
226
  getFeatureFlagsAndPayloads(): {
183
227
  flags: PostHogDecideResponse['featureFlags'] | undefined;
184
228
  payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
185
229
  };
186
230
  isFeatureEnabled(key: string): boolean | undefined;
187
- reloadFeatureFlagsAsync(sendAnonDistinctId?: boolean): Promise<PostHogDecideResponse['featureFlags']>;
231
+ reloadFeatureFlags(cb?: (err?: Error, flags?: PostHogDecideResponse['featureFlags']) => void): void;
232
+ reloadFeatureFlagsAsync(sendAnonDistinctId?: boolean): Promise<PostHogDecideResponse['featureFlags'] | undefined>;
188
233
  onFeatureFlags(cb: (flags: PostHogDecideResponse['featureFlags']) => void): () => void;
189
234
  onFeatureFlag(key: string, cb: (value: string | boolean) => void): () => void;
190
235
  overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): void;
191
- _sendFeatureFlags(event: string, properties?: {
192
- [key: string]: any;
193
- }): 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
236
  }
204
237
 
205
238
  declare type PostHogOptions = {