posthog-js-lite 2.6.1 → 3.0.0-beta.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/CHANGELOG.md +13 -0
- package/lib/index.cjs.js +995 -1149
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +65 -35
- package/lib/index.esm.js +995 -1149
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +44 -30
- package/lib/posthog-core/src/types.d.ts +19 -3
- package/lib/posthog-core/src/utils.d.ts +5 -4
- package/lib/posthog-core/src/vendor/uuidv7.d.ts +179 -0
- package/lib/posthog-web/src/types.d.ts +2 -2
- package/package.json +1 -1
- package/src/types.ts +2 -2
- package/test/posthog-web.spec.ts +6 -2
- package/tsconfig.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PostHogFetchOptions, PostHogFetchResponse, PostHogAutocaptureElement, PostHogDecideResponse,
|
|
1
|
+
import { PostHogFetchOptions, PostHogFetchResponse, PostHogAutocaptureElement, PostHogDecideResponse, PostHogCoreOptions, PostHogEventProperties, PostHogPersistedProperty, PostHogCaptureOptions, JsonType } from './types';
|
|
2
2
|
import { RetriableOptions } from './utils';
|
|
3
3
|
export * as utils from './utils';
|
|
4
4
|
import { LZString } from './lz-string';
|
|
@@ -9,44 +9,49 @@ export declare abstract class PostHogCoreStateless {
|
|
|
9
9
|
private flushAt;
|
|
10
10
|
private flushInterval;
|
|
11
11
|
private requestTimeout;
|
|
12
|
+
private featureFlagsRequestTimeoutMs;
|
|
12
13
|
private captureMode;
|
|
13
14
|
private removeDebugCallback?;
|
|
14
|
-
private debugMode;
|
|
15
15
|
private disableGeoip;
|
|
16
|
-
|
|
16
|
+
disabled: boolean;
|
|
17
|
+
private defaultOptIn;
|
|
17
18
|
private pendingPromises;
|
|
18
19
|
protected _events: SimpleEventEmitter;
|
|
19
20
|
protected _flushTimer?: any;
|
|
20
21
|
protected _retryOptions: RetriableOptions;
|
|
22
|
+
protected _initPromise: Promise<void>;
|
|
23
|
+
protected _isInitialized: boolean;
|
|
21
24
|
abstract fetch(url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse>;
|
|
22
25
|
abstract getLibraryId(): string;
|
|
23
26
|
abstract getLibraryVersion(): string;
|
|
24
27
|
abstract getCustomUserAgent(): string | void;
|
|
25
28
|
abstract getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
|
|
26
29
|
abstract setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
|
|
27
|
-
constructor(apiKey: string, options?:
|
|
30
|
+
constructor(apiKey: string, options?: PostHogCoreOptions);
|
|
31
|
+
protected wrap(fn: () => void): void;
|
|
28
32
|
protected getCommonEventProperties(): any;
|
|
29
33
|
get optedOut(): boolean;
|
|
30
|
-
optIn(): void
|
|
31
|
-
optOut(): void
|
|
34
|
+
optIn(): Promise<void>;
|
|
35
|
+
optOut(): Promise<void>;
|
|
32
36
|
on(event: string, cb: (...args: any[]) => void): () => void;
|
|
33
37
|
debug(enabled?: boolean): void;
|
|
38
|
+
get isDebug(): boolean;
|
|
34
39
|
private buildPayload;
|
|
35
40
|
protected addPendingPromise(promise: Promise<any>): void;
|
|
36
41
|
/***
|
|
37
42
|
*** TRACKING
|
|
38
43
|
***/
|
|
39
|
-
protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions):
|
|
44
|
+
protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
40
45
|
protected captureStateless(distinctId: string, event: string, properties?: {
|
|
41
46
|
[key: string]: any;
|
|
42
|
-
}, options?: PostHogCaptureOptions):
|
|
47
|
+
}, options?: PostHogCaptureOptions): void;
|
|
43
48
|
protected aliasStateless(alias: string, distinctId: string, properties?: {
|
|
44
49
|
[key: string]: any;
|
|
45
|
-
}, options?: PostHogCaptureOptions):
|
|
50
|
+
}, options?: PostHogCaptureOptions): void;
|
|
46
51
|
/***
|
|
47
52
|
*** GROUPS
|
|
48
53
|
***/
|
|
49
|
-
protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties):
|
|
54
|
+
protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): void;
|
|
50
55
|
/***
|
|
51
56
|
*** FEATURE FLAGS
|
|
52
57
|
***/
|
|
@@ -67,8 +72,8 @@ export declare abstract class PostHogCoreStateless {
|
|
|
67
72
|
flushAsync(): Promise<any>;
|
|
68
73
|
flush(callback?: (err?: any, data?: any) => void): void;
|
|
69
74
|
private fetchWithRetry;
|
|
70
|
-
shutdownAsync(): Promise<void>;
|
|
71
|
-
shutdown(): void;
|
|
75
|
+
shutdownAsync(shutdownTimeoutMs?: number): Promise<void>;
|
|
76
|
+
shutdown(shutdownTimeoutMs?: number): void;
|
|
72
77
|
}
|
|
73
78
|
export declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
74
79
|
private sendFeatureFlagEvent;
|
|
@@ -76,8 +81,8 @@ export declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
76
81
|
protected _decideResponsePromise?: Promise<PostHogDecideResponse | undefined>;
|
|
77
82
|
protected _sessionExpirationTimeSeconds: number;
|
|
78
83
|
protected sessionProps: PostHogEventProperties;
|
|
79
|
-
constructor(apiKey: string, options?:
|
|
80
|
-
protected setupBootstrap(options?: Partial<
|
|
84
|
+
constructor(apiKey: string, options?: PostHogCoreOptions);
|
|
85
|
+
protected setupBootstrap(options?: Partial<PostHogCoreOptions>): void;
|
|
81
86
|
private get props();
|
|
82
87
|
private set props(value);
|
|
83
88
|
private clearProps;
|
|
@@ -85,15 +90,24 @@ export declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
85
90
|
on(event: string, cb: (...args: any[]) => void): () => void;
|
|
86
91
|
reset(propertiesToKeep?: PostHogPersistedProperty[]): void;
|
|
87
92
|
protected getCommonEventProperties(): any;
|
|
88
|
-
enrichProperties
|
|
89
|
-
|
|
93
|
+
private enrichProperties;
|
|
94
|
+
/**
|
|
95
|
+
* * @returns {string} The stored session ID for the current session. This may be an empty string if the client is not yet fully initialized.
|
|
96
|
+
*/
|
|
97
|
+
getSessionId(): string;
|
|
90
98
|
resetSessionId(): void;
|
|
99
|
+
/**
|
|
100
|
+
* * @returns {string} The stored anonymous ID. This may be an empty string if the client is not yet fully initialized.
|
|
101
|
+
*/
|
|
91
102
|
getAnonymousId(): string;
|
|
103
|
+
/**
|
|
104
|
+
* * @returns {string} The stored distinct ID. This may be an empty string if the client is not yet fully initialized.
|
|
105
|
+
*/
|
|
92
106
|
getDistinctId(): string;
|
|
93
|
-
unregister(property: string): void
|
|
107
|
+
unregister(property: string): Promise<void>;
|
|
94
108
|
register(properties: {
|
|
95
109
|
[key: string]: any;
|
|
96
|
-
}): void
|
|
110
|
+
}): Promise<void>;
|
|
97
111
|
registerForSession(properties: {
|
|
98
112
|
[key: string]: any;
|
|
99
113
|
}): void;
|
|
@@ -101,39 +115,39 @@ export declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
101
115
|
/***
|
|
102
116
|
*** TRACKING
|
|
103
117
|
***/
|
|
104
|
-
identify(distinctId?: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions):
|
|
118
|
+
identify(distinctId?: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
105
119
|
capture(event: string, properties?: {
|
|
106
120
|
[key: string]: any;
|
|
107
|
-
}, options?: PostHogCaptureOptions):
|
|
108
|
-
alias(alias: string):
|
|
109
|
-
autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PostHogCaptureOptions):
|
|
121
|
+
}, options?: PostHogCaptureOptions): void;
|
|
122
|
+
alias(alias: string): void;
|
|
123
|
+
autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
110
124
|
/***
|
|
111
125
|
*** GROUPS
|
|
112
126
|
***/
|
|
113
127
|
groups(groups: {
|
|
114
128
|
[type: string]: string | number;
|
|
115
|
-
}):
|
|
116
|
-
group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions):
|
|
117
|
-
groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions):
|
|
129
|
+
}): void;
|
|
130
|
+
group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
131
|
+
groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): void;
|
|
118
132
|
/***
|
|
119
133
|
* PROPERTIES
|
|
120
134
|
***/
|
|
121
135
|
setPersonPropertiesForFlags(properties: {
|
|
122
136
|
[type: string]: string;
|
|
123
|
-
}):
|
|
137
|
+
}): void;
|
|
124
138
|
resetPersonPropertiesForFlags(): void;
|
|
125
139
|
/** @deprecated - Renamed to setPersonPropertiesForFlags */
|
|
126
140
|
personProperties(properties: {
|
|
127
141
|
[type: string]: string;
|
|
128
|
-
}):
|
|
142
|
+
}): void;
|
|
129
143
|
setGroupPropertiesForFlags(properties: {
|
|
130
144
|
[type: string]: Record<string, string>;
|
|
131
|
-
}):
|
|
145
|
+
}): void;
|
|
132
146
|
resetGroupPropertiesForFlags(): void;
|
|
133
147
|
/** @deprecated - Renamed to setGroupPropertiesForFlags */
|
|
134
148
|
groupProperties(properties: {
|
|
135
149
|
[type: string]: Record<string, string>;
|
|
136
|
-
}):
|
|
150
|
+
}): void;
|
|
137
151
|
/***
|
|
138
152
|
*** FEATURE FLAGS
|
|
139
153
|
***/
|
|
@@ -154,7 +168,7 @@ export declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
154
168
|
reloadFeatureFlagsAsync(sendAnonDistinctId?: boolean): Promise<PostHogDecideResponse['featureFlags'] | undefined>;
|
|
155
169
|
onFeatureFlags(cb: (flags: PostHogDecideResponse['featureFlags']) => void): () => void;
|
|
156
170
|
onFeatureFlag(key: string, cb: (value: string | boolean) => void): () => void;
|
|
157
|
-
overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): void
|
|
171
|
+
overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): Promise<void>;
|
|
158
172
|
}
|
|
159
173
|
export * from './types';
|
|
160
174
|
export { LZString };
|
|
@@ -1,20 +1,36 @@
|
|
|
1
|
-
export declare type
|
|
1
|
+
export declare type PostHogCoreOptions = {
|
|
2
|
+
/** PostHog API host, usually 'https://app.posthog.com' or 'https://eu.posthog.com' */
|
|
2
3
|
host?: string;
|
|
4
|
+
/** The number of events to queue before sending to PostHog (flushing) */
|
|
3
5
|
flushAt?: number;
|
|
6
|
+
/** The interval in milliseconds between periodic flushes */
|
|
4
7
|
flushInterval?: number;
|
|
5
|
-
|
|
8
|
+
/** If set to true the SDK is essentially disabled (useful for local environments where you don't want to track anything) */
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
/** If set to false the SDK will not track until the `optIn` function is called. */
|
|
11
|
+
defaultOptIn?: boolean;
|
|
12
|
+
/** Whether to track that `getFeatureFlag` was called (used by Experiments) */
|
|
6
13
|
sendFeatureFlagEvent?: boolean;
|
|
14
|
+
/** Whether to load feature flags when initialized or not */
|
|
7
15
|
preloadFeatureFlags?: boolean;
|
|
16
|
+
/** Option to bootstrap the library with given distinctId and feature flags */
|
|
8
17
|
bootstrap?: {
|
|
9
18
|
distinctId?: string;
|
|
10
19
|
isIdentifiedId?: boolean;
|
|
11
20
|
featureFlags?: Record<string, boolean | string>;
|
|
12
21
|
featureFlagPayloads?: Record<string, JsonType>;
|
|
13
22
|
};
|
|
23
|
+
/** How many times we will retry HTTP requests. Defaults to 3. */
|
|
14
24
|
fetchRetryCount?: number;
|
|
25
|
+
/** The delay between HTTP request retries, Defaults to 3 seconds. */
|
|
15
26
|
fetchRetryDelay?: number;
|
|
27
|
+
/** Timeout in milliseconds for any calls. Defaults to 10 seconds. */
|
|
16
28
|
requestTimeout?: number;
|
|
29
|
+
/** Timeout in milliseconds for feature flag calls. Defaults to 10 seconds for stateful clients, and 3 seconds for stateless. */
|
|
30
|
+
featureFlagsRequestTimeoutMs?: number;
|
|
31
|
+
/** For Session Analysis how long before we expire a session (defaults to 30 mins) */
|
|
17
32
|
sessionExpirationTimeSeconds?: number;
|
|
33
|
+
/** Whether to post events to PostHog in JSON or compressed format */
|
|
18
34
|
captureMode?: 'json' | 'form';
|
|
19
35
|
disableGeoip?: boolean;
|
|
20
36
|
};
|
|
@@ -92,7 +108,7 @@ export declare type PostHogDecideResponse = {
|
|
|
92
108
|
errorsWhileComputingFlags: boolean;
|
|
93
109
|
sessionRecording: boolean;
|
|
94
110
|
};
|
|
95
|
-
export declare type
|
|
111
|
+
export declare type PostHogFlagsAndPayloadsResponse = {
|
|
96
112
|
featureFlags: PostHogDecideResponse['featureFlags'];
|
|
97
113
|
featureFlagPayloads: PostHogDecideResponse['featureFlagPayloads'];
|
|
98
114
|
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export declare function assert(truthyValue: any, message: string): void;
|
|
2
2
|
export declare function removeTrailingSlash(url: string): string;
|
|
3
3
|
export interface RetriableOptions {
|
|
4
|
-
retryCount
|
|
5
|
-
retryDelay
|
|
6
|
-
retryCheck
|
|
4
|
+
retryCount: number;
|
|
5
|
+
retryDelay: number;
|
|
6
|
+
retryCheck: (err: any) => boolean;
|
|
7
7
|
}
|
|
8
|
-
export declare function retriable<T>(fn: () => Promise<T>, props
|
|
8
|
+
export declare function retriable<T>(fn: () => Promise<T>, props: RetriableOptions): Promise<T>;
|
|
9
9
|
export declare function currentTimestamp(): number;
|
|
10
10
|
export declare function currentISOTime(): string;
|
|
11
11
|
export declare function safeSetTimeout(fn: () => void, timeout: number): any;
|
|
12
|
+
export declare const isPromise: (obj: any) => obj is Promise<any>;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/** Represents a UUID as a 16-byte byte array. */
|
|
2
|
+
export declare class UUID {
|
|
3
|
+
readonly bytes: Readonly<Uint8Array>;
|
|
4
|
+
/** @param bytes - The 16-byte byte array representation. */
|
|
5
|
+
private constructor();
|
|
6
|
+
/**
|
|
7
|
+
* Creates an object from the internal representation, a 16-byte byte array
|
|
8
|
+
* containing the binary UUID representation in the big-endian byte order.
|
|
9
|
+
*
|
|
10
|
+
* This method does NOT shallow-copy the argument, and thus the created object
|
|
11
|
+
* holds the reference to the underlying buffer.
|
|
12
|
+
*
|
|
13
|
+
* @throws TypeError if the length of the argument is not 16.
|
|
14
|
+
*/
|
|
15
|
+
static ofInner(bytes: Readonly<Uint8Array>): UUID;
|
|
16
|
+
/**
|
|
17
|
+
* Builds a byte array from UUIDv7 field values.
|
|
18
|
+
*
|
|
19
|
+
* @param unixTsMs - A 48-bit `unix_ts_ms` field value.
|
|
20
|
+
* @param randA - A 12-bit `rand_a` field value.
|
|
21
|
+
* @param randBHi - The higher 30 bits of 62-bit `rand_b` field value.
|
|
22
|
+
* @param randBLo - The lower 32 bits of 62-bit `rand_b` field value.
|
|
23
|
+
* @throws RangeError if any field value is out of the specified range.
|
|
24
|
+
*/
|
|
25
|
+
static fromFieldsV7(unixTsMs: number, randA: number, randBHi: number, randBLo: number): UUID;
|
|
26
|
+
/**
|
|
27
|
+
* Builds a byte array from a string representation.
|
|
28
|
+
*
|
|
29
|
+
* This method accepts the following formats:
|
|
30
|
+
*
|
|
31
|
+
* - 32-digit hexadecimal format without hyphens: `0189dcd553117d408db09496a2eef37b`
|
|
32
|
+
* - 8-4-4-4-12 hyphenated format: `0189dcd5-5311-7d40-8db0-9496a2eef37b`
|
|
33
|
+
* - Hyphenated format with surrounding braces: `{0189dcd5-5311-7d40-8db0-9496a2eef37b}`
|
|
34
|
+
* - RFC 4122 URN format: `urn:uuid:0189dcd5-5311-7d40-8db0-9496a2eef37b`
|
|
35
|
+
*
|
|
36
|
+
* Leading and trailing whitespaces represents an error.
|
|
37
|
+
*
|
|
38
|
+
* @throws SyntaxError if the argument could not parse as a valid UUID string.
|
|
39
|
+
*/
|
|
40
|
+
static parse(uuid: string): UUID;
|
|
41
|
+
/**
|
|
42
|
+
* @returns The 8-4-4-4-12 canonical hexadecimal string representation
|
|
43
|
+
* (`0189dcd5-5311-7d40-8db0-9496a2eef37b`).
|
|
44
|
+
*/
|
|
45
|
+
toString(): string;
|
|
46
|
+
/**
|
|
47
|
+
* @returns The 32-digit hexadecimal representation without hyphens
|
|
48
|
+
* (`0189dcd553117d408db09496a2eef37b`).
|
|
49
|
+
*/
|
|
50
|
+
toHex(): string;
|
|
51
|
+
/** @returns The 8-4-4-4-12 canonical hexadecimal string representation. */
|
|
52
|
+
toJSON(): string;
|
|
53
|
+
/**
|
|
54
|
+
* Reports the variant field value of the UUID or, if appropriate, "NIL" or
|
|
55
|
+
* "MAX".
|
|
56
|
+
*
|
|
57
|
+
* For convenience, this method reports "NIL" or "MAX" if `this` represents
|
|
58
|
+
* the Nil or Max UUID, although the Nil and Max UUIDs are technically
|
|
59
|
+
* subsumed under the variants `0b0` and `0b111`, respectively.
|
|
60
|
+
*/
|
|
61
|
+
getVariant(): "VAR_0" | "VAR_10" | "VAR_110" | "VAR_RESERVED" | "NIL" | "MAX";
|
|
62
|
+
/**
|
|
63
|
+
* Returns the version field value of the UUID or `undefined` if the UUID does
|
|
64
|
+
* not have the variant field value of `0b10`.
|
|
65
|
+
*/
|
|
66
|
+
getVersion(): number | undefined;
|
|
67
|
+
/** Creates an object from `this`. */
|
|
68
|
+
clone(): UUID;
|
|
69
|
+
/** Returns true if `this` is equivalent to `other`. */
|
|
70
|
+
equals(other: UUID): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Returns a negative integer, zero, or positive integer if `this` is less
|
|
73
|
+
* than, equal to, or greater than `other`, respectively.
|
|
74
|
+
*/
|
|
75
|
+
compareTo(other: UUID): number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Encapsulates the monotonic counter state.
|
|
79
|
+
*
|
|
80
|
+
* This class provides APIs to utilize a separate counter state from that of the
|
|
81
|
+
* global generator used by {@link uuidv7} and {@link uuidv7obj}. In addition to
|
|
82
|
+
* the default {@link generate} method, this class has {@link generateOrAbort}
|
|
83
|
+
* that is useful to absolutely guarantee the monotonically increasing order of
|
|
84
|
+
* generated UUIDs. See their respective documentation for details.
|
|
85
|
+
*/
|
|
86
|
+
export declare class V7Generator {
|
|
87
|
+
private timestamp;
|
|
88
|
+
private counter;
|
|
89
|
+
/** The random number generator used by the generator. */
|
|
90
|
+
private readonly random;
|
|
91
|
+
/**
|
|
92
|
+
* Creates a generator object with the default random number generator, or
|
|
93
|
+
* with the specified one if passed as an argument. The specified random
|
|
94
|
+
* number generator should be cryptographically strong and securely seeded.
|
|
95
|
+
*/
|
|
96
|
+
constructor(randomNumberGenerator?: {
|
|
97
|
+
/** Returns a 32-bit random unsigned integer. */
|
|
98
|
+
nextUint32(): number;
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* Generates a new UUIDv7 object from the current timestamp, or resets the
|
|
102
|
+
* generator upon significant timestamp rollback.
|
|
103
|
+
*
|
|
104
|
+
* This method returns a monotonically increasing UUID by reusing the previous
|
|
105
|
+
* timestamp even if the up-to-date timestamp is smaller than the immediately
|
|
106
|
+
* preceding UUID's. However, when such a clock rollback is considered
|
|
107
|
+
* significant (i.e., by more than ten seconds), this method resets the
|
|
108
|
+
* generator and returns a new UUID based on the given timestamp, breaking the
|
|
109
|
+
* increasing order of UUIDs.
|
|
110
|
+
*
|
|
111
|
+
* See {@link generateOrAbort} for the other mode of generation and
|
|
112
|
+
* {@link generateOrResetCore} for the low-level primitive.
|
|
113
|
+
*/
|
|
114
|
+
generate(): UUID;
|
|
115
|
+
/**
|
|
116
|
+
* Generates a new UUIDv7 object from the current timestamp, or returns
|
|
117
|
+
* `undefined` upon significant timestamp rollback.
|
|
118
|
+
*
|
|
119
|
+
* This method returns a monotonically increasing UUID by reusing the previous
|
|
120
|
+
* timestamp even if the up-to-date timestamp is smaller than the immediately
|
|
121
|
+
* preceding UUID's. However, when such a clock rollback is considered
|
|
122
|
+
* significant (i.e., by more than ten seconds), this method aborts and
|
|
123
|
+
* returns `undefined` immediately.
|
|
124
|
+
*
|
|
125
|
+
* See {@link generate} for the other mode of generation and
|
|
126
|
+
* {@link generateOrAbortCore} for the low-level primitive.
|
|
127
|
+
*/
|
|
128
|
+
generateOrAbort(): UUID | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* Generates a new UUIDv7 object from the `unixTsMs` passed, or resets the
|
|
131
|
+
* generator upon significant timestamp rollback.
|
|
132
|
+
*
|
|
133
|
+
* This method is equivalent to {@link generate} except that it takes a custom
|
|
134
|
+
* timestamp and clock rollback allowance.
|
|
135
|
+
*
|
|
136
|
+
* @param rollbackAllowance - The amount of `unixTsMs` rollback that is
|
|
137
|
+
* considered significant. A suggested value is `10_000` (milliseconds).
|
|
138
|
+
* @throws RangeError if `unixTsMs` is not a 48-bit positive integer.
|
|
139
|
+
*/
|
|
140
|
+
generateOrResetCore(unixTsMs: number, rollbackAllowance: number): UUID;
|
|
141
|
+
/**
|
|
142
|
+
* Generates a new UUIDv7 object from the `unixTsMs` passed, or returns
|
|
143
|
+
* `undefined` upon significant timestamp rollback.
|
|
144
|
+
*
|
|
145
|
+
* This method is equivalent to {@link generateOrAbort} except that it takes a
|
|
146
|
+
* custom timestamp and clock rollback allowance.
|
|
147
|
+
*
|
|
148
|
+
* @param rollbackAllowance - The amount of `unixTsMs` rollback that is
|
|
149
|
+
* considered significant. A suggested value is `10_000` (milliseconds).
|
|
150
|
+
* @throws RangeError if `unixTsMs` is not a 48-bit positive integer.
|
|
151
|
+
*/
|
|
152
|
+
generateOrAbortCore(unixTsMs: number, rollbackAllowance: number): UUID | undefined;
|
|
153
|
+
/** Initializes the counter at a 42-bit random integer. */
|
|
154
|
+
private resetCounter;
|
|
155
|
+
/**
|
|
156
|
+
* Generates a new UUIDv4 object utilizing the random number generator inside.
|
|
157
|
+
*
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
generateV4(): UUID;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Generates a UUIDv7 string.
|
|
164
|
+
*
|
|
165
|
+
* @returns The 8-4-4-4-12 canonical hexadecimal string representation
|
|
166
|
+
* ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").
|
|
167
|
+
*/
|
|
168
|
+
export declare const uuidv7: () => string;
|
|
169
|
+
/** Generates a UUIDv7 object. */
|
|
170
|
+
export declare const uuidv7obj: () => UUID;
|
|
171
|
+
/**
|
|
172
|
+
* Generates a UUIDv4 string.
|
|
173
|
+
*
|
|
174
|
+
* @returns The 8-4-4-4-12 canonical hexadecimal string representation
|
|
175
|
+
* ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").
|
|
176
|
+
*/
|
|
177
|
+
export declare const uuidv4: () => string;
|
|
178
|
+
/** Generates a UUIDv4 object. */
|
|
179
|
+
export declare const uuidv4obj: () => UUID;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PostHogCoreOptions } from '../../posthog-core/src';
|
|
2
2
|
export declare type PostHogOptions = {
|
|
3
3
|
autocapture?: boolean;
|
|
4
4
|
persistence?: 'localStorage' | 'sessionStorage' | 'cookie' | 'memory';
|
|
5
5
|
persistence_name?: string;
|
|
6
|
-
} &
|
|
6
|
+
} & PostHogCoreOptions;
|
package/package.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PostHogCoreOptions } from '../../posthog-core/src'
|
|
2
2
|
|
|
3
3
|
export type PostHogOptions = {
|
|
4
4
|
autocapture?: boolean
|
|
5
5
|
persistence?: 'localStorage' | 'sessionStorage' | 'cookie' | 'memory'
|
|
6
6
|
persistence_name?: string
|
|
7
|
-
} &
|
|
7
|
+
} & PostHogCoreOptions
|
package/test/posthog-web.spec.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* @jest-environment jsdom
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import { waitForPromises } from 'posthog-core/test/test-utils/test-utils'
|
|
5
6
|
import { PostHog } from '..'
|
|
6
7
|
|
|
7
|
-
describe('
|
|
8
|
+
describe('PostHogWeb', () => {
|
|
8
9
|
let fetch: jest.Mock
|
|
9
10
|
jest.useRealTimers()
|
|
10
11
|
|
|
@@ -41,13 +42,14 @@ describe('PosthogWeb', () => {
|
|
|
41
42
|
})
|
|
42
43
|
|
|
43
44
|
describe('init', () => {
|
|
44
|
-
it('should initialise', () => {
|
|
45
|
+
it('should initialise', async () => {
|
|
45
46
|
const posthog = new PostHog('TEST_API_KEY', {
|
|
46
47
|
flushAt: 1,
|
|
47
48
|
})
|
|
48
49
|
expect(posthog.optedOut).toEqual(false)
|
|
49
50
|
|
|
50
51
|
posthog.capture('test')
|
|
52
|
+
await waitForPromises()
|
|
51
53
|
|
|
52
54
|
expect(fetch).toHaveBeenCalledTimes(2)
|
|
53
55
|
})
|
|
@@ -57,6 +59,8 @@ describe('PosthogWeb', () => {
|
|
|
57
59
|
flushAt: 1,
|
|
58
60
|
})
|
|
59
61
|
|
|
62
|
+
await waitForPromises()
|
|
63
|
+
|
|
60
64
|
expect(fetch).toHaveBeenCalledWith('https://app.posthog.com/decide/?v=3', {
|
|
61
65
|
body: JSON.stringify({
|
|
62
66
|
token: 'TEST_API_KEY',
|