@aws-amplify/core 6.0.1-console-preview.d7e0545.0 → 6.0.1-console-preview.7739091.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 (153) hide show
  1. package/lib/Cache/Utils/CacheUtils.js +2 -4
  2. package/lib/Platform/version.d.ts +1 -1
  3. package/lib/Platform/version.js +1 -1
  4. package/lib/RNComponents/index.d.ts +1 -1
  5. package/lib/RNComponents/index.js +4 -4
  6. package/lib/ServiceWorker/ServiceWorker.js +1 -1
  7. package/lib/Util/JS.d.ts +1 -4
  8. package/lib/Util/JS.js +4 -11
  9. package/lib/Util/Reachability.js +0 -3
  10. package/lib/clients/handlers/fetch.d.ts +0 -1
  11. package/lib/clients/handlers/fetch.js +0 -1
  12. package/lib/index.d.ts +1 -1
  13. package/lib/index.js +6 -8
  14. package/lib/libraryUtils.d.ts +1 -2
  15. package/lib/libraryUtils.js +3 -6
  16. package/lib/parseAWSExports.js +20 -1
  17. package/lib/providers/pinpoint/apis/record.d.ts +2 -2
  18. package/lib/providers/pinpoint/apis/record.js +3 -3
  19. package/lib/providers/pinpoint/apis/updateEndpoint.d.ts +2 -2
  20. package/lib/providers/pinpoint/types/pinpoint.d.ts +2 -2
  21. package/lib/singleton/API/types.d.ts +34 -0
  22. package/lib/singleton/API/types.js +2 -0
  23. package/lib/singleton/Auth/index.js +6 -16
  24. package/lib/singleton/Auth/types.d.ts +2 -2
  25. package/lib/singleton/Storage/types.d.ts +5 -0
  26. package/lib/singleton/types.d.ts +4 -1
  27. package/lib/{StorageHelper/cookieStorage.d.ts → storage/CookieStorage.d.ts} +4 -3
  28. package/lib/{StorageHelper/cookieStorage.js → storage/CookieStorage.js} +35 -83
  29. package/lib/storage/CookieStorage.native.d.ts +7 -0
  30. package/lib/storage/CookieStorage.native.js +32 -0
  31. package/lib/storage/DefaultStorage.d.ts +7 -0
  32. package/lib/storage/DefaultStorage.js +33 -0
  33. package/{lib-esm/StorageHelper/localStorage.d.ts → lib/storage/DefaultStorage.native.d.ts} +7 -6
  34. package/lib/{StorageHelper/sessionStorage.js → storage/DefaultStorage.native.js} +46 -43
  35. package/lib/storage/InMemoryStorage.d.ts +12 -0
  36. package/lib/storage/InMemoryStorage.js +41 -0
  37. package/lib/{StorageHelper/sessionStorage.d.ts → storage/KeyValueStorage.d.ts} +5 -4
  38. package/lib/{StorageHelper/localStorage.js → storage/KeyValueStorage.js} +13 -15
  39. package/lib/storage/SessionStorage.d.ts +7 -0
  40. package/lib/storage/SessionStorage.js +33 -0
  41. package/lib/storage/index.d.ts +7 -0
  42. package/lib/storage/index.js +14 -0
  43. package/lib/storage/utils.d.ts +10 -0
  44. package/lib/storage/utils.js +26 -0
  45. package/lib/tsconfig.tsbuildinfo +1 -1
  46. package/lib/types/storage.d.ts +3 -0
  47. package/lib-esm/Cache/Utils/CacheUtils.js +2 -4
  48. package/lib-esm/Platform/version.d.ts +1 -1
  49. package/lib-esm/Platform/version.js +1 -1
  50. package/lib-esm/RNComponents/index.d.ts +1 -1
  51. package/lib-esm/RNComponents/index.js +5 -5
  52. package/lib-esm/ServiceWorker/ServiceWorker.js +2 -2
  53. package/lib-esm/Util/JS.d.ts +1 -4
  54. package/lib-esm/Util/JS.js +2 -9
  55. package/lib-esm/Util/Reachability.js +1 -4
  56. package/lib-esm/clients/handlers/fetch.d.ts +0 -1
  57. package/lib-esm/clients/handlers/fetch.js +0 -1
  58. package/lib-esm/index.d.ts +1 -1
  59. package/lib-esm/index.js +1 -1
  60. package/lib-esm/libraryUtils.d.ts +1 -2
  61. package/lib-esm/libraryUtils.js +1 -2
  62. package/lib-esm/parseAWSExports.js +20 -1
  63. package/lib-esm/providers/pinpoint/apis/record.d.ts +2 -2
  64. package/lib-esm/providers/pinpoint/apis/record.js +3 -3
  65. package/lib-esm/providers/pinpoint/apis/updateEndpoint.d.ts +2 -2
  66. package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +2 -2
  67. package/lib-esm/singleton/API/types.d.ts +34 -0
  68. package/lib-esm/singleton/API/types.js +1 -0
  69. package/lib-esm/singleton/Auth/index.js +6 -16
  70. package/lib-esm/singleton/Auth/types.d.ts +2 -2
  71. package/lib-esm/singleton/Storage/types.d.ts +5 -0
  72. package/lib-esm/singleton/types.d.ts +4 -1
  73. package/lib-esm/{StorageHelper/cookieStorage.d.ts → storage/CookieStorage.d.ts} +4 -3
  74. package/lib-esm/{StorageHelper/cookieStorage.js → storage/CookieStorage.js} +36 -61
  75. package/lib-esm/storage/CookieStorage.native.d.ts +7 -0
  76. package/lib-esm/storage/CookieStorage.native.js +29 -0
  77. package/lib-esm/storage/DefaultStorage.d.ts +7 -0
  78. package/lib-esm/storage/DefaultStorage.js +30 -0
  79. package/{lib/StorageHelper/localStorage.d.ts → lib-esm/storage/DefaultStorage.native.d.ts} +7 -6
  80. package/lib-esm/{StorageHelper/sessionStorage.js → storage/DefaultStorage.native.js} +45 -42
  81. package/lib-esm/storage/InMemoryStorage.d.ts +12 -0
  82. package/lib-esm/storage/InMemoryStorage.js +38 -0
  83. package/lib-esm/{StorageHelper/sessionStorage.d.ts → storage/KeyValueStorage.d.ts} +5 -4
  84. package/lib-esm/{StorageHelper/localStorage.js → storage/KeyValueStorage.js} +12 -14
  85. package/lib-esm/storage/SessionStorage.d.ts +7 -0
  86. package/lib-esm/storage/SessionStorage.js +30 -0
  87. package/lib-esm/storage/index.d.ts +7 -0
  88. package/lib-esm/storage/index.js +10 -0
  89. package/lib-esm/storage/utils.d.ts +10 -0
  90. package/lib-esm/storage/utils.js +21 -0
  91. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  92. package/lib-esm/types/storage.d.ts +3 -0
  93. package/package.json +3 -5
  94. package/src/Cache/Utils/CacheUtils.ts +2 -4
  95. package/src/Platform/version.ts +1 -1
  96. package/src/RNComponents/index.ts +5 -5
  97. package/src/ServiceWorker/ServiceWorker.ts +2 -2
  98. package/src/Util/JS.ts +2 -13
  99. package/src/Util/Reachability.ts +1 -5
  100. package/src/clients/handlers/fetch.ts +0 -1
  101. package/src/index.ts +4 -6
  102. package/src/libraryUtils.ts +1 -2
  103. package/src/parseAWSExports.ts +26 -0
  104. package/src/providers/pinpoint/apis/record.ts +8 -8
  105. package/src/providers/pinpoint/apis/updateEndpoint.ts +2 -2
  106. package/src/providers/pinpoint/types/pinpoint.ts +7 -6
  107. package/src/singleton/API/types.ts +31 -0
  108. package/src/singleton/Auth/index.ts +1 -10
  109. package/src/singleton/Auth/types.ts +2 -2
  110. package/src/singleton/Storage/types.ts +6 -2
  111. package/src/singleton/types.ts +4 -1
  112. package/src/storage/CookieStorage.native.ts +13 -0
  113. package/src/storage/CookieStorage.ts +72 -0
  114. package/src/storage/DefaultStorage.native.ts +78 -0
  115. package/src/storage/DefaultStorage.ts +14 -0
  116. package/src/storage/InMemoryStorage.ts +36 -0
  117. package/src/{StorageHelper/sessionStorage.ts → storage/KeyValueStorage.ts} +10 -13
  118. package/src/storage/SessionStorage.ts +14 -0
  119. package/src/storage/index.ts +13 -0
  120. package/src/storage/utils.ts +22 -0
  121. package/src/types/storage.ts +4 -0
  122. package/lib/OAuthHelper/FacebookOAuth.d.ts +0 -6
  123. package/lib/OAuthHelper/FacebookOAuth.js +0 -124
  124. package/lib/OAuthHelper/GoogleOAuth.d.ts +0 -6
  125. package/lib/OAuthHelper/GoogleOAuth.js +0 -134
  126. package/lib/OAuthHelper/index.d.ts +0 -4
  127. package/lib/OAuthHelper/index.js +0 -9
  128. package/lib/StorageHelper/inMemoryStorage.d.ts +0 -10
  129. package/lib/StorageHelper/inMemoryStorage.js +0 -82
  130. package/lib/StorageHelper/index.d.ts +0 -45
  131. package/lib/StorageHelper/index.js +0 -83
  132. package/lib/StorageHelper/reactnative.d.ts +0 -83
  133. package/lib/StorageHelper/reactnative.js +0 -250
  134. package/lib-esm/OAuthHelper/FacebookOAuth.d.ts +0 -6
  135. package/lib-esm/OAuthHelper/FacebookOAuth.js +0 -121
  136. package/lib-esm/OAuthHelper/GoogleOAuth.d.ts +0 -6
  137. package/lib-esm/OAuthHelper/GoogleOAuth.js +0 -131
  138. package/lib-esm/OAuthHelper/index.d.ts +0 -4
  139. package/lib-esm/OAuthHelper/index.js +0 -6
  140. package/lib-esm/StorageHelper/inMemoryStorage.d.ts +0 -10
  141. package/lib-esm/StorageHelper/inMemoryStorage.js +0 -79
  142. package/lib-esm/StorageHelper/index.d.ts +0 -45
  143. package/lib-esm/StorageHelper/index.js +0 -76
  144. package/lib-esm/StorageHelper/reactnative.d.ts +0 -83
  145. package/lib-esm/StorageHelper/reactnative.js +0 -244
  146. package/src/OAuthHelper/FacebookOAuth.ts +0 -83
  147. package/src/OAuthHelper/GoogleOAuth.ts +0 -97
  148. package/src/OAuthHelper/index.ts +0 -7
  149. package/src/StorageHelper/cookieStorage.ts +0 -99
  150. package/src/StorageHelper/inMemoryStorage.ts +0 -32
  151. package/src/StorageHelper/index.ts +0 -78
  152. package/src/StorageHelper/localStorage.ts +0 -60
  153. package/src/StorageHelper/reactnative.ts +0 -182
@@ -1,26 +1,16 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ var __assign = (this && this.__assign) || function () {
5
+ __assign = Object.assign || function(t) {
6
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
7
+ s = arguments[i];
8
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
9
+ t[p] = s[p];
10
+ }
11
+ return t;
12
+ };
13
+ return __assign.apply(this, arguments);
24
14
  };
25
15
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
16
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -60,101 +50,60 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
60
50
  };
61
51
  Object.defineProperty(exports, "__esModule", { value: true });
62
52
  exports.CookieStorage = void 0;
63
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
64
- // SPDX-License-Identifier: Apache-2.0
65
- // @ts-ignore
66
- var Cookies = __importStar(require("js-cookie"));
53
+ var js_cookie_1 = require("js-cookie");
67
54
  var CookieStorage = /** @class */ (function () {
68
55
  function CookieStorage(data) {
69
56
  if (data === void 0) { data = {}; }
70
- if (data.domain) {
71
- this.domain = data.domain;
72
- }
73
- if (data.path) {
74
- this.path = data.path;
75
- }
76
- else {
77
- this.path = '/';
78
- }
79
- if (Object.prototype.hasOwnProperty.call(data, 'expires')) {
80
- this.expires = data.expires;
81
- }
82
- else {
83
- this.expires = 365;
84
- }
85
- if (Object.prototype.hasOwnProperty.call(data, 'secure')) {
86
- this.secure = data.secure;
87
- }
88
- else {
89
- this.secure = true;
90
- }
57
+ var path = data.path, domain = data.domain, expires = data.expires, sameSite = data.sameSite, secure = data.secure;
58
+ this.domain = domain;
59
+ this.path = path ? path : '/';
60
+ this.expires = data.hasOwnProperty('expires') ? expires : 365;
61
+ this.secure = data.hasOwnProperty('secure') ? secure : true;
91
62
  if (data.hasOwnProperty('sameSite')) {
92
- if (!data.sameSite ||
93
- !['strict', 'lax', 'none'].includes(data.sameSite)) {
63
+ if (!sameSite || !['strict', 'lax', 'none'].includes(sameSite)) {
94
64
  throw new Error('The sameSite value of cookieStorage must be "lax", "strict" or "none".');
95
65
  }
96
- if (data.sameSite === 'none' && !this.secure) {
66
+ if (sameSite === 'none' && !this.secure) {
97
67
  throw new Error('sameSite = None requires the Secure attribute in latest browser versions.');
98
68
  }
99
- this.sameSite = data.sameSite;
69
+ this.sameSite = sameSite;
100
70
  }
101
71
  }
102
72
  CookieStorage.prototype.setItem = function (key, value) {
103
73
  return __awaiter(this, void 0, void 0, function () {
104
- var options;
105
74
  return __generator(this, function (_a) {
106
- options = {
107
- path: this.path,
108
- expires: this.expires,
109
- domain: this.domain,
110
- secure: this.secure,
111
- };
112
- if (this.sameSite) {
113
- options.sameSite = this.sameSite;
114
- }
115
- Cookies.set(key, value, options);
116
- return [2 /*return*/, Cookies.get(key)];
75
+ (0, js_cookie_1.set)(key, value, this.getData());
76
+ return [2 /*return*/];
117
77
  });
118
78
  });
119
79
  };
120
80
  CookieStorage.prototype.getItem = function (key) {
121
81
  return __awaiter(this, void 0, void 0, function () {
82
+ var item;
122
83
  return __generator(this, function (_a) {
123
- return [2 /*return*/, Cookies.get(key)];
84
+ item = (0, js_cookie_1.get)(key);
85
+ return [2 /*return*/, item !== null && item !== void 0 ? item : null];
124
86
  });
125
87
  });
126
88
  };
127
89
  CookieStorage.prototype.removeItem = function (key) {
128
90
  return __awaiter(this, void 0, void 0, function () {
129
- var options;
130
91
  return __generator(this, function (_a) {
131
- options = {
132
- path: this.path,
133
- expires: this.expires,
134
- domain: this.domain,
135
- secure: this.secure,
136
- };
137
- if (this.sameSite) {
138
- options.sameSite = this.sameSite;
139
- }
140
- Cookies.remove(key, options);
92
+ (0, js_cookie_1.remove)(key, this.getData());
141
93
  return [2 /*return*/];
142
94
  });
143
95
  });
144
96
  };
145
97
  CookieStorage.prototype.clear = function () {
146
98
  return __awaiter(this, void 0, void 0, function () {
147
- var cookies, numKeys, promiseArray, index;
99
+ var cookie, promises;
100
+ var _this = this;
148
101
  return __generator(this, function (_a) {
149
102
  switch (_a.label) {
150
103
  case 0:
151
- cookies = Cookies.get();
152
- numKeys = Object.keys(cookies).length;
153
- promiseArray = [];
154
- for (index = 0; index < numKeys; ++index) {
155
- promiseArray.push(this.removeItem(Object.keys(cookies)[index]));
156
- }
157
- return [4 /*yield*/, Promise.all(promiseArray)];
104
+ cookie = (0, js_cookie_1.get)();
105
+ promises = Object.keys(cookie).map(function (key) { return _this.removeItem(key); });
106
+ return [4 /*yield*/, Promise.all(promises)];
158
107
  case 1:
159
108
  _a.sent();
160
109
  return [2 /*return*/];
@@ -162,6 +111,9 @@ var CookieStorage = /** @class */ (function () {
162
111
  });
163
112
  });
164
113
  };
114
+ CookieStorage.prototype.getData = function () {
115
+ return __assign({ path: this.path, expires: this.expires, domain: this.domain, secure: this.secure }, (this.sameSite && { sameSite: this.sameSite }));
116
+ };
165
117
  return CookieStorage;
166
118
  }());
167
119
  exports.CookieStorage = CookieStorage;
@@ -0,0 +1,7 @@
1
+ import { KeyValueStorage } from './KeyValueStorage';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class CookieStorage extends KeyValueStorage {
6
+ constructor();
7
+ }
@@ -0,0 +1,32 @@
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.CookieStorage = void 0;
21
+ var KeyValueStorage_1 = require("./KeyValueStorage");
22
+ /**
23
+ * @internal
24
+ */
25
+ var CookieStorage = /** @class */ (function (_super) {
26
+ __extends(CookieStorage, _super);
27
+ function CookieStorage() {
28
+ return _super.call(this) || this;
29
+ }
30
+ return CookieStorage;
31
+ }(KeyValueStorage_1.KeyValueStorage));
32
+ exports.CookieStorage = CookieStorage;
@@ -0,0 +1,7 @@
1
+ import { KeyValueStorage } from './KeyValueStorage';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class DefaultStorage 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.DefaultStorage = void 0;
21
+ var KeyValueStorage_1 = require("./KeyValueStorage");
22
+ var utils_1 = require("./utils");
23
+ /**
24
+ * @internal
25
+ */
26
+ var DefaultStorage = /** @class */ (function (_super) {
27
+ __extends(DefaultStorage, _super);
28
+ function DefaultStorage() {
29
+ return _super.call(this, (0, utils_1.getDefaultStorageWithFallback)()) || this;
30
+ }
31
+ return DefaultStorage;
32
+ }(KeyValueStorage_1.KeyValueStorage));
33
+ exports.DefaultStorage = DefaultStorage;
@@ -1,7 +1,9 @@
1
- import { KeyValueStorageInterface } from "../types";
2
- declare class LocalStorageClass implements KeyValueStorageInterface {
3
- storage?: Storage;
4
- constructor();
1
+ import { KeyValueStorageInterface } from '../types';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare class DefaultStorage implements KeyValueStorageInterface {
6
+ private asyncStorage?;
5
7
  /**
6
8
  * This is used to set a specific item in storage
7
9
  * @param {string} key - the key for the item
@@ -27,6 +29,5 @@ declare class LocalStorageClass implements KeyValueStorageInterface {
27
29
  * @returns {string} nothing
28
30
  */
29
31
  clear(): Promise<void>;
32
+ private assertModule;
30
33
  }
31
- export declare const LocalStorage: LocalStorageClass;
32
- export {};
@@ -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;