posthog-js-lite 3.4.1 → 3.4.2
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 +6 -0
- package/README.md +2 -2
- package/lib/index.cjs.js +53 -33
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.esm.js +53 -33
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/types.d.ts +1 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.esm.js
CHANGED
|
@@ -950,6 +950,11 @@ class PostHogFetchNetworkError extends Error {
|
|
|
950
950
|
function isPostHogFetchError(err) {
|
|
951
951
|
return typeof err === 'object' && (err instanceof PostHogFetchHttpError || err instanceof PostHogFetchNetworkError);
|
|
952
952
|
}
|
|
953
|
+
var QuotaLimitedFeature;
|
|
954
|
+
(function (QuotaLimitedFeature) {
|
|
955
|
+
QuotaLimitedFeature["FeatureFlags"] = "feature_flags";
|
|
956
|
+
QuotaLimitedFeature["Recordings"] = "recordings";
|
|
957
|
+
})(QuotaLimitedFeature || (QuotaLimitedFeature = {}));
|
|
953
958
|
class PostHogCoreStateless {
|
|
954
959
|
constructor(apiKey, options) {
|
|
955
960
|
this.flushPromise = null;
|
|
@@ -1193,6 +1198,14 @@ class PostHogCoreStateless {
|
|
|
1193
1198
|
extraPayload['geoip_disable'] = true;
|
|
1194
1199
|
}
|
|
1195
1200
|
const decideResponse = await this.getDecide(distinctId, groups, personProperties, groupProperties, extraPayload);
|
|
1201
|
+
// Add check for quota limitation on feature flags
|
|
1202
|
+
if (decideResponse?.quotaLimited?.includes(QuotaLimitedFeature.FeatureFlags)) {
|
|
1203
|
+
console.warn('[FEATURE FLAGS] Feature flags quota limit exceeded - feature flags unavailable. Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts');
|
|
1204
|
+
return {
|
|
1205
|
+
flags: undefined,
|
|
1206
|
+
payloads: undefined,
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1196
1209
|
const flags = decideResponse?.featureFlags;
|
|
1197
1210
|
const payloads = decideResponse?.featureFlagPayloads;
|
|
1198
1211
|
let parsedPayloads = payloads;
|
|
@@ -1745,7 +1758,7 @@ class PostHogCore extends PostHogCoreStateless {
|
|
|
1745
1758
|
}
|
|
1746
1759
|
async _decideAsync(sendAnonDistinctId = true) {
|
|
1747
1760
|
this._decideResponsePromise = this._initPromise
|
|
1748
|
-
.then(() => {
|
|
1761
|
+
.then(async () => {
|
|
1749
1762
|
const distinctId = this.getDistinctId();
|
|
1750
1763
|
const groups = this.props.$groups || {};
|
|
1751
1764
|
const personProperties = this.getPersistedProperty(PostHogPersistedProperty.PersonProperties) || {};
|
|
@@ -1754,38 +1767,45 @@ class PostHogCore extends PostHogCoreStateless {
|
|
|
1754
1767
|
const extraProperties = {
|
|
1755
1768
|
$anon_distinct_id: sendAnonDistinctId ? this.getAnonymousId() : undefined,
|
|
1756
1769
|
};
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
let newFeatureFlagPayloads = res.featureFlagPayloads;
|
|
1765
|
-
if (res.errorsWhileComputingFlags) {
|
|
1766
|
-
// if not all flags were computed, we upsert flags instead of replacing them
|
|
1767
|
-
const currentFlags = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlags);
|
|
1768
|
-
this.logMsgIfDebug(() => console.log('PostHog Debug', 'Cached feature flags: ', JSON.stringify(currentFlags)));
|
|
1769
|
-
const currentFlagPayloads = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlagPayloads);
|
|
1770
|
-
newFeatureFlags = { ...currentFlags, ...res.featureFlags };
|
|
1771
|
-
newFeatureFlagPayloads = { ...currentFlagPayloads, ...res.featureFlagPayloads };
|
|
1772
|
-
}
|
|
1773
|
-
this.setKnownFeatureFlags(newFeatureFlags);
|
|
1774
|
-
this.setKnownFeatureFlagPayloads(Object.fromEntries(Object.entries(newFeatureFlagPayloads || {}).map(([k, v]) => [k, this._parsePayload(v)])));
|
|
1775
|
-
// Mark that we hit the /decide endpoint so we can capture this in the $feature_flag_called event
|
|
1776
|
-
this.setPersistedProperty(PostHogPersistedProperty.DecideEndpointWasHit, true);
|
|
1777
|
-
const sessionReplay = res?.sessionRecording;
|
|
1778
|
-
if (sessionReplay) {
|
|
1779
|
-
this.setPersistedProperty(PostHogPersistedProperty.SessionReplay, sessionReplay);
|
|
1780
|
-
this.logMsgIfDebug(() => console.log('PostHog Debug', 'Session replay config: ', JSON.stringify(sessionReplay)));
|
|
1781
|
-
}
|
|
1782
|
-
else {
|
|
1783
|
-
this.logMsgIfDebug(() => console.info('PostHog Debug', 'Session replay config disabled.'));
|
|
1784
|
-
this.setPersistedProperty(PostHogPersistedProperty.SessionReplay, null);
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1770
|
+
const res = await super.getDecide(distinctId, groups, personProperties, groupProperties, extraProperties);
|
|
1771
|
+
// Add check for quota limitation on feature flags
|
|
1772
|
+
if (res?.quotaLimited?.includes(QuotaLimitedFeature.FeatureFlags)) {
|
|
1773
|
+
// Unset all feature flags by setting to null
|
|
1774
|
+
this.setKnownFeatureFlags(null);
|
|
1775
|
+
this.setKnownFeatureFlagPayloads(null);
|
|
1776
|
+
console.warn('[FEATURE FLAGS] Feature flags quota limit exceeded - unsetting all flags. Learn more about billing limits at https://posthog.com/docs/billing/limits-alerts');
|
|
1787
1777
|
return res;
|
|
1788
|
-
}
|
|
1778
|
+
}
|
|
1779
|
+
if (res?.featureFlags) {
|
|
1780
|
+
// clear flag call reported if we have new flags since they might have changed
|
|
1781
|
+
if (this.sendFeatureFlagEvent) {
|
|
1782
|
+
this.flagCallReported = {};
|
|
1783
|
+
}
|
|
1784
|
+
let newFeatureFlags = res.featureFlags;
|
|
1785
|
+
let newFeatureFlagPayloads = res.featureFlagPayloads;
|
|
1786
|
+
if (res.errorsWhileComputingFlags) {
|
|
1787
|
+
// if not all flags were computed, we upsert flags instead of replacing them
|
|
1788
|
+
const currentFlags = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlags);
|
|
1789
|
+
this.logMsgIfDebug(() => console.log('PostHog Debug', 'Cached feature flags: ', JSON.stringify(currentFlags)));
|
|
1790
|
+
const currentFlagPayloads = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlagPayloads);
|
|
1791
|
+
newFeatureFlags = { ...currentFlags, ...res.featureFlags };
|
|
1792
|
+
newFeatureFlagPayloads = { ...currentFlagPayloads, ...res.featureFlagPayloads };
|
|
1793
|
+
}
|
|
1794
|
+
this.setKnownFeatureFlags(newFeatureFlags);
|
|
1795
|
+
this.setKnownFeatureFlagPayloads(Object.fromEntries(Object.entries(newFeatureFlagPayloads || {}).map(([k, v]) => [k, this._parsePayload(v)])));
|
|
1796
|
+
// Mark that we hit the /decide endpoint so we can capture this in the $feature_flag_called event
|
|
1797
|
+
this.setPersistedProperty(PostHogPersistedProperty.DecideEndpointWasHit, true);
|
|
1798
|
+
const sessionReplay = res?.sessionRecording;
|
|
1799
|
+
if (sessionReplay) {
|
|
1800
|
+
this.setPersistedProperty(PostHogPersistedProperty.SessionReplay, sessionReplay);
|
|
1801
|
+
this.logMsgIfDebug(() => console.log('PostHog Debug', 'Session replay config: ', JSON.stringify(sessionReplay)));
|
|
1802
|
+
}
|
|
1803
|
+
else {
|
|
1804
|
+
this.logMsgIfDebug(() => console.info('PostHog Debug', 'Session replay config disabled.'));
|
|
1805
|
+
this.setPersistedProperty(PostHogPersistedProperty.SessionReplay, null);
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
return res;
|
|
1789
1809
|
})
|
|
1790
1810
|
.finally(() => {
|
|
1791
1811
|
this._decideResponsePromise = undefined;
|
|
@@ -1966,7 +1986,7 @@ class PostHogCore extends PostHogCoreStateless {
|
|
|
1966
1986
|
}
|
|
1967
1987
|
}
|
|
1968
1988
|
|
|
1969
|
-
var version = "3.4.
|
|
1989
|
+
var version = "3.4.2";
|
|
1970
1990
|
|
|
1971
1991
|
function getContext(window) {
|
|
1972
1992
|
let context = {};
|