@aws-amplify/core 6.0.1-console-preview.047a1dd.0 → 6.0.1-next.3e9fc9c.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.
Files changed (122) hide show
  1. package/lib/Cache/Utils/CacheUtils.js +4 -2
  2. package/lib/Platform/version.d.ts +1 -1
  3. package/lib/Platform/version.js +1 -1
  4. package/lib/RNComponents/index.d.ts +6 -0
  5. package/lib/RNComponents/index.js +16 -0
  6. package/lib/{providers/pinpoint/utils → RNComponents}/isAppInForeground.js +4 -1
  7. package/lib/RNComponents/reactnative.d.ts +3 -0
  8. package/lib/RNComponents/reactnative.js +14 -0
  9. package/lib/{storage/CookieStorage.d.ts → StorageHelper/cookieStorage.d.ts} +3 -4
  10. package/lib/{storage/CookieStorage.js → StorageHelper/cookieStorage.js} +83 -35
  11. package/lib/StorageHelper/inMemoryStorage.d.ts +10 -0
  12. package/lib/StorageHelper/inMemoryStorage.js +82 -0
  13. package/lib/StorageHelper/index.d.ts +45 -0
  14. package/lib/StorageHelper/index.js +83 -0
  15. package/lib/{storage/DefaultStorage.native.d.ts → StorageHelper/localStorage.d.ts} +6 -7
  16. package/lib/{storage/KeyValueStorage.js → StorageHelper/localStorage.js} +15 -13
  17. package/lib/StorageHelper/reactnative.d.ts +83 -0
  18. package/lib/StorageHelper/reactnative.js +250 -0
  19. package/lib/{storage/KeyValueStorage.d.ts → StorageHelper/sessionStorage.d.ts} +4 -5
  20. package/lib/{storage/DefaultStorage.native.js → StorageHelper/sessionStorage.js} +43 -46
  21. package/lib/index.d.ts +1 -1
  22. package/lib/index.js +8 -6
  23. package/lib/libraryUtils.d.ts +1 -0
  24. package/lib/libraryUtils.js +5 -1
  25. package/lib/parseAWSExports.js +1 -20
  26. package/lib/providers/pinpoint/utils/PinpointEventBuffer.js +5 -7
  27. package/lib/singleton/types.d.ts +1 -4
  28. package/lib/tsconfig.tsbuildinfo +1 -1
  29. package/lib/types/storage.d.ts +0 -3
  30. package/lib-esm/Cache/Utils/CacheUtils.js +4 -2
  31. package/lib-esm/Platform/version.d.ts +1 -1
  32. package/lib-esm/Platform/version.js +1 -1
  33. package/lib-esm/RNComponents/index.d.ts +6 -0
  34. package/lib-esm/RNComponents/index.js +13 -0
  35. package/lib-esm/RNComponents/isAppInForeground.js +6 -0
  36. package/lib-esm/RNComponents/reactnative.d.ts +3 -0
  37. package/lib-esm/RNComponents/reactnative.js +6 -0
  38. package/lib-esm/{storage/CookieStorage.d.ts → StorageHelper/cookieStorage.d.ts} +3 -4
  39. package/lib-esm/{storage/CookieStorage.js → StorageHelper/cookieStorage.js} +61 -36
  40. package/lib-esm/StorageHelper/inMemoryStorage.d.ts +10 -0
  41. package/lib-esm/StorageHelper/inMemoryStorage.js +79 -0
  42. package/lib-esm/StorageHelper/index.d.ts +45 -0
  43. package/lib-esm/StorageHelper/index.js +76 -0
  44. package/lib-esm/{storage/DefaultStorage.native.d.ts → StorageHelper/localStorage.d.ts} +6 -7
  45. package/lib-esm/{storage/KeyValueStorage.js → StorageHelper/localStorage.js} +14 -12
  46. package/lib-esm/StorageHelper/reactnative.d.ts +83 -0
  47. package/lib-esm/StorageHelper/reactnative.js +244 -0
  48. package/lib-esm/{storage/KeyValueStorage.d.ts → StorageHelper/sessionStorage.d.ts} +4 -5
  49. package/lib-esm/{storage/DefaultStorage.native.js → StorageHelper/sessionStorage.js} +42 -45
  50. package/lib-esm/index.d.ts +1 -1
  51. package/lib-esm/index.js +1 -1
  52. package/lib-esm/libraryUtils.d.ts +1 -0
  53. package/lib-esm/libraryUtils.js +1 -0
  54. package/lib-esm/parseAWSExports.js +1 -20
  55. package/lib-esm/providers/pinpoint/utils/PinpointEventBuffer.js +5 -7
  56. package/lib-esm/singleton/types.d.ts +1 -4
  57. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  58. package/lib-esm/types/storage.d.ts +0 -3
  59. package/package.json +4 -3
  60. package/src/Cache/Utils/CacheUtils.ts +4 -2
  61. package/src/Platform/version.ts +1 -1
  62. package/src/RNComponents/index.ts +16 -0
  63. package/src/RNComponents/isAppInForeground.ts +8 -0
  64. package/src/RNComponents/reactnative.ts +6 -0
  65. package/src/StorageHelper/cookieStorage.ts +99 -0
  66. package/src/StorageHelper/inMemoryStorage.ts +32 -0
  67. package/src/StorageHelper/index.ts +78 -0
  68. package/src/StorageHelper/localStorage.ts +60 -0
  69. package/src/StorageHelper/reactnative.ts +182 -0
  70. package/src/{storage/KeyValueStorage.ts → StorageHelper/sessionStorage.ts} +13 -10
  71. package/src/index.ts +6 -4
  72. package/src/libraryUtils.ts +1 -0
  73. package/src/parseAWSExports.ts +0 -26
  74. package/src/providers/pinpoint/utils/PinpointEventBuffer.ts +12 -16
  75. package/src/singleton/types.ts +1 -4
  76. package/src/types/storage.ts +0 -4
  77. package/lib/providers/pinpoint/utils/isAppInForeground.native.d.ts +0 -1
  78. package/lib/providers/pinpoint/utils/isAppInForeground.native.js +0 -9
  79. package/lib/singleton/API/types.d.ts +0 -34
  80. package/lib/singleton/API/types.js +0 -2
  81. package/lib/storage/CookieStorage.native.d.ts +0 -7
  82. package/lib/storage/CookieStorage.native.js +0 -32
  83. package/lib/storage/DefaultStorage.d.ts +0 -7
  84. package/lib/storage/DefaultStorage.js +0 -33
  85. package/lib/storage/InMemoryStorage.d.ts +0 -12
  86. package/lib/storage/InMemoryStorage.js +0 -41
  87. package/lib/storage/SessionStorage.d.ts +0 -7
  88. package/lib/storage/SessionStorage.js +0 -33
  89. package/lib/storage/index.d.ts +0 -7
  90. package/lib/storage/index.js +0 -14
  91. package/lib/storage/utils.d.ts +0 -10
  92. package/lib/storage/utils.js +0 -26
  93. package/lib-esm/providers/pinpoint/utils/isAppInForeground.js +0 -3
  94. package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.d.ts +0 -1
  95. package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.js +0 -5
  96. package/lib-esm/singleton/API/types.d.ts +0 -34
  97. package/lib-esm/singleton/API/types.js +0 -1
  98. package/lib-esm/storage/CookieStorage.native.d.ts +0 -7
  99. package/lib-esm/storage/CookieStorage.native.js +0 -29
  100. package/lib-esm/storage/DefaultStorage.d.ts +0 -7
  101. package/lib-esm/storage/DefaultStorage.js +0 -30
  102. package/lib-esm/storage/InMemoryStorage.d.ts +0 -12
  103. package/lib-esm/storage/InMemoryStorage.js +0 -38
  104. package/lib-esm/storage/SessionStorage.d.ts +0 -7
  105. package/lib-esm/storage/SessionStorage.js +0 -30
  106. package/lib-esm/storage/index.d.ts +0 -7
  107. package/lib-esm/storage/index.js +0 -10
  108. package/lib-esm/storage/utils.d.ts +0 -10
  109. package/lib-esm/storage/utils.js +0 -21
  110. package/src/providers/pinpoint/utils/isAppInForeground.native.ts +0 -7
  111. package/src/providers/pinpoint/utils/isAppInForeground.ts +0 -4
  112. package/src/singleton/API/types.ts +0 -31
  113. package/src/storage/CookieStorage.native.ts +0 -13
  114. package/src/storage/CookieStorage.ts +0 -72
  115. package/src/storage/DefaultStorage.native.ts +0 -78
  116. package/src/storage/DefaultStorage.ts +0 -14
  117. package/src/storage/InMemoryStorage.ts +0 -36
  118. package/src/storage/SessionStorage.ts +0 -14
  119. package/src/storage/index.ts +0 -13
  120. package/src/storage/utils.ts +0 -22
  121. /package/lib/{providers/pinpoint/utils → RNComponents}/isAppInForeground.d.ts +0 -0
  122. /package/lib-esm/{providers/pinpoint/utils → RNComponents}/isAppInForeground.d.ts +0 -0
@@ -1,16 +1,3 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- var __assign = (this && this.__assign) || function () {
4
- __assign = Object.assign || function(t) {
5
- for (var s, i = 1, n = arguments.length; i < n; i++) {
6
- s = arguments[i];
7
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
- t[p] = s[p];
9
- }
10
- return t;
11
- };
12
- return __assign.apply(this, arguments);
13
- };
14
1
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
2
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
3
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -47,60 +34,101 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
48
35
  }
49
36
  };
50
- import { get as getJsCookie, remove as removeJsCookie, set as setJsCookie, } from 'js-cookie';
37
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
38
+ // SPDX-License-Identifier: Apache-2.0
39
+ // @ts-ignore
40
+ import * as Cookies from 'js-cookie';
51
41
  var CookieStorage = /** @class */ (function () {
52
42
  function CookieStorage(data) {
53
43
  if (data === void 0) { data = {}; }
54
- var path = data.path, domain = data.domain, expires = data.expires, sameSite = data.sameSite, secure = data.secure;
55
- this.domain = domain;
56
- this.path = path ? path : '/';
57
- this.expires = data.hasOwnProperty('expires') ? expires : 365;
58
- this.secure = data.hasOwnProperty('secure') ? secure : true;
44
+ if (data.domain) {
45
+ this.domain = data.domain;
46
+ }
47
+ if (data.path) {
48
+ this.path = data.path;
49
+ }
50
+ else {
51
+ this.path = '/';
52
+ }
53
+ if (Object.prototype.hasOwnProperty.call(data, 'expires')) {
54
+ this.expires = data.expires;
55
+ }
56
+ else {
57
+ this.expires = 365;
58
+ }
59
+ if (Object.prototype.hasOwnProperty.call(data, 'secure')) {
60
+ this.secure = data.secure;
61
+ }
62
+ else {
63
+ this.secure = true;
64
+ }
59
65
  if (data.hasOwnProperty('sameSite')) {
60
- if (!sameSite || !['strict', 'lax', 'none'].includes(sameSite)) {
66
+ if (!data.sameSite ||
67
+ !['strict', 'lax', 'none'].includes(data.sameSite)) {
61
68
  throw new Error('The sameSite value of cookieStorage must be "lax", "strict" or "none".');
62
69
  }
63
- if (sameSite === 'none' && !this.secure) {
70
+ if (data.sameSite === 'none' && !this.secure) {
64
71
  throw new Error('sameSite = None requires the Secure attribute in latest browser versions.');
65
72
  }
66
- this.sameSite = sameSite;
73
+ this.sameSite = data.sameSite;
67
74
  }
68
75
  }
69
76
  CookieStorage.prototype.setItem = function (key, value) {
70
77
  return __awaiter(this, void 0, void 0, function () {
78
+ var options;
71
79
  return __generator(this, function (_a) {
72
- setJsCookie(key, value, this.getData());
73
- return [2 /*return*/];
80
+ options = {
81
+ path: this.path,
82
+ expires: this.expires,
83
+ domain: this.domain,
84
+ secure: this.secure,
85
+ };
86
+ if (this.sameSite) {
87
+ options.sameSite = this.sameSite;
88
+ }
89
+ Cookies.set(key, value, options);
90
+ return [2 /*return*/, Cookies.get(key)];
74
91
  });
75
92
  });
76
93
  };
77
94
  CookieStorage.prototype.getItem = function (key) {
78
95
  return __awaiter(this, void 0, void 0, function () {
79
- var item;
80
96
  return __generator(this, function (_a) {
81
- item = getJsCookie(key);
82
- return [2 /*return*/, item !== null && item !== void 0 ? item : null];
97
+ return [2 /*return*/, Cookies.get(key)];
83
98
  });
84
99
  });
85
100
  };
86
101
  CookieStorage.prototype.removeItem = function (key) {
87
102
  return __awaiter(this, void 0, void 0, function () {
103
+ var options;
88
104
  return __generator(this, function (_a) {
89
- removeJsCookie(key, this.getData());
105
+ options = {
106
+ path: this.path,
107
+ expires: this.expires,
108
+ domain: this.domain,
109
+ secure: this.secure,
110
+ };
111
+ if (this.sameSite) {
112
+ options.sameSite = this.sameSite;
113
+ }
114
+ Cookies.remove(key, options);
90
115
  return [2 /*return*/];
91
116
  });
92
117
  });
93
118
  };
94
119
  CookieStorage.prototype.clear = function () {
95
120
  return __awaiter(this, void 0, void 0, function () {
96
- var cookie, promises;
97
- var _this = this;
121
+ var cookies, numKeys, promiseArray, index;
98
122
  return __generator(this, function (_a) {
99
123
  switch (_a.label) {
100
124
  case 0:
101
- cookie = getJsCookie();
102
- promises = Object.keys(cookie).map(function (key) { return _this.removeItem(key); });
103
- return [4 /*yield*/, Promise.all(promises)];
125
+ cookies = Cookies.get();
126
+ numKeys = Object.keys(cookies).length;
127
+ promiseArray = [];
128
+ for (index = 0; index < numKeys; ++index) {
129
+ promiseArray.push(this.removeItem(Object.keys(cookies)[index]));
130
+ }
131
+ return [4 /*yield*/, Promise.all(promiseArray)];
104
132
  case 1:
105
133
  _a.sent();
106
134
  return [2 /*return*/];
@@ -108,9 +136,6 @@ var CookieStorage = /** @class */ (function () {
108
136
  });
109
137
  });
110
138
  };
111
- CookieStorage.prototype.getData = function () {
112
- return __assign({ path: this.path, expires: this.expires, domain: this.domain, secure: this.secure }, (this.sameSite && { sameSite: this.sameSite }));
113
- };
114
139
  return CookieStorage;
115
140
  }());
116
141
  export { CookieStorage };
@@ -0,0 +1,10 @@
1
+ import { KeyValueStorageInterface } from '../types';
2
+ declare class MemoryKeyValueStorageClass implements KeyValueStorageInterface {
3
+ myStorage: Record<string, string>;
4
+ setItem(key: string, value: string): Promise<void>;
5
+ getItem(key: string): Promise<string | null>;
6
+ removeItem(key: string): Promise<void>;
7
+ clear(): Promise<void>;
8
+ }
9
+ export declare const MemoryKeyValueStorage: MemoryKeyValueStorageClass;
10
+ export {};
@@ -0,0 +1,79 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
12
+ var __generator = (this && this.__generator) || function (thisArg, body) {
13
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
14
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
15
+ function verb(n) { return function (v) { return step([n, v]); }; }
16
+ function step(op) {
17
+ if (f) throw new TypeError("Generator is already executing.");
18
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
19
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
20
+ if (y = 0, t) op = [op[0] & 2, t.value];
21
+ switch (op[0]) {
22
+ case 0: case 1: t = op; break;
23
+ case 4: _.label++; return { value: op[1], done: false };
24
+ case 5: _.label++; y = op[1]; op = [0]; continue;
25
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
26
+ default:
27
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
28
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
29
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
30
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
31
+ if (t[2]) _.ops.pop();
32
+ _.trys.pop(); continue;
33
+ }
34
+ op = body.call(thisArg, _);
35
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
36
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37
+ }
38
+ };
39
+ var MemoryKeyValueStorageClass = /** @class */ (function () {
40
+ function MemoryKeyValueStorageClass() {
41
+ this.myStorage = {};
42
+ }
43
+ MemoryKeyValueStorageClass.prototype.setItem = function (key, value) {
44
+ return __awaiter(this, void 0, void 0, function () {
45
+ return __generator(this, function (_a) {
46
+ this.myStorage[key] = value;
47
+ return [2 /*return*/];
48
+ });
49
+ });
50
+ };
51
+ MemoryKeyValueStorageClass.prototype.getItem = function (key) {
52
+ return __awaiter(this, void 0, void 0, function () {
53
+ return __generator(this, function (_a) {
54
+ return [2 /*return*/, this.myStorage[key]];
55
+ });
56
+ });
57
+ };
58
+ MemoryKeyValueStorageClass.prototype.removeItem = function (key) {
59
+ return __awaiter(this, void 0, void 0, function () {
60
+ return __generator(this, function (_a) {
61
+ delete this.myStorage[key];
62
+ return [2 /*return*/];
63
+ });
64
+ });
65
+ };
66
+ MemoryKeyValueStorageClass.prototype.clear = function () {
67
+ return __awaiter(this, void 0, void 0, function () {
68
+ var _this = this;
69
+ return __generator(this, function (_a) {
70
+ Object.keys(this.myStorage).forEach(function (key) {
71
+ delete _this.myStorage[key];
72
+ });
73
+ return [2 /*return*/];
74
+ });
75
+ });
76
+ };
77
+ return MemoryKeyValueStorageClass;
78
+ }());
79
+ export var MemoryKeyValueStorage = new MemoryKeyValueStorageClass();
@@ -0,0 +1,45 @@
1
+ /** @class */
2
+ export declare class MemoryStorage {
3
+ /**
4
+ * This is used to set a specific item in storage
5
+ * @param {string} key - the key for the item
6
+ * @param {object} value - the value
7
+ * @returns {string} value that was set
8
+ */
9
+ static setItem(key: string, value: any): string;
10
+ /**
11
+ * This is used to get a specific key from storage
12
+ * @param {string} key - the key for the item
13
+ * This is used to clear the storage
14
+ * @returns {string} the data item
15
+ */
16
+ static getItem(key: string): string | undefined;
17
+ /**
18
+ * This is used to remove an item from storage
19
+ * @param {string} key - the key being set
20
+ * @returns {string} value - value that was deleted
21
+ */
22
+ static removeItem(key: string): boolean;
23
+ /**
24
+ * This is used to clear the storage
25
+ * @returns {string} nothing
26
+ */
27
+ static clear(): Record<string, string>;
28
+ }
29
+ export declare class StorageHelper {
30
+ private storageWindow;
31
+ /**
32
+ * This is used to get a storage object
33
+ * @returns {object} the storage
34
+ */
35
+ constructor();
36
+ /**
37
+ * This is used to return the storage
38
+ * @returns {object} the storage
39
+ */
40
+ getStorage(): any;
41
+ }
42
+ export { SessionStorage } from './sessionStorage';
43
+ export { LocalStorage } from './localStorage';
44
+ export { MemoryKeyValueStorage } from './inMemoryStorage';
45
+ export { CookieStorage } from './cookieStorage';
@@ -0,0 +1,76 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ var dataMemory = {};
4
+ /** @class */
5
+ var MemoryStorage = /** @class */ (function () {
6
+ function MemoryStorage() {
7
+ }
8
+ /**
9
+ * This is used to set a specific item in storage
10
+ * @param {string} key - the key for the item
11
+ * @param {object} value - the value
12
+ * @returns {string} value that was set
13
+ */
14
+ MemoryStorage.setItem = function (key, value) {
15
+ dataMemory[key] = value;
16
+ return dataMemory[key];
17
+ };
18
+ /**
19
+ * This is used to get a specific key from storage
20
+ * @param {string} key - the key for the item
21
+ * This is used to clear the storage
22
+ * @returns {string} the data item
23
+ */
24
+ MemoryStorage.getItem = function (key) {
25
+ return Object.prototype.hasOwnProperty.call(dataMemory, key)
26
+ ? dataMemory[key]
27
+ : undefined;
28
+ };
29
+ /**
30
+ * This is used to remove an item from storage
31
+ * @param {string} key - the key being set
32
+ * @returns {string} value - value that was deleted
33
+ */
34
+ MemoryStorage.removeItem = function (key) {
35
+ return delete dataMemory[key];
36
+ };
37
+ /**
38
+ * This is used to clear the storage
39
+ * @returns {string} nothing
40
+ */
41
+ MemoryStorage.clear = function () {
42
+ dataMemory = {};
43
+ return dataMemory;
44
+ };
45
+ return MemoryStorage;
46
+ }());
47
+ export { MemoryStorage };
48
+ var StorageHelper = /** @class */ (function () {
49
+ /**
50
+ * This is used to get a storage object
51
+ * @returns {object} the storage
52
+ */
53
+ function StorageHelper() {
54
+ try {
55
+ this.storageWindow = window.localStorage;
56
+ this.storageWindow.setItem('aws.amplify.test-ls', 1);
57
+ this.storageWindow.removeItem('aws.amplify.test-ls');
58
+ }
59
+ catch (exception) {
60
+ this.storageWindow = MemoryStorage;
61
+ }
62
+ }
63
+ /**
64
+ * This is used to return the storage
65
+ * @returns {object} the storage
66
+ */
67
+ StorageHelper.prototype.getStorage = function () {
68
+ return this.storageWindow;
69
+ };
70
+ return StorageHelper;
71
+ }());
72
+ export { StorageHelper };
73
+ export { SessionStorage } from './sessionStorage';
74
+ export { LocalStorage } from './localStorage';
75
+ export { MemoryKeyValueStorage } from './inMemoryStorage';
76
+ export { CookieStorage } from './cookieStorage';
@@ -1,9 +1,7 @@
1
- import { KeyValueStorageInterface } from '../types';
2
- /**
3
- * @internal
4
- */
5
- export declare class DefaultStorage implements KeyValueStorageInterface {
6
- private asyncStorage?;
1
+ import { KeyValueStorageInterface } from "../types";
2
+ declare class LocalStorageClass implements KeyValueStorageInterface {
3
+ storage?: Storage;
4
+ constructor();
7
5
  /**
8
6
  * This is used to set a specific item in storage
9
7
  * @param {string} key - the key for the item
@@ -29,5 +27,6 @@ export declare class DefaultStorage implements KeyValueStorageInterface {
29
27
  * @returns {string} nothing
30
28
  */
31
29
  clear(): Promise<void>;
32
- private assertModule;
33
30
  }
31
+ export declare const LocalStorage: LocalStorageClass;
32
+ export {};
@@ -37,12 +37,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  }
38
38
  };
39
39
  import { PlatformNotSupportedError } from '../Util/Errors';
40
- /**
41
- * @internal
42
- */
43
- var KeyValueStorage = /** @class */ (function () {
44
- function KeyValueStorage(storage) {
45
- this.storage = storage;
40
+ var LocalStorageClass = /** @class */ (function () {
41
+ function LocalStorageClass() {
42
+ if (typeof window !== undefined) {
43
+ try {
44
+ this.storage = window === null || window === void 0 ? void 0 : window.localStorage;
45
+ }
46
+ catch (error) { }
47
+ }
46
48
  }
47
49
  /**
48
50
  * This is used to set a specific item in storage
@@ -50,7 +52,7 @@ var KeyValueStorage = /** @class */ (function () {
50
52
  * @param {object} value - the value
51
53
  * @returns {string} value that was set
52
54
  */
53
- KeyValueStorage.prototype.setItem = function (key, value) {
55
+ LocalStorageClass.prototype.setItem = function (key, value) {
54
56
  return __awaiter(this, void 0, void 0, function () {
55
57
  return __generator(this, function (_a) {
56
58
  if (!this.storage)
@@ -66,7 +68,7 @@ var KeyValueStorage = /** @class */ (function () {
66
68
  * This is used to clear the storage
67
69
  * @returns {string} the data item
68
70
  */
69
- KeyValueStorage.prototype.getItem = function (key) {
71
+ LocalStorageClass.prototype.getItem = function (key) {
70
72
  return __awaiter(this, void 0, void 0, function () {
71
73
  return __generator(this, function (_a) {
72
74
  if (!this.storage)
@@ -80,7 +82,7 @@ var KeyValueStorage = /** @class */ (function () {
80
82
  * @param {string} key - the key being set
81
83
  * @returns {string} value - value that was deleted
82
84
  */
83
- KeyValueStorage.prototype.removeItem = function (key) {
85
+ LocalStorageClass.prototype.removeItem = function (key) {
84
86
  return __awaiter(this, void 0, void 0, function () {
85
87
  return __generator(this, function (_a) {
86
88
  if (!this.storage)
@@ -94,7 +96,7 @@ var KeyValueStorage = /** @class */ (function () {
94
96
  * This is used to clear the storage
95
97
  * @returns {string} nothing
96
98
  */
97
- KeyValueStorage.prototype.clear = function () {
99
+ LocalStorageClass.prototype.clear = function () {
98
100
  return __awaiter(this, void 0, void 0, function () {
99
101
  return __generator(this, function (_a) {
100
102
  if (!this.storage)
@@ -104,6 +106,6 @@ var KeyValueStorage = /** @class */ (function () {
104
106
  });
105
107
  });
106
108
  };
107
- return KeyValueStorage;
109
+ return LocalStorageClass;
108
110
  }());
109
- export { KeyValueStorage };
111
+ export var LocalStorage = new LocalStorageClass();
@@ -0,0 +1,83 @@
1
+ import { KeyValueStorageInterface } from '../types';
2
+ /** @class */
3
+ declare class MemoryStorage {
4
+ static syncPromise: Promise<void> | null;
5
+ /**
6
+ * This is used to set a specific item in storage
7
+ * @param {string} key - the key for the item
8
+ * @param {object} value - the value
9
+ * @returns {string} value that was set
10
+ */
11
+ static setItem(key: string, value: string): string | null | undefined;
12
+ /**
13
+ * This is used to get a specific key from storage
14
+ * @param {string} key - the key for the item
15
+ * This is used to clear the storage
16
+ * @returns {string} the data item
17
+ */
18
+ static getItem(key: string): string | null | undefined;
19
+ /**
20
+ * This is used to remove an item from storage
21
+ * @param {string} key - the key being set
22
+ * @returns {string} value - value that was deleted
23
+ */
24
+ static removeItem(key: string): boolean;
25
+ /**
26
+ * This is used to clear the storage
27
+ * @returns {string} nothing
28
+ */
29
+ static clear(): Record<string, string | null>;
30
+ /**
31
+ * Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
32
+ * @returns {void}
33
+ */
34
+ static sync(): Promise<void>;
35
+ }
36
+ export declare class StorageHelper {
37
+ private storageWindow;
38
+ /**
39
+ * This is used to get a storage object
40
+ * @returns {object} the storage
41
+ */
42
+ constructor();
43
+ /**
44
+ * This is used to return the storage
45
+ * @returns {object} the storage
46
+ */
47
+ getStorage(): typeof MemoryStorage;
48
+ }
49
+ declare class AsyncStorageClass implements KeyValueStorageInterface {
50
+ syncPromise: Promise<void> | null;
51
+ /**
52
+ * This is used to set a specific item in storage
53
+ * @param {string} key - the key for the item
54
+ * @param {object} value - the value
55
+ * @returns {string} value that was set
56
+ */
57
+ setItem(key: string, value: string): Promise<void>;
58
+ /**
59
+ * This is used to get a specific key from storage
60
+ * @param {string} key - the key for the item
61
+ * This is used to clear the storage
62
+ * @returns {string} the data item
63
+ */
64
+ getItem(key: string): Promise<string | null>;
65
+ /**
66
+ * This is used to remove an item from storage
67
+ * @param {string} key - the key being set
68
+ * @returns {string} value - value that was deleted
69
+ */
70
+ removeItem(key: string): Promise<void>;
71
+ /**
72
+ * This is used to clear the storage
73
+ * @returns {string} nothing
74
+ */
75
+ clear(): Promise<void>;
76
+ /**
77
+ * Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
78
+ * @returns {void}
79
+ */
80
+ sync(): Promise<void>;
81
+ }
82
+ export declare const AsyncStorageKeyValue: AsyncStorageClass;
83
+ export {};