@posthog/core 1.70.0 → 1.71.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.
Files changed (117) hide show
  1. package/capture-v1/package.json +6 -0
  2. package/dist/capture-v1/compression.d.ts +18 -0
  3. package/dist/capture-v1/compression.d.ts.map +1 -0
  4. package/dist/capture-v1/compression.js +70 -0
  5. package/dist/capture-v1/compression.mjs +26 -0
  6. package/dist/capture-v1/errors.d.ts +48 -0
  7. package/dist/capture-v1/errors.d.ts.map +1 -0
  8. package/dist/capture-v1/errors.js +82 -0
  9. package/dist/capture-v1/errors.mjs +38 -0
  10. package/dist/capture-v1/index.d.ts +15 -0
  11. package/dist/capture-v1/index.d.ts.map +1 -0
  12. package/dist/capture-v1/index.js +88 -0
  13. package/dist/capture-v1/index.mjs +7 -0
  14. package/dist/capture-v1/sender.d.ts +150 -0
  15. package/dist/capture-v1/sender.d.ts.map +1 -0
  16. package/dist/capture-v1/sender.js +554 -0
  17. package/dist/capture-v1/sender.mjs +507 -0
  18. package/dist/capture-v1/serialize.d.ts +30 -0
  19. package/dist/capture-v1/serialize.d.ts.map +1 -0
  20. package/dist/capture-v1/serialize.js +106 -0
  21. package/dist/capture-v1/serialize.mjs +59 -0
  22. package/dist/capture-v1/transform.d.ts +19 -0
  23. package/dist/capture-v1/transform.d.ts.map +1 -0
  24. package/dist/capture-v1/transform.js +118 -0
  25. package/dist/capture-v1/transform.mjs +77 -0
  26. package/dist/capture-v1/types.d.ts +52 -0
  27. package/dist/capture-v1/types.d.ts.map +1 -0
  28. package/dist/capture-v1/types.js +44 -0
  29. package/dist/capture-v1/types.mjs +3 -0
  30. package/dist/capture-v1/uuid.d.ts +9 -0
  31. package/dist/capture-v1/uuid.d.ts.map +1 -0
  32. package/dist/capture-v1/uuid.js +75 -0
  33. package/dist/capture-v1/uuid.mjs +34 -0
  34. package/dist/featureFlagUtils.d.ts +7 -5
  35. package/dist/featureFlagUtils.d.ts.map +1 -1
  36. package/dist/featureFlagUtils.js +17 -11
  37. package/dist/featureFlagUtils.mjs +14 -11
  38. package/dist/index.d.ts +1 -1
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +27 -16
  41. package/dist/index.mjs +1 -1
  42. package/dist/posthog-core-stateless.d.ts +40 -3
  43. package/dist/posthog-core-stateless.d.ts.map +1 -1
  44. package/dist/posthog-core-stateless.js +87 -19
  45. package/dist/posthog-core-stateless.mjs +87 -19
  46. package/dist/posthog-core.d.ts +138 -53
  47. package/dist/posthog-core.d.ts.map +1 -1
  48. package/dist/posthog-core.js +341 -115
  49. package/dist/posthog-core.mjs +338 -115
  50. package/dist/types.d.ts +24 -1
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/utils/index.d.ts +1 -1
  53. package/dist/utils/index.d.ts.map +1 -1
  54. package/dist/utils/index.js +25 -12
  55. package/dist/utils/index.mjs +1 -1
  56. package/dist/utils/json-utils.d.ts +11 -1
  57. package/dist/utils/json-utils.d.ts.map +1 -1
  58. package/dist/utils/json-utils.js +50 -2
  59. package/dist/utils/json-utils.mjs +46 -1
  60. package/package.json +12 -2
  61. package/src/capture-v1/compression.ts +50 -0
  62. package/src/capture-v1/errors.ts +91 -0
  63. package/src/capture-v1/index.ts +34 -0
  64. package/src/capture-v1/sender.ts +779 -0
  65. package/src/capture-v1/serialize.ts +113 -0
  66. package/src/capture-v1/transform.ts +135 -0
  67. package/src/capture-v1/types.ts +59 -0
  68. package/src/capture-v1/uuid.ts +53 -0
  69. package/src/featureFlagUtils.ts +22 -10
  70. package/src/index.ts +1 -0
  71. package/src/posthog-core-stateless.ts +166 -30
  72. package/src/posthog-core.ts +615 -178
  73. package/src/types.ts +21 -1
  74. package/src/utils/index.ts +1 -1
  75. package/src/utils/json-utils.ts +64 -1
  76. package/src/error-tracking/chunk-ids.spec.ts +0 -77
  77. package/src/error-tracking/coercers/error-event-coercer.spec.ts +0 -142
  78. package/src/error-tracking/coercers/promise-rejection-event.spec.ts +0 -77
  79. package/src/error-tracking/coercers/string-coercer.spec.ts +0 -26
  80. package/src/error-tracking/error-properties-builder.aggregate-errors.spec.ts +0 -412
  81. package/src/error-tracking/error-properties-builder.coerce.spec.ts +0 -337
  82. package/src/error-tracking/error-properties-builder.metadata.spec.ts +0 -318
  83. package/src/error-tracking/error-properties-builder.parse.spec.ts +0 -37
  84. package/src/error-tracking/exception-steps.spec.ts +0 -115
  85. package/src/error-tracking/parsers/base.spec.ts +0 -156
  86. package/src/error-tracking/parsers/index.spec.ts +0 -270
  87. package/src/error-tracking/parsers/node.spec.ts +0 -34
  88. package/src/error-tracking/release.spec.ts +0 -34
  89. package/src/logs/index.spec.ts +0 -2421
  90. package/src/logs/logs-utils.spec.ts +0 -266
  91. package/src/metrics/index.spec.ts +0 -1249
  92. package/src/surveys/activation.spec.ts +0 -61
  93. package/src/surveys/events.spec.ts +0 -183
  94. package/src/surveys/keys.spec.ts +0 -29
  95. package/src/surveys/property-matching.spec.ts +0 -539
  96. package/src/surveys/shuffling.spec.ts +0 -51
  97. package/src/surveys/translations.spec.ts +0 -274
  98. package/src/surveys/validation.spec.ts +0 -168
  99. package/src/traces/config.spec.ts +0 -271
  100. package/src/traces/ids.spec.ts +0 -115
  101. package/src/traces/index.spec.ts +0 -3287
  102. package/src/traces/live-spans.spec.ts +0 -69
  103. package/src/traces/otlp.spec.ts +0 -368
  104. package/src/traces/span.spec.ts +0 -1137
  105. package/src/traces/traceparent.spec.ts +0 -184
  106. package/src/utils/bot-detection.spec.ts +0 -107
  107. package/src/utils/bucketed-rate-limiter.spec.ts +0 -327
  108. package/src/utils/json-utils.spec.ts +0 -115
  109. package/src/utils/named-error.spec.ts +0 -36
  110. package/src/utils/number-utils.spec.ts +0 -212
  111. package/src/utils/otlp-any-value.spec.ts +0 -376
  112. package/src/utils/otlp-resource.spec.ts +0 -171
  113. package/src/utils/promise-queue.spec.ts +0 -55
  114. package/src/utils/string-utils.spec.ts +0 -158
  115. package/src/utils/type-utils.spec.ts +0 -38
  116. package/src/utils/webview-app-utils.spec.ts +0 -118
  117. package/src/vendor/uuidv7.spec.ts +0 -26
@@ -1,10 +1,51 @@
1
- import { createFlagsResponseFromFlagsAndPayloads, flagDetailsToResults, getEnabledFromValue, getFeatureFlagValue, getFlagValuesFromFlags, getPayloadsFromFlags, getVariantFromValue, normalizeFlagsResponse, parsePayload, updateFlagValue } from "./featureFlagUtils.mjs";
1
+ import { createFlagsResponseFromFlagsAndPayloads, flagDetailsToResults, getEnabledFromValue, getFeatureFlagValue, getFlagValuesFromFlags, getPayloadsFromFlags, getVariantFromValue, isEnabledFlagValue, normalizeFlagsResponse, parsePayload, updateFlagValue } from "./featureFlagUtils.mjs";
2
2
  import { Compression, FeatureFlagError, PostHogPersistedProperty } from "./types.mjs";
3
3
  import { PostHogCoreStateless, QuotaLimitedFeature, maybeAdd } from "./posthog-core-stateless.mjs";
4
4
  import { uuidv7 } from "./vendor/uuidv7.mjs";
5
5
  import { getEventUuid, getPersonPropertiesHash, isArray, isEmptyObject, isNullish, isObject, isString } from "./utils/index.mjs";
6
+ const resolveSendFeatureFlagEvent = (options)=>options?.sendFeatureFlagEvent ?? options?.sendEvent;
7
+ const holdsNoCachedFlags = (storedDetails)=>{
8
+ if (void 0 !== storedDetails.noFlagsCached) return storedDetails.noFlagsCached;
9
+ const failedOrQuotaLimited = void 0 !== storedDetails.requestError || storedDetails.quotaLimited?.includes(QuotaLimitedFeature.FeatureFlags) === true;
10
+ return failedOrQuotaLimited && void 0 === storedDetails.minimalFlagCalledEvents && 0 === Object.keys(storedDetails.flags ?? {}).length;
11
+ };
12
+ const eventOptionsOf = (options)=>{
13
+ const eventOptions = options?.options;
14
+ return isObject(eventOptions) ? eventOptions : void 0;
15
+ };
16
+ const IDENTITY_EVENTS = [
17
+ '$identify',
18
+ '$create_alias',
19
+ '$merge_dangerously',
20
+ '$groupidentify',
21
+ '$set',
22
+ '$set_once'
23
+ ];
24
+ const isFilledString = (value)=>'string' == typeof value && value.length > 0;
25
+ function fillLibraryIdentity(properties, lib, libVersion) {
26
+ if (isFilledString(properties.$lib)) {
27
+ if (properties.$lib === lib && !isFilledString(properties.$lib_version)) properties.$lib_version = libVersion;
28
+ } else {
29
+ properties.$lib = lib;
30
+ properties.$lib_version = libVersion;
31
+ }
32
+ }
33
+ function personPropertiesHashOrNull(distinctId, userPropertiesToSet, userPropertiesToSetOnce) {
34
+ try {
35
+ return getPersonPropertiesHash(distinctId, userPropertiesToSet, userPropertiesToSetOnce);
36
+ } catch {
37
+ return null;
38
+ }
39
+ }
40
+ function sentPersonPropertiesHash(message) {
41
+ const properties = isObject(message.properties) ? message.properties : {};
42
+ const set = properties.$set;
43
+ const setOnce = properties.$set_once;
44
+ if (!isNullish(set) && !isObject(set) || !isNullish(setOnce) && !isObject(setOnce)) return null;
45
+ return personPropertiesHashOrNull(String(message.distinct_id), set, setOnce);
46
+ }
6
47
  const SESSION_ACTIVITY_PERSIST_GRANULARITY_MS = 5000;
7
- class PostHogCore extends PostHogCoreStateless {
48
+ class PostHogCoreBase extends PostHogCoreStateless {
8
49
  constructor(projectToken, options){
9
50
  const disableGeoipOption = options?.disableGeoip ?? false;
10
51
  const featureFlagsRequestTimeoutMs = options?.featureFlagsRequestTimeoutMs ?? 10000;
@@ -12,7 +53,7 @@ class PostHogCore extends PostHogCoreStateless {
12
53
  ...options,
13
54
  disableGeoip: disableGeoipOption,
14
55
  featureFlagsRequestTimeoutMs
15
- }), this.flagCallReported = {}, this.flagCallsPendingOptIn = new Set(), this._sessionMaxLengthSeconds = 86400, this.sessionProps = {}, this._cachedPersonProperties = null;
56
+ }), this.flagCallReported = {}, this.flagCallsPendingOptIn = new Set(), this._sessionMaxLengthSeconds = 86400, this.sessionProps = {}, this._flagsResetCount = 0, this._cachedPersonProperties = null, this._pendingPersonPropertiesHash = void 0;
16
57
  this.sendFeatureFlagEvent = options?.sendFeatureFlagEvent ?? true;
17
58
  this.disableRemoteFeatureFlags = options?.disableRemoteFeatureFlags ?? false;
18
59
  this._sessionExpirationTimeSeconds = options?.sessionExpirationTimeSeconds ?? 1800;
@@ -35,7 +76,7 @@ class PostHogCore extends PostHogCoreStateless {
35
76
  const bootstrapFeatureFlags = bootstrap.featureFlags;
36
77
  const bootstrapFeatureFlagPayloads = bootstrap.featureFlagPayloads ?? {};
37
78
  if (bootstrapFeatureFlags && Object.keys(bootstrapFeatureFlags).length) {
38
- const normalizedBootstrapFeatureFlagDetails = createFlagsResponseFromFlagsAndPayloads(bootstrapFeatureFlags, bootstrapFeatureFlagPayloads);
79
+ const normalizedBootstrapFeatureFlagDetails = createFlagsResponseFromFlagsAndPayloads(bootstrapFeatureFlags, bootstrapFeatureFlagPayloads, this.usesLegacyFlagValues() ? parsePayload : (payload)=>payload);
39
80
  if (Object.keys(normalizedBootstrapFeatureFlagDetails.flags).length > 0) {
40
81
  this.setBootstrappedFeatureFlagDetails(normalizedBootstrapFeatureFlagDetails);
41
82
  const currentFeatureFlagDetails = this.getKnownFeatureFlagDetails() || {
@@ -45,6 +86,7 @@ class PostHogCore extends PostHogCoreStateless {
45
86
  const newFeatureFlagDetails = {
46
87
  ...this.getStoredFlagDetails(),
47
88
  requestError: void 0,
89
+ noFlagsCached: void 0,
48
90
  flags: {
49
91
  ...normalizedBootstrapFeatureFlagDetails.flags,
50
92
  ...Object.fromEntries(Object.entries(currentFeatureFlagDetails.flags).filter(([key, detail])=>!detail.failed || !Object.prototype.hasOwnProperty.call(normalizedBootstrapFeatureFlagDetails.flags, key)))
@@ -79,6 +121,7 @@ class PostHogCore extends PostHogCoreStateless {
79
121
  }
80
122
  reset(propertiesToKeep) {
81
123
  this.wrap(()=>{
124
+ this._flagsResetCount++;
82
125
  const allPropertiesToKeep = [
83
126
  PostHogPersistedProperty.Queue,
84
127
  PostHogPersistedProperty.AiQueue,
@@ -103,31 +146,110 @@ class PostHogCore extends PostHogCoreStateless {
103
146
  this.flagCallReported = {};
104
147
  }
105
148
  }
149
+ usesLegacyFlagValues() {
150
+ return false;
151
+ }
152
+ isFlagValueEnabled(value) {
153
+ return this.usesLegacyFlagValues() ? getEnabledFromValue(value) : isEnabledFlagValue(value);
154
+ }
106
155
  getCommonEventProperties() {
107
- const featureFlags = this.getFeatureFlags();
156
+ const featureFlags = this.getFeatureFlagValues();
108
157
  const featureVariantProperties = {};
109
158
  if (featureFlags) for (const [feature, variant] of Object.entries(featureFlags))featureVariantProperties[`$feature/${feature}`] = variant;
110
159
  return {
111
- ...maybeAdd('$active_feature_flags', featureFlags ? Object.keys(featureFlags) : void 0),
160
+ ...maybeAdd('$active_feature_flags', featureFlags ? Object.keys(featureFlags).filter((key)=>this.usesLegacyFlagValues() || isEnabledFlagValue(featureFlags[key])) : void 0),
112
161
  ...featureVariantProperties,
113
162
  ...super.getCommonEventProperties()
114
163
  };
115
164
  }
116
- enrichProperties(properties) {
165
+ enrichProperties(properties, options) {
117
166
  const userProperties = properties || {};
118
- return {
167
+ if (this.usesLegacyEventPropertyOrder()) return {
119
168
  ...this.props,
120
169
  ...this.sessionProps,
121
170
  ...this.getCommonEventProperties(),
122
171
  ...userProperties,
123
172
  $session_id: this.getSessionId()
124
173
  };
174
+ const { $lib, $lib_version, ...sdkProperties } = this.getCommonEventProperties();
175
+ const callerSessionId = userProperties.$session_id;
176
+ const sessionId = isFilledString(callerSessionId) && callerSessionId.trim() ? void 0 : this.getSessionId();
177
+ const registered = {
178
+ ...sdkProperties,
179
+ ...this.props,
180
+ ...this.sessionProps,
181
+ ...options?.disableGeoip != null && {
182
+ $geoip_disable: options.disableGeoip
183
+ }
184
+ };
185
+ const enriched = {
186
+ ...registered,
187
+ ...userProperties
188
+ };
189
+ if (isObject(registered.$groups) && isObject(userProperties.$groups)) enriched.$groups = {
190
+ ...registered.$groups,
191
+ ...userProperties.$groups
192
+ };
193
+ if (!isFilledString(enriched.$session_id) || !enriched.$session_id.trim()) enriched.$session_id = sessionId ?? this.getSessionId();
194
+ fillLibraryIdentity(enriched, $lib, $lib_version);
195
+ return enriched;
196
+ }
197
+ usesLegacyEventPropertyOrder() {
198
+ return false;
199
+ }
200
+ usesLegacyEventPersonState() {
201
+ return false;
202
+ }
203
+ stampPersonState(properties, options) {
204
+ const hasPersonProcessing = this._hasPersonProcessing();
205
+ let stampedOptions = options;
206
+ if (this.usesLegacyEventPersonState()) properties['$process_person_profile'] = hasPersonProcessing;
207
+ else if (null == properties['$process_person_profile']) {
208
+ delete properties['$process_person_profile'];
209
+ const eventOptions = eventOptionsOf(options);
210
+ if (!hasPersonProcessing && eventOptions?.process_person_profile == null) {
211
+ const personless = {
212
+ ...options,
213
+ options: {
214
+ ...eventOptions,
215
+ process_person_profile: false
216
+ }
217
+ };
218
+ stampedOptions = personless;
219
+ }
220
+ }
221
+ if (this.usesLegacyEventPersonState() || !Object.prototype.hasOwnProperty.call(properties, '$is_identified')) properties['$is_identified'] = this._isIdentified();
222
+ if (hasPersonProcessing) this._requirePersonProcessing('capture');
223
+ return stampedOptions;
224
+ }
225
+ prepareMessage(message, options) {
226
+ const eventGeoipDisable = message?.properties?.['$geoip_disable'];
227
+ const geoipDisable = this.usesLegacyEventPropertyOrder() ? void 0 : null != eventGeoipDisable ? eventGeoipDisable : options?.disableGeoip;
228
+ const prepared = super.prepareMessage(message, options);
229
+ if (null != geoipDisable) prepared.properties['$geoip_disable'] = geoipDisable;
230
+ const eventOptions = eventOptionsOf(options);
231
+ if (eventOptions) prepared.options = {
232
+ ...eventOptions
233
+ };
234
+ return prepared;
235
+ }
236
+ enrichIdentityProperties(properties, options) {
237
+ const enriched = this.enrichProperties(properties, options);
238
+ if (!this.usesLegacyEventPersonState()) delete enriched['$process_person_profile'];
239
+ return enriched;
125
240
  }
126
241
  mergeCommonEventProperties(properties) {
127
- return {
242
+ if (this.usesLegacyEventPropertyOrder()) return {
128
243
  ...this.getCommonEventProperties(),
129
244
  ...properties
130
245
  };
246
+ const { $lib, $lib_version, ...sdkProperties } = this.getCommonEventProperties();
247
+ const merged = {
248
+ ...sdkProperties,
249
+ ...properties
250
+ };
251
+ fillLibraryIdentity(merged, $lib, $lib_version);
252
+ return merged;
131
253
  }
132
254
  getSessionId() {
133
255
  if (!this._isInitialized) return '';
@@ -188,21 +310,26 @@ class PostHogCore extends PostHogCoreStateless {
188
310
  unregisterForSession(property) {
189
311
  delete this.sessionProps[property];
190
312
  }
313
+ isIgnoredIdentifyId(distinctId) {
314
+ if ('string' != typeof distinctId || '' !== distinctId.trim()) return false;
315
+ return '' !== distinctId || !this.usesLegacyEventPersonState();
316
+ }
191
317
  identify(distinctId, properties, options) {
192
318
  this.wrap(()=>{
319
+ if (this.isIgnoredIdentifyId(distinctId)) return void this._logger.warn('identify() was called with an empty or whitespace-only distinct id, so it is ignored.');
193
320
  if (!this._requirePersonProcessing('posthog.identify')) return;
194
321
  const previousDistinctId = this.getDistinctId();
195
322
  const idWasSupplied = !!distinctId;
196
323
  distinctId = distinctId || previousDistinctId;
197
- if (properties?.$groups) this.groups(properties.$groups);
324
+ if (this.usesLegacyEventPropertyOrder() && properties?.$groups) this.groups(properties.$groups);
198
325
  const userPropsOnce = properties?.$set_once;
199
326
  delete properties?.$set_once;
200
327
  const userProps = properties?.$set || properties;
201
- const allProperties = this.enrichProperties({
328
+ const allProperties = this.enrichIdentityProperties({
202
329
  $anon_distinct_id: this.getAnonymousId(),
203
330
  ...maybeAdd('$set', userProps),
204
331
  ...maybeAdd('$set_once', userPropsOnce)
205
- });
332
+ }, options);
206
333
  const userPropsObj = isObject(userProps) ? userProps : void 0;
207
334
  const userPropsOnceObj = isObject(userPropsOnce) ? userPropsOnce : void 0;
208
335
  const identityChanged = distinctId !== previousDistinctId;
@@ -213,8 +340,8 @@ class PostHogCore extends PostHogCoreStateless {
213
340
  this.setPersistedProperty(PostHogPersistedProperty.DistinctId, distinctId);
214
341
  this.setPersistedProperty(PostHogPersistedProperty.PersonMode, 'identified');
215
342
  this.reloadFeatureFlags();
216
- super.identifyStateless(distinctId, allProperties, options);
217
- this._cachedPersonProperties = getPersonPropertiesHash(distinctId, userPropsObj, userPropsOnceObj);
343
+ const newDistinctId = distinctId;
344
+ this._captureWithPersonPropertiesHash(this._surelyProcessesPerson(options) ? personPropertiesHashOrNull(newDistinctId, userPropsObj, userPropsOnceObj) : null, ()=>super.identifyStateless(newDistinctId, allProperties, options));
218
345
  } else if (shouldTransitionToIdentified) {
219
346
  this.setPersistedProperty(PostHogPersistedProperty.PersonMode, 'identified');
220
347
  const setProps = userPropsObj || {};
@@ -223,49 +350,48 @@ class PostHogCore extends PostHogCoreStateless {
223
350
  $set: setProps,
224
351
  $set_once: setOnceProps
225
352
  }, false);
226
- this.capture('$set', {
227
- $set: setProps,
228
- $set_once: setOnceProps
229
- });
230
- this._cachedPersonProperties = getPersonPropertiesHash(distinctId, userPropsObj, userPropsOnceObj);
353
+ this._captureWithPersonPropertiesHash(this._surelyProcessesPerson(options) ? personPropertiesHashOrNull(distinctId, userPropsObj, userPropsOnceObj) : null, ()=>this.capture('$set', {
354
+ $set: setProps,
355
+ $set_once: setOnceProps
356
+ }, options));
231
357
  if (userPropsObj || userPropsOnceObj) this.reloadFeatureFlags();
232
- } else if (userPropsObj || userPropsOnceObj) this.setPersonProperties(userPropsObj, userPropsOnceObj);
358
+ } else if (userPropsObj || userPropsOnceObj) this.setPersonProperties(userPropsObj, userPropsOnceObj, true, options);
233
359
  });
234
360
  }
235
361
  capture(event, properties, options) {
236
362
  if ('$exception' === event && !options?._originatedFromCaptureException) this._logger.warn("Using `posthog.capture('$exception')` is unreliable because it does not attach required metadata. Use `posthog.captureException(error)` instead, which attaches required metadata automatically.");
237
363
  this.wrap(()=>{
238
364
  const distinctId = this.getDistinctId();
239
- if (properties?.$groups) this.groups(properties.$groups);
240
- const allProperties = this.enrichProperties(properties);
241
- const hasPersonProcessing = this._hasPersonProcessing();
242
- allProperties['$process_person_profile'] = hasPersonProcessing;
243
- allProperties['$is_identified'] = this._isIdentified();
244
- if (hasPersonProcessing) this._requirePersonProcessing('capture');
245
- super.captureStateless(distinctId, event, allProperties, options);
365
+ if (this.usesLegacyEventPropertyOrder() && properties?.$groups) this.groups(properties.$groups);
366
+ const allProperties = this.enrichProperties(properties, options);
367
+ if (!this.usesLegacyEventPersonState() && IDENTITY_EVENTS.includes(event) && properties?.['$process_person_profile'] == null) delete allProperties['$process_person_profile'];
368
+ const stampedOptions = this.stampPersonState(allProperties, options);
369
+ super.captureStateless(distinctId, event, allProperties, stampedOptions);
246
370
  });
247
371
  }
248
- alias(alias) {
372
+ alias(alias, options) {
249
373
  this.wrap(()=>{
250
374
  if (!this._requirePersonProcessing('posthog.alias')) return;
251
375
  const distinctId = this.getDistinctId();
252
- const allProperties = this.enrichProperties({});
253
- super.aliasStateless(alias, distinctId, allProperties);
376
+ const allProperties = this.enrichIdentityProperties({}, options);
377
+ super.aliasStateless(alias, distinctId, allProperties, options);
254
378
  });
255
379
  }
256
380
  autocapture(eventType, elements, properties = {}, options) {
257
381
  this.wrap(()=>{
258
382
  const distinctId = this.getDistinctId();
383
+ const autocaptureProperties = {
384
+ ...this.enrichProperties(properties, options),
385
+ $event_type: eventType,
386
+ $elements: elements
387
+ };
388
+ const stampedOptions = this.usesLegacyEventPersonState() ? options : this.stampPersonState(autocaptureProperties, options);
259
389
  const payload = {
260
390
  distinct_id: distinctId,
261
391
  event: '$autocapture',
262
- properties: {
263
- ...this.enrichProperties(properties),
264
- $event_type: eventType,
265
- $elements: elements
266
- }
392
+ properties: autocaptureProperties
267
393
  };
268
- this.enqueue('autocapture', payload, options);
394
+ this.enqueue('autocapture', payload, stampedOptions);
269
395
  });
270
396
  }
271
397
  groups(groups) {
@@ -295,7 +421,7 @@ class PostHogCore extends PostHogCoreStateless {
295
421
  this.wrap(()=>{
296
422
  if (!this._requirePersonProcessing('posthog.groupIdentify')) return;
297
423
  const distinctId = this.getDistinctId();
298
- const eventProperties = this.enrichProperties({});
424
+ const eventProperties = this.enrichIdentityProperties({}, options);
299
425
  super.groupIdentifyStateless(groupType, groupKey, groupProperties, options, distinctId, eventProperties);
300
426
  });
301
427
  }
@@ -469,6 +595,7 @@ class PostHogCore extends PostHogCoreStateless {
469
595
  });
470
596
  return this._remoteConfigResponsePromise;
471
597
  }
598
+ getFlagsRequestTimezone() {}
472
599
  getFlagsForContext(...args) {
473
600
  return super.getFlags(...args);
474
601
  }
@@ -477,6 +604,7 @@ class PostHogCore extends PostHogCoreStateless {
477
604
  const fetchConfig = options?.fetchConfig ?? false;
478
605
  const triggerOnRemoteConfig = options?.triggerOnRemoteConfig ?? false;
479
606
  this._flagsResponsePromise = this._initPromise.then(async ()=>{
607
+ const resetCount = this._flagsResetCount;
480
608
  const distinctId = this.getDistinctId();
481
609
  const groups = this.props.$groups || {};
482
610
  const personProperties = this.getPersistedProperty(PostHogPersistedProperty.PersonProperties) || {};
@@ -485,37 +613,47 @@ class PostHogCore extends PostHogCoreStateless {
485
613
  const extraProperties = {
486
614
  $anon_distinct_id: sendAnonDistinctId ? this.getAnonymousId() : void 0,
487
615
  $device_id: deviceId ?? void 0,
616
+ ...maybeAdd('timezone', this.getFlagsRequestTimezone()),
488
617
  ...this.disableRemoteFeatureFlags ? {
489
618
  disable_flags: true
490
619
  } : {}
491
620
  };
492
621
  const result = await this.getFlagsForContext(distinctId, groups, personProperties, groupProperties, extraProperties, fetchConfig);
493
622
  if (void 0 === result) return;
623
+ const isForPreviousIdentity = resetCount !== this._flagsResetCount;
494
624
  if (!result.success) {
495
- if (!this.disableRemoteFeatureFlags) this.setKnownFeatureFlagDetails({
496
- flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
497
- requestError: result.error,
498
- minimalFlagCalledEvents: this.getStoredFlagDetails()?.minimalFlagCalledEvents
499
- });
625
+ if (!this.disableRemoteFeatureFlags && !isForPreviousIdentity) {
626
+ const storedDetails = this.getStoredFlagDetails();
627
+ this.setKnownFeatureFlagDetails({
628
+ flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
629
+ requestError: result.error,
630
+ minimalFlagCalledEvents: storedDetails?.minimalFlagCalledEvents,
631
+ noFlagsCached: !storedDetails || holdsNoCachedFlags(storedDetails)
632
+ });
633
+ }
500
634
  return;
501
635
  }
502
636
  const res = result.response;
503
637
  if (res?.quotaLimited?.includes(QuotaLimitedFeature.FeatureFlags)) {
504
- if (!this.disableRemoteFeatureFlags) this.setKnownFeatureFlagDetails({
505
- flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
506
- quotaLimited: res.quotaLimited,
507
- minimalFlagCalledEvents: this.getStoredFlagDetails()?.minimalFlagCalledEvents
508
- });
638
+ if (!this.disableRemoteFeatureFlags && !isForPreviousIdentity) {
639
+ const storedDetails = this.getStoredFlagDetails();
640
+ this.setKnownFeatureFlagDetails({
641
+ flags: this.getKnownFeatureFlagDetails()?.flags ?? {},
642
+ quotaLimited: res.quotaLimited,
643
+ minimalFlagCalledEvents: storedDetails?.minimalFlagCalledEvents,
644
+ noFlagsCached: !storedDetails || holdsNoCachedFlags(storedDetails)
645
+ });
646
+ }
509
647
  this._logger.warn('[FEATURE FLAGS] Feature flags quota limit exceeded. Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts');
510
648
  this.maybeNotifyRemoteConfig(triggerOnRemoteConfig, res);
511
649
  return res;
512
650
  }
513
651
  if (res?.featureFlags) {
514
- if (this.disableRemoteFeatureFlags) {
652
+ if (this.disableRemoteFeatureFlags || isForPreviousIdentity) {
515
653
  this.cacheSessionReplay('flags', res);
516
654
  this.syncRemoteConfigSessionRecording(res);
517
655
  this.maybeNotifyRemoteConfig(triggerOnRemoteConfig, res);
518
- return res;
656
+ return isForPreviousIdentity ? void 0 : res;
519
657
  }
520
658
  let newFeatureFlagDetails = res;
521
659
  if (res.errorsWhileComputingFlags) {
@@ -574,11 +712,14 @@ class PostHogCore extends PostHogCoreStateless {
574
712
  if (void 0 === featureFlags && void 0 === featureFlagPayloads) return;
575
713
  return createFlagsResponseFromFlagsAndPayloads(featureFlags ?? {}, featureFlagPayloads ?? {});
576
714
  }
577
- return normalizeFlagsResponse(storedDetails);
715
+ return normalizeFlagsResponse(storedDetails, (payload)=>this.decodeFeatureFlagPayload(payload));
578
716
  }
579
717
  getStoredFlagDetails() {
580
718
  return this.getPersistedProperty(PostHogPersistedProperty.FeatureFlagDetails);
581
719
  }
720
+ didLatestFeatureFlagsLoadFail() {
721
+ return this.getStoredFlagDetails()?.requestError !== void 0;
722
+ }
582
723
  isMinimalFlagCalledEventsEnabled() {
583
724
  return this.getStoredFlagDetails()?.minimalFlagCalledEvents === true;
584
725
  }
@@ -603,13 +744,27 @@ class PostHogCore extends PostHogCoreStateless {
603
744
  getBootstrappedFeatureFlagPayloads() {
604
745
  const details = this.getBootstrappedFeatureFlagDetails();
605
746
  if (!details) return;
606
- return getPayloadsFromFlags(details.flags);
747
+ return getPayloadsFromFlags(details.flags, (payload)=>this.decodeFeatureFlagPayload(payload));
607
748
  }
608
749
  getFeatureFlagResult(key, options) {
609
- return this._getFeatureFlagResult(key, options);
750
+ return this._getFeatureFlagResult(key, {
751
+ sendEvent: resolveSendFeatureFlagEvent(options)
752
+ });
753
+ }
754
+ decodeFeatureFlagPayload(payload) {
755
+ return parsePayload(payload);
756
+ }
757
+ getFlagsResponseFormat() {
758
+ return {
759
+ version: super.getFlagsResponseFormat().version,
760
+ read: (body)=>normalizeFlagsResponse(body, (payload)=>this.decodeFeatureFlagPayload(payload))
761
+ };
610
762
  }
611
763
  getAllFeatureFlags() {
612
- return flagDetailsToResults(this.getFeatureFlagDetails()?.flags ?? {});
764
+ const flags = this.getFeatureFlagDetails()?.flags;
765
+ const storedDetails = this.getStoredFlagDetails();
766
+ if (!flags || storedDetails && holdsNoCachedFlags(storedDetails)) return;
767
+ return flagDetailsToResults(flags, (payload)=>this.decodeFeatureFlagPayload(payload), (value)=>this.isFlagValueEnabled(value));
613
768
  }
614
769
  _getFeatureFlagResult(key, options = {}) {
615
770
  const storedDetails = this.getStoredFlagDetails();
@@ -647,7 +802,9 @@ class PostHogCore extends PostHogCoreStateless {
647
802
  ...maybeAdd('$feature_flag_reason', featureFlag?.reason?.description ?? featureFlag?.reason?.code),
648
803
  ...maybeAdd('$feature_flag_bootstrapped_response', bootstrappedResponse),
649
804
  ...maybeAdd('$feature_flag_bootstrapped_payload', bootstrappedPayload),
650
- $used_bootstrap_value: !this.getPersistedProperty(PostHogPersistedProperty.FlagsEndpointWasHit),
805
+ ...this.usesLegacyFlagValues() || void 0 !== bootstrappedResponse ? {
806
+ $used_bootstrap_value: !this.getPersistedProperty(PostHogPersistedProperty.FlagsEndpointWasHit)
807
+ } : {},
651
808
  ...maybeAdd('$feature_flag_request_id', details?.requestId),
652
809
  ...maybeAdd('$feature_flag_evaluated_at', details?.evaluatedAt),
653
810
  ...maybeAdd('$feature_flag_error', featureFlagError),
@@ -672,32 +829,21 @@ class PostHogCore extends PostHogCoreStateless {
672
829
  return;
673
830
  }
674
831
  const rawPayload = featureFlag?.metadata?.payload;
675
- const payload = void 0 !== rawPayload ? parsePayload(rawPayload) : null;
832
+ const payload = void 0 !== rawPayload ? this.decodeFeatureFlagPayload(rawPayload) : null;
676
833
  return {
677
834
  key,
678
- enabled: getEnabledFromValue(flagValue),
835
+ enabled: this.isFlagValueEnabled(flagValue),
679
836
  variant: getVariantFromValue(flagValue),
680
837
  payload
681
838
  };
682
839
  }
683
840
  getFeatureFlag(key, options) {
684
841
  const result = this._getFeatureFlagResult(key, {
685
- missingFlagBehavior: 'getFeatureFlag',
686
- sendEvent: options?.sendEvent
842
+ sendEvent: resolveSendFeatureFlagEvent(options)
687
843
  });
688
844
  return result?.variant ?? result?.enabled;
689
845
  }
690
- getFeatureFlagPayload(key) {
691
- const result = this._getFeatureFlagResult(key, {
692
- missingFlagBehavior: 'getFeatureFlagPayload',
693
- sendEvent: false
694
- });
695
- return result?.payload;
696
- }
697
- getFeatureFlagPayloads() {
698
- return this.getFeatureFlagDetails()?.featureFlagPayloads;
699
- }
700
- getFeatureFlags() {
846
+ getFeatureFlagValues() {
701
847
  return this.getFeatureFlagDetails()?.featureFlags;
702
848
  }
703
849
  getFeatureFlagDetails() {
@@ -712,21 +858,16 @@ class PostHogCore extends PostHogCoreStateless {
712
858
  const flags = {
713
859
  ...details.flags ?? {}
714
860
  };
715
- for(const key in overriddenFlags)if (overriddenFlags[key]) flags[key] = updateFlagValue(flags[key], overriddenFlags[key]);
861
+ for(const key in overriddenFlags)if (overriddenFlags[key]) flags[key] = {
862
+ ...updateFlagValue(flags[key], overriddenFlags[key]),
863
+ key
864
+ };
716
865
  else delete flags[key];
717
866
  const result = {
718
867
  ...details,
719
868
  flags
720
869
  };
721
- return normalizeFlagsResponse(result);
722
- }
723
- getFeatureFlagsAndPayloads() {
724
- const flags = this.getFeatureFlags();
725
- const payloads = this.getFeatureFlagPayloads();
726
- return {
727
- flags,
728
- payloads
729
- };
870
+ return normalizeFlagsResponse(result, (payload)=>this.decodeFeatureFlagPayload(payload));
730
871
  }
731
872
  isFeatureEnabled(key, options) {
732
873
  if (options?.defaultValue === void 0) {
@@ -734,13 +875,13 @@ class PostHogCore extends PostHogCoreStateless {
734
875
  return void 0 === response ? void 0 : !!response;
735
876
  }
736
877
  const result = this._getFeatureFlagResult(key, {
737
- sendEvent: options.sendEvent
878
+ sendEvent: resolveSendFeatureFlagEvent(options)
738
879
  });
739
880
  const value = result?.variant ?? result?.enabled;
740
881
  return void 0 === value ? options.defaultValue : !!value;
741
882
  }
742
883
  reloadFeatureFlags(options) {
743
- if (this.disableRemoteFeatureFlags && !this.disabled) return void this._initPromise.then(()=>options?.cb?.(void 0, this.getFeatureFlags()));
884
+ if (this.disableRemoteFeatureFlags && !this.disabled) return void this._initPromise.then(()=>options?.cb?.(void 0, this.getFeatureFlagValues()));
744
885
  this.flagsAsync({
745
886
  sendAnonDistinctId: true
746
887
  }).then((res)=>{
@@ -753,33 +894,15 @@ class PostHogCore extends PostHogCoreStateless {
753
894
  async reloadRemoteConfigAsync() {
754
895
  return await this.remoteConfigAsync();
755
896
  }
756
- async reloadFeatureFlagsAsync(sendAnonDistinctId) {
897
+ async loadFeatureFlagsAsync(sendAnonDistinctId) {
757
898
  if (this.disableRemoteFeatureFlags && !this.disabled) {
758
899
  await this._initPromise;
759
- return this.getFeatureFlags();
900
+ return this.getFeatureFlagValues();
760
901
  }
761
902
  return (await this.flagsAsync({
762
903
  sendAnonDistinctId: sendAnonDistinctId
763
904
  }))?.featureFlags;
764
905
  }
765
- onFeatureFlags(cb) {
766
- return this.on('featureflags', async ()=>{
767
- const flags = this.getFeatureFlags();
768
- if (flags) cb(flags);
769
- });
770
- }
771
- onFeatureFlag(key, cb) {
772
- return this.on('featureflags', async ()=>{
773
- const flagResponse = this.getFeatureFlag(key);
774
- if (void 0 !== flagResponse) cb(flagResponse);
775
- });
776
- }
777
- async overrideFeatureFlag(flags) {
778
- this.wrap(()=>{
779
- if (null === flags) return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, null);
780
- return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, flags);
781
- });
782
- }
783
906
  updateFlags(flags, payloads, options) {
784
907
  this.wrap(()=>{
785
908
  const existingDetails = options?.merge ? this.getKnownFeatureFlagDetails()?.flags : void 0;
@@ -787,7 +910,7 @@ class PostHogCore extends PostHogCoreStateless {
787
910
  const existingPayloads = {};
788
911
  for(const key in existingDetails){
789
912
  const storedPayload = existingDetails[key].metadata?.payload;
790
- if (!existingDetails[key].failed && void 0 !== storedPayload) existingPayloads[key] = parsePayload(storedPayload);
913
+ if (!existingDetails[key].failed && void 0 !== storedPayload) existingPayloads[key] = this.decodeFeatureFlagPayload(storedPayload);
791
914
  }
792
915
  const finalFlags = {
793
916
  ...existingFlags,
@@ -887,26 +1010,46 @@ class PostHogCore extends PostHogCoreStateless {
887
1010
  $set_once: {}
888
1011
  });
889
1012
  }
890
- setPersonProperties(userPropertiesToSet, userPropertiesToSetOnce, reloadFeatureFlags = true) {
1013
+ setPersonProperties(userPropertiesToSet, userPropertiesToSetOnce, reloadFeatureFlags = true, options) {
891
1014
  this.wrap(()=>{
892
1015
  const isSetEmpty = isNullish(userPropertiesToSet) || isEmptyObject(userPropertiesToSet);
893
1016
  const isSetOnceEmpty = isNullish(userPropertiesToSetOnce) || isEmptyObject(userPropertiesToSetOnce);
894
1017
  if (isSetEmpty && isSetOnceEmpty) return;
895
1018
  if (!this._requirePersonProcessing('posthog.setPersonProperties')) return;
896
- const hash = getPersonPropertiesHash(this.getDistinctId(), userPropertiesToSet, userPropertiesToSetOnce);
897
- if (this._cachedPersonProperties === hash) return void this._logger.info('A duplicate setPersonProperties call was made with the same properties. It has been ignored.');
1019
+ const hash = personPropertiesHashOrNull(this.getDistinctId(), userPropertiesToSet, userPropertiesToSetOnce);
1020
+ const tracksHash = this._surelyProcessesPerson(options);
1021
+ if (tracksHash && null !== hash && this._cachedPersonProperties === hash) return void this._logger.info('A duplicate setPersonProperties call was made with the same properties. It has been ignored.');
898
1022
  this.setPersonPropertiesForFlags({
899
1023
  $set: userPropertiesToSet || {},
900
1024
  $set_once: userPropertiesToSetOnce || {}
901
1025
  }, reloadFeatureFlags);
902
- this.capture('$set', {
903
- $set: userPropertiesToSet || {},
904
- $set_once: userPropertiesToSetOnce || {}
905
- });
906
- this._cachedPersonProperties = hash;
1026
+ this._captureWithPersonPropertiesHash(tracksHash ? hash : null, ()=>this.capture('$set', {
1027
+ $set: userPropertiesToSet || {},
1028
+ $set_once: userPropertiesToSetOnce || {}
1029
+ }, options));
907
1030
  });
908
1031
  }
909
- unsetPersonProperties(propertyNames, reloadFeatureFlags = true) {
1032
+ _surelyProcessesPerson(options) {
1033
+ const eventOptions = options?.options;
1034
+ const setting = isObject(eventOptions) ? eventOptions.process_person_profile : void 0;
1035
+ return isNullish(setting) || true === setting;
1036
+ }
1037
+ _captureWithPersonPropertiesHash(hash, capture) {
1038
+ this._pendingPersonPropertiesHash = hash;
1039
+ try {
1040
+ capture();
1041
+ } finally{
1042
+ this._pendingPersonPropertiesHash = void 0;
1043
+ }
1044
+ }
1045
+ _recordPersonPropertiesHash(captured, sent) {
1046
+ const option = isObject(sent.options) ? sent.options.process_person_profile : void 0;
1047
+ const properties = isObject(sent.properties) ? sent.properties : {};
1048
+ const setting = isNullish(option) ? properties.$process_person_profile : option;
1049
+ const surelyProcessesPerson = null !== captured.hash && sent.event === captured.event && (isNullish(setting) || true === setting) && null !== captured.payloadHash && sentPersonPropertiesHash(sent) === captured.payloadHash;
1050
+ this._cachedPersonProperties = surelyProcessesPerson ? captured.hash : null;
1051
+ }
1052
+ unsetPersonProperties(propertyNames, reloadFeatureFlags = true, options) {
910
1053
  this.wrap(()=>{
911
1054
  const names = (isArray(propertyNames) ? propertyNames : [
912
1055
  propertyNames
@@ -922,11 +1065,23 @@ class PostHogCore extends PostHogCoreStateless {
922
1065
  if (reloadFeatureFlags) this.reloadFeatureFlags();
923
1066
  this.capture('$set', {
924
1067
  $unset: names
925
- });
1068
+ }, options);
926
1069
  this._cachedPersonProperties = null;
927
1070
  });
928
1071
  }
929
1072
  processBeforeEnqueue(message) {
1073
+ const hash = this._pendingPersonPropertiesHash;
1074
+ this._pendingPersonPropertiesHash = void 0;
1075
+ const captured = void 0 === hash ? void 0 : {
1076
+ hash,
1077
+ event: message.event,
1078
+ payloadHash: sentPersonPropertiesHash(message)
1079
+ };
1080
+ const result = this._runBeforeSendOnMessage(message);
1081
+ if (result && captured) this._recordPersonPropertiesHash(captured, result);
1082
+ return result;
1083
+ }
1084
+ _runBeforeSendOnMessage(message) {
930
1085
  if (!this._beforeSend) return message;
931
1086
  const timestamp = message.timestamp;
932
1087
  const props = message.properties || {};
@@ -938,6 +1093,7 @@ class PostHogCore extends PostHogCoreStateless {
938
1093
  $set_once: props.$set_once,
939
1094
  timestamp: 'string' == typeof timestamp ? new Date(timestamp) : timestamp
940
1095
  };
1096
+ if (void 0 !== message.options) captureEvent.options = message.options;
941
1097
  const result = this._runBeforeSend(captureEvent);
942
1098
  if (!result) return null;
943
1099
  const resultProps = {
@@ -952,7 +1108,10 @@ class PostHogCore extends PostHogCoreStateless {
952
1108
  uuid: getEventUuid(result.uuid ?? message.uuid, uuidv7),
953
1109
  event: result.event,
954
1110
  properties: resultProps,
955
- timestamp: result.timestamp
1111
+ timestamp: result.timestamp,
1112
+ ...void 0 !== result.options ? {
1113
+ options: result.options
1114
+ } : {}
956
1115
  };
957
1116
  }
958
1117
  _runBeforeSend(captureEvent) {
@@ -969,10 +1128,74 @@ class PostHogCore extends PostHogCoreStateless {
969
1128
  return null;
970
1129
  }
971
1130
  } catch (e) {
972
- this._logger.error(`Error in before_send function for event '${captureEvent.event}':`, e);
1131
+ const errorType = e instanceof Error ? e.name : typeof e;
1132
+ this._logger.error(`Error in before_send function for event '${captureEvent.event}' (${errorType})`);
973
1133
  return null;
974
1134
  }
975
1135
  return result;
976
1136
  }
977
1137
  }
978
- export { PostHogCore };
1138
+ class PostHogCore extends PostHogCoreBase {
1139
+ usesLegacyEventPersonState() {
1140
+ return true;
1141
+ }
1142
+ usesLegacyEventPropertyOrder() {
1143
+ return true;
1144
+ }
1145
+ usesLegacyFlagValues() {
1146
+ return true;
1147
+ }
1148
+ async reloadFeatureFlagsAsync(sendAnonDistinctId) {
1149
+ return this.loadFeatureFlagsAsync(sendAnonDistinctId);
1150
+ }
1151
+ getAllFeatureFlags() {
1152
+ return flagDetailsToResults(this.getFeatureFlagDetails()?.flags ?? {});
1153
+ }
1154
+ onFeatureFlags(cb) {
1155
+ return this.on('featureflags', async ()=>{
1156
+ const flags = this.getFeatureFlagValues();
1157
+ if (flags) cb(flags);
1158
+ });
1159
+ }
1160
+ getFeatureFlag(key, options) {
1161
+ const result = this._getFeatureFlagResult(key, {
1162
+ missingFlagBehavior: 'getFeatureFlag',
1163
+ sendEvent: resolveSendFeatureFlagEvent(options)
1164
+ });
1165
+ return result?.variant ?? result?.enabled;
1166
+ }
1167
+ getFeatureFlagPayload(key) {
1168
+ const result = this._getFeatureFlagResult(key, {
1169
+ missingFlagBehavior: 'getFeatureFlagPayload',
1170
+ sendEvent: false
1171
+ });
1172
+ return result?.payload;
1173
+ }
1174
+ getFeatureFlagPayloads() {
1175
+ return this.getFeatureFlagDetails()?.featureFlagPayloads;
1176
+ }
1177
+ getFeatureFlags() {
1178
+ return this.getFeatureFlagDetails()?.featureFlags;
1179
+ }
1180
+ getFeatureFlagsAndPayloads() {
1181
+ const flags = this.getFeatureFlags();
1182
+ const payloads = this.getFeatureFlagPayloads();
1183
+ return {
1184
+ flags,
1185
+ payloads
1186
+ };
1187
+ }
1188
+ onFeatureFlag(key, cb) {
1189
+ return this.on('featureflags', async ()=>{
1190
+ const flagResponse = this.getFeatureFlag(key);
1191
+ if (void 0 !== flagResponse) cb(flagResponse);
1192
+ });
1193
+ }
1194
+ async overrideFeatureFlag(flags) {
1195
+ this.wrap(()=>{
1196
+ if (null === flags) return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, null);
1197
+ return this.setPersistedProperty(PostHogPersistedProperty.OverrideFeatureFlags, flags);
1198
+ });
1199
+ }
1200
+ }
1201
+ export { PostHogCore, PostHogCoreBase };