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/lib/index.esm.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { createHash } from 'rusha';
2
- import axios from 'axios';
3
2
 
4
3
  /******************************************************************************
5
4
  Copyright (c) Microsoft Corporation.
@@ -155,7 +154,7 @@ function __spreadArray(to, from, pack) {
155
154
  return to.concat(ar || Array.prototype.slice.call(from));
156
155
  }
157
156
 
158
- var version = "3.1.3";
157
+ var version = "3.2.0";
159
158
 
160
159
  var PostHogPersistedProperty;
161
160
  (function (PostHogPersistedProperty) {
@@ -1372,13 +1371,20 @@ var PostHogCoreStateless = /** @class */ (function () {
1372
1371
  /***
1373
1372
  * PROPERTIES
1374
1373
  ***/
1375
- PostHogCore.prototype.personProperties = function (properties) {
1374
+ PostHogCore.prototype.setPersonPropertiesForFlags = function (properties) {
1376
1375
  // Get persisted person properties
1377
1376
  var existingProperties = this.getPersistedProperty(PostHogPersistedProperty.PersonProperties) || {};
1378
1377
  this.setPersistedProperty(PostHogPersistedProperty.PersonProperties, __assign(__assign({}, existingProperties), properties));
1379
1378
  return this;
1380
1379
  };
1381
- PostHogCore.prototype.groupProperties = function (properties) {
1380
+ PostHogCore.prototype.resetPersonPropertiesForFlags = function () {
1381
+ this.setPersistedProperty(PostHogPersistedProperty.PersonProperties, {});
1382
+ };
1383
+ /** @deprecated - Renamed to setPersonPropertiesForFlags */
1384
+ PostHogCore.prototype.personProperties = function (properties) {
1385
+ return this.setPersonPropertiesForFlags(properties);
1386
+ };
1387
+ PostHogCore.prototype.setGroupPropertiesForFlags = function (properties) {
1382
1388
  // Get persisted group properties
1383
1389
  var existingProperties = this.getPersistedProperty(PostHogPersistedProperty.GroupProperties) || {};
1384
1390
  if (Object.keys(existingProperties).length !== 0) {
@@ -1390,6 +1396,13 @@ var PostHogCoreStateless = /** @class */ (function () {
1390
1396
  this.setPersistedProperty(PostHogPersistedProperty.GroupProperties, __assign(__assign({}, existingProperties), properties));
1391
1397
  return this;
1392
1398
  };
1399
+ PostHogCore.prototype.resetGroupPropertiesForFlags = function () {
1400
+ this.setPersistedProperty(PostHogPersistedProperty.GroupProperties, {});
1401
+ };
1402
+ /** @deprecated - Renamed to setGroupPropertiesForFlags */
1403
+ PostHogCore.prototype.groupProperties = function (properties) {
1404
+ return this.setGroupPropertiesForFlags(properties);
1405
+ };
1393
1406
  /***
1394
1407
  *** FEATURE FLAGS
1395
1408
  ***/
@@ -1594,57 +1607,76 @@ var PostHogMemoryStorage = /** @class */ (function () {
1594
1607
  return PostHogMemoryStorage;
1595
1608
  }());
1596
1609
 
1597
- // So that alternative implementations can be used if desired
1598
-
1599
- var fetch = function (url, options) {
1600
- return __awaiter(void 0, void 0, void 0, function () {
1601
- var res;
1602
- return __generator(this, function (_a) {
1603
- switch (_a.label) {
1604
- case 0:
1605
- return [4
1606
- /*yield*/
1607
- , axios.request({
1608
- url: url,
1609
- headers: options.headers,
1610
- method: options.method.toLowerCase(),
1611
- data: options.body,
1612
- signal: options.signal,
1613
- // fetch only throws on network errors, not on HTTP errors
1614
- validateStatus: function () {
1615
- return true;
1616
- }
1617
- })];
1618
-
1619
- case 1:
1620
- res = _a.sent();
1621
- return [2
1622
- /*return*/
1623
- , {
1624
- status: res.status,
1625
- text: function () {
1626
- return __awaiter(void 0, void 0, void 0, function () {
1627
- return __generator(this, function (_a) {
1628
- return [2
1629
- /*return*/
1630
- , res.data];
1610
+ /**
1611
+ * Fetch wrapper
1612
+ *
1613
+ * We want to polyfill fetch when not available with axios but use it when it is.
1614
+ * NOTE: The current version of Axios has an issue when in non-node environments like Clouflare Workers.
1615
+ * This is currently solved by using the global fetch if available instead.
1616
+ * See https://github.com/PostHog/posthog-js-lite/issues/127 for more info
1617
+ */
1618
+
1619
+ var _fetch = // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
1620
+ // @ts-ignore
1621
+ typeof fetch !== 'undefined' ? fetch : typeof global.fetch !== 'undefined' ? global.fetch : undefined;
1622
+
1623
+ if (!_fetch) {
1624
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
1625
+ var axios_1 = require('axios');
1626
+
1627
+ _fetch = function (url, options) {
1628
+ return __awaiter(void 0, void 0, void 0, function () {
1629
+ var res;
1630
+ return __generator(this, function (_a) {
1631
+ switch (_a.label) {
1632
+ case 0:
1633
+ return [4
1634
+ /*yield*/
1635
+ , axios_1.request({
1636
+ url: url,
1637
+ headers: options.headers,
1638
+ method: options.method.toLowerCase(),
1639
+ data: options.body,
1640
+ signal: options.signal,
1641
+ // fetch only throws on network errors, not on HTTP errors
1642
+ validateStatus: function () {
1643
+ return true;
1644
+ }
1645
+ })];
1646
+
1647
+ case 1:
1648
+ res = _a.sent();
1649
+ return [2
1650
+ /*return*/
1651
+ , {
1652
+ status: res.status,
1653
+ text: function () {
1654
+ return __awaiter(void 0, void 0, void 0, function () {
1655
+ return __generator(this, function (_a) {
1656
+ return [2
1657
+ /*return*/
1658
+ , res.data];
1659
+ });
1631
1660
  });
1632
- });
1633
- },
1634
- json: function () {
1635
- return __awaiter(void 0, void 0, void 0, function () {
1636
- return __generator(this, function (_a) {
1637
- return [2
1638
- /*return*/
1639
- , res.data];
1661
+ },
1662
+ json: function () {
1663
+ return __awaiter(void 0, void 0, void 0, function () {
1664
+ return __generator(this, function (_a) {
1665
+ return [2
1666
+ /*return*/
1667
+ , res.data];
1668
+ });
1640
1669
  });
1641
- });
1642
- }
1643
- }];
1644
- }
1670
+ }
1671
+ }];
1672
+ }
1673
+ });
1645
1674
  });
1646
- });
1647
- };
1675
+ };
1676
+ } // 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
1677
+
1678
+
1679
+ var fetch$1 = _fetch;
1648
1680
 
1649
1681
  var LONG_SCALE = 0xfffffffffffffff;
1650
1682
 
@@ -1710,7 +1742,7 @@ function () {
1710
1742
  this.host = host;
1711
1743
  this.poller = undefined; // NOTE: as any is required here as the AbortSignal typing is slightly misaligned but works just fine
1712
1744
 
1713
- this.fetch = options.fetch || fetch;
1745
+ this.fetch = options.fetch || fetch$1;
1714
1746
  void this.loadFeatureFlags();
1715
1747
  }
1716
1748
 
@@ -2544,7 +2576,7 @@ function (_super) {
2544
2576
  };
2545
2577
 
2546
2578
  PostHog.prototype.fetch = function (url, options) {
2547
- return this.options.fetch ? this.options.fetch(url, options) : fetch(url, options);
2579
+ return this.options.fetch ? this.options.fetch(url, options) : fetch$1(url, options);
2548
2580
  };
2549
2581
 
2550
2582
  PostHog.prototype.getLibraryId = function () {