posthog-js-lite 3.4.0 → 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 +12 -0
- package/README.md +2 -2
- package/lib/index.cjs.js +58 -35
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.esm.js +58 -35
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +1 -1
- package/lib/posthog-core/src/types.d.ts +1 -0
- package/lib/posthog-core/src/utils.d.ts +1 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -114,6 +114,7 @@ type PostHogDecideResponse = {
|
|
|
114
114
|
[key: string]: JsonType;
|
|
115
115
|
};
|
|
116
116
|
errorsWhileComputingFlags: boolean;
|
|
117
|
+
quotaLimited?: string[];
|
|
117
118
|
sessionRecording?: boolean | {
|
|
118
119
|
[key: string]: JsonType;
|
|
119
120
|
};
|
|
@@ -320,7 +321,7 @@ declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
320
321
|
/***
|
|
321
322
|
*** ERROR TRACKING
|
|
322
323
|
***/
|
|
323
|
-
captureException(error:
|
|
324
|
+
captureException(error: unknown, additionalProperties?: {
|
|
324
325
|
[key: string]: any;
|
|
325
326
|
}): void;
|
|
326
327
|
/**
|
package/lib/index.esm.js
CHANGED
|
@@ -62,6 +62,9 @@ function safeSetTimeout(fn, timeout) {
|
|
|
62
62
|
t?.unref && t?.unref();
|
|
63
63
|
return t;
|
|
64
64
|
}
|
|
65
|
+
const isError = (x) => {
|
|
66
|
+
return x instanceof Error;
|
|
67
|
+
};
|
|
65
68
|
function getFetch() {
|
|
66
69
|
return typeof fetch !== 'undefined' ? fetch : typeof global.fetch !== 'undefined' ? global.fetch : undefined;
|
|
67
70
|
}
|
|
@@ -947,6 +950,11 @@ class PostHogFetchNetworkError extends Error {
|
|
|
947
950
|
function isPostHogFetchError(err) {
|
|
948
951
|
return typeof err === 'object' && (err instanceof PostHogFetchHttpError || err instanceof PostHogFetchNetworkError);
|
|
949
952
|
}
|
|
953
|
+
var QuotaLimitedFeature;
|
|
954
|
+
(function (QuotaLimitedFeature) {
|
|
955
|
+
QuotaLimitedFeature["FeatureFlags"] = "feature_flags";
|
|
956
|
+
QuotaLimitedFeature["Recordings"] = "recordings";
|
|
957
|
+
})(QuotaLimitedFeature || (QuotaLimitedFeature = {}));
|
|
950
958
|
class PostHogCoreStateless {
|
|
951
959
|
constructor(apiKey, options) {
|
|
952
960
|
this.flushPromise = null;
|
|
@@ -1190,6 +1198,14 @@ class PostHogCoreStateless {
|
|
|
1190
1198
|
extraPayload['geoip_disable'] = true;
|
|
1191
1199
|
}
|
|
1192
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
|
+
}
|
|
1193
1209
|
const flags = decideResponse?.featureFlags;
|
|
1194
1210
|
const payloads = decideResponse?.featureFlagPayloads;
|
|
1195
1211
|
let parsedPayloads = payloads;
|
|
@@ -1742,7 +1758,7 @@ class PostHogCore extends PostHogCoreStateless {
|
|
|
1742
1758
|
}
|
|
1743
1759
|
async _decideAsync(sendAnonDistinctId = true) {
|
|
1744
1760
|
this._decideResponsePromise = this._initPromise
|
|
1745
|
-
.then(() => {
|
|
1761
|
+
.then(async () => {
|
|
1746
1762
|
const distinctId = this.getDistinctId();
|
|
1747
1763
|
const groups = this.props.$groups || {};
|
|
1748
1764
|
const personProperties = this.getPersistedProperty(PostHogPersistedProperty.PersonProperties) || {};
|
|
@@ -1751,38 +1767,45 @@ class PostHogCore extends PostHogCoreStateless {
|
|
|
1751
1767
|
const extraProperties = {
|
|
1752
1768
|
$anon_distinct_id: sendAnonDistinctId ? this.getAnonymousId() : undefined,
|
|
1753
1769
|
};
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
let newFeatureFlagPayloads = res.featureFlagPayloads;
|
|
1762
|
-
if (res.errorsWhileComputingFlags) {
|
|
1763
|
-
// if not all flags were computed, we upsert flags instead of replacing them
|
|
1764
|
-
const currentFlags = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlags);
|
|
1765
|
-
this.logMsgIfDebug(() => console.log('PostHog Debug', 'Cached feature flags: ', JSON.stringify(currentFlags)));
|
|
1766
|
-
const currentFlagPayloads = this.getPersistedProperty(PostHogPersistedProperty.FeatureFlagPayloads);
|
|
1767
|
-
newFeatureFlags = { ...currentFlags, ...res.featureFlags };
|
|
1768
|
-
newFeatureFlagPayloads = { ...currentFlagPayloads, ...res.featureFlagPayloads };
|
|
1769
|
-
}
|
|
1770
|
-
this.setKnownFeatureFlags(newFeatureFlags);
|
|
1771
|
-
this.setKnownFeatureFlagPayloads(Object.fromEntries(Object.entries(newFeatureFlagPayloads || {}).map(([k, v]) => [k, this._parsePayload(v)])));
|
|
1772
|
-
// Mark that we hit the /decide endpoint so we can capture this in the $feature_flag_called event
|
|
1773
|
-
this.setPersistedProperty(PostHogPersistedProperty.DecideEndpointWasHit, true);
|
|
1774
|
-
const sessionReplay = res?.sessionRecording;
|
|
1775
|
-
if (sessionReplay) {
|
|
1776
|
-
this.setPersistedProperty(PostHogPersistedProperty.SessionReplay, sessionReplay);
|
|
1777
|
-
this.logMsgIfDebug(() => console.log('PostHog Debug', 'Session replay config: ', JSON.stringify(sessionReplay)));
|
|
1778
|
-
}
|
|
1779
|
-
else {
|
|
1780
|
-
this.logMsgIfDebug(() => console.info('PostHog Debug', 'Session replay config disabled.'));
|
|
1781
|
-
this.setPersistedProperty(PostHogPersistedProperty.SessionReplay, null);
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
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');
|
|
1784
1777
|
return res;
|
|
1785
|
-
}
|
|
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;
|
|
1786
1809
|
})
|
|
1787
1810
|
.finally(() => {
|
|
1788
1811
|
this._decideResponsePromise = undefined;
|
|
@@ -1924,8 +1947,8 @@ class PostHogCore extends PostHogCoreStateless {
|
|
|
1924
1947
|
$exception_level: 'error',
|
|
1925
1948
|
$exception_list: [
|
|
1926
1949
|
{
|
|
1927
|
-
type: error.name,
|
|
1928
|
-
value: error.message,
|
|
1950
|
+
type: isError(error) ? error.name : 'Error',
|
|
1951
|
+
value: isError(error) ? error.message : error,
|
|
1929
1952
|
mechanism: {
|
|
1930
1953
|
handled: true,
|
|
1931
1954
|
synthetic: false,
|
|
@@ -1963,7 +1986,7 @@ class PostHogCore extends PostHogCoreStateless {
|
|
|
1963
1986
|
}
|
|
1964
1987
|
}
|
|
1965
1988
|
|
|
1966
|
-
var version = "3.4.
|
|
1989
|
+
var version = "3.4.2";
|
|
1967
1990
|
|
|
1968
1991
|
function getContext(window) {
|
|
1969
1992
|
let context = {};
|