posthog-node 2.4.0 → 2.5.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
@@ -18,6 +18,20 @@ declare type PosthogCoreOptions = {
18
18
  sessionExpirationTimeSeconds?: number;
19
19
  captureMode?: 'json' | 'form';
20
20
  };
21
+ declare enum PostHogPersistedProperty {
22
+ AnonymousId = "anonymous_id",
23
+ DistinctId = "distinct_id",
24
+ Props = "props",
25
+ FeatureFlags = "feature_flags",
26
+ FeatureFlagPayloads = "feature_flag_payloads",
27
+ OverrideFeatureFlags = "override_feature_flags",
28
+ Queue = "queue",
29
+ OptedOut = "opted_out",
30
+ SessionId = "session_id",
31
+ SessionLastTimestamp = "session_timestamp",
32
+ PersonProperties = "person_properties",
33
+ GroupProperties = "group_properties"
34
+ }
21
35
  declare type PostHogFetchOptions = {
22
36
  method: 'GET' | 'POST' | 'PUT' | 'PATCH';
23
37
  mode?: 'no-cors';
@@ -28,11 +42,17 @@ declare type PostHogFetchOptions = {
28
42
  body?: string;
29
43
  signal?: AbortSignal;
30
44
  };
45
+ declare type PosthogCaptureOptions = {
46
+ timestamp?: Date;
47
+ };
31
48
  declare type PostHogFetchResponse = {
32
49
  status: number;
33
50
  text: () => Promise<string>;
34
51
  json: () => Promise<any>;
35
52
  };
53
+ declare type PostHogEventProperties = {
54
+ [key: string]: any;
55
+ };
36
56
  declare type PostHogDecideResponse = {
37
57
  config: {
38
58
  enable_collect_everything: boolean;
@@ -60,6 +80,85 @@ declare type JsonType = string | number | boolean | null | {
60
80
  [key: string]: JsonType;
61
81
  } | Array<JsonType>;
62
82
 
83
+ interface RetriableOptions {
84
+ retryCount?: number;
85
+ retryDelay?: number;
86
+ retryCheck?: (err: any) => true;
87
+ }
88
+
89
+ declare class SimpleEventEmitter {
90
+ events: {
91
+ [key: string]: ((...args: any[]) => void)[];
92
+ };
93
+ constructor();
94
+ on(event: string, listener: (...args: any[]) => void): () => void;
95
+ emit(event: string, payload: any): void;
96
+ }
97
+
98
+ declare abstract class PostHogCoreStateless {
99
+ private apiKey;
100
+ host: string;
101
+ private flushAt;
102
+ private flushInterval;
103
+ private requestTimeout;
104
+ private captureMode;
105
+ private removeDebugCallback?;
106
+ private _optoutOverride;
107
+ protected _events: SimpleEventEmitter;
108
+ protected _flushTimer?: any;
109
+ protected _retryOptions: RetriableOptions;
110
+ abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
111
+ abstract getLibraryId(): string;
112
+ abstract getLibraryVersion(): string;
113
+ abstract getCustomUserAgent(): string | void;
114
+ abstract getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
115
+ abstract setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
116
+ constructor(apiKey: string, options?: PosthogCoreOptions);
117
+ protected getCommonEventProperties(): any;
118
+ get optedOut(): boolean;
119
+ optIn(): void;
120
+ optOut(): void;
121
+ on(event: string, cb: (...args: any[]) => void): () => void;
122
+ debug(enabled?: boolean): void;
123
+ private buildPayload;
124
+ /***
125
+ *** TRACKING
126
+ ***/
127
+ protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
128
+ protected captureStateless(distinctId: string, event: string, properties?: {
129
+ [key: string]: any;
130
+ }, options?: PosthogCaptureOptions): this;
131
+ protected aliasStateless(alias: string, distinctId: string, properties?: {
132
+ [key: string]: any;
133
+ }): this;
134
+ /***
135
+ *** GROUPS
136
+ ***/
137
+ protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): this;
138
+ /***
139
+ *** FEATURE FLAGS
140
+ ***/
141
+ 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>;
142
+ protected getFeatureFlagStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<boolean | string | undefined>;
143
+ protected getFeatureFlagPayloadStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<JsonType | undefined>;
144
+ protected getFeatureFlagPayloadsStateless(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<PostHogDecideResponse['featureFlagPayloads'] | undefined>;
145
+ protected _parsePayload(response: any): any;
146
+ protected getFeatureFlagsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<PostHogDecideResponse['featureFlags'] | undefined>;
147
+ protected getFeatureFlagsAndPayloadsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<{
148
+ flags: PostHogDecideResponse['featureFlags'] | undefined;
149
+ payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
150
+ }>;
151
+ /***
152
+ *** QUEUEING AND FLUSHING
153
+ ***/
154
+ protected enqueue(type: string, _message: any, options?: PosthogCaptureOptions): void;
155
+ flushAsync(): Promise<any>;
156
+ flush(callback?: (err?: any, data?: any) => void): void;
157
+ private fetchWithRetry;
158
+ shutdownAsync(): Promise<void>;
159
+ shutdown(): void;
160
+ }
161
+
63
162
  interface IdentifyMessageV1 {
64
163
  distinctId: string;
65
164
  properties?: Record<string | number, any>;
@@ -203,13 +302,19 @@ declare type PostHogOptions = PosthogCoreOptions & {
203
302
  maxCacheSize?: number;
204
303
  fetch?: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>;
205
304
  };
206
- declare class PostHog implements PostHogNodeV1 {
207
- private _sharedClient;
305
+ declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
306
+ private _memoryStorage;
208
307
  private featureFlagsPoller?;
209
308
  private maxCacheSize;
309
+ private options;
210
310
  distinctIdHasSentFlagCalls: Record<string, string[]>;
211
311
  constructor(apiKey: string, options?: PostHogOptions);
212
- private reInit;
312
+ getPersistedProperty(key: PostHogPersistedProperty): any | undefined;
313
+ setPersistedProperty(key: PostHogPersistedProperty, value: any | null): void;
314
+ fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
315
+ getLibraryId(): string;
316
+ getLibraryVersion(): string;
317
+ getCustomUserAgent(): string;
213
318
  enable(): void;
214
319
  disable(): void;
215
320
  capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp }: EventMessageV1): void;
@@ -253,10 +358,8 @@ declare class PostHog implements PostHogNodeV1 {
253
358
  }): Promise<PosthogFlagsAndPayloadsResponse>;
254
359
  groupIdentify({ groupType, groupKey, properties }: GroupIdentifyMessage): void;
255
360
  reloadFeatureFlags(): Promise<void>;
256
- flush(): void;
257
361
  shutdown(): void;
258
362
  shutdownAsync(): Promise<void>;
259
- debug(enabled?: boolean): void;
260
363
  }
261
364
 
262
365
  export { PostHog, PostHogOptions };