posthog-node 2.4.0 → 2.5.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
@@ -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,86 @@ 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 pendingPromises;
107
+ private _optoutOverride;
108
+ protected _events: SimpleEventEmitter;
109
+ protected _flushTimer?: any;
110
+ protected _retryOptions: RetriableOptions;
111
+ abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
112
+ abstract getLibraryId(): string;
113
+ abstract getLibraryVersion(): string;
114
+ abstract getCustomUserAgent(): string | void;
115
+ abstract getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
116
+ abstract setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
117
+ constructor(apiKey: string, options?: PosthogCoreOptions);
118
+ protected getCommonEventProperties(): any;
119
+ get optedOut(): boolean;
120
+ optIn(): void;
121
+ optOut(): void;
122
+ on(event: string, cb: (...args: any[]) => void): () => void;
123
+ debug(enabled?: boolean): void;
124
+ private buildPayload;
125
+ /***
126
+ *** TRACKING
127
+ ***/
128
+ protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
129
+ protected captureStateless(distinctId: string, event: string, properties?: {
130
+ [key: string]: any;
131
+ }, options?: PosthogCaptureOptions): this;
132
+ protected aliasStateless(alias: string, distinctId: string, properties?: {
133
+ [key: string]: any;
134
+ }): this;
135
+ /***
136
+ *** GROUPS
137
+ ***/
138
+ protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): this;
139
+ /***
140
+ *** FEATURE FLAGS
141
+ ***/
142
+ 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>;
143
+ protected getFeatureFlagStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<boolean | string | undefined>;
144
+ protected getFeatureFlagPayloadStateless(key: string, distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<JsonType | undefined>;
145
+ protected getFeatureFlagPayloadsStateless(distinctId: string, groups?: Record<string, string>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<PostHogDecideResponse['featureFlagPayloads'] | undefined>;
146
+ protected _parsePayload(response: any): any;
147
+ protected getFeatureFlagsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<PostHogDecideResponse['featureFlags'] | undefined>;
148
+ protected getFeatureFlagsAndPayloadsStateless(distinctId: string, groups?: Record<string, string | number>, personProperties?: Record<string, string>, groupProperties?: Record<string, Record<string, string>>): Promise<{
149
+ flags: PostHogDecideResponse['featureFlags'] | undefined;
150
+ payloads: PostHogDecideResponse['featureFlagPayloads'] | undefined;
151
+ }>;
152
+ /***
153
+ *** QUEUEING AND FLUSHING
154
+ ***/
155
+ protected enqueue(type: string, _message: any, options?: PosthogCaptureOptions): void;
156
+ flushAsync(): Promise<any>;
157
+ flush(callback?: (err?: any, data?: any) => void): void;
158
+ private fetchWithRetry;
159
+ shutdownAsync(): Promise<void>;
160
+ shutdown(): void;
161
+ }
162
+
63
163
  interface IdentifyMessageV1 {
64
164
  distinctId: string;
65
165
  properties?: Record<string | number, any>;
@@ -203,13 +303,19 @@ declare type PostHogOptions = PosthogCoreOptions & {
203
303
  maxCacheSize?: number;
204
304
  fetch?: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>;
205
305
  };
206
- declare class PostHog implements PostHogNodeV1 {
207
- private _sharedClient;
306
+ declare class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
307
+ private _memoryStorage;
208
308
  private featureFlagsPoller?;
209
309
  private maxCacheSize;
310
+ private options;
210
311
  distinctIdHasSentFlagCalls: Record<string, string[]>;
211
312
  constructor(apiKey: string, options?: PostHogOptions);
212
- private reInit;
313
+ getPersistedProperty(key: PostHogPersistedProperty): any | undefined;
314
+ setPersistedProperty(key: PostHogPersistedProperty, value: any | null): void;
315
+ fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
316
+ getLibraryId(): string;
317
+ getLibraryVersion(): string;
318
+ getCustomUserAgent(): string;
213
319
  enable(): void;
214
320
  disable(): void;
215
321
  capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp }: EventMessageV1): void;
@@ -253,10 +359,8 @@ declare class PostHog implements PostHogNodeV1 {
253
359
  }): Promise<PosthogFlagsAndPayloadsResponse>;
254
360
  groupIdentify({ groupType, groupKey, properties }: GroupIdentifyMessage): void;
255
361
  reloadFeatureFlags(): Promise<void>;
256
- flush(): void;
257
362
  shutdown(): void;
258
363
  shutdownAsync(): Promise<void>;
259
- debug(enabled?: boolean): void;
260
364
  }
261
365
 
262
366
  export { PostHog, PostHogOptions };