posthog-react-native 2.1.0 → 2.1.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 CHANGED
@@ -1,3 +1,6 @@
1
+ # 2.1.1 - 2022-09-09
2
+
3
+ 1. Support for bootstrapping feature flags and distinctIDs. This allows you to initialise the library with a set of feature flags and distinctID that are immediately available.
1
4
  # 2.1.0 - 2022-09-02
2
5
 
3
6
  What's new:
package/lib/index.cjs.js CHANGED
@@ -772,6 +772,26 @@ var PostHogCore = /** @class */ (function () {
772
772
  }
773
773
  return __assign({ $lib: this.getLibraryId(), $lib_version: this.getLibraryVersion(), $active_feature_flags: featureFlags ? Object.keys(featureFlags) : undefined }, featureVariantProperties);
774
774
  };
775
+ PostHogCore.prototype.setupBootstrap = function (options) {
776
+ var _a, _b, _c, _d;
777
+ if ((_a = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _a === void 0 ? void 0 : _a.distinctId) {
778
+ if ((_b = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _b === void 0 ? void 0 : _b.isIdentifiedId) {
779
+ this.setPersistedProperty(PostHogPersistedProperty.DistinctId, options.bootstrap.distinctId);
780
+ }
781
+ else {
782
+ this.setPersistedProperty(PostHogPersistedProperty.AnonymousId, options.bootstrap.distinctId);
783
+ }
784
+ }
785
+ if ((_c = options === null || options === void 0 ? void 0 : options.bootstrap) === null || _c === void 0 ? void 0 : _c.featureFlags) {
786
+ var activeFlags = Object.keys(((_d = options.bootstrap) === null || _d === void 0 ? void 0 : _d.featureFlags) || {})
787
+ .filter(function (flag) { var _a, _b; return !!((_b = (_a = options.bootstrap) === null || _a === void 0 ? void 0 : _a.featureFlags) === null || _b === void 0 ? void 0 : _b[flag]); })
788
+ .reduce(function (res, key) {
789
+ var _a, _b;
790
+ return ((res[key] = ((_b = (_a = options.bootstrap) === null || _a === void 0 ? void 0 : _a.featureFlags) === null || _b === void 0 ? void 0 : _b[key]) || false), res);
791
+ }, {});
792
+ this.setKnownFeatureFlags(activeFlags);
793
+ }
794
+ };
775
795
  Object.defineProperty(PostHogCore.prototype, "props", {
776
796
  // NOTE: Props are lazy loaded from localstorage hence the complex getter setter logic
777
797
  get: function () {
@@ -1015,8 +1035,7 @@ var PostHogCore = /** @class */ (function () {
1015
1035
  .then(function (r) { return r.json(); })
1016
1036
  .then(function (res) {
1017
1037
  if (res.featureFlags) {
1018
- _this.setPersistedProperty(PostHogPersistedProperty.FeatureFlags, res.featureFlags);
1019
- _this._events.emit('featureflags', res.featureFlags);
1038
+ _this.setKnownFeatureFlags(res.featureFlags);
1020
1039
  }
1021
1040
  return res;
1022
1041
  })
@@ -1027,6 +1046,10 @@ var PostHogCore = /** @class */ (function () {
1027
1046
  });
1028
1047
  });
1029
1048
  };
1049
+ PostHogCore.prototype.setKnownFeatureFlags = function (featureFlags) {
1050
+ this.setPersistedProperty(PostHogPersistedProperty.FeatureFlags, featureFlags);
1051
+ this._events.emit('featureflags', featureFlags);
1052
+ };
1030
1053
  PostHogCore.prototype.getFeatureFlag = function (key) {
1031
1054
  var featureFlags = this.getFeatureFlags();
1032
1055
  if (!featureFlags) {
@@ -1338,7 +1361,7 @@ var loadStorageAsync = function () {
1338
1361
  return __generator(this, function (_a) {
1339
1362
  switch (_a.label) {
1340
1363
  case 0:
1341
- uri = FileSystem__namespace.documentDirectory + POSTHOG_STORAGE_KEY;
1364
+ uri = (FileSystem__namespace.documentDirectory || '') + POSTHOG_STORAGE_KEY;
1342
1365
  _a.label = 1;
1343
1366
 
1344
1367
  case 1:
@@ -1375,7 +1398,7 @@ var persitStorageAsync = function (content) {
1375
1398
  return __generator(this, function (_a) {
1376
1399
  switch (_a.label) {
1377
1400
  case 0:
1378
- uri = FileSystem__namespace.documentDirectory + POSTHOG_STORAGE_KEY;
1401
+ uri = (FileSystem__namespace.documentDirectory || '') + POSTHOG_STORAGE_KEY;
1379
1402
  data = {
1380
1403
  version: POSTHOG_STORAGE_VERSION,
1381
1404
  content: content
@@ -1438,7 +1461,7 @@ var preloadSemiAsyncStorage = function () {
1438
1461
  return _preloadSemiAsyncStoragePromise;
1439
1462
  };
1440
1463
 
1441
- var version = "2.1.0";
1464
+ var version = "2.1.1";
1442
1465
 
1443
1466
  var PostHog =
1444
1467
  /** @class */
@@ -1456,6 +1479,8 @@ function (_super) {
1456
1479
  // It is possible that the old library was used so we try to get the legacy distinctID
1457
1480
 
1458
1481
  void preloadSemiAsyncStorage().then(function () {
1482
+ _this.setupBootstrap(options);
1483
+
1459
1484
  if (!SemiAsyncStorage.getItem(PostHogPersistedProperty.AnonymousId)) {
1460
1485
  getLegacyValues().then(function (legacyValues) {
1461
1486
  if (legacyValues === null || legacyValues === void 0 ? void 0 : legacyValues.distinctId) {
@@ -1482,7 +1507,7 @@ function (_super) {
1482
1507
 
1483
1508
  PostHog.prototype.setPersistedProperty = function (key, value) {
1484
1509
  if (this._persistence === 'memory') {
1485
- return this._memoryStorage.getProperty(key);
1510
+ return this._memoryStorage.setProperty(key, value);
1486
1511
  }
1487
1512
 
1488
1513
  return value !== null ? SemiAsyncStorage.setItem(key, value) : SemiAsyncStorage.removeItem(key);