posthog-js-lite 2.0.0-alpha4 → 2.0.0-alpha5

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.cjs.js CHANGED
@@ -1125,7 +1125,7 @@ var PostHogCore = /** @class */ (function () {
1125
1125
  return PostHogCore;
1126
1126
  }());
1127
1127
 
1128
- var version = "2.0.0-alpha4";
1128
+ var version = "2.0.0-alpha5";
1129
1129
 
1130
1130
  function getContext(window) {
1131
1131
  var context = {};
@@ -1416,17 +1416,66 @@ var checkStoreIsSupported = function (storage, key) {
1416
1416
  var localStore = checkStoreIsSupported(_localStore) ? _localStore : undefined;
1417
1417
  var sessionStorage = checkStoreIsSupported(_sessionStore) ? _sessionStore : undefined;
1418
1418
 
1419
+ var createMemoryStorage = function () {
1420
+ var _cache = {};
1421
+ var store = {
1422
+ getItem: function (key) {
1423
+ return _cache[key];
1424
+ },
1425
+ setItem: function (key, value) {
1426
+ _cache[key] = value !== null ? value : undefined;
1427
+ },
1428
+ removeItem: function (key) {
1429
+ delete _cache[key];
1430
+ },
1431
+ clear: function () {
1432
+ for (var key in _cache) {
1433
+ delete _cache[key];
1434
+ }
1435
+ },
1436
+ getAllKeys: function () {
1437
+ var keys = [];
1438
+
1439
+ for (var key in _cache) {
1440
+ keys.push(key);
1441
+ }
1442
+
1443
+ return keys;
1444
+ }
1445
+ };
1446
+ return store;
1447
+ };
1448
+
1449
+ var getStorage = function (type) {
1450
+ switch (type) {
1451
+ case 'cookie':
1452
+ return cookieStore || localStore || sessionStorage || createMemoryStorage();
1453
+
1454
+ case 'localStorage':
1455
+ return localStore || sessionStorage || createMemoryStorage();
1456
+
1457
+ case 'sessionStorage':
1458
+ return sessionStorage || createMemoryStorage();
1459
+
1460
+ case 'memory':
1461
+ return createMemoryStorage();
1462
+
1463
+ default:
1464
+ return createMemoryStorage();
1465
+ }
1466
+ };
1467
+
1419
1468
  var PostHog =
1420
1469
  /** @class */
1421
1470
  function (_super) {
1422
1471
  __extends(PostHog, _super);
1423
1472
 
1424
1473
  function PostHog(apiKey, options) {
1425
- var _this = _super.call(this, apiKey, options) || this;
1474
+ var _this = _super.call(this, apiKey, options) || this; // posthog-js stores options in one object on
1426
1475
 
1427
- _this._storage = localStore || sessionStorage || cookieStore; // posthog-js stores options in one object on
1428
1476
 
1429
1477
  _this._storageKey = (options === null || options === void 0 ? void 0 : options.persistence_name) ? "ph_".concat(options.persistence_name) : "ph_".concat(apiKey, "_posthog");
1478
+ _this._storage = getStorage((options === null || options === void 0 ? void 0 : options.persistence) || 'localStorage');
1430
1479
  return _this;
1431
1480
  }
1432
1481