posthog-node 3.1.3 → 3.2.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.
- package/CHANGELOG.md +5 -0
- package/lib/index.cjs.js +86 -58
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +86 -54
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +10 -0
- package/lib/posthog-node/src/fetch.d.ts +11 -1
- package/package.json +2 -2
- package/src/feature-flags.ts +1 -1
- package/src/fetch.ts +38 -17
- package/src/posthog-node.ts +1 -1
- package/test/feature-flags.spec.ts +2 -2
- package/test/posthog-node.spec.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
# 3.2.0 - 2023-12-05
|
|
2
|
+
|
|
3
|
+
1. Fixes issues with Axios imports for non-node environments like Cloudflare workers
|
|
4
|
+
2. Uses the globally defined `fetch` if available, otherwise imports and uses axios as a polyfill
|
|
5
|
+
|
|
1
6
|
# 3.1.3 - 2023-10-27
|
|
2
7
|
|
|
3
8
|
1. Updates axios dependency
|
package/lib/index.cjs.js
CHANGED
|
@@ -3,11 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var rusha = require('rusha');
|
|
6
|
-
var axios = require('axios');
|
|
7
|
-
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
11
6
|
|
|
12
7
|
/******************************************************************************
|
|
13
8
|
Copyright (c) Microsoft Corporation.
|
|
@@ -163,7 +158,7 @@ function __spreadArray(to, from, pack) {
|
|
|
163
158
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
164
159
|
}
|
|
165
160
|
|
|
166
|
-
var version = "3.
|
|
161
|
+
var version = "3.2.0";
|
|
167
162
|
|
|
168
163
|
var PostHogPersistedProperty;
|
|
169
164
|
(function (PostHogPersistedProperty) {
|
|
@@ -1380,13 +1375,20 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1380
1375
|
/***
|
|
1381
1376
|
* PROPERTIES
|
|
1382
1377
|
***/
|
|
1383
|
-
PostHogCore.prototype.
|
|
1378
|
+
PostHogCore.prototype.setPersonPropertiesForFlags = function (properties) {
|
|
1384
1379
|
// Get persisted person properties
|
|
1385
1380
|
var existingProperties = this.getPersistedProperty(PostHogPersistedProperty.PersonProperties) || {};
|
|
1386
1381
|
this.setPersistedProperty(PostHogPersistedProperty.PersonProperties, __assign(__assign({}, existingProperties), properties));
|
|
1387
1382
|
return this;
|
|
1388
1383
|
};
|
|
1389
|
-
PostHogCore.prototype.
|
|
1384
|
+
PostHogCore.prototype.resetPersonPropertiesForFlags = function () {
|
|
1385
|
+
this.setPersistedProperty(PostHogPersistedProperty.PersonProperties, {});
|
|
1386
|
+
};
|
|
1387
|
+
/** @deprecated - Renamed to setPersonPropertiesForFlags */
|
|
1388
|
+
PostHogCore.prototype.personProperties = function (properties) {
|
|
1389
|
+
return this.setPersonPropertiesForFlags(properties);
|
|
1390
|
+
};
|
|
1391
|
+
PostHogCore.prototype.setGroupPropertiesForFlags = function (properties) {
|
|
1390
1392
|
// Get persisted group properties
|
|
1391
1393
|
var existingProperties = this.getPersistedProperty(PostHogPersistedProperty.GroupProperties) || {};
|
|
1392
1394
|
if (Object.keys(existingProperties).length !== 0) {
|
|
@@ -1398,6 +1400,13 @@ var PostHogCoreStateless = /** @class */ (function () {
|
|
|
1398
1400
|
this.setPersistedProperty(PostHogPersistedProperty.GroupProperties, __assign(__assign({}, existingProperties), properties));
|
|
1399
1401
|
return this;
|
|
1400
1402
|
};
|
|
1403
|
+
PostHogCore.prototype.resetGroupPropertiesForFlags = function () {
|
|
1404
|
+
this.setPersistedProperty(PostHogPersistedProperty.GroupProperties, {});
|
|
1405
|
+
};
|
|
1406
|
+
/** @deprecated - Renamed to setGroupPropertiesForFlags */
|
|
1407
|
+
PostHogCore.prototype.groupProperties = function (properties) {
|
|
1408
|
+
return this.setGroupPropertiesForFlags(properties);
|
|
1409
|
+
};
|
|
1401
1410
|
/***
|
|
1402
1411
|
*** FEATURE FLAGS
|
|
1403
1412
|
***/
|
|
@@ -1602,57 +1611,76 @@ var PostHogMemoryStorage = /** @class */ (function () {
|
|
|
1602
1611
|
return PostHogMemoryStorage;
|
|
1603
1612
|
}());
|
|
1604
1613
|
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1614
|
+
/**
|
|
1615
|
+
* Fetch wrapper
|
|
1616
|
+
*
|
|
1617
|
+
* We want to polyfill fetch when not available with axios but use it when it is.
|
|
1618
|
+
* NOTE: The current version of Axios has an issue when in non-node environments like Clouflare Workers.
|
|
1619
|
+
* This is currently solved by using the global fetch if available instead.
|
|
1620
|
+
* See https://github.com/PostHog/posthog-js-lite/issues/127 for more info
|
|
1621
|
+
*/
|
|
1622
|
+
|
|
1623
|
+
var _fetch = // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
|
|
1624
|
+
// @ts-ignore
|
|
1625
|
+
typeof fetch !== 'undefined' ? fetch : typeof global.fetch !== 'undefined' ? global.fetch : undefined;
|
|
1626
|
+
|
|
1627
|
+
if (!_fetch) {
|
|
1628
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
1629
|
+
var axios_1 = require('axios');
|
|
1630
|
+
|
|
1631
|
+
_fetch = function (url, options) {
|
|
1632
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
1633
|
+
var res;
|
|
1634
|
+
return __generator(this, function (_a) {
|
|
1635
|
+
switch (_a.label) {
|
|
1636
|
+
case 0:
|
|
1637
|
+
return [4
|
|
1638
|
+
/*yield*/
|
|
1639
|
+
, axios_1.request({
|
|
1640
|
+
url: url,
|
|
1641
|
+
headers: options.headers,
|
|
1642
|
+
method: options.method.toLowerCase(),
|
|
1643
|
+
data: options.body,
|
|
1644
|
+
signal: options.signal,
|
|
1645
|
+
// fetch only throws on network errors, not on HTTP errors
|
|
1646
|
+
validateStatus: function () {
|
|
1647
|
+
return true;
|
|
1648
|
+
}
|
|
1649
|
+
})];
|
|
1650
|
+
|
|
1651
|
+
case 1:
|
|
1652
|
+
res = _a.sent();
|
|
1653
|
+
return [2
|
|
1654
|
+
/*return*/
|
|
1655
|
+
, {
|
|
1656
|
+
status: res.status,
|
|
1657
|
+
text: function () {
|
|
1658
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
1659
|
+
return __generator(this, function (_a) {
|
|
1660
|
+
return [2
|
|
1661
|
+
/*return*/
|
|
1662
|
+
, res.data];
|
|
1663
|
+
});
|
|
1639
1664
|
});
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1665
|
+
},
|
|
1666
|
+
json: function () {
|
|
1667
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
1668
|
+
return __generator(this, function (_a) {
|
|
1669
|
+
return [2
|
|
1670
|
+
/*return*/
|
|
1671
|
+
, res.data];
|
|
1672
|
+
});
|
|
1648
1673
|
});
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
|
|
1652
|
-
}
|
|
1674
|
+
}
|
|
1675
|
+
}];
|
|
1676
|
+
}
|
|
1677
|
+
});
|
|
1653
1678
|
});
|
|
1654
|
-
}
|
|
1655
|
-
}
|
|
1679
|
+
};
|
|
1680
|
+
} // 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
|
|
1681
|
+
|
|
1682
|
+
|
|
1683
|
+
var fetch$1 = _fetch;
|
|
1656
1684
|
|
|
1657
1685
|
var LONG_SCALE = 0xfffffffffffffff;
|
|
1658
1686
|
|
|
@@ -1718,7 +1746,7 @@ function () {
|
|
|
1718
1746
|
this.host = host;
|
|
1719
1747
|
this.poller = undefined; // NOTE: as any is required here as the AbortSignal typing is slightly misaligned but works just fine
|
|
1720
1748
|
|
|
1721
|
-
this.fetch = options.fetch || fetch;
|
|
1749
|
+
this.fetch = options.fetch || fetch$1;
|
|
1722
1750
|
void this.loadFeatureFlags();
|
|
1723
1751
|
}
|
|
1724
1752
|
|
|
@@ -2552,7 +2580,7 @@ function (_super) {
|
|
|
2552
2580
|
};
|
|
2553
2581
|
|
|
2554
2582
|
PostHog.prototype.fetch = function (url, options) {
|
|
2555
|
-
return this.options.fetch ? this.options.fetch(url, options) : fetch(url, options);
|
|
2583
|
+
return this.options.fetch ? this.options.fetch(url, options) : fetch$1(url, options);
|
|
2556
2584
|
};
|
|
2557
2585
|
|
|
2558
2586
|
PostHog.prototype.getLibraryId = function () {
|