@aws-amplify/core 6.0.1-console-preview.7739091.0 → 6.0.1-preview-testing.ddb17c0.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 (150) 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 +4 -2
  10. package/lib/Platform/version.d.ts +1 -1
  11. package/lib/Platform/version.js +1 -1
  12. package/lib/RNComponents/index.d.ts +1 -1
  13. package/lib/RNComponents/index.js +2 -2
  14. package/{lib-esm/storage/CookieStorage.d.ts → lib/StorageHelper/cookieStorage.d.ts} +3 -4
  15. package/lib/{storage/CookieStorage.js → StorageHelper/cookieStorage.js} +83 -35
  16. package/lib/StorageHelper/inMemoryStorage.d.ts +10 -0
  17. package/lib/StorageHelper/inMemoryStorage.js +82 -0
  18. package/lib/StorageHelper/index.d.ts +45 -0
  19. package/lib/StorageHelper/index.js +83 -0
  20. package/lib/{storage/DefaultStorage.native.d.ts → StorageHelper/localStorage.d.ts} +6 -7
  21. package/lib/{storage/KeyValueStorage.js → StorageHelper/localStorage.js} +15 -13
  22. package/lib/StorageHelper/reactnative.d.ts +83 -0
  23. package/lib/StorageHelper/reactnative.js +250 -0
  24. package/lib/{storage/KeyValueStorage.d.ts → StorageHelper/sessionStorage.d.ts} +4 -5
  25. package/lib/{storage/DefaultStorage.native.js → StorageHelper/sessionStorage.js} +43 -46
  26. package/lib/clients/handlers/authenticated.d.ts +1 -1
  27. package/lib/clients/handlers/fetch.js +2 -1
  28. package/lib/clients/handlers/unauthenticated.d.ts +1 -1
  29. package/lib/clients/internal/composeServiceApi.d.ts +5 -3
  30. package/lib/clients/types/aws.d.ts +1 -5
  31. package/lib/clients/types/http.d.ts +8 -0
  32. package/lib/clients/types/index.d.ts +1 -1
  33. package/lib/index.d.ts +1 -1
  34. package/lib/index.js +8 -6
  35. package/lib/parseAWSExports.js +1 -20
  36. package/lib/providers/pinpoint/types/buffer.d.ts +1 -1
  37. package/lib/providers/pinpoint/types/pinpoint.d.ts +1 -1
  38. package/lib/singleton/Auth/index.d.ts +2 -1
  39. package/lib/singleton/Auth/index.js +22 -12
  40. package/lib/singleton/Auth/utils/index.js +3 -3
  41. package/lib/singleton/types.d.ts +1 -4
  42. package/lib/tsconfig.tsbuildinfo +1 -1
  43. package/lib/types/storage.d.ts +0 -3
  44. package/lib-esm/AwsClients/CognitoIdentity/base.d.ts +12 -4
  45. package/lib-esm/AwsClients/CognitoIdentity/base.js +1 -0
  46. package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +15 -3
  47. package/lib-esm/AwsClients/CognitoIdentity/getId.d.ts +15 -3
  48. package/lib-esm/AwsClients/Pinpoint/base.d.ts +10 -2
  49. package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +17 -3
  50. package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +17 -3
  51. package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +17 -3
  52. package/lib-esm/Cache/Utils/CacheUtils.js +4 -2
  53. package/lib-esm/Platform/version.d.ts +1 -1
  54. package/lib-esm/Platform/version.js +1 -1
  55. package/lib-esm/RNComponents/index.d.ts +1 -1
  56. package/lib-esm/RNComponents/index.js +2 -2
  57. package/{lib/storage/CookieStorage.d.ts → lib-esm/StorageHelper/cookieStorage.d.ts} +3 -4
  58. package/lib-esm/{storage/CookieStorage.js → StorageHelper/cookieStorage.js} +61 -36
  59. package/lib-esm/StorageHelper/inMemoryStorage.d.ts +10 -0
  60. package/lib-esm/StorageHelper/inMemoryStorage.js +79 -0
  61. package/lib-esm/StorageHelper/index.d.ts +45 -0
  62. package/lib-esm/StorageHelper/index.js +76 -0
  63. package/lib-esm/{storage/DefaultStorage.native.d.ts → StorageHelper/localStorage.d.ts} +6 -7
  64. package/lib-esm/{storage/KeyValueStorage.js → StorageHelper/localStorage.js} +14 -12
  65. package/lib-esm/StorageHelper/reactnative.d.ts +83 -0
  66. package/lib-esm/StorageHelper/reactnative.js +244 -0
  67. package/lib-esm/{storage/KeyValueStorage.d.ts → StorageHelper/sessionStorage.d.ts} +4 -5
  68. package/lib-esm/{storage/DefaultStorage.native.js → StorageHelper/sessionStorage.js} +42 -45
  69. package/lib-esm/clients/handlers/authenticated.d.ts +1 -1
  70. package/lib-esm/clients/handlers/fetch.js +2 -1
  71. package/lib-esm/clients/handlers/unauthenticated.d.ts +1 -1
  72. package/lib-esm/clients/internal/composeServiceApi.d.ts +5 -3
  73. package/lib-esm/clients/types/aws.d.ts +1 -5
  74. package/lib-esm/clients/types/http.d.ts +8 -0
  75. package/lib-esm/clients/types/index.d.ts +1 -1
  76. package/lib-esm/index.d.ts +1 -1
  77. package/lib-esm/index.js +1 -1
  78. package/lib-esm/parseAWSExports.js +1 -20
  79. package/lib-esm/providers/pinpoint/types/buffer.d.ts +1 -1
  80. package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +1 -1
  81. package/lib-esm/singleton/Auth/index.d.ts +2 -1
  82. package/lib-esm/singleton/Auth/index.js +22 -12
  83. package/lib-esm/singleton/Auth/utils/index.js +3 -3
  84. package/lib-esm/singleton/types.d.ts +1 -4
  85. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  86. package/lib-esm/types/storage.d.ts +0 -3
  87. package/package.json +3 -3
  88. package/src/AwsClients/CognitoIdentity/base.ts +2 -2
  89. package/src/AwsClients/Pinpoint/base.ts +2 -6
  90. package/src/Cache/Utils/CacheUtils.ts +4 -2
  91. package/src/Platform/version.ts +1 -1
  92. package/src/RNComponents/index.ts +2 -2
  93. package/src/StorageHelper/cookieStorage.ts +99 -0
  94. package/src/StorageHelper/inMemoryStorage.ts +32 -0
  95. package/src/StorageHelper/index.ts +78 -0
  96. package/src/StorageHelper/localStorage.ts +60 -0
  97. package/src/StorageHelper/reactnative.ts +182 -0
  98. package/src/{storage/KeyValueStorage.ts → StorageHelper/sessionStorage.ts} +13 -10
  99. package/src/clients/handlers/authenticated.ts +2 -1
  100. package/src/clients/handlers/fetch.ts +2 -1
  101. package/src/clients/handlers/unauthenticated.ts +2 -1
  102. package/src/clients/internal/composeServiceApi.ts +10 -3
  103. package/src/clients/types/aws.ts +4 -11
  104. package/src/clients/types/http.ts +8 -0
  105. package/src/clients/types/index.ts +0 -1
  106. package/src/index.ts +6 -4
  107. package/src/parseAWSExports.ts +0 -26
  108. package/src/providers/pinpoint/types/buffer.ts +1 -1
  109. package/src/providers/pinpoint/types/pinpoint.ts +1 -1
  110. package/src/singleton/Auth/index.ts +9 -2
  111. package/src/singleton/Auth/utils/index.ts +3 -3
  112. package/src/singleton/types.ts +1 -4
  113. package/src/types/storage.ts +0 -4
  114. package/lib/singleton/API/types.d.ts +0 -34
  115. package/lib/singleton/API/types.js +0 -2
  116. package/lib/storage/CookieStorage.native.d.ts +0 -7
  117. package/lib/storage/CookieStorage.native.js +0 -32
  118. package/lib/storage/DefaultStorage.d.ts +0 -7
  119. package/lib/storage/DefaultStorage.js +0 -33
  120. package/lib/storage/InMemoryStorage.d.ts +0 -12
  121. package/lib/storage/InMemoryStorage.js +0 -41
  122. package/lib/storage/SessionStorage.d.ts +0 -7
  123. package/lib/storage/SessionStorage.js +0 -33
  124. package/lib/storage/index.d.ts +0 -7
  125. package/lib/storage/index.js +0 -14
  126. package/lib/storage/utils.d.ts +0 -10
  127. package/lib/storage/utils.js +0 -26
  128. package/lib-esm/singleton/API/types.d.ts +0 -34
  129. package/lib-esm/singleton/API/types.js +0 -1
  130. package/lib-esm/storage/CookieStorage.native.d.ts +0 -7
  131. package/lib-esm/storage/CookieStorage.native.js +0 -29
  132. package/lib-esm/storage/DefaultStorage.d.ts +0 -7
  133. package/lib-esm/storage/DefaultStorage.js +0 -30
  134. package/lib-esm/storage/InMemoryStorage.d.ts +0 -12
  135. package/lib-esm/storage/InMemoryStorage.js +0 -38
  136. package/lib-esm/storage/SessionStorage.d.ts +0 -7
  137. package/lib-esm/storage/SessionStorage.js +0 -30
  138. package/lib-esm/storage/index.d.ts +0 -7
  139. package/lib-esm/storage/index.js +0 -10
  140. package/lib-esm/storage/utils.d.ts +0 -10
  141. package/lib-esm/storage/utils.js +0 -21
  142. package/src/singleton/API/types.ts +0 -31
  143. package/src/storage/CookieStorage.native.ts +0 -13
  144. package/src/storage/CookieStorage.ts +0 -72
  145. package/src/storage/DefaultStorage.native.ts +0 -78
  146. package/src/storage/DefaultStorage.ts +0 -14
  147. package/src/storage/InMemoryStorage.ts +0 -36
  148. package/src/storage/SessionStorage.ts +0 -14
  149. package/src/storage/index.ts +0 -13
  150. package/src/storage/utils.ts +0 -22
@@ -0,0 +1,244 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ 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;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
38
+ // SPDX-License-Identifier: Apache-2.0
39
+ import AsyncStorage from '@react-native-async-storage/async-storage';
40
+ var MEMORY_KEY_PREFIX = '@MemoryStorage:';
41
+ var dataMemory = {};
42
+ /** @class */
43
+ var MemoryStorage = /** @class */ (function () {
44
+ function MemoryStorage() {
45
+ }
46
+ /**
47
+ * This is used to set a specific item in storage
48
+ * @param {string} key - the key for the item
49
+ * @param {object} value - the value
50
+ * @returns {string} value that was set
51
+ */
52
+ MemoryStorage.setItem = function (key, value) {
53
+ if (value) {
54
+ AsyncStorage.setItem(MEMORY_KEY_PREFIX + key, value);
55
+ dataMemory[key] = value;
56
+ return dataMemory[key];
57
+ }
58
+ };
59
+ /**
60
+ * This is used to get a specific key from storage
61
+ * @param {string} key - the key for the item
62
+ * This is used to clear the storage
63
+ * @returns {string} the data item
64
+ */
65
+ MemoryStorage.getItem = function (key) {
66
+ return Object.prototype.hasOwnProperty.call(dataMemory, key)
67
+ ? dataMemory[key]
68
+ : undefined;
69
+ };
70
+ /**
71
+ * This is used to remove an item from storage
72
+ * @param {string} key - the key being set
73
+ * @returns {string} value - value that was deleted
74
+ */
75
+ MemoryStorage.removeItem = function (key) {
76
+ AsyncStorage.removeItem(MEMORY_KEY_PREFIX + key);
77
+ return delete dataMemory[key];
78
+ };
79
+ /**
80
+ * This is used to clear the storage
81
+ * @returns {string} nothing
82
+ */
83
+ MemoryStorage.clear = function () {
84
+ dataMemory = {};
85
+ return dataMemory;
86
+ };
87
+ /**
88
+ * Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
89
+ * @returns {void}
90
+ */
91
+ MemoryStorage.sync = function () {
92
+ if (!MemoryStorage.syncPromise) {
93
+ MemoryStorage.syncPromise = new Promise(function (res, rej) {
94
+ AsyncStorage.getAllKeys(function (errKeys, keys) {
95
+ var _a;
96
+ if (errKeys)
97
+ rej(errKeys);
98
+ var memoryKeys = (_a = keys === null || keys === void 0 ? void 0 : keys.filter(function (key) { return key.startsWith(MEMORY_KEY_PREFIX); })) !== null && _a !== void 0 ? _a : [];
99
+ AsyncStorage.multiGet(memoryKeys, function (err, stores) {
100
+ if (err)
101
+ rej(err);
102
+ stores &&
103
+ stores.map(function (result, index, store) {
104
+ var key = store[index][0];
105
+ var value = store[index][1];
106
+ var memoryKey = key.replace(MEMORY_KEY_PREFIX, '');
107
+ dataMemory[memoryKey] = value;
108
+ });
109
+ res();
110
+ });
111
+ });
112
+ });
113
+ }
114
+ return MemoryStorage.syncPromise;
115
+ };
116
+ MemoryStorage.syncPromise = null;
117
+ return MemoryStorage;
118
+ }());
119
+ var StorageHelper = /** @class */ (function () {
120
+ /**
121
+ * This is used to get a storage object
122
+ * @returns {object} the storage
123
+ */
124
+ function StorageHelper() {
125
+ this.storageWindow = MemoryStorage;
126
+ }
127
+ /**
128
+ * This is used to return the storage
129
+ * @returns {object} the storage
130
+ */
131
+ StorageHelper.prototype.getStorage = function () {
132
+ return this.storageWindow;
133
+ };
134
+ return StorageHelper;
135
+ }());
136
+ export { StorageHelper };
137
+ var AsyncStorageClass = /** @class */ (function () {
138
+ function AsyncStorageClass() {
139
+ this.syncPromise = null;
140
+ }
141
+ /**
142
+ * This is used to set a specific item in storage
143
+ * @param {string} key - the key for the item
144
+ * @param {object} value - the value
145
+ * @returns {string} value that was set
146
+ */
147
+ AsyncStorageClass.prototype.setItem = function (key, value) {
148
+ return __awaiter(this, void 0, void 0, function () {
149
+ return __generator(this, function (_a) {
150
+ switch (_a.label) {
151
+ case 0:
152
+ if (!value) return [3 /*break*/, 2];
153
+ return [4 /*yield*/, AsyncStorage.setItem(MEMORY_KEY_PREFIX + key, value)];
154
+ case 1:
155
+ _a.sent();
156
+ dataMemory[key] = value;
157
+ _a.label = 2;
158
+ case 2: return [2 /*return*/];
159
+ }
160
+ });
161
+ });
162
+ };
163
+ /**
164
+ * This is used to get a specific key from storage
165
+ * @param {string} key - the key for the item
166
+ * This is used to clear the storage
167
+ * @returns {string} the data item
168
+ */
169
+ AsyncStorageClass.prototype.getItem = function (key) {
170
+ return __awaiter(this, void 0, void 0, function () {
171
+ return __generator(this, function (_a) {
172
+ return [2 /*return*/, Object.prototype.hasOwnProperty.call(dataMemory, key)
173
+ ? dataMemory[key]
174
+ : null];
175
+ });
176
+ });
177
+ };
178
+ /**
179
+ * This is used to remove an item from storage
180
+ * @param {string} key - the key being set
181
+ * @returns {string} value - value that was deleted
182
+ */
183
+ AsyncStorageClass.prototype.removeItem = function (key) {
184
+ return __awaiter(this, void 0, void 0, function () {
185
+ return __generator(this, function (_a) {
186
+ switch (_a.label) {
187
+ case 0: return [4 /*yield*/, AsyncStorage.removeItem(MEMORY_KEY_PREFIX + key)];
188
+ case 1:
189
+ _a.sent();
190
+ delete dataMemory[key];
191
+ return [2 /*return*/];
192
+ }
193
+ });
194
+ });
195
+ };
196
+ /**
197
+ * This is used to clear the storage
198
+ * @returns {string} nothing
199
+ */
200
+ AsyncStorageClass.prototype.clear = function () {
201
+ return __awaiter(this, void 0, void 0, function () {
202
+ return __generator(this, function (_a) {
203
+ dataMemory = {};
204
+ return [2 /*return*/];
205
+ });
206
+ });
207
+ };
208
+ /**
209
+ * Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
210
+ * @returns {void}
211
+ */
212
+ AsyncStorageClass.prototype.sync = function () {
213
+ return __awaiter(this, void 0, void 0, function () {
214
+ return __generator(this, function (_a) {
215
+ if (!this.syncPromise) {
216
+ this.syncPromise = new Promise(function (res, rej) {
217
+ AsyncStorage.getAllKeys(function (errKeys, keys) {
218
+ var _a;
219
+ if (errKeys)
220
+ rej(errKeys);
221
+ var memoryKeys = (_a = keys === null || keys === void 0 ? void 0 : keys.filter(function (key) { return key.startsWith(MEMORY_KEY_PREFIX); })) !== null && _a !== void 0 ? _a : [];
222
+ AsyncStorage.multiGet(memoryKeys, function (err, stores) {
223
+ if (err)
224
+ rej(err);
225
+ stores &&
226
+ stores.map(function (result, index, store) {
227
+ var key = store[index][0];
228
+ var value = store[index][1];
229
+ var memoryKey = key.replace(MEMORY_KEY_PREFIX, '');
230
+ dataMemory[memoryKey] = value;
231
+ });
232
+ res();
233
+ });
234
+ });
235
+ });
236
+ }
237
+ return [2 /*return*/];
238
+ });
239
+ });
240
+ };
241
+ return AsyncStorageClass;
242
+ }());
243
+ // TODO: Add this to the react-native Amplify package.
244
+ export var AsyncStorageKeyValue = new AsyncStorageClass();
@@ -1,10 +1,7 @@
1
1
  import { KeyValueStorageInterface } from '../types';
2
- /**
3
- * @internal
4
- */
5
- export declare class KeyValueStorage implements KeyValueStorageInterface {
2
+ declare class SessionStorageClass implements KeyValueStorageInterface {
6
3
  storage?: Storage;
7
- constructor(storage?: Storage);
4
+ constructor();
8
5
  /**
9
6
  * This is used to set a specific item in storage
10
7
  * @param {string} key - the key for the item
@@ -31,3 +28,5 @@ export declare class KeyValueStorage implements KeyValueStorageInterface {
31
28
  */
32
29
  clear(): Promise<void>;
33
30
  }
31
+ export declare const SessionStorage: SessionStorageClass;
32
+ export {};
@@ -36,14 +36,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
37
37
  }
38
38
  };
39
- import { AmplifyError } from '../libraryUtils';
40
- var ASYNC_STORAGE_MODULE = '@react-native-async-storage/async-storage';
41
- var MEMORY_KEY_PREFIX = '@MemoryStorage:';
42
- /**
43
- * @internal
44
- */
45
- var DefaultStorage = /** @class */ (function () {
46
- function DefaultStorage() {
39
+ import { PlatformNotSupportedError } from '../Util/Errors';
40
+ var SessionStorageClass = /** @class */ (function () {
41
+ function SessionStorageClass() {
42
+ if (typeof window !== undefined) {
43
+ try {
44
+ this.storage = window === null || window === void 0 ? void 0 : window.sessionStorage;
45
+ }
46
+ catch (error) { }
47
+ }
47
48
  }
48
49
  /**
49
50
  * This is used to set a specific item in storage
@@ -51,9 +52,15 @@ var DefaultStorage = /** @class */ (function () {
51
52
  * @param {object} value - the value
52
53
  * @returns {string} value that was set
53
54
  */
54
- DefaultStorage.prototype.setItem = function (key, value) {
55
- this.assertModule(this.asyncStorage);
56
- return this.asyncStorage.setItem("".concat(MEMORY_KEY_PREFIX).concat(key), value);
55
+ SessionStorageClass.prototype.setItem = function (key, value) {
56
+ return __awaiter(this, void 0, void 0, function () {
57
+ return __generator(this, function (_a) {
58
+ if (!this.storage)
59
+ throw PlatformNotSupportedError;
60
+ this.storage.setItem(key, value);
61
+ return [2 /*return*/];
62
+ });
63
+ });
57
64
  };
58
65
  /**
59
66
  * This is used to get a specific key from storage
@@ -61,54 +68,44 @@ var DefaultStorage = /** @class */ (function () {
61
68
  * This is used to clear the storage
62
69
  * @returns {string} the data item
63
70
  */
64
- DefaultStorage.prototype.getItem = function (key) {
65
- this.assertModule(this.asyncStorage);
66
- return this.asyncStorage.getItem("".concat(MEMORY_KEY_PREFIX).concat(key));
71
+ SessionStorageClass.prototype.getItem = function (key) {
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ return __generator(this, function (_a) {
74
+ if (!this.storage)
75
+ throw PlatformNotSupportedError;
76
+ return [2 /*return*/, this.storage.getItem(key)];
77
+ });
78
+ });
67
79
  };
68
80
  /**
69
81
  * This is used to remove an item from storage
70
82
  * @param {string} key - the key being set
71
83
  * @returns {string} value - value that was deleted
72
84
  */
73
- DefaultStorage.prototype.removeItem = function (key) {
74
- this.assertModule(this.asyncStorage);
75
- return this.asyncStorage.removeItem("".concat(MEMORY_KEY_PREFIX).concat(key));
85
+ SessionStorageClass.prototype.removeItem = function (key) {
86
+ return __awaiter(this, void 0, void 0, function () {
87
+ return __generator(this, function (_a) {
88
+ if (!this.storage)
89
+ throw PlatformNotSupportedError;
90
+ this.storage.removeItem(key);
91
+ return [2 /*return*/];
92
+ });
93
+ });
76
94
  };
77
95
  /**
78
96
  * This is used to clear the storage
79
97
  * @returns {string} nothing
80
98
  */
81
- DefaultStorage.prototype.clear = function () {
99
+ SessionStorageClass.prototype.clear = function () {
82
100
  return __awaiter(this, void 0, void 0, function () {
83
- var allKeys;
84
101
  return __generator(this, function (_a) {
85
- switch (_a.label) {
86
- case 0:
87
- this.assertModule(this.asyncStorage);
88
- return [4 /*yield*/, this.asyncStorage.getAllKeys()];
89
- case 1:
90
- allKeys = _a.sent();
91
- return [2 /*return*/, this.asyncStorage.multiRemove(allKeys.filter(function (key) { return key.startsWith(MEMORY_KEY_PREFIX); }))];
92
- }
102
+ if (!this.storage)
103
+ throw PlatformNotSupportedError;
104
+ this.storage.clear();
105
+ return [2 /*return*/];
93
106
  });
94
107
  });
95
108
  };
96
- DefaultStorage.prototype.assertModule = function (asyncStorage) {
97
- if (!!asyncStorage) {
98
- return;
99
- }
100
- try {
101
- this.asyncStorage = require(ASYNC_STORAGE_MODULE)
102
- .default;
103
- }
104
- catch (err) {
105
- throw new AmplifyError({
106
- name: 'NativeModuleException',
107
- message: "Unable to find ".concat(ASYNC_STORAGE_MODULE),
108
- recoverySuggestion: "Make sure to install ".concat(ASYNC_STORAGE_MODULE),
109
- });
110
- }
111
- };
112
- return DefaultStorage;
109
+ return SessionStorageClass;
113
110
  }());
114
- export { DefaultStorage };
111
+ export var SessionStorage = new SessionStorageClass();
@@ -2,4 +2,4 @@ import { RetryOptions } from '../middleware/retry';
2
2
  import { SigningOptions } from '../middleware/signing';
3
3
  import { UserAgentOptions } from '../middleware/userAgent';
4
4
  import { HttpRequest, HttpResponse } from '../types';
5
- export declare const authenticatedHandler: (request: HttpRequest, options: UserAgentOptions & RetryOptions<HttpResponse> & SigningOptions) => Promise<HttpResponse>;
5
+ export declare const authenticatedHandler: (request: HttpRequest, options: UserAgentOptions & RetryOptions<HttpResponse> & SigningOptions & import("../types").HttpTransferOptions) => Promise<HttpResponse>;
@@ -54,7 +54,7 @@ var shouldSendBody = function (method) {
54
54
  // TODO[AllanZhengYP]: we need to provide isCanceledError utility
55
55
  export var fetchTransferHandler = function (_a, _b) {
56
56
  var url = _a.url, method = _a.method, headers = _a.headers, body = _a.body;
57
- var abortSignal = _b.abortSignal;
57
+ var abortSignal = _b.abortSignal, cache = _b.cache;
58
58
  return __awaiter(void 0, void 0, void 0, function () {
59
59
  var resp, e_1, responseHeaders, httpResponse, bodyWithMixin;
60
60
  var _c, _d;
@@ -67,6 +67,7 @@ export var fetchTransferHandler = function (_a, _b) {
67
67
  headers: headers,
68
68
  body: shouldSendBody(method) ? body : undefined,
69
69
  signal: abortSignal,
70
+ cache: cache,
70
71
  })];
71
72
  case 1:
72
73
  resp = _e.sent();
@@ -1,4 +1,4 @@
1
1
  import { RetryOptions } from '../middleware/retry';
2
2
  import { UserAgentOptions } from '../middleware/userAgent';
3
3
  import { HttpRequest, HttpResponse } from '../types';
4
- export declare const unauthenticatedHandler: (request: HttpRequest, options: UserAgentOptions & RetryOptions<HttpResponse>) => Promise<HttpResponse>;
4
+ export declare const unauthenticatedHandler: (request: HttpRequest, options: UserAgentOptions & RetryOptions<HttpResponse> & import("../types").HttpTransferOptions) => Promise<HttpResponse>;
@@ -1,9 +1,11 @@
1
1
  import { ServiceClientOptions } from '../types/aws';
2
2
  import { TransferHandler, Endpoint } from '../types/core';
3
3
  import { HttpRequest, HttpResponse } from '../types/http';
4
- export declare const composeServiceApi: <TransferHandlerOptions, Input, Output, DefaultConfig>(transferHandler: TransferHandler<HttpRequest, HttpResponse, TransferHandlerOptions>, serializer: (input: Input, endpoint: Endpoint) => Promise<HttpRequest> | HttpRequest, deserializer: (output: HttpResponse) => Promise<Output>, defaultConfig: Partial<DefaultConfig>) => (config: OptionalizeKey<TransferHandlerOptions & ServiceClientOptions & Partial<DefaultConfig> & InferEndpointResolverOptionType<DefaultConfig>, keyof DefaultConfig>, input: Input) => Promise<Output>;
5
- type OptionalizeKey<T, K extends keyof T> = Omit<T, K> & {
6
- [P in K & keyof T]?: T[P];
4
+ export declare const composeServiceApi: <TransferHandlerOptions, Input, Output, DefaultConfig>(transferHandler: TransferHandler<HttpRequest, HttpResponse, TransferHandlerOptions>, serializer: (input: Input, endpoint: Endpoint) => Promise<HttpRequest> | HttpRequest, deserializer: (output: HttpResponse) => Promise<Output>, defaultConfig: Partial<DefaultConfig>) => (config: OptionalizeKey<TransferHandlerOptions & ServiceClientOptions & Partial<DefaultConfig> & InferEndpointResolverOptionType<DefaultConfig>, DefaultConfig>, input: Input) => Promise<Output>;
5
+ type OptionalizeKey<InputType, InputDefaultsType> = {
6
+ [KeyWithDefaultValue in keyof InputDefaultsType]?: KeyWithDefaultValue extends keyof InputType ? InputType[KeyWithDefaultValue] : never;
7
+ } & {
8
+ [KeyWithoutDefaultValue in keyof Omit<InputType, keyof InputDefaultsType>]: InputType[KeyWithoutDefaultValue];
7
9
  };
8
10
  type InferEndpointResolverOptionType<T> = T extends {
9
11
  endpointResolver: (options: infer EndpointOptions) => any;
@@ -1,7 +1,7 @@
1
1
  import { MetadataBearer } from '@aws-sdk/types';
2
2
  import { Endpoint } from './core';
3
3
  import { HttpResponse } from './http';
4
- export type { Credentials, MetadataBearer } from '@aws-sdk/types';
4
+ export type { AwsCredentialIdentity as Credentials, MetadataBearer, } from '@aws-sdk/types';
5
5
  export type SourceData = string | ArrayBuffer | ArrayBufferView;
6
6
  /**
7
7
  * Basic option type for endpoint resolvers. It contains region only.
@@ -18,7 +18,3 @@ export interface ServiceClientOptions {
18
18
  * This function is protocol-specific (e.g. JSON, XML, etc.)
19
19
  */
20
20
  export type ErrorParser = (response?: HttpResponse) => Promise<(Error & MetadataBearer) | undefined>;
21
- /**
22
- * Default config options for the `composeServiceApi`.
23
- */
24
- export type DefaultConfigOptions<TransferHandlerOptions extends Record<string, unknown> = Record<string, unknown>> = Partial<TransferHandlerOptions & ServiceClientOptions>;
@@ -26,5 +26,13 @@ export interface HttpResponse extends Response {
26
26
  }
27
27
  export interface HttpTransferOptions {
28
28
  abortSignal?: AbortSignal;
29
+ /**
30
+ * Cache mode for the request. Note that this is only effective when the underlying HTTP handler is fetch.
31
+ * For XHR handler, or Node.js `"http(s)"` module or running on React Native, this option is ignored.
32
+ * Instead, you can configure the `Cache-Control` headers to achieve similar effects.
33
+ * @default 'default'
34
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/cache}
35
+ */
36
+ cache?: RequestCache;
29
37
  }
30
38
  export type HttpTransferHandler = TransferHandler<HttpRequest, HttpResponse, HttpTransferOptions>;
@@ -1,3 +1,3 @@
1
1
  export { Middleware, MiddlewareHandler, Request, Response, TransferHandler, Endpoint, } from './core';
2
2
  export { Headers, HttpRequest, HttpResponse, HttpTransferHandler, HttpTransferOptions, ResponseBodyMixin, } from './http';
3
- export { Credentials, EndpointResolverOptions, ErrorParser, ServiceClientOptions, DefaultConfigOptions, } from './aws';
3
+ export { Credentials, EndpointResolverOptions, ErrorParser, ServiceClientOptions, } from './aws';
@@ -5,7 +5,7 @@ export { AuthConfig, AuthUserPoolConfig, AuthUserPoolAndIdentityPoolConfig, Stor
5
5
  export { Amplify, fetchAuthSession, AmplifyClass as AmplifyClassV6, clearCredentials, } from './singleton';
6
6
  export { getCredentialsForIdentity, getId, GetCredentialsForIdentityInput, GetCredentialsForIdentityOutput, } from './AwsClients/CognitoIdentity';
7
7
  export { UserProfile } from './types';
8
- export { CookieStorage, defaultStorage, sessionStorage, sharedInMemoryStorage, } from './storage';
8
+ export { StorageHelper, MemoryStorage, LocalStorage, CookieStorage, SessionStorage, MemoryKeyValueStorage, } from './StorageHelper';
9
9
  export { KeyValueStorageInterface } from './types';
10
10
  import { BrowserStorageCache } from './Cache/BrowserStorageCache';
11
11
  export { InMemoryCache } from './Cache/InMemoryCache';
package/lib-esm/index.js CHANGED
@@ -9,7 +9,7 @@ export { Amplify, fetchAuthSession, AmplifyClass as AmplifyClassV6, clearCredent
9
9
  // AWSClients exports
10
10
  export { getCredentialsForIdentity, getId, } from './AwsClients/CognitoIdentity';
11
11
  // Storage helpers
12
- export { CookieStorage, defaultStorage, sessionStorage, sharedInMemoryStorage, } from './storage';
12
+ export { StorageHelper, MemoryStorage, LocalStorage, CookieStorage, SessionStorage, MemoryKeyValueStorage, } from './StorageHelper';
13
13
  // Cache exports
14
14
  import { BrowserStorageCache } from './Cache/BrowserStorageCache';
15
15
  export { InMemoryCache } from './Cache/InMemoryCache';
@@ -9,11 +9,6 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- var authTypeMapping = {
13
- API_KEY: 'apiKey',
14
- AWS_IAM: 'iam',
15
- AMAZON_COGNITO_USER_POOLS: 'jwt',
16
- };
17
12
  /**
18
13
  * This utility converts the `aws-exports.js` file generated by the Amplify CLI into a {@link ResourcesConfig} object
19
14
  * consumable by Amplify.
@@ -24,7 +19,7 @@ var authTypeMapping = {
24
19
  */
25
20
  export var parseAWSExports = function (config) {
26
21
  if (config === void 0) { config = {}; }
27
- var aws_appsync_apiKey = config.aws_appsync_apiKey, aws_appsync_authenticationType = config.aws_appsync_authenticationType, aws_appsync_graphqlEndpoint = config.aws_appsync_graphqlEndpoint, aws_appsync_region = config.aws_appsync_region, aws_cognito_identity_pool_id = config.aws_cognito_identity_pool_id, aws_cognito_sign_up_verification_method = config.aws_cognito_sign_up_verification_method, aws_mandatory_sign_in = config.aws_mandatory_sign_in, aws_mobile_analytics_app_id = config.aws_mobile_analytics_app_id, aws_mobile_analytics_app_region = config.aws_mobile_analytics_app_region, aws_user_files_s3_bucket = config.aws_user_files_s3_bucket, aws_user_files_s3_bucket_region = config.aws_user_files_s3_bucket_region, aws_user_files_s3_dangerously_connect_to_http_endpoint_for_testing = config.aws_user_files_s3_dangerously_connect_to_http_endpoint_for_testing, aws_user_pools_id = config.aws_user_pools_id, aws_user_pools_web_client_id = config.aws_user_pools_web_client_id, geo = config.geo, oauth = config.oauth;
22
+ var aws_cognito_identity_pool_id = config.aws_cognito_identity_pool_id, aws_cognito_sign_up_verification_method = config.aws_cognito_sign_up_verification_method, aws_mandatory_sign_in = config.aws_mandatory_sign_in, aws_mobile_analytics_app_id = config.aws_mobile_analytics_app_id, aws_mobile_analytics_app_region = config.aws_mobile_analytics_app_region, aws_user_files_s3_bucket = config.aws_user_files_s3_bucket, aws_user_files_s3_bucket_region = config.aws_user_files_s3_bucket_region, aws_user_files_s3_dangerously_connect_to_http_endpoint_for_testing = config.aws_user_files_s3_dangerously_connect_to_http_endpoint_for_testing, aws_user_pools_id = config.aws_user_pools_id, aws_user_pools_web_client_id = config.aws_user_pools_web_client_id, geo = config.geo, oauth = config.oauth;
28
23
  var amplifyConfig = {};
29
24
  // Analytics
30
25
  if (aws_mobile_analytics_app_id) {
@@ -35,20 +30,6 @@ export var parseAWSExports = function (config) {
35
30
  },
36
31
  };
37
32
  }
38
- // TODO: Need to support all API configurations
39
- // API
40
- if (aws_appsync_graphqlEndpoint) {
41
- amplifyConfig.API = {
42
- AppSync: {
43
- defaultAuthMode: {
44
- type: authTypeMapping[aws_appsync_authenticationType],
45
- apiKey: aws_appsync_apiKey,
46
- },
47
- endpoint: aws_appsync_graphqlEndpoint,
48
- region: aws_appsync_region,
49
- },
50
- };
51
- }
52
33
  // Auth
53
34
  if (aws_cognito_identity_pool_id || aws_user_pools_id) {
54
35
  amplifyConfig.Auth = {
@@ -3,7 +3,7 @@ import { PinpointAnalyticsEvent, PinpointSession } from './pinpoint';
3
3
  export type EventBufferConfig = {
4
4
  appId: string;
5
5
  bufferSize: number;
6
- credentials: AuthSession['credentials'];
6
+ credentials: Required<AuthSession>['credentials'];
7
7
  identityId: AuthSession['identityId'];
8
8
  flushInterval: number;
9
9
  flushSize: number;
@@ -24,7 +24,7 @@ export type PinpointAnalyticsEvent = {
24
24
  type PinpointCommonParameters = {
25
25
  appId: string;
26
26
  category: SupportedCategory;
27
- credentials: AuthSession['credentials'];
27
+ credentials: Required<AuthSession>['credentials'];
28
28
  identityId?: AuthSession['identityId'];
29
29
  region: string;
30
30
  userAgentValue?: string;
@@ -1,4 +1,4 @@
1
- import { AuthConfig, AuthSession, FetchAuthSessionOptions, LibraryAuthOptions } from './types';
1
+ import { AuthConfig, AuthSession, AuthTokens, FetchAuthSessionOptions, LibraryAuthOptions } from './types';
2
2
  export declare function isTokenExpired({ expiresAt, clockDrift, }: {
3
3
  expiresAt: number;
4
4
  clockDrift: number;
@@ -20,4 +20,5 @@ export declare class AuthClass {
20
20
  configure(authResourcesConfig: AuthConfig, authOptions?: LibraryAuthOptions): void;
21
21
  fetchAuthSession(options?: FetchAuthSessionOptions): Promise<AuthSession>;
22
22
  clearCredentials(): Promise<void>;
23
+ getTokens(options: FetchAuthSessionOptions): Promise<AuthTokens | undefined>;
23
24
  }
@@ -57,20 +57,19 @@ var AuthClass = /** @class */ (function () {
57
57
  this.authOptions = authOptions;
58
58
  };
59
59
  AuthClass.prototype.fetchAuthSession = function (options) {
60
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
60
+ var _a, _b, _c, _d, _e, _f;
61
61
  if (options === void 0) { options = {}; }
62
62
  return __awaiter(this, void 0, void 0, function () {
63
63
  var tokens, credentialsAndIdentityId, userSub;
64
- return __generator(this, function (_k) {
65
- switch (_k.label) {
66
- case 0: return [4 /*yield*/, ((_b = (_a = this.authOptions) === null || _a === void 0 ? void 0 : _a.tokenProvider) === null || _b === void 0 ? void 0 : _b.getTokens(options))];
64
+ return __generator(this, function (_g) {
65
+ switch (_g.label) {
66
+ case 0: return [4 /*yield*/, this.getTokens(options)];
67
67
  case 1:
68
68
  // Get tokens will throw if session cannot be refreshed (network or service error) or return null if not available
69
- tokens =
70
- (_c = (_k.sent())) !== null && _c !== void 0 ? _c : undefined;
69
+ tokens = _g.sent();
71
70
  if (!tokens) return [3 /*break*/, 3];
72
- userSub = (_e = (_d = tokens.accessToken) === null || _d === void 0 ? void 0 : _d.payload) === null || _e === void 0 ? void 0 : _e.sub;
73
- return [4 /*yield*/, ((_g = (_f = this.authOptions) === null || _f === void 0 ? void 0 : _f.credentialsProvider) === null || _g === void 0 ? void 0 : _g.getCredentialsAndIdentityId({
71
+ userSub = (_b = (_a = tokens.accessToken) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.sub;
72
+ return [4 /*yield*/, ((_d = (_c = this.authOptions) === null || _c === void 0 ? void 0 : _c.credentialsProvider) === null || _d === void 0 ? void 0 : _d.getCredentialsAndIdentityId({
74
73
  authConfig: this.authConfig,
75
74
  tokens: tokens,
76
75
  authenticated: true,
@@ -79,9 +78,9 @@ var AuthClass = /** @class */ (function () {
79
78
  case 2:
80
79
  // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
81
80
  credentialsAndIdentityId =
82
- _k.sent();
81
+ _g.sent();
83
82
  return [3 /*break*/, 5];
84
- case 3: return [4 /*yield*/, ((_j = (_h = this.authOptions) === null || _h === void 0 ? void 0 : _h.credentialsProvider) === null || _j === void 0 ? void 0 : _j.getCredentialsAndIdentityId({
83
+ case 3: return [4 /*yield*/, ((_f = (_e = this.authOptions) === null || _e === void 0 ? void 0 : _e.credentialsProvider) === null || _f === void 0 ? void 0 : _f.getCredentialsAndIdentityId({
85
84
  authConfig: this.authConfig,
86
85
  authenticated: false,
87
86
  forceRefresh: options.forceRefresh,
@@ -89,8 +88,8 @@ var AuthClass = /** @class */ (function () {
89
88
  case 4:
90
89
  // getCredentialsAndIdentityId will throw if cannot get credentials (network or service error)
91
90
  credentialsAndIdentityId =
92
- _k.sent();
93
- _k.label = 5;
91
+ _g.sent();
92
+ _g.label = 5;
94
93
  case 5: return [2 /*return*/, {
95
94
  tokens: tokens,
96
95
  credentials: credentialsAndIdentityId === null || credentialsAndIdentityId === void 0 ? void 0 : credentialsAndIdentityId.credentials,
@@ -115,6 +114,17 @@ var AuthClass = /** @class */ (function () {
115
114
  });
116
115
  });
117
116
  };
117
+ AuthClass.prototype.getTokens = function (options) {
118
+ var _a, _b, _c;
119
+ return __awaiter(this, void 0, void 0, function () {
120
+ return __generator(this, function (_d) {
121
+ switch (_d.label) {
122
+ case 0: return [4 /*yield*/, ((_b = (_a = this.authOptions) === null || _a === void 0 ? void 0 : _a.tokenProvider) === null || _b === void 0 ? void 0 : _b.getTokens(options))];
123
+ case 1: return [2 /*return*/, ((_c = (_d.sent())) !== null && _c !== void 0 ? _c : undefined)];
124
+ }
125
+ });
126
+ });
127
+ };
118
128
  return AuthClass;
119
129
  }());
120
130
  export { AuthClass };