@aws-amplify/core 6.0.1-console-preview.814dea6.0 → 6.0.1-console-preview.047a1dd.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 (219) hide show
  1. package/lib/AwsClients/CognitoIdentity/base.d.ts +12 -4
  2. package/lib/AwsClients/CognitoIdentity/base.js +1 -0
  3. package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +15 -3
  4. package/lib/AwsClients/CognitoIdentity/getId.d.ts +15 -3
  5. package/lib/AwsClients/Pinpoint/base.d.ts +10 -2
  6. package/lib/AwsClients/Pinpoint/getInAppMessages.d.ts +17 -3
  7. package/lib/AwsClients/Pinpoint/putEvents.d.ts +17 -3
  8. package/lib/AwsClients/Pinpoint/updateEndpoint.d.ts +17 -3
  9. package/lib/Cache/Utils/CacheUtils.js +2 -4
  10. package/lib/Platform/version.d.ts +1 -1
  11. package/lib/Platform/version.js +1 -1
  12. package/lib/ServiceWorker/ServiceWorker.js +1 -1
  13. package/lib/Util/JS.d.ts +1 -4
  14. package/lib/Util/JS.js +4 -11
  15. package/lib/Util/Reachability.js +0 -3
  16. package/lib/clients/handlers/authenticated.d.ts +1 -1
  17. package/lib/clients/handlers/fetch.d.ts +0 -1
  18. package/lib/clients/handlers/fetch.js +2 -2
  19. package/lib/clients/handlers/unauthenticated.d.ts +1 -1
  20. package/lib/clients/internal/composeServiceApi.d.ts +5 -3
  21. package/lib/clients/types/aws.d.ts +1 -5
  22. package/lib/clients/types/http.d.ts +8 -0
  23. package/lib/clients/types/index.d.ts +1 -1
  24. package/lib/index.d.ts +1 -2
  25. package/lib/index.js +6 -10
  26. package/lib/libraryUtils.d.ts +3 -3
  27. package/lib/libraryUtils.js +5 -10
  28. package/lib/parseAWSExports.js +20 -1
  29. package/lib/providers/pinpoint/apis/record.d.ts +2 -2
  30. package/lib/providers/pinpoint/apis/record.js +3 -3
  31. package/lib/providers/pinpoint/apis/updateEndpoint.d.ts +2 -2
  32. package/lib/providers/pinpoint/types/buffer.d.ts +1 -1
  33. package/lib/providers/pinpoint/types/pinpoint.d.ts +3 -3
  34. package/lib/providers/pinpoint/utils/PinpointEventBuffer.js +7 -5
  35. package/lib/providers/pinpoint/utils/isAppInForeground.d.ts +1 -0
  36. package/lib/{RNComponents → providers/pinpoint/utils}/isAppInForeground.js +1 -4
  37. package/lib/providers/pinpoint/utils/isAppInForeground.native.d.ts +1 -0
  38. package/lib/providers/pinpoint/utils/isAppInForeground.native.js +9 -0
  39. package/lib/singleton/API/types.d.ts +34 -0
  40. package/lib/singleton/API/types.js +2 -0
  41. package/lib/singleton/Amplify.d.ts +2 -2
  42. package/lib/singleton/Amplify.js +9 -1
  43. package/lib/singleton/Auth/index.d.ts +2 -1
  44. package/lib/singleton/Auth/index.js +22 -12
  45. package/lib/singleton/Auth/utils/index.js +3 -3
  46. package/lib/singleton/Storage/types.d.ts +5 -0
  47. package/lib/singleton/types.d.ts +10 -1
  48. package/lib/{StorageHelper/cookieStorage.d.ts → storage/CookieStorage.d.ts} +4 -3
  49. package/lib/{StorageHelper/cookieStorage.js → storage/CookieStorage.js} +35 -83
  50. package/lib/storage/CookieStorage.native.d.ts +7 -0
  51. package/lib/storage/CookieStorage.native.js +32 -0
  52. package/lib/storage/DefaultStorage.d.ts +7 -0
  53. package/lib/storage/DefaultStorage.js +33 -0
  54. package/{lib-esm/StorageHelper/localStorage.d.ts → lib/storage/DefaultStorage.native.d.ts} +7 -6
  55. package/lib/{StorageHelper/sessionStorage.js → storage/DefaultStorage.native.js} +46 -43
  56. package/lib/storage/InMemoryStorage.d.ts +12 -0
  57. package/lib/storage/InMemoryStorage.js +41 -0
  58. package/lib/{StorageHelper/sessionStorage.d.ts → storage/KeyValueStorage.d.ts} +5 -4
  59. package/lib/{StorageHelper/localStorage.js → storage/KeyValueStorage.js} +13 -15
  60. package/lib/storage/SessionStorage.d.ts +7 -0
  61. package/lib/storage/SessionStorage.js +33 -0
  62. package/lib/storage/index.d.ts +7 -0
  63. package/lib/storage/index.js +14 -0
  64. package/lib/storage/utils.d.ts +10 -0
  65. package/lib/storage/utils.js +26 -0
  66. package/lib/tsconfig.tsbuildinfo +1 -1
  67. package/lib/types/storage.d.ts +3 -0
  68. package/lib-esm/AwsClients/CognitoIdentity/base.d.ts +12 -4
  69. package/lib-esm/AwsClients/CognitoIdentity/base.js +1 -0
  70. package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +15 -3
  71. package/lib-esm/AwsClients/CognitoIdentity/getId.d.ts +15 -3
  72. package/lib-esm/AwsClients/Pinpoint/base.d.ts +10 -2
  73. package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +17 -3
  74. package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +17 -3
  75. package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +17 -3
  76. package/lib-esm/Cache/Utils/CacheUtils.js +2 -4
  77. package/lib-esm/Platform/version.d.ts +1 -1
  78. package/lib-esm/Platform/version.js +1 -1
  79. package/lib-esm/ServiceWorker/ServiceWorker.js +2 -2
  80. package/lib-esm/Util/JS.d.ts +1 -4
  81. package/lib-esm/Util/JS.js +2 -9
  82. package/lib-esm/Util/Reachability.js +1 -4
  83. package/lib-esm/clients/handlers/authenticated.d.ts +1 -1
  84. package/lib-esm/clients/handlers/fetch.d.ts +0 -1
  85. package/lib-esm/clients/handlers/fetch.js +2 -2
  86. package/lib-esm/clients/handlers/unauthenticated.d.ts +1 -1
  87. package/lib-esm/clients/internal/composeServiceApi.d.ts +5 -3
  88. package/lib-esm/clients/types/aws.d.ts +1 -5
  89. package/lib-esm/clients/types/http.d.ts +8 -0
  90. package/lib-esm/clients/types/index.d.ts +1 -1
  91. package/lib-esm/index.d.ts +1 -2
  92. package/lib-esm/index.js +1 -2
  93. package/lib-esm/libraryUtils.d.ts +3 -3
  94. package/lib-esm/libraryUtils.js +2 -3
  95. package/lib-esm/parseAWSExports.js +20 -1
  96. package/lib-esm/providers/pinpoint/apis/record.d.ts +2 -2
  97. package/lib-esm/providers/pinpoint/apis/record.js +3 -3
  98. package/lib-esm/providers/pinpoint/apis/updateEndpoint.d.ts +2 -2
  99. package/lib-esm/providers/pinpoint/types/buffer.d.ts +1 -1
  100. package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +3 -3
  101. package/lib-esm/providers/pinpoint/utils/PinpointEventBuffer.js +7 -5
  102. package/lib-esm/providers/pinpoint/utils/isAppInForeground.js +3 -0
  103. package/lib-esm/providers/pinpoint/utils/isAppInForeground.native.js +5 -0
  104. package/lib-esm/singleton/API/types.d.ts +34 -0
  105. package/lib-esm/singleton/API/types.js +1 -0
  106. package/lib-esm/singleton/Amplify.d.ts +2 -2
  107. package/lib-esm/singleton/Amplify.js +9 -1
  108. package/lib-esm/singleton/Auth/index.d.ts +2 -1
  109. package/lib-esm/singleton/Auth/index.js +22 -12
  110. package/lib-esm/singleton/Auth/utils/index.js +3 -3
  111. package/lib-esm/singleton/Storage/types.d.ts +5 -0
  112. package/lib-esm/singleton/types.d.ts +10 -1
  113. package/lib-esm/{StorageHelper/cookieStorage.d.ts → storage/CookieStorage.d.ts} +4 -3
  114. package/lib-esm/{StorageHelper/cookieStorage.js → storage/CookieStorage.js} +36 -61
  115. package/lib-esm/storage/CookieStorage.native.d.ts +7 -0
  116. package/lib-esm/storage/CookieStorage.native.js +29 -0
  117. package/lib-esm/storage/DefaultStorage.d.ts +7 -0
  118. package/lib-esm/storage/DefaultStorage.js +30 -0
  119. package/{lib/StorageHelper/localStorage.d.ts → lib-esm/storage/DefaultStorage.native.d.ts} +7 -6
  120. package/lib-esm/{StorageHelper/sessionStorage.js → storage/DefaultStorage.native.js} +45 -42
  121. package/lib-esm/storage/InMemoryStorage.d.ts +12 -0
  122. package/lib-esm/storage/InMemoryStorage.js +38 -0
  123. package/lib-esm/{StorageHelper/sessionStorage.d.ts → storage/KeyValueStorage.d.ts} +5 -4
  124. package/lib-esm/{StorageHelper/localStorage.js → storage/KeyValueStorage.js} +12 -14
  125. package/lib-esm/storage/SessionStorage.d.ts +7 -0
  126. package/lib-esm/storage/SessionStorage.js +30 -0
  127. package/lib-esm/storage/index.d.ts +7 -0
  128. package/lib-esm/storage/index.js +10 -0
  129. package/lib-esm/storage/utils.d.ts +10 -0
  130. package/lib-esm/storage/utils.js +21 -0
  131. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  132. package/lib-esm/types/storage.d.ts +3 -0
  133. package/package.json +3 -6
  134. package/src/AwsClients/CognitoIdentity/base.ts +2 -2
  135. package/src/AwsClients/Pinpoint/base.ts +2 -6
  136. package/src/Cache/Utils/CacheUtils.ts +2 -4
  137. package/src/Platform/version.ts +1 -1
  138. package/src/ServiceWorker/ServiceWorker.ts +2 -2
  139. package/src/Util/JS.ts +2 -13
  140. package/src/Util/Reachability.ts +1 -5
  141. package/src/clients/handlers/authenticated.ts +2 -1
  142. package/src/clients/handlers/fetch.ts +2 -2
  143. package/src/clients/handlers/unauthenticated.ts +2 -1
  144. package/src/clients/internal/composeServiceApi.ts +10 -3
  145. package/src/clients/types/aws.ts +4 -11
  146. package/src/clients/types/http.ts +8 -0
  147. package/src/clients/types/index.ts +0 -1
  148. package/src/index.ts +4 -8
  149. package/src/libraryUtils.ts +3 -4
  150. package/src/parseAWSExports.ts +26 -0
  151. package/src/providers/pinpoint/apis/record.ts +8 -8
  152. package/src/providers/pinpoint/apis/updateEndpoint.ts +2 -2
  153. package/src/providers/pinpoint/types/buffer.ts +1 -1
  154. package/src/providers/pinpoint/types/pinpoint.ts +8 -7
  155. package/src/providers/pinpoint/utils/PinpointEventBuffer.ts +16 -12
  156. package/src/providers/pinpoint/utils/isAppInForeground.native.ts +7 -0
  157. package/src/providers/pinpoint/utils/isAppInForeground.ts +4 -0
  158. package/src/singleton/API/types.ts +31 -0
  159. package/src/singleton/Amplify.ts +12 -3
  160. package/src/singleton/Auth/index.ts +9 -2
  161. package/src/singleton/Auth/utils/index.ts +3 -3
  162. package/src/singleton/Storage/types.ts +6 -2
  163. package/src/singleton/types.ts +11 -1
  164. package/src/storage/CookieStorage.native.ts +13 -0
  165. package/src/storage/CookieStorage.ts +72 -0
  166. package/src/storage/DefaultStorage.native.ts +78 -0
  167. package/src/storage/DefaultStorage.ts +14 -0
  168. package/src/storage/InMemoryStorage.ts +36 -0
  169. package/src/{StorageHelper/sessionStorage.ts → storage/KeyValueStorage.ts} +10 -13
  170. package/src/storage/SessionStorage.ts +14 -0
  171. package/src/storage/index.ts +13 -0
  172. package/src/storage/utils.ts +22 -0
  173. package/src/types/storage.ts +4 -0
  174. package/lib/OAuthHelper/FacebookOAuth.d.ts +0 -6
  175. package/lib/OAuthHelper/FacebookOAuth.js +0 -124
  176. package/lib/OAuthHelper/GoogleOAuth.d.ts +0 -6
  177. package/lib/OAuthHelper/GoogleOAuth.js +0 -134
  178. package/lib/OAuthHelper/index.d.ts +0 -4
  179. package/lib/OAuthHelper/index.js +0 -9
  180. package/lib/RNComponents/index.d.ts +0 -6
  181. package/lib/RNComponents/index.js +0 -16
  182. package/lib/RNComponents/reactnative.d.ts +0 -3
  183. package/lib/RNComponents/reactnative.js +0 -14
  184. package/lib/StorageHelper/inMemoryStorage.d.ts +0 -10
  185. package/lib/StorageHelper/inMemoryStorage.js +0 -82
  186. package/lib/StorageHelper/index.d.ts +0 -45
  187. package/lib/StorageHelper/index.js +0 -83
  188. package/lib/StorageHelper/reactnative.d.ts +0 -83
  189. package/lib/StorageHelper/reactnative.js +0 -250
  190. package/lib-esm/OAuthHelper/FacebookOAuth.d.ts +0 -6
  191. package/lib-esm/OAuthHelper/FacebookOAuth.js +0 -121
  192. package/lib-esm/OAuthHelper/GoogleOAuth.d.ts +0 -6
  193. package/lib-esm/OAuthHelper/GoogleOAuth.js +0 -131
  194. package/lib-esm/OAuthHelper/index.d.ts +0 -4
  195. package/lib-esm/OAuthHelper/index.js +0 -6
  196. package/lib-esm/RNComponents/index.d.ts +0 -6
  197. package/lib-esm/RNComponents/index.js +0 -13
  198. package/lib-esm/RNComponents/isAppInForeground.js +0 -6
  199. package/lib-esm/RNComponents/reactnative.d.ts +0 -3
  200. package/lib-esm/RNComponents/reactnative.js +0 -6
  201. package/lib-esm/StorageHelper/inMemoryStorage.d.ts +0 -10
  202. package/lib-esm/StorageHelper/inMemoryStorage.js +0 -79
  203. package/lib-esm/StorageHelper/index.d.ts +0 -45
  204. package/lib-esm/StorageHelper/index.js +0 -76
  205. package/lib-esm/StorageHelper/reactnative.d.ts +0 -83
  206. package/lib-esm/StorageHelper/reactnative.js +0 -244
  207. package/src/OAuthHelper/FacebookOAuth.ts +0 -83
  208. package/src/OAuthHelper/GoogleOAuth.ts +0 -97
  209. package/src/OAuthHelper/index.ts +0 -7
  210. package/src/RNComponents/index.ts +0 -16
  211. package/src/RNComponents/isAppInForeground.ts +0 -8
  212. package/src/RNComponents/reactnative.ts +0 -6
  213. package/src/StorageHelper/cookieStorage.ts +0 -99
  214. package/src/StorageHelper/inMemoryStorage.ts +0 -32
  215. package/src/StorageHelper/index.ts +0 -78
  216. package/src/StorageHelper/localStorage.ts +0 -60
  217. package/src/StorageHelper/reactnative.ts +0 -182
  218. /package/lib-esm/{RNComponents → providers/pinpoint/utils}/isAppInForeground.d.ts +0 -0
  219. /package/{lib/RNComponents/isAppInForeground.d.ts → lib-esm/providers/pinpoint/utils/isAppInForeground.native.d.ts} +0 -0
@@ -38,16 +38,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  }
39
39
  };
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.SessionStorage = void 0;
42
- var Errors_1 = require("../Util/Errors");
43
- var SessionStorageClass = /** @class */ (function () {
44
- function SessionStorageClass() {
45
- if (typeof window !== undefined) {
46
- try {
47
- this.storage = window === null || window === void 0 ? void 0 : window.sessionStorage;
48
- }
49
- catch (error) { }
50
- }
41
+ exports.DefaultStorage = void 0;
42
+ var libraryUtils_1 = require("../libraryUtils");
43
+ var ASYNC_STORAGE_MODULE = '@react-native-async-storage/async-storage';
44
+ var MEMORY_KEY_PREFIX = '@MemoryStorage:';
45
+ /**
46
+ * @internal
47
+ */
48
+ var DefaultStorage = /** @class */ (function () {
49
+ function DefaultStorage() {
51
50
  }
52
51
  /**
53
52
  * This is used to set a specific item in storage
@@ -55,15 +54,9 @@ var SessionStorageClass = /** @class */ (function () {
55
54
  * @param {object} value - the value
56
55
  * @returns {string} value that was set
57
56
  */
58
- SessionStorageClass.prototype.setItem = function (key, value) {
59
- return __awaiter(this, void 0, void 0, function () {
60
- return __generator(this, function (_a) {
61
- if (!this.storage)
62
- throw Errors_1.PlatformNotSupportedError;
63
- this.storage.setItem(key, value);
64
- return [2 /*return*/];
65
- });
66
- });
57
+ DefaultStorage.prototype.setItem = function (key, value) {
58
+ this.assertModule(this.asyncStorage);
59
+ return this.asyncStorage.setItem("".concat(MEMORY_KEY_PREFIX).concat(key), value);
67
60
  };
68
61
  /**
69
62
  * This is used to get a specific key from storage
@@ -71,44 +64,54 @@ var SessionStorageClass = /** @class */ (function () {
71
64
  * This is used to clear the storage
72
65
  * @returns {string} the data item
73
66
  */
74
- SessionStorageClass.prototype.getItem = function (key) {
75
- return __awaiter(this, void 0, void 0, function () {
76
- return __generator(this, function (_a) {
77
- if (!this.storage)
78
- throw Errors_1.PlatformNotSupportedError;
79
- return [2 /*return*/, this.storage.getItem(key)];
80
- });
81
- });
67
+ DefaultStorage.prototype.getItem = function (key) {
68
+ this.assertModule(this.asyncStorage);
69
+ return this.asyncStorage.getItem("".concat(MEMORY_KEY_PREFIX).concat(key));
82
70
  };
83
71
  /**
84
72
  * This is used to remove an item from storage
85
73
  * @param {string} key - the key being set
86
74
  * @returns {string} value - value that was deleted
87
75
  */
88
- SessionStorageClass.prototype.removeItem = function (key) {
89
- return __awaiter(this, void 0, void 0, function () {
90
- return __generator(this, function (_a) {
91
- if (!this.storage)
92
- throw Errors_1.PlatformNotSupportedError;
93
- this.storage.removeItem(key);
94
- return [2 /*return*/];
95
- });
96
- });
76
+ DefaultStorage.prototype.removeItem = function (key) {
77
+ this.assertModule(this.asyncStorage);
78
+ return this.asyncStorage.removeItem("".concat(MEMORY_KEY_PREFIX).concat(key));
97
79
  };
98
80
  /**
99
81
  * This is used to clear the storage
100
82
  * @returns {string} nothing
101
83
  */
102
- SessionStorageClass.prototype.clear = function () {
84
+ DefaultStorage.prototype.clear = function () {
103
85
  return __awaiter(this, void 0, void 0, function () {
86
+ var allKeys;
104
87
  return __generator(this, function (_a) {
105
- if (!this.storage)
106
- throw Errors_1.PlatformNotSupportedError;
107
- this.storage.clear();
108
- return [2 /*return*/];
88
+ switch (_a.label) {
89
+ case 0:
90
+ this.assertModule(this.asyncStorage);
91
+ return [4 /*yield*/, this.asyncStorage.getAllKeys()];
92
+ case 1:
93
+ allKeys = _a.sent();
94
+ return [2 /*return*/, this.asyncStorage.multiRemove(allKeys.filter(function (key) { return key.startsWith(MEMORY_KEY_PREFIX); }))];
95
+ }
109
96
  });
110
97
  });
111
98
  };
112
- return SessionStorageClass;
99
+ DefaultStorage.prototype.assertModule = function (asyncStorage) {
100
+ if (!!asyncStorage) {
101
+ return;
102
+ }
103
+ try {
104
+ this.asyncStorage = require(ASYNC_STORAGE_MODULE)
105
+ .default;
106
+ }
107
+ catch (err) {
108
+ throw new libraryUtils_1.AmplifyError({
109
+ name: 'NativeModuleException',
110
+ message: "Unable to find ".concat(ASYNC_STORAGE_MODULE),
111
+ recoverySuggestion: "Make sure to install ".concat(ASYNC_STORAGE_MODULE),
112
+ });
113
+ }
114
+ };
115
+ return DefaultStorage;
113
116
  }());
114
- exports.SessionStorage = new SessionStorageClass();
117
+ exports.DefaultStorage = DefaultStorage;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @internal
3
+ */
4
+ export declare class InMemoryStorage implements Storage {
5
+ storage: Map<string, string>;
6
+ get length(): number;
7
+ key(index: number): string | null;
8
+ setItem(key: string, value: string): void;
9
+ getItem(key: string): string | null;
10
+ removeItem(key: string): void;
11
+ clear(): void;
12
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.InMemoryStorage = void 0;
6
+ /**
7
+ * @internal
8
+ */
9
+ var InMemoryStorage = /** @class */ (function () {
10
+ function InMemoryStorage() {
11
+ this.storage = new Map();
12
+ }
13
+ Object.defineProperty(InMemoryStorage.prototype, "length", {
14
+ get: function () {
15
+ return this.storage.size;
16
+ },
17
+ enumerable: false,
18
+ configurable: true
19
+ });
20
+ InMemoryStorage.prototype.key = function (index) {
21
+ if (index > this.length - 1) {
22
+ return null;
23
+ }
24
+ return Array.from(this.storage.keys())[index];
25
+ };
26
+ InMemoryStorage.prototype.setItem = function (key, value) {
27
+ this.storage.set(key, value);
28
+ };
29
+ InMemoryStorage.prototype.getItem = function (key) {
30
+ var _a;
31
+ return (_a = this.storage.get(key)) !== null && _a !== void 0 ? _a : null;
32
+ };
33
+ InMemoryStorage.prototype.removeItem = function (key) {
34
+ this.storage.delete(key);
35
+ };
36
+ InMemoryStorage.prototype.clear = function () {
37
+ this.storage.clear();
38
+ };
39
+ return InMemoryStorage;
40
+ }());
41
+ exports.InMemoryStorage = InMemoryStorage;
@@ -1,7 +1,10 @@
1
1
  import { KeyValueStorageInterface } from '../types';
2
- declare class SessionStorageClass implements KeyValueStorageInterface {
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class KeyValueStorage implements KeyValueStorageInterface {
3
6
  storage?: Storage;
4
- constructor();
7
+ constructor(storage?: Storage);
5
8
  /**
6
9
  * This is used to set a specific item in storage
7
10
  * @param {string} key - the key for the item
@@ -28,5 +31,3 @@ declare class SessionStorageClass implements KeyValueStorageInterface {
28
31
  */
29
32
  clear(): Promise<void>;
30
33
  }
31
- export declare const SessionStorage: SessionStorageClass;
32
- export {};
@@ -38,16 +38,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  }
39
39
  };
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.LocalStorage = void 0;
41
+ exports.KeyValueStorage = void 0;
42
42
  var Errors_1 = require("../Util/Errors");
43
- var LocalStorageClass = /** @class */ (function () {
44
- function LocalStorageClass() {
45
- if (typeof window !== undefined) {
46
- try {
47
- this.storage = window === null || window === void 0 ? void 0 : window.localStorage;
48
- }
49
- catch (error) { }
50
- }
43
+ /**
44
+ * @internal
45
+ */
46
+ var KeyValueStorage = /** @class */ (function () {
47
+ function KeyValueStorage(storage) {
48
+ this.storage = storage;
51
49
  }
52
50
  /**
53
51
  * This is used to set a specific item in storage
@@ -55,7 +53,7 @@ var LocalStorageClass = /** @class */ (function () {
55
53
  * @param {object} value - the value
56
54
  * @returns {string} value that was set
57
55
  */
58
- LocalStorageClass.prototype.setItem = function (key, value) {
56
+ KeyValueStorage.prototype.setItem = function (key, value) {
59
57
  return __awaiter(this, void 0, void 0, function () {
60
58
  return __generator(this, function (_a) {
61
59
  if (!this.storage)
@@ -71,7 +69,7 @@ var LocalStorageClass = /** @class */ (function () {
71
69
  * This is used to clear the storage
72
70
  * @returns {string} the data item
73
71
  */
74
- LocalStorageClass.prototype.getItem = function (key) {
72
+ KeyValueStorage.prototype.getItem = function (key) {
75
73
  return __awaiter(this, void 0, void 0, function () {
76
74
  return __generator(this, function (_a) {
77
75
  if (!this.storage)
@@ -85,7 +83,7 @@ var LocalStorageClass = /** @class */ (function () {
85
83
  * @param {string} key - the key being set
86
84
  * @returns {string} value - value that was deleted
87
85
  */
88
- LocalStorageClass.prototype.removeItem = function (key) {
86
+ KeyValueStorage.prototype.removeItem = function (key) {
89
87
  return __awaiter(this, void 0, void 0, function () {
90
88
  return __generator(this, function (_a) {
91
89
  if (!this.storage)
@@ -99,7 +97,7 @@ var LocalStorageClass = /** @class */ (function () {
99
97
  * This is used to clear the storage
100
98
  * @returns {string} nothing
101
99
  */
102
- LocalStorageClass.prototype.clear = function () {
100
+ KeyValueStorage.prototype.clear = function () {
103
101
  return __awaiter(this, void 0, void 0, function () {
104
102
  return __generator(this, function (_a) {
105
103
  if (!this.storage)
@@ -109,6 +107,6 @@ var LocalStorageClass = /** @class */ (function () {
109
107
  });
110
108
  });
111
109
  };
112
- return LocalStorageClass;
110
+ return KeyValueStorage;
113
111
  }());
114
- exports.LocalStorage = new LocalStorageClass();
112
+ exports.KeyValueStorage = KeyValueStorage;
@@ -0,0 +1,7 @@
1
+ import { KeyValueStorage } from './KeyValueStorage';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class SessionStorage extends KeyValueStorage {
6
+ constructor();
7
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var __extends = (this && this.__extends) || (function () {
5
+ var extendStatics = function (d, b) {
6
+ extendStatics = Object.setPrototypeOf ||
7
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
8
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
9
+ return extendStatics(d, b);
10
+ };
11
+ return function (d, b) {
12
+ if (typeof b !== "function" && b !== null)
13
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
14
+ extendStatics(d, b);
15
+ function __() { this.constructor = d; }
16
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17
+ };
18
+ })();
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.SessionStorage = void 0;
21
+ var KeyValueStorage_1 = require("./KeyValueStorage");
22
+ var utils_1 = require("./utils");
23
+ /**
24
+ * @internal
25
+ */
26
+ var SessionStorage = /** @class */ (function (_super) {
27
+ __extends(SessionStorage, _super);
28
+ function SessionStorage() {
29
+ return _super.call(this, (0, utils_1.getSessionStorageWithFallback)()) || this;
30
+ }
31
+ return SessionStorage;
32
+ }(KeyValueStorage_1.KeyValueStorage));
33
+ exports.SessionStorage = SessionStorage;
@@ -0,0 +1,7 @@
1
+ import { DefaultStorage } from './DefaultStorage';
2
+ import { KeyValueStorage } from './KeyValueStorage';
3
+ import { SessionStorage } from './SessionStorage';
4
+ export { CookieStorage } from './CookieStorage';
5
+ export declare const defaultStorage: DefaultStorage;
6
+ export declare const sessionStorage: SessionStorage;
7
+ export declare const sharedInMemoryStorage: KeyValueStorage;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.sharedInMemoryStorage = exports.sessionStorage = exports.defaultStorage = exports.CookieStorage = void 0;
6
+ var DefaultStorage_1 = require("./DefaultStorage");
7
+ var InMemoryStorage_1 = require("./InMemoryStorage");
8
+ var KeyValueStorage_1 = require("./KeyValueStorage");
9
+ var SessionStorage_1 = require("./SessionStorage");
10
+ var CookieStorage_1 = require("./CookieStorage");
11
+ Object.defineProperty(exports, "CookieStorage", { enumerable: true, get: function () { return CookieStorage_1.CookieStorage; } });
12
+ exports.defaultStorage = new DefaultStorage_1.DefaultStorage();
13
+ exports.sessionStorage = new SessionStorage_1.SessionStorage();
14
+ exports.sharedInMemoryStorage = new KeyValueStorage_1.KeyValueStorage(new InMemoryStorage_1.InMemoryStorage());
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @internal
3
+ * @returns Either a reference to window.localStorage or an in-memory storage as fallback
4
+ */
5
+ export declare const getDefaultStorageWithFallback: () => Storage;
6
+ /**
7
+ * @internal
8
+ * @returns Either a reference to window.sessionStorage or an in-memory storage as fallback
9
+ */
10
+ export declare const getSessionStorageWithFallback: () => Storage;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.getSessionStorageWithFallback = exports.getDefaultStorageWithFallback = void 0;
6
+ var InMemoryStorage_1 = require("./InMemoryStorage");
7
+ /**
8
+ * @internal
9
+ * @returns Either a reference to window.localStorage or an in-memory storage as fallback
10
+ */
11
+ var getDefaultStorageWithFallback = function () {
12
+ return typeof window !== 'undefined' && window.localStorage
13
+ ? window.localStorage
14
+ : new InMemoryStorage_1.InMemoryStorage();
15
+ };
16
+ exports.getDefaultStorageWithFallback = getDefaultStorageWithFallback;
17
+ /**
18
+ * @internal
19
+ * @returns Either a reference to window.sessionStorage or an in-memory storage as fallback
20
+ */
21
+ var getSessionStorageWithFallback = function () {
22
+ return typeof window !== 'undefined' && window.sessionStorage
23
+ ? window.sessionStorage
24
+ : new InMemoryStorage_1.InMemoryStorage();
25
+ };
26
+ exports.getSessionStorageWithFallback = getSessionStorageWithFallback;