posthog-node 4.13.0 → 5.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/lib/index.cjs.js +27 -38
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +10 -0
- package/lib/index.esm.js +27 -38
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +10 -7
- package/package.json +2 -5
- package/src/feature-flags.ts +0 -1
- package/src/posthog-node.ts +0 -1
- package/test/extensions/sentry-integration.spec.ts +1 -3
- package/test/feature-flags.decide.spec.ts +1 -3
- package/test/feature-flags.spec.ts +1 -3
- package/test/posthog-node.spec.ts +2 -4
- package/lib/posthog-node/src/fetch.d.ts +0 -11
- package/src/fetch.ts +0 -39
package/lib/index.d.ts
CHANGED
|
@@ -481,6 +481,16 @@ declare abstract class PostHogCoreStateless {
|
|
|
481
481
|
*** SURVEYS
|
|
482
482
|
***/
|
|
483
483
|
getSurveysStateless(): Promise<SurveyResponse['surveys']>;
|
|
484
|
+
/***
|
|
485
|
+
*** SUPER PROPERTIES
|
|
486
|
+
***/
|
|
487
|
+
private _props;
|
|
488
|
+
protected get props(): PostHogEventProperties;
|
|
489
|
+
protected set props(val: PostHogEventProperties | undefined);
|
|
490
|
+
register(properties: {
|
|
491
|
+
[key: string]: any;
|
|
492
|
+
}): Promise<void>;
|
|
493
|
+
unregister(property: string): Promise<void>;
|
|
484
494
|
/***
|
|
485
495
|
*** QUEUEING AND FLUSHING
|
|
486
496
|
***/
|
package/lib/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { posix, dirname, sep } from 'path';
|
|
2
2
|
|
|
3
|
-
var version = "
|
|
3
|
+
var version = "5.0.0-alpha.1";
|
|
4
4
|
|
|
5
5
|
var PostHogPersistedProperty;
|
|
6
6
|
(function (PostHogPersistedProperty) {
|
|
@@ -304,9 +304,6 @@ function safeSetTimeout(fn, timeout) {
|
|
|
304
304
|
t?.unref && t?.unref();
|
|
305
305
|
return t;
|
|
306
306
|
}
|
|
307
|
-
function getFetch() {
|
|
308
|
-
return typeof fetch !== 'undefined' ? fetch : typeof global.fetch !== 'undefined' ? global.fetch : undefined;
|
|
309
|
-
}
|
|
310
307
|
// FNV-1a hash function
|
|
311
308
|
// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
|
|
312
309
|
// I know, I know, I'm rolling my own hash function, but I didn't want to take on
|
|
@@ -1573,6 +1570,30 @@ class PostHogCoreStateless {
|
|
|
1573
1570
|
}
|
|
1574
1571
|
return newSurveys ?? [];
|
|
1575
1572
|
}
|
|
1573
|
+
get props() {
|
|
1574
|
+
if (!this._props) {
|
|
1575
|
+
this._props = this.getPersistedProperty(PostHogPersistedProperty.Props);
|
|
1576
|
+
}
|
|
1577
|
+
return this._props || {};
|
|
1578
|
+
}
|
|
1579
|
+
set props(val) {
|
|
1580
|
+
this._props = val;
|
|
1581
|
+
}
|
|
1582
|
+
async register(properties) {
|
|
1583
|
+
this.wrap(() => {
|
|
1584
|
+
this.props = {
|
|
1585
|
+
...this.props,
|
|
1586
|
+
...properties,
|
|
1587
|
+
};
|
|
1588
|
+
this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
async unregister(property) {
|
|
1592
|
+
this.wrap(() => {
|
|
1593
|
+
delete this.props[property];
|
|
1594
|
+
this.setPersistedProperty(PostHogPersistedProperty.Props, this.props);
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1576
1597
|
/***
|
|
1577
1598
|
*** QUEUEING AND FLUSHING
|
|
1578
1599
|
***/
|
|
@@ -1790,38 +1811,6 @@ class PostHogMemoryStorage {
|
|
|
1790
1811
|
}
|
|
1791
1812
|
}
|
|
1792
1813
|
|
|
1793
|
-
/**
|
|
1794
|
-
* Fetch wrapper
|
|
1795
|
-
*
|
|
1796
|
-
* We want to polyfill fetch when not available with axios but use it when it is.
|
|
1797
|
-
* NOTE: The current version of Axios has an issue when in non-node environments like Clouflare Workers.
|
|
1798
|
-
* This is currently solved by using the global fetch if available instead.
|
|
1799
|
-
* See https://github.com/PostHog/posthog-js-lite/issues/127 for more info
|
|
1800
|
-
*/
|
|
1801
|
-
let _fetch = getFetch();
|
|
1802
|
-
if (!_fetch) {
|
|
1803
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1804
|
-
const axios = require('axios');
|
|
1805
|
-
_fetch = async (url, options) => {
|
|
1806
|
-
const res = await axios.request({
|
|
1807
|
-
url,
|
|
1808
|
-
headers: options.headers,
|
|
1809
|
-
method: options.method.toLowerCase(),
|
|
1810
|
-
data: options.body,
|
|
1811
|
-
signal: options.signal,
|
|
1812
|
-
// fetch only throws on network errors, not on HTTP errors
|
|
1813
|
-
validateStatus: () => true
|
|
1814
|
-
});
|
|
1815
|
-
return {
|
|
1816
|
-
status: res.status,
|
|
1817
|
-
text: async () => res.data,
|
|
1818
|
-
json: async () => res.data
|
|
1819
|
-
};
|
|
1820
|
-
};
|
|
1821
|
-
}
|
|
1822
|
-
// NOTE: We have to export this as default, even though we prefer named exports as we are relying on detecting "fetch" in the global scope
|
|
1823
|
-
var fetch$1 = _fetch;
|
|
1824
|
-
|
|
1825
1814
|
/**
|
|
1826
1815
|
* A lazy value that is only computed when needed. Inspired by C#'s Lazy<T> class.
|
|
1827
1816
|
*/
|
|
@@ -1963,7 +1952,7 @@ class FeatureFlagsPoller {
|
|
|
1963
1952
|
this.projectApiKey = projectApiKey;
|
|
1964
1953
|
this.host = host;
|
|
1965
1954
|
this.poller = undefined;
|
|
1966
|
-
this.fetch = options.fetch || fetch
|
|
1955
|
+
this.fetch = options.fetch || fetch;
|
|
1967
1956
|
this.onError = options.onError;
|
|
1968
1957
|
this.customHeaders = customHeaders;
|
|
1969
1958
|
this.onLoad = options.onLoad;
|
|
@@ -3548,7 +3537,7 @@ class PostHog extends PostHogCoreStateless {
|
|
|
3548
3537
|
return this._memoryStorage.setProperty(key, value);
|
|
3549
3538
|
}
|
|
3550
3539
|
fetch(url, options) {
|
|
3551
|
-
return this.options.fetch ? this.options.fetch(url, options) : fetch
|
|
3540
|
+
return this.options.fetch ? this.options.fetch(url, options) : fetch(url, options);
|
|
3552
3541
|
}
|
|
3553
3542
|
getLibraryId() {
|
|
3554
3543
|
return 'posthog-node';
|