@posthog/browser-common 0.9.2 → 0.9.3
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/dist/config.js +1 -1
- package/dist/config.mjs +1 -1
- package/dist/constants.d.ts +16 -0
- package/dist/constants.js +64 -0
- package/dist/constants.mjs +17 -1
- package/dist/feature-flags-config.d.ts +23 -0
- package/dist/feature-flags-config.js +18 -0
- package/dist/feature-flags-config.mjs +1 -0
- package/dist/feature-flags.d.ts +329 -0
- package/dist/feature-flags.js +1222 -0
- package/dist/feature-flags.mjs +1172 -0
- package/dist/types/feature-flags.d.ts +18 -0
- package/dist/types/feature-flags.js +18 -0
- package/dist/types/feature-flags.mjs +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +7 -0
- package/dist/types/index.mjs +1 -0
- package/dist/utils/event-utils.d.ts +1 -1
- package/dist/utils/event-utils.js +3 -9
- package/dist/utils/event-utils.mjs +1 -7
- package/dist/utils/logger.js +8 -3
- package/dist/utils/logger.mjs +8 -3
- package/dist/utils/request-reachability.d.ts +2 -0
- package/dist/utils/request-reachability.js +61 -0
- package/dist/utils/request-reachability.mjs +20 -0
- package/dist/utils/request-utils.d.ts +1 -2
- package/dist/utils/request-utils.js +3 -14
- package/dist/utils/request-utils.mjs +3 -14
- package/dist/utils/timezone.d.ts +1 -0
- package/dist/utils/timezone.js +46 -0
- package/dist/utils/timezone.mjs +8 -0
- package/package.json +19 -3
package/dist/config.js
CHANGED
package/dist/config.mjs
CHANGED
package/dist/constants.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
1
|
export declare const TOOLBAR_ID = "__POSTHOG_TOOLBAR__";
|
|
2
2
|
export declare const TOOLBAR_CONTAINER_CLASS = "toolbar-global-fade-container";
|
|
3
3
|
export declare const SDK_DIST_CHANNEL = "$sdk_dist_channel";
|
|
4
|
+
export declare const PERSISTENCE_EARLY_ACCESS_FEATURES = "$early_access_features";
|
|
5
|
+
export declare const PERSISTENCE_ACTIVE_FEATURE_FLAGS = "$active_feature_flags";
|
|
6
|
+
export declare const PERSISTENCE_FEATURE_FLAG_DETAILS = "$feature_flag_details";
|
|
7
|
+
export declare const PERSISTENCE_FEATURE_FLAG_ERRORS = "$feature_flag_errors";
|
|
8
|
+
export declare const PERSISTENCE_FEATURE_FLAG_EVALUATED_AT = "$feature_flag_evaluated_at";
|
|
9
|
+
export declare const PERSISTENCE_FEATURE_FLAG_REQUEST_ID = "$feature_flag_request_id";
|
|
10
|
+
export declare const PERSISTENCE_MINIMAL_FLAG_CALLED_EVENTS = "$minimal_flag_called_events";
|
|
11
|
+
export declare const ENABLED_FEATURE_FLAGS = "$enabled_feature_flags";
|
|
12
|
+
export declare const STORED_GROUP_PROPERTIES_KEY = "$stored_group_properties";
|
|
13
|
+
export declare const STORED_PERSON_PROPERTIES_KEY = "$stored_person_properties";
|
|
14
|
+
export declare const FLAG_CALL_REPORTED = "$flag_call_reported";
|
|
15
|
+
export declare const FLAG_CALL_REPORTED_SESSION_ID = "$flag_call_reported_session_id";
|
|
16
|
+
export declare const PERSISTENCE_FEATURE_FLAG_PAYLOADS = "$feature_flag_payloads";
|
|
17
|
+
export declare const PERSISTENCE_OVERRIDE_FEATURE_FLAGS = "$override_feature_flags";
|
|
18
|
+
export declare const PERSISTENCE_OVERRIDE_FEATURE_FLAG_PAYLOADS = "$override_feature_flag_payloads";
|
|
19
|
+
export declare const DOM_EVENT_VISIBILITYCHANGE = "visibilitychange";
|
package/dist/constants.js
CHANGED
|
@@ -30,16 +30,80 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
30
30
|
const TOOLBAR_ID = '__POSTHOG_TOOLBAR__';
|
|
31
31
|
const TOOLBAR_CONTAINER_CLASS = 'toolbar-global-fade-container';
|
|
32
32
|
const SDK_DIST_CHANNEL = '$sdk_dist_channel';
|
|
33
|
+
const PERSISTENCE_EARLY_ACCESS_FEATURES = '$early_access_features';
|
|
34
|
+
const PERSISTENCE_ACTIVE_FEATURE_FLAGS = '$active_feature_flags';
|
|
35
|
+
const PERSISTENCE_FEATURE_FLAG_DETAILS = '$feature_flag_details';
|
|
36
|
+
const PERSISTENCE_FEATURE_FLAG_ERRORS = '$feature_flag_errors';
|
|
37
|
+
const PERSISTENCE_FEATURE_FLAG_EVALUATED_AT = '$feature_flag_evaluated_at';
|
|
38
|
+
const PERSISTENCE_FEATURE_FLAG_REQUEST_ID = '$feature_flag_request_id';
|
|
39
|
+
const PERSISTENCE_MINIMAL_FLAG_CALLED_EVENTS = '$minimal_flag_called_events';
|
|
40
|
+
const ENABLED_FEATURE_FLAGS = '$enabled_feature_flags';
|
|
41
|
+
const STORED_GROUP_PROPERTIES_KEY = '$stored_group_properties';
|
|
42
|
+
const STORED_PERSON_PROPERTIES_KEY = '$stored_person_properties';
|
|
43
|
+
const FLAG_CALL_REPORTED = '$flag_call_reported';
|
|
44
|
+
const FLAG_CALL_REPORTED_SESSION_ID = '$flag_call_reported_session_id';
|
|
45
|
+
const PERSISTENCE_FEATURE_FLAG_PAYLOADS = '$feature_flag_payloads';
|
|
46
|
+
const PERSISTENCE_OVERRIDE_FEATURE_FLAGS = '$override_feature_flags';
|
|
47
|
+
const PERSISTENCE_OVERRIDE_FEATURE_FLAG_PAYLOADS = '$override_feature_flag_payloads';
|
|
48
|
+
const DOM_EVENT_VISIBILITYCHANGE = 'visibilitychange';
|
|
33
49
|
__webpack_require__.d(__webpack_exports__, {}, {
|
|
50
|
+
DOM_EVENT_VISIBILITYCHANGE: DOM_EVENT_VISIBILITYCHANGE,
|
|
51
|
+
ENABLED_FEATURE_FLAGS: ENABLED_FEATURE_FLAGS,
|
|
52
|
+
FLAG_CALL_REPORTED: FLAG_CALL_REPORTED,
|
|
53
|
+
FLAG_CALL_REPORTED_SESSION_ID: FLAG_CALL_REPORTED_SESSION_ID,
|
|
54
|
+
PERSISTENCE_ACTIVE_FEATURE_FLAGS: PERSISTENCE_ACTIVE_FEATURE_FLAGS,
|
|
55
|
+
PERSISTENCE_EARLY_ACCESS_FEATURES: PERSISTENCE_EARLY_ACCESS_FEATURES,
|
|
56
|
+
PERSISTENCE_FEATURE_FLAG_DETAILS: PERSISTENCE_FEATURE_FLAG_DETAILS,
|
|
57
|
+
PERSISTENCE_FEATURE_FLAG_ERRORS: PERSISTENCE_FEATURE_FLAG_ERRORS,
|
|
58
|
+
PERSISTENCE_FEATURE_FLAG_EVALUATED_AT: PERSISTENCE_FEATURE_FLAG_EVALUATED_AT,
|
|
59
|
+
PERSISTENCE_FEATURE_FLAG_PAYLOADS: PERSISTENCE_FEATURE_FLAG_PAYLOADS,
|
|
60
|
+
PERSISTENCE_FEATURE_FLAG_REQUEST_ID: PERSISTENCE_FEATURE_FLAG_REQUEST_ID,
|
|
61
|
+
PERSISTENCE_MINIMAL_FLAG_CALLED_EVENTS: PERSISTENCE_MINIMAL_FLAG_CALLED_EVENTS,
|
|
62
|
+
PERSISTENCE_OVERRIDE_FEATURE_FLAGS: PERSISTENCE_OVERRIDE_FEATURE_FLAGS,
|
|
63
|
+
PERSISTENCE_OVERRIDE_FEATURE_FLAG_PAYLOADS: PERSISTENCE_OVERRIDE_FEATURE_FLAG_PAYLOADS,
|
|
34
64
|
SDK_DIST_CHANNEL: SDK_DIST_CHANNEL,
|
|
65
|
+
STORED_GROUP_PROPERTIES_KEY: STORED_GROUP_PROPERTIES_KEY,
|
|
66
|
+
STORED_PERSON_PROPERTIES_KEY: STORED_PERSON_PROPERTIES_KEY,
|
|
35
67
|
TOOLBAR_CONTAINER_CLASS: TOOLBAR_CONTAINER_CLASS,
|
|
36
68
|
TOOLBAR_ID: TOOLBAR_ID
|
|
37
69
|
});
|
|
70
|
+
exports.DOM_EVENT_VISIBILITYCHANGE = __webpack_exports__.DOM_EVENT_VISIBILITYCHANGE;
|
|
71
|
+
exports.ENABLED_FEATURE_FLAGS = __webpack_exports__.ENABLED_FEATURE_FLAGS;
|
|
72
|
+
exports.FLAG_CALL_REPORTED = __webpack_exports__.FLAG_CALL_REPORTED;
|
|
73
|
+
exports.FLAG_CALL_REPORTED_SESSION_ID = __webpack_exports__.FLAG_CALL_REPORTED_SESSION_ID;
|
|
74
|
+
exports.PERSISTENCE_ACTIVE_FEATURE_FLAGS = __webpack_exports__.PERSISTENCE_ACTIVE_FEATURE_FLAGS;
|
|
75
|
+
exports.PERSISTENCE_EARLY_ACCESS_FEATURES = __webpack_exports__.PERSISTENCE_EARLY_ACCESS_FEATURES;
|
|
76
|
+
exports.PERSISTENCE_FEATURE_FLAG_DETAILS = __webpack_exports__.PERSISTENCE_FEATURE_FLAG_DETAILS;
|
|
77
|
+
exports.PERSISTENCE_FEATURE_FLAG_ERRORS = __webpack_exports__.PERSISTENCE_FEATURE_FLAG_ERRORS;
|
|
78
|
+
exports.PERSISTENCE_FEATURE_FLAG_EVALUATED_AT = __webpack_exports__.PERSISTENCE_FEATURE_FLAG_EVALUATED_AT;
|
|
79
|
+
exports.PERSISTENCE_FEATURE_FLAG_PAYLOADS = __webpack_exports__.PERSISTENCE_FEATURE_FLAG_PAYLOADS;
|
|
80
|
+
exports.PERSISTENCE_FEATURE_FLAG_REQUEST_ID = __webpack_exports__.PERSISTENCE_FEATURE_FLAG_REQUEST_ID;
|
|
81
|
+
exports.PERSISTENCE_MINIMAL_FLAG_CALLED_EVENTS = __webpack_exports__.PERSISTENCE_MINIMAL_FLAG_CALLED_EVENTS;
|
|
82
|
+
exports.PERSISTENCE_OVERRIDE_FEATURE_FLAGS = __webpack_exports__.PERSISTENCE_OVERRIDE_FEATURE_FLAGS;
|
|
83
|
+
exports.PERSISTENCE_OVERRIDE_FEATURE_FLAG_PAYLOADS = __webpack_exports__.PERSISTENCE_OVERRIDE_FEATURE_FLAG_PAYLOADS;
|
|
38
84
|
exports.SDK_DIST_CHANNEL = __webpack_exports__.SDK_DIST_CHANNEL;
|
|
85
|
+
exports.STORED_GROUP_PROPERTIES_KEY = __webpack_exports__.STORED_GROUP_PROPERTIES_KEY;
|
|
86
|
+
exports.STORED_PERSON_PROPERTIES_KEY = __webpack_exports__.STORED_PERSON_PROPERTIES_KEY;
|
|
39
87
|
exports.TOOLBAR_CONTAINER_CLASS = __webpack_exports__.TOOLBAR_CONTAINER_CLASS;
|
|
40
88
|
exports.TOOLBAR_ID = __webpack_exports__.TOOLBAR_ID;
|
|
41
89
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
90
|
+
"DOM_EVENT_VISIBILITYCHANGE",
|
|
91
|
+
"ENABLED_FEATURE_FLAGS",
|
|
92
|
+
"FLAG_CALL_REPORTED",
|
|
93
|
+
"FLAG_CALL_REPORTED_SESSION_ID",
|
|
94
|
+
"PERSISTENCE_ACTIVE_FEATURE_FLAGS",
|
|
95
|
+
"PERSISTENCE_EARLY_ACCESS_FEATURES",
|
|
96
|
+
"PERSISTENCE_FEATURE_FLAG_DETAILS",
|
|
97
|
+
"PERSISTENCE_FEATURE_FLAG_ERRORS",
|
|
98
|
+
"PERSISTENCE_FEATURE_FLAG_EVALUATED_AT",
|
|
99
|
+
"PERSISTENCE_FEATURE_FLAG_PAYLOADS",
|
|
100
|
+
"PERSISTENCE_FEATURE_FLAG_REQUEST_ID",
|
|
101
|
+
"PERSISTENCE_MINIMAL_FLAG_CALLED_EVENTS",
|
|
102
|
+
"PERSISTENCE_OVERRIDE_FEATURE_FLAGS",
|
|
103
|
+
"PERSISTENCE_OVERRIDE_FEATURE_FLAG_PAYLOADS",
|
|
42
104
|
"SDK_DIST_CHANNEL",
|
|
105
|
+
"STORED_GROUP_PROPERTIES_KEY",
|
|
106
|
+
"STORED_PERSON_PROPERTIES_KEY",
|
|
43
107
|
"TOOLBAR_CONTAINER_CLASS",
|
|
44
108
|
"TOOLBAR_ID"
|
|
45
109
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
package/dist/constants.mjs
CHANGED
|
@@ -1,4 +1,20 @@
|
|
|
1
1
|
const TOOLBAR_ID = '__POSTHOG_TOOLBAR__';
|
|
2
2
|
const TOOLBAR_CONTAINER_CLASS = 'toolbar-global-fade-container';
|
|
3
3
|
const SDK_DIST_CHANNEL = '$sdk_dist_channel';
|
|
4
|
-
|
|
4
|
+
const PERSISTENCE_EARLY_ACCESS_FEATURES = '$early_access_features';
|
|
5
|
+
const PERSISTENCE_ACTIVE_FEATURE_FLAGS = '$active_feature_flags';
|
|
6
|
+
const PERSISTENCE_FEATURE_FLAG_DETAILS = '$feature_flag_details';
|
|
7
|
+
const PERSISTENCE_FEATURE_FLAG_ERRORS = '$feature_flag_errors';
|
|
8
|
+
const PERSISTENCE_FEATURE_FLAG_EVALUATED_AT = '$feature_flag_evaluated_at';
|
|
9
|
+
const PERSISTENCE_FEATURE_FLAG_REQUEST_ID = '$feature_flag_request_id';
|
|
10
|
+
const PERSISTENCE_MINIMAL_FLAG_CALLED_EVENTS = '$minimal_flag_called_events';
|
|
11
|
+
const ENABLED_FEATURE_FLAGS = '$enabled_feature_flags';
|
|
12
|
+
const STORED_GROUP_PROPERTIES_KEY = '$stored_group_properties';
|
|
13
|
+
const STORED_PERSON_PROPERTIES_KEY = '$stored_person_properties';
|
|
14
|
+
const FLAG_CALL_REPORTED = '$flag_call_reported';
|
|
15
|
+
const FLAG_CALL_REPORTED_SESSION_ID = '$flag_call_reported_session_id';
|
|
16
|
+
const PERSISTENCE_FEATURE_FLAG_PAYLOADS = '$feature_flag_payloads';
|
|
17
|
+
const PERSISTENCE_OVERRIDE_FEATURE_FLAGS = '$override_feature_flags';
|
|
18
|
+
const PERSISTENCE_OVERRIDE_FEATURE_FLAG_PAYLOADS = '$override_feature_flag_payloads';
|
|
19
|
+
const DOM_EVENT_VISIBILITYCHANGE = 'visibilitychange';
|
|
20
|
+
export { DOM_EVENT_VISIBILITYCHANGE, ENABLED_FEATURE_FLAGS, FLAG_CALL_REPORTED, FLAG_CALL_REPORTED_SESSION_ID, PERSISTENCE_ACTIVE_FEATURE_FLAGS, PERSISTENCE_EARLY_ACCESS_FEATURES, PERSISTENCE_FEATURE_FLAG_DETAILS, PERSISTENCE_FEATURE_FLAG_ERRORS, PERSISTENCE_FEATURE_FLAG_EVALUATED_AT, PERSISTENCE_FEATURE_FLAG_PAYLOADS, PERSISTENCE_FEATURE_FLAG_REQUEST_ID, PERSISTENCE_MINIMAL_FLAG_CALLED_EVENTS, PERSISTENCE_OVERRIDE_FEATURE_FLAGS, PERSISTENCE_OVERRIDE_FEATURE_FLAG_PAYLOADS, SDK_DIST_CHANNEL, STORED_GROUP_PROPERTIES_KEY, STORED_PERSON_PROPERTIES_KEY, TOOLBAR_CONTAINER_CLASS, TOOLBAR_ID };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { JsonType } from '@posthog/types';
|
|
2
|
+
import type { Compression } from './types/compression';
|
|
3
|
+
export interface FeatureFlagsConfig {
|
|
4
|
+
readonly bootstrap: {
|
|
5
|
+
readonly featureFlags?: Readonly<Record<string, string | boolean>>;
|
|
6
|
+
readonly featureFlagPayloads?: Readonly<Record<string, JsonType>>;
|
|
7
|
+
};
|
|
8
|
+
readonly remoteRequestsDisabled: boolean;
|
|
9
|
+
readonly featureFlagsDisabled: boolean;
|
|
10
|
+
readonly onlyEvaluateSurveyFeatureFlags: boolean;
|
|
11
|
+
readonly deduplicateCallsPerSession: boolean;
|
|
12
|
+
readonly cacheTtlMs?: number;
|
|
13
|
+
readonly refreshIntervalMs?: number;
|
|
14
|
+
readonly idleRefreshBackoff: boolean;
|
|
15
|
+
readonly requestTimeoutMs: number;
|
|
16
|
+
readonly requestMaxRetries?: number;
|
|
17
|
+
readonly compression?: Compression | 'best-available';
|
|
18
|
+
readonly evaluationContexts: readonly string[];
|
|
19
|
+
readonly flagKeys?: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
export interface FeatureFlagsConfigSource {
|
|
22
|
+
get(): Readonly<FeatureFlagsConfig>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import type { Client } from './client';
|
|
2
|
+
import type { Extension } from './extension';
|
|
3
|
+
import type { FlagsResponse } from './types/feature-flags';
|
|
4
|
+
import type { FeatureFlagsCallback, EarlyAccessFeatureCallback, Properties, JsonType, EarlyAccessFeature, RemoteConfigFeatureFlagCallback, EarlyAccessFeatureStage, FeatureFlagDetail, FeatureFlagResult, FeatureFlagOptions, IsFeatureEnabledOptions, OverrideFeatureFlagsOptions } from '@posthog/types';
|
|
5
|
+
import type { FeatureFlagsConfigSource } from './feature-flags-config';
|
|
6
|
+
import { PERSISTENCE_EARLY_ACCESS_FEATURES, PERSISTENCE_ACTIVE_FEATURE_FLAGS, PERSISTENCE_FEATURE_FLAG_DETAILS, PERSISTENCE_FEATURE_FLAG_ERRORS, PERSISTENCE_FEATURE_FLAG_EVALUATED_AT, PERSISTENCE_FEATURE_FLAG_REQUEST_ID, PERSISTENCE_MINIMAL_FLAG_CALLED_EVENTS, ENABLED_FEATURE_FLAGS, STORED_GROUP_PROPERTIES_KEY, STORED_PERSON_PROPERTIES_KEY, FLAG_CALL_REPORTED, FLAG_CALL_REPORTED_SESSION_ID, PERSISTENCE_FEATURE_FLAG_PAYLOADS, PERSISTENCE_OVERRIDE_FEATURE_FLAGS, PERSISTENCE_OVERRIDE_FEATURE_FLAG_PAYLOADS } from './constants';
|
|
7
|
+
import { type Logger } from '@posthog/core';
|
|
8
|
+
type FeatureFlagsState = {
|
|
9
|
+
[PERSISTENCE_ACTIVE_FEATURE_FLAGS]?: string[];
|
|
10
|
+
[ENABLED_FEATURE_FLAGS]?: Record<string, string | boolean>;
|
|
11
|
+
[PERSISTENCE_FEATURE_FLAG_DETAILS]?: Record<string, FeatureFlagDetail>;
|
|
12
|
+
[PERSISTENCE_FEATURE_FLAG_PAYLOADS]?: Record<string, JsonType>;
|
|
13
|
+
[PERSISTENCE_FEATURE_FLAG_REQUEST_ID]?: string;
|
|
14
|
+
[PERSISTENCE_FEATURE_FLAG_EVALUATED_AT]?: number;
|
|
15
|
+
[PERSISTENCE_MINIMAL_FLAG_CALLED_EVENTS]?: boolean;
|
|
16
|
+
[PERSISTENCE_FEATURE_FLAG_ERRORS]?: string[];
|
|
17
|
+
[PERSISTENCE_OVERRIDE_FEATURE_FLAGS]?: Record<string, string | boolean>;
|
|
18
|
+
[PERSISTENCE_OVERRIDE_FEATURE_FLAG_PAYLOADS]?: Record<string, JsonType>;
|
|
19
|
+
[FLAG_CALL_REPORTED]?: Record<string, string[]>;
|
|
20
|
+
[FLAG_CALL_REPORTED_SESSION_ID]?: string;
|
|
21
|
+
[STORED_PERSON_PROPERTIES_KEY]?: Properties;
|
|
22
|
+
[STORED_GROUP_PROPERTIES_KEY]?: Record<string, Properties>;
|
|
23
|
+
[PERSISTENCE_EARLY_ACCESS_FEATURES]?: EarlyAccessFeature[];
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Error type constants for the $feature_flag_error property.
|
|
27
|
+
*
|
|
28
|
+
* These values are sent in analytics events to track flag evaluation failures.
|
|
29
|
+
* They should not be changed without considering impact on existing dashboards
|
|
30
|
+
* and queries that filter on these values.
|
|
31
|
+
*/
|
|
32
|
+
export declare const FeatureFlagError: {
|
|
33
|
+
readonly ERRORS_WHILE_COMPUTING: 'errors_while_computing_flags';
|
|
34
|
+
readonly FLAG_MISSING: 'flag_missing';
|
|
35
|
+
readonly QUOTA_LIMITED: 'quota_limited';
|
|
36
|
+
readonly TIMEOUT: 'timeout';
|
|
37
|
+
readonly CONNECTION_ERROR: 'connection_error';
|
|
38
|
+
readonly UNKNOWN_ERROR: 'unknown_error';
|
|
39
|
+
readonly apiError: (status: number | string) => string;
|
|
40
|
+
};
|
|
41
|
+
export declare const filterActiveFeatureFlags: (featureFlags?: Record<string, string | boolean>) => Record<string, string | boolean>;
|
|
42
|
+
export declare const parseFlagsResponse: (response: Partial<FlagsResponse>, currentFlags?: Record<string, string | boolean>, currentFlagPayloads?: Record<string, JsonType>, currentFlagDetails?: Record<string, FeatureFlagDetail>, options?: {
|
|
43
|
+
partialResponse?: boolean;
|
|
44
|
+
}, responseLogger?: Logger) => FeatureFlagsState | undefined;
|
|
45
|
+
export declare const QuotaLimitedResource: {
|
|
46
|
+
readonly FeatureFlags: 'feature_flags';
|
|
47
|
+
readonly Recordings: 'recordings';
|
|
48
|
+
};
|
|
49
|
+
export type QuotaLimitedResource = (typeof QuotaLimitedResource)[keyof typeof QuotaLimitedResource];
|
|
50
|
+
export interface FeatureFlagsReloadResult {
|
|
51
|
+
/** loaded: evaluation completed; error: request/evaluation failed; skipped: evaluation unavailable; cancelled: reset/disposal. */
|
|
52
|
+
status: 'loaded' | 'error' | 'skipped' | 'cancelled';
|
|
53
|
+
}
|
|
54
|
+
export declare class PostHogFeatureFlags implements Extension {
|
|
55
|
+
readonly name: string;
|
|
56
|
+
_override_warning: boolean;
|
|
57
|
+
featureFlagEventHandlers: FeatureFlagsCallback[];
|
|
58
|
+
$anon_distinct_id: string | undefined;
|
|
59
|
+
private _window;
|
|
60
|
+
private _document;
|
|
61
|
+
private _client;
|
|
62
|
+
private _initializingClient;
|
|
63
|
+
private _logger;
|
|
64
|
+
private _dynamicProperties;
|
|
65
|
+
private _crossTabPersistenceUnsubscribe;
|
|
66
|
+
private _baseEventProperties;
|
|
67
|
+
private _eventPropertiesWithFlagValues;
|
|
68
|
+
private _bootstrapState;
|
|
69
|
+
private _reloadingHandlers;
|
|
70
|
+
private _pendingReloads;
|
|
71
|
+
private _activeReloads;
|
|
72
|
+
private _hasLoadedFlags;
|
|
73
|
+
private _requestInFlight;
|
|
74
|
+
private _requestGeneration;
|
|
75
|
+
private _reloadingDisabled;
|
|
76
|
+
private _additionalReloadRequested;
|
|
77
|
+
private _reloadDebouncer;
|
|
78
|
+
private _flagsLoadedFromRemote;
|
|
79
|
+
private _staleCacheRefreshTriggered;
|
|
80
|
+
private _consecutiveStatusZeroFailures;
|
|
81
|
+
private _refreshInterval;
|
|
82
|
+
private _refreshIntervalMs;
|
|
83
|
+
private _dueRefreshIntervalMs;
|
|
84
|
+
private _hadUserInteraction;
|
|
85
|
+
private _lastRefreshAt;
|
|
86
|
+
private readonly _configSource;
|
|
87
|
+
constructor(configSource: FeatureFlagsConfigSource);
|
|
88
|
+
/** Host persistence may merge flag snapshots across tabs independently of KV writes. */
|
|
89
|
+
protected get _crossTabPersistence(): {
|
|
90
|
+
onCrossTabFeatureFlagChange(handler: () => void): () => void;
|
|
91
|
+
markCrossTabFeatureFlagChanges(changes: Record<string, readonly string[] | true>): void;
|
|
92
|
+
} | undefined;
|
|
93
|
+
protected _onConfigUpdated(): void;
|
|
94
|
+
setup(client: Client): void | Promise<void>;
|
|
95
|
+
private _finishSetup;
|
|
96
|
+
private _onOnline;
|
|
97
|
+
private _refreshIfDue;
|
|
98
|
+
private _onUserInteraction;
|
|
99
|
+
private _onVisibilityChange;
|
|
100
|
+
private _resumeConfiguredInterval;
|
|
101
|
+
private _syncAutomaticRefresh;
|
|
102
|
+
private _scheduleNextRefresh;
|
|
103
|
+
private _stopAutomaticRefresh;
|
|
104
|
+
destroy(): void;
|
|
105
|
+
dispose(): void;
|
|
106
|
+
private _dispose;
|
|
107
|
+
private get _config();
|
|
108
|
+
private _prop;
|
|
109
|
+
private _clearBootstrapState;
|
|
110
|
+
private _fallBackToPersistedFlags;
|
|
111
|
+
private _set;
|
|
112
|
+
private _markCrossTabFeatureFlagSnapshot;
|
|
113
|
+
private _remove;
|
|
114
|
+
private _persist;
|
|
115
|
+
private _rebuildEventProperties;
|
|
116
|
+
/**
|
|
117
|
+
* Check if the feature flag cache is stale based on the configured TTL.
|
|
118
|
+
*/
|
|
119
|
+
private _isCacheStale;
|
|
120
|
+
/**
|
|
121
|
+
* Triggers a debounced reload when cache staleness is first detected.
|
|
122
|
+
* Returns true if cache is stale, false otherwise.
|
|
123
|
+
*/
|
|
124
|
+
private _checkAndTriggerStaleRefresh;
|
|
125
|
+
private _getValidEvaluationEnvironments;
|
|
126
|
+
private _getValidFlagKeys;
|
|
127
|
+
initialize(): void;
|
|
128
|
+
updateFlags(flags: Record<string, boolean | string>, payloads?: Record<string, JsonType>, options?: {
|
|
129
|
+
merge?: boolean;
|
|
130
|
+
}): void;
|
|
131
|
+
get hasLoadedFlags(): boolean;
|
|
132
|
+
getFlags(): string[];
|
|
133
|
+
getFlagsWithDetails(): Record<string, FeatureFlagDetail>;
|
|
134
|
+
getAllFeatureFlags(): FeatureFlagResult[];
|
|
135
|
+
getFlagVariants(): Record<string, string | boolean>;
|
|
136
|
+
getFlagPayloads(): Record<string, JsonType>;
|
|
137
|
+
/**
|
|
138
|
+
* Reloads feature flags asynchronously.
|
|
139
|
+
*
|
|
140
|
+
* Constraints:
|
|
141
|
+
*
|
|
142
|
+
* 1. Avoid parallel requests
|
|
143
|
+
* 2. Delay a few milliseconds after each reloadFeatureFlags call to batch subsequent changes together
|
|
144
|
+
*/
|
|
145
|
+
reloadFeatureFlags(): void;
|
|
146
|
+
/** Await the next requested evaluation, rather than cached or locally injected flag changes. */
|
|
147
|
+
reloadFeatureFlagsAsync(): Promise<FeatureFlagsReloadResult>;
|
|
148
|
+
private _settleReloads;
|
|
149
|
+
private _clearDebouncer;
|
|
150
|
+
onReloading(handler: () => void): () => void;
|
|
151
|
+
ensureFlagsLoaded(): void;
|
|
152
|
+
setAnonymousDistinctId(anon_distinct_id: string | undefined): void;
|
|
153
|
+
setReloadingPaused(isPaused: boolean): void;
|
|
154
|
+
resetFlagCallReported(): void;
|
|
155
|
+
_callFlagsEndpoint(options?: {
|
|
156
|
+
disableFlags?: boolean;
|
|
157
|
+
}): void;
|
|
158
|
+
private _hasStatusZeroCircuitBreakerTripped;
|
|
159
|
+
private _trackStatusZeroReachability;
|
|
160
|
+
/**
|
|
161
|
+
* Get feature flag's value for user.
|
|
162
|
+
*
|
|
163
|
+
* By default, this method may return cached values from localStorage if the `/flags` endpoint
|
|
164
|
+
* hasn't responded yet. This reduces flicker but means you might briefly see stale values
|
|
165
|
+
* (e.g., a flag that was made globally inactive on the server).
|
|
166
|
+
*
|
|
167
|
+
* An evaluated boolean flag returns `true` or `false`; `undefined` means no current evaluation
|
|
168
|
+
* is available for the key. Globally inactive flags are omitted from the remote `/flags`
|
|
169
|
+
* response, so after that response loads they are unavailable rather than represented by
|
|
170
|
+
* a `false` result.
|
|
171
|
+
*
|
|
172
|
+
* ### Usage:
|
|
173
|
+
*
|
|
174
|
+
* if(posthog.getFeatureFlag('my-flag') === 'some-variant') { // do something }
|
|
175
|
+
*
|
|
176
|
+
* // Only use fresh values from the server (returns undefined until /flags responds)
|
|
177
|
+
* if(posthog.getFeatureFlag('my-flag', { fresh: true }) === 'some-variant') { // do something }
|
|
178
|
+
*
|
|
179
|
+
* @param {String} key Key of the feature flag.
|
|
180
|
+
* @param {Object} options Optional settings.
|
|
181
|
+
* @param {boolean} [options.send_event=true] If false, won't send a $feature_flag_called event to PostHog.
|
|
182
|
+
* @param {boolean} [options.fresh=false] If true, only returns values loaded from the server, not cached localStorage values.
|
|
183
|
+
* Use this when you need to ensure the flag value reflects the current server state,
|
|
184
|
+
* such as after making a flag globally inactive. Returns undefined until the /flags endpoint responds.
|
|
185
|
+
* @returns {boolean | string | undefined} The flag value, or undefined if no current evaluation is available.
|
|
186
|
+
*/
|
|
187
|
+
getFeatureFlag(key: string, options?: FeatureFlagOptions): boolean | string | undefined;
|
|
188
|
+
getFeatureFlagDetails(key: string): FeatureFlagDetail | undefined;
|
|
189
|
+
/**
|
|
190
|
+
* @deprecated Use `getFeatureFlagResult()` instead which properly tracks the feature flag call.
|
|
191
|
+
* `getFeatureFlagPayload()` does not emit the `$feature_flag_called` event which may result in
|
|
192
|
+
* missing analytics. This method will be removed in a future version.
|
|
193
|
+
*/
|
|
194
|
+
getFeatureFlagPayload(key: string): JsonType;
|
|
195
|
+
/**
|
|
196
|
+
* Get a feature flag result including both the flag value and payload, while properly tracking the call.
|
|
197
|
+
* This method emits the `$feature_flag_called` event by default.
|
|
198
|
+
*
|
|
199
|
+
* By default, this method may return cached values from localStorage if the `/flags` endpoint
|
|
200
|
+
* hasn't responded yet. This reduces flicker but means you might briefly see stale values
|
|
201
|
+
* (e.g., a flag that was made globally inactive on the server).
|
|
202
|
+
*
|
|
203
|
+
* A result with `enabled: false` is a conclusive off evaluation. `undefined` means no current
|
|
204
|
+
* evaluation is available for the key. This includes globally inactive flags, which are omitted
|
|
205
|
+
* from the remote `/flags` response.
|
|
206
|
+
*
|
|
207
|
+
* ### Usage:
|
|
208
|
+
*
|
|
209
|
+
* const result = posthog.getFeatureFlagResult('my-flag')
|
|
210
|
+
* if (result?.enabled) {
|
|
211
|
+
* console.log('Flag is enabled with payload:', result.payload)
|
|
212
|
+
* }
|
|
213
|
+
*
|
|
214
|
+
* // Only use fresh values from the server
|
|
215
|
+
* const freshResult = posthog.getFeatureFlagResult('my-flag', { fresh: true })
|
|
216
|
+
*
|
|
217
|
+
* @param {String} key Key of the feature flag.
|
|
218
|
+
* @param {Object} [options] Options for the feature flag lookup.
|
|
219
|
+
* @param {boolean} [options.send_event=true] If false, won't send the $feature_flag_called event.
|
|
220
|
+
* @param {boolean} [options.fresh=false] If true, only returns values loaded from the server, not cached localStorage values.
|
|
221
|
+
* Use this when you need to ensure the flag value reflects the current server state.
|
|
222
|
+
* Returns undefined until the /flags endpoint responds.
|
|
223
|
+
* @returns {FeatureFlagResult | undefined} The feature flag result including key, enabled, variant, and payload.
|
|
224
|
+
*/
|
|
225
|
+
getFeatureFlagResult(key: string, options?: FeatureFlagOptions): FeatureFlagResult | undefined;
|
|
226
|
+
private _captureFeatureFlagCalled;
|
|
227
|
+
getRemoteConfigPayload(key: string, callback: RemoteConfigFeatureFlagCallback): void;
|
|
228
|
+
private _getRemoteConfigPayload;
|
|
229
|
+
/**
|
|
230
|
+
* See if feature flag is enabled for user.
|
|
231
|
+
*
|
|
232
|
+
* By default, this method may return cached values from localStorage if the `/flags` endpoint
|
|
233
|
+
* hasn't responded yet. This reduces flicker but means you might briefly see stale values
|
|
234
|
+
* (e.g., a flag that was made globally inactive on the server).
|
|
235
|
+
*
|
|
236
|
+
* A `false` result means the flag value evaluated off; it does not mean the SDK observed the
|
|
237
|
+
* flag's global active setting. When no current evaluation is available, this method returns
|
|
238
|
+
* `options.defaultValue` if provided, otherwise `undefined`. Globally inactive flags are omitted
|
|
239
|
+
* from the remote `/flags` response and therefore have no value.
|
|
240
|
+
*
|
|
241
|
+
* ### Usage:
|
|
242
|
+
*
|
|
243
|
+
* if(posthog.isFeatureEnabled('beta-feature')) { // do something }
|
|
244
|
+
*
|
|
245
|
+
* // Only use fresh values from the server
|
|
246
|
+
* if(posthog.isFeatureEnabled('beta-feature', { fresh: true })) { // do something }
|
|
247
|
+
*
|
|
248
|
+
* @param {String} key Key of the feature flag.
|
|
249
|
+
* @param {Object} [options] Optional settings.
|
|
250
|
+
* @param {boolean} [options.send_event=true] If false, won't send a $feature_flag_called event to PostHog.
|
|
251
|
+
* @param {boolean} [options.fresh=false] If true, only returns values loaded from the server, not cached localStorage values.
|
|
252
|
+
* Use this when you need to ensure the flag value reflects the current server state.
|
|
253
|
+
* Returns undefined until the /flags endpoint responds.
|
|
254
|
+
* @param {boolean} [options.defaultValue] Value to return when the flag has no value, e.g. flags have not loaded yet or no flag with that key exists.
|
|
255
|
+
* @returns {boolean | undefined} Whether the flag is enabled; when the flag has no value, defaultValue if given, otherwise undefined.
|
|
256
|
+
*/
|
|
257
|
+
isFeatureEnabled(key: string, options: IsFeatureEnabledOptions & {
|
|
258
|
+
defaultValue: boolean;
|
|
259
|
+
}): boolean;
|
|
260
|
+
isFeatureEnabled(key: string, options?: IsFeatureEnabledOptions): boolean | undefined;
|
|
261
|
+
addFeatureFlagsHandler(handler: FeatureFlagsCallback): void;
|
|
262
|
+
removeFeatureFlagsHandler(handler: FeatureFlagsCallback): void;
|
|
263
|
+
receivedFeatureFlags(response: Partial<FlagsResponse>, errorsLoading?: boolean, options?: {
|
|
264
|
+
partialResponse?: boolean;
|
|
265
|
+
}): void;
|
|
266
|
+
private _receivedFeatureFlags;
|
|
267
|
+
/**
|
|
268
|
+
* @deprecated Use overrideFeatureFlags instead. This will be removed in a future version.
|
|
269
|
+
*/
|
|
270
|
+
override(flags: boolean | string[] | Record<string, string | boolean>, suppressWarning?: boolean): void;
|
|
271
|
+
/**
|
|
272
|
+
* Override feature flags on the client-side. Useful for setting non-persistent feature flags,
|
|
273
|
+
* or for testing/debugging feature flags in the PostHog app.
|
|
274
|
+
*
|
|
275
|
+
* ### Usage:
|
|
276
|
+
*
|
|
277
|
+
* - posthog.featureFlags.overrideFeatureFlags(false) // clear all overrides
|
|
278
|
+
* - posthog.featureFlags.overrideFeatureFlags(['beta-feature']) // enable flags
|
|
279
|
+
* - posthog.featureFlags.overrideFeatureFlags({'beta-feature': 'variant'}) // set variants
|
|
280
|
+
* - posthog.featureFlags.overrideFeatureFlags({ flags: ['beta-feature'] }) // enable flags
|
|
281
|
+
* - posthog.featureFlags.overrideFeatureFlags({ flags: {'beta-feature': 'variant'} }) // set variants
|
|
282
|
+
* - posthog.featureFlags.overrideFeatureFlags({ // set both flags and payloads
|
|
283
|
+
* flags: {'beta-feature': 'variant'},
|
|
284
|
+
* payloads: { 'beta-feature': { someData: true } }
|
|
285
|
+
* })
|
|
286
|
+
* - posthog.featureFlags.overrideFeatureFlags({ // only override payloads
|
|
287
|
+
* payloads: { 'beta-feature': { someData: true } }
|
|
288
|
+
* })
|
|
289
|
+
*/
|
|
290
|
+
overrideFeatureFlags(overrideOptions: OverrideFeatureFlagsOptions): void;
|
|
291
|
+
private _overrideFeatureFlags;
|
|
292
|
+
onFeatureFlags(callback: FeatureFlagsCallback): () => void;
|
|
293
|
+
updateEarlyAccessFeatureEnrollment(key: string, isEnrolled: boolean, stage?: string): void;
|
|
294
|
+
getEarlyAccessFeatures(callback: EarlyAccessFeatureCallback, force_reload?: boolean, stages?: EarlyAccessFeatureStage[]): void;
|
|
295
|
+
private _getEarlyAccessFeatures;
|
|
296
|
+
_prepareFeatureFlagsForCallbacks(): {
|
|
297
|
+
flags: string[];
|
|
298
|
+
flagVariants: Record<string, string | boolean>;
|
|
299
|
+
};
|
|
300
|
+
_fireFeatureFlagsCallbacks(errorsLoading?: boolean): void;
|
|
301
|
+
/**
|
|
302
|
+
* Set override person properties for feature flags.
|
|
303
|
+
* This is used when dealing with new persons / where you don't want to wait for ingestion
|
|
304
|
+
* to update user properties.
|
|
305
|
+
*/
|
|
306
|
+
setPersonPropertiesForFlags(properties: Properties, reloadFeatureFlags?: boolean): void;
|
|
307
|
+
private _setPersonPropertiesForFlags;
|
|
308
|
+
/**
|
|
309
|
+
* Remove override person properties used for feature flags.
|
|
310
|
+
* This is the counterpart to setPersonPropertiesForFlags, used when person properties
|
|
311
|
+
* are unset so flags re-evaluate without the removed values.
|
|
312
|
+
*/
|
|
313
|
+
unsetPersonPropertiesForFlags(propertyNames: string[], reloadFeatureFlags?: boolean): void;
|
|
314
|
+
resetPersonPropertiesForFlags(reloadFeatureFlags?: boolean): void;
|
|
315
|
+
/**
|
|
316
|
+
* Set override group properties for feature flags.
|
|
317
|
+
* This is used when dealing with new groups / where you don't want to wait for ingestion
|
|
318
|
+
* to update properties.
|
|
319
|
+
* Takes in an object, the key of which is the group type.
|
|
320
|
+
* For example:
|
|
321
|
+
* setGroupPropertiesForFlags({'organization': { name: 'CYZ', employees: '11' } })
|
|
322
|
+
*/
|
|
323
|
+
setGroupPropertiesForFlags(properties: {
|
|
324
|
+
[type: string]: Properties;
|
|
325
|
+
}, reloadFeatureFlags?: boolean): void;
|
|
326
|
+
resetGroupPropertiesForFlags(group_type?: string): void;
|
|
327
|
+
reset(): void;
|
|
328
|
+
}
|
|
329
|
+
export {};
|