@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,99 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // @ts-ignore
4
+ import * as Cookies from 'js-cookie';
5
+ import {
6
+ CookieStorageData,
7
+ KeyValueStorageInterface,
8
+ SameSite,
9
+ } from '../types';
10
+
11
+ export class CookieStorage implements KeyValueStorageInterface {
12
+ domain?: string;
13
+ path: string;
14
+ expires?: number; // days;
15
+ secure?: boolean;
16
+ sameSite?: SameSite;
17
+
18
+ constructor(data: CookieStorageData = {}) {
19
+ if (data.domain) {
20
+ this.domain = data.domain;
21
+ }
22
+ if (data.path) {
23
+ this.path = data.path;
24
+ } else {
25
+ this.path = '/';
26
+ }
27
+ if (Object.prototype.hasOwnProperty.call(data, 'expires')) {
28
+ this.expires = data.expires;
29
+ } else {
30
+ this.expires = 365;
31
+ }
32
+ if (Object.prototype.hasOwnProperty.call(data, 'secure')) {
33
+ this.secure = data.secure;
34
+ } else {
35
+ this.secure = true;
36
+ }
37
+ if (data.hasOwnProperty('sameSite')) {
38
+ if (
39
+ !data.sameSite ||
40
+ !['strict', 'lax', 'none'].includes(data.sameSite)
41
+ ) {
42
+ throw new Error(
43
+ 'The sameSite value of cookieStorage must be "lax", "strict" or "none".'
44
+ );
45
+ }
46
+ if (data.sameSite === 'none' && !this.secure) {
47
+ throw new Error(
48
+ 'sameSite = None requires the Secure attribute in latest browser versions.'
49
+ );
50
+ }
51
+ this.sameSite = data.sameSite;
52
+ }
53
+ }
54
+
55
+ async setItem(key: string, value: string): Promise<void> {
56
+ const options: CookieStorageData = {
57
+ path: this.path,
58
+ expires: this.expires,
59
+ domain: this.domain,
60
+ secure: this.secure,
61
+ };
62
+
63
+ if (this.sameSite) {
64
+ options.sameSite = this.sameSite;
65
+ }
66
+
67
+ Cookies.set(key, value, options);
68
+ return Cookies.get(key);
69
+ }
70
+
71
+ async getItem(key: string): Promise<string> {
72
+ return Cookies.get(key);
73
+ }
74
+
75
+ async removeItem(key: string): Promise<void> {
76
+ const options: CookieStorageData = {
77
+ path: this.path,
78
+ expires: this.expires,
79
+ domain: this.domain,
80
+ secure: this.secure,
81
+ };
82
+
83
+ if (this.sameSite) {
84
+ options.sameSite = this.sameSite;
85
+ }
86
+
87
+ Cookies.remove(key, options);
88
+ }
89
+
90
+ async clear(): Promise<void> {
91
+ const cookies = Cookies.get();
92
+ const numKeys = Object.keys(cookies).length;
93
+ const promiseArray: Promise<void>[] = [];
94
+ for (let index = 0; index < numKeys; ++index) {
95
+ promiseArray.push(this.removeItem(Object.keys(cookies)[index]));
96
+ }
97
+ await Promise.all(promiseArray);
98
+ }
99
+ }
@@ -0,0 +1,32 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { KeyValueStorageInterface } from '../types';
5
+
6
+ class MemoryKeyValueStorageClass implements KeyValueStorageInterface {
7
+ myStorage: Record<string, string> = {};
8
+
9
+ async setItem(key: string, value: string): Promise<void> {
10
+ this.myStorage[key] = value;
11
+ return;
12
+ }
13
+
14
+ async getItem(key: string): Promise<string | null> {
15
+ return this.myStorage[key];
16
+ }
17
+
18
+ async removeItem(key: string): Promise<void> {
19
+ delete this.myStorage[key];
20
+ return;
21
+ }
22
+
23
+ async clear(): Promise<void> {
24
+ Object.keys(this.myStorage).forEach(key => {
25
+ delete this.myStorage[key];
26
+ });
27
+
28
+ return;
29
+ }
30
+ }
31
+
32
+ export const MemoryKeyValueStorage = new MemoryKeyValueStorageClass();
@@ -0,0 +1,78 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ let dataMemory: Record<string, string> = {};
5
+
6
+ /** @class */
7
+ export class MemoryStorage {
8
+ /**
9
+ * This is used to set a specific item in storage
10
+ * @param {string} key - the key for the item
11
+ * @param {object} value - the value
12
+ * @returns {string} value that was set
13
+ */
14
+ static setItem(key: string, value: any) {
15
+ dataMemory[key] = value;
16
+ return dataMemory[key];
17
+ }
18
+
19
+ /**
20
+ * This is used to get a specific key from storage
21
+ * @param {string} key - the key for the item
22
+ * This is used to clear the storage
23
+ * @returns {string} the data item
24
+ */
25
+ static getItem(key: string) {
26
+ return Object.prototype.hasOwnProperty.call(dataMemory, key)
27
+ ? dataMemory[key]
28
+ : undefined;
29
+ }
30
+
31
+ /**
32
+ * This is used to remove an item from storage
33
+ * @param {string} key - the key being set
34
+ * @returns {string} value - value that was deleted
35
+ */
36
+ static removeItem(key: string) {
37
+ return delete dataMemory[key];
38
+ }
39
+
40
+ /**
41
+ * This is used to clear the storage
42
+ * @returns {string} nothing
43
+ */
44
+ static clear() {
45
+ dataMemory = {};
46
+ return dataMemory;
47
+ }
48
+ }
49
+
50
+ export class StorageHelper {
51
+ private storageWindow: any;
52
+ /**
53
+ * This is used to get a storage object
54
+ * @returns {object} the storage
55
+ */
56
+ constructor() {
57
+ try {
58
+ this.storageWindow = window.localStorage;
59
+ this.storageWindow.setItem('aws.amplify.test-ls', 1);
60
+ this.storageWindow.removeItem('aws.amplify.test-ls');
61
+ } catch (exception) {
62
+ this.storageWindow = MemoryStorage;
63
+ }
64
+ }
65
+
66
+ /**
67
+ * This is used to return the storage
68
+ * @returns {object} the storage
69
+ */
70
+ getStorage(): any {
71
+ return this.storageWindow;
72
+ }
73
+ }
74
+
75
+ export { SessionStorage } from './sessionStorage';
76
+ export { LocalStorage } from './localStorage';
77
+ export { MemoryKeyValueStorage } from './inMemoryStorage';
78
+ export { CookieStorage } from './cookieStorage';
@@ -0,0 +1,60 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { KeyValueStorageInterface } from "../types";
5
+ import { PlatformNotSupportedError } from '../Util/Errors';
6
+
7
+ class LocalStorageClass implements KeyValueStorageInterface {
8
+ storage?: Storage;
9
+
10
+ constructor() {
11
+ if (typeof window !== undefined) {
12
+ try {
13
+ this.storage = window?.localStorage;
14
+ } catch (error) {}
15
+ }
16
+ }
17
+
18
+ /**
19
+ * This is used to set a specific item in storage
20
+ * @param {string} key - the key for the item
21
+ * @param {object} value - the value
22
+ * @returns {string} value that was set
23
+ */
24
+ async setItem(key: string, value: string): Promise<void> {
25
+ if (!this.storage) throw PlatformNotSupportedError;
26
+ this.storage.setItem(key, value);
27
+ }
28
+
29
+ /**
30
+ * This is used to get a specific key from storage
31
+ * @param {string} key - the key for the item
32
+ * This is used to clear the storage
33
+ * @returns {string} the data item
34
+ */
35
+ async getItem(key: string): Promise<string | null> {
36
+ if (!this.storage) throw PlatformNotSupportedError;
37
+ return this.storage.getItem(key);
38
+ }
39
+
40
+ /**
41
+ * This is used to remove an item from storage
42
+ * @param {string} key - the key being set
43
+ * @returns {string} value - value that was deleted
44
+ */
45
+ async removeItem(key: string): Promise<void> {
46
+ if (!this.storage) throw PlatformNotSupportedError;
47
+ this.storage.removeItem(key);
48
+ }
49
+
50
+ /**
51
+ * This is used to clear the storage
52
+ * @returns {string} nothing
53
+ */
54
+ async clear(): Promise<void> {
55
+ if (!this.storage) throw PlatformNotSupportedError;
56
+ this.storage.clear();
57
+ }
58
+ }
59
+
60
+ export const LocalStorage = new LocalStorageClass();
@@ -0,0 +1,182 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ import AsyncStorage from '@react-native-async-storage/async-storage';
4
+ import { KeyValueStorageInterface } from '../types';
5
+
6
+ const MEMORY_KEY_PREFIX = '@MemoryStorage:';
7
+ let dataMemory: Record<string, string | null> = {};
8
+
9
+ /** @class */
10
+ class MemoryStorage {
11
+ static syncPromise: Promise<void> | null = null;
12
+ /**
13
+ * This is used to set a specific item in storage
14
+ * @param {string} key - the key for the item
15
+ * @param {object} value - the value
16
+ * @returns {string} value that was set
17
+ */
18
+ static setItem(key: string, value: string) {
19
+ if (value) {
20
+ AsyncStorage.setItem(MEMORY_KEY_PREFIX + key, value);
21
+ dataMemory[key] = value;
22
+ return dataMemory[key];
23
+ }
24
+ }
25
+
26
+ /**
27
+ * This is used to get a specific key from storage
28
+ * @param {string} key - the key for the item
29
+ * This is used to clear the storage
30
+ * @returns {string} the data item
31
+ */
32
+ static getItem(key: string) {
33
+ return Object.prototype.hasOwnProperty.call(dataMemory, key)
34
+ ? dataMemory[key]
35
+ : undefined;
36
+ }
37
+
38
+ /**
39
+ * This is used to remove an item from storage
40
+ * @param {string} key - the key being set
41
+ * @returns {string} value - value that was deleted
42
+ */
43
+ static removeItem(key: string) {
44
+ AsyncStorage.removeItem(MEMORY_KEY_PREFIX + key);
45
+ return delete dataMemory[key];
46
+ }
47
+
48
+ /**
49
+ * This is used to clear the storage
50
+ * @returns {string} nothing
51
+ */
52
+ static clear() {
53
+ dataMemory = {};
54
+ return dataMemory;
55
+ }
56
+
57
+ /**
58
+ * Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
59
+ * @returns {void}
60
+ */
61
+ static sync() {
62
+ if (!MemoryStorage.syncPromise) {
63
+ MemoryStorage.syncPromise = new Promise<void>((res, rej) => {
64
+ AsyncStorage.getAllKeys((errKeys, keys) => {
65
+ if (errKeys) rej(errKeys);
66
+
67
+ const memoryKeys =
68
+ keys?.filter(key => key.startsWith(MEMORY_KEY_PREFIX)) ?? [];
69
+
70
+ AsyncStorage.multiGet(memoryKeys, (err, stores) => {
71
+ if (err) rej(err);
72
+ stores &&
73
+ stores.map((result, index, store) => {
74
+ const key = store[index][0];
75
+ const value = store[index][1];
76
+ const memoryKey = key.replace(MEMORY_KEY_PREFIX, '');
77
+ dataMemory[memoryKey] = value;
78
+ });
79
+ res();
80
+ });
81
+ });
82
+ });
83
+ }
84
+ return MemoryStorage.syncPromise;
85
+ }
86
+ }
87
+
88
+ export class StorageHelper {
89
+ private storageWindow;
90
+ /**
91
+ * This is used to get a storage object
92
+ * @returns {object} the storage
93
+ */
94
+ constructor() {
95
+ this.storageWindow = MemoryStorage;
96
+ }
97
+
98
+ /**
99
+ * This is used to return the storage
100
+ * @returns {object} the storage
101
+ */
102
+ getStorage() {
103
+ return this.storageWindow;
104
+ }
105
+ }
106
+
107
+ class AsyncStorageClass implements KeyValueStorageInterface {
108
+ syncPromise: Promise<void> | null = null;
109
+ /**
110
+ * This is used to set a specific item in storage
111
+ * @param {string} key - the key for the item
112
+ * @param {object} value - the value
113
+ * @returns {string} value that was set
114
+ */
115
+ async setItem(key: string, value: string): Promise<void> {
116
+ if (value) {
117
+ await AsyncStorage.setItem(MEMORY_KEY_PREFIX + key, value);
118
+ dataMemory[key] = value;
119
+ }
120
+ }
121
+
122
+ /**
123
+ * This is used to get a specific key from storage
124
+ * @param {string} key - the key for the item
125
+ * This is used to clear the storage
126
+ * @returns {string} the data item
127
+ */
128
+ async getItem(key: string): Promise<string | null> {
129
+ return Object.prototype.hasOwnProperty.call(dataMemory, key)
130
+ ? dataMemory[key]
131
+ : null;
132
+ }
133
+
134
+ /**
135
+ * This is used to remove an item from storage
136
+ * @param {string} key - the key being set
137
+ * @returns {string} value - value that was deleted
138
+ */
139
+ async removeItem(key: string): Promise<void> {
140
+ await AsyncStorage.removeItem(MEMORY_KEY_PREFIX + key);
141
+ delete dataMemory[key];
142
+ }
143
+
144
+ /**
145
+ * This is used to clear the storage
146
+ * @returns {string} nothing
147
+ */
148
+ async clear(): Promise<void> {
149
+ dataMemory = {};
150
+ }
151
+
152
+ /**
153
+ * Will sync the MemoryStorage data from AsyncStorage to storageWindow MemoryStorage
154
+ * @returns {void}
155
+ */
156
+ async sync() {
157
+ if (!this.syncPromise) {
158
+ this.syncPromise = new Promise<void>((res, rej) => {
159
+ AsyncStorage.getAllKeys((errKeys, keys) => {
160
+ if (errKeys) rej(errKeys);
161
+ const memoryKeys =
162
+ keys?.filter(key => key.startsWith(MEMORY_KEY_PREFIX)) ?? [];
163
+
164
+ AsyncStorage.multiGet(memoryKeys, (err, stores) => {
165
+ if (err) rej(err);
166
+ stores &&
167
+ stores.map((result, index, store) => {
168
+ const key = store[index][0];
169
+ const value = store[index][1];
170
+ const memoryKey = key.replace(MEMORY_KEY_PREFIX, '');
171
+ dataMemory[memoryKey] = value;
172
+ });
173
+ res();
174
+ });
175
+ });
176
+ });
177
+ }
178
+ }
179
+ }
180
+
181
+ // TODO: Add this to the react-native Amplify package.
182
+ export const AsyncStorageKeyValue = new AsyncStorageClass();
@@ -4,14 +4,15 @@
4
4
  import { PlatformNotSupportedError } from '../Util/Errors';
5
5
  import { KeyValueStorageInterface } from '../types';
6
6
 
7
- /**
8
- * @internal
9
- */
10
- export class KeyValueStorage implements KeyValueStorageInterface {
7
+ class SessionStorageClass implements KeyValueStorageInterface {
11
8
  storage?: Storage;
12
9
 
13
- constructor(storage?: Storage) {
14
- this.storage = storage;
10
+ constructor() {
11
+ if (typeof window !== undefined) {
12
+ try {
13
+ this.storage = window?.sessionStorage;
14
+ } catch (error) {}
15
+ }
15
16
  }
16
17
 
17
18
  /**
@@ -20,7 +21,7 @@ export class KeyValueStorage implements KeyValueStorageInterface {
20
21
  * @param {object} value - the value
21
22
  * @returns {string} value that was set
22
23
  */
23
- async setItem(key: string, value: string) {
24
+ async setItem(key: string, value: string): Promise<void> {
24
25
  if (!this.storage) throw PlatformNotSupportedError;
25
26
  this.storage.setItem(key, value);
26
27
  }
@@ -31,7 +32,7 @@ export class KeyValueStorage implements KeyValueStorageInterface {
31
32
  * This is used to clear the storage
32
33
  * @returns {string} the data item
33
34
  */
34
- async getItem(key: string) {
35
+ async getItem(key: string): Promise<string | null> {
35
36
  if (!this.storage) throw PlatformNotSupportedError;
36
37
  return this.storage.getItem(key);
37
38
  }
@@ -41,7 +42,7 @@ export class KeyValueStorage implements KeyValueStorageInterface {
41
42
  * @param {string} key - the key being set
42
43
  * @returns {string} value - value that was deleted
43
44
  */
44
- async removeItem(key: string) {
45
+ async removeItem(key: string): Promise<void> {
45
46
  if (!this.storage) throw PlatformNotSupportedError;
46
47
  this.storage.removeItem(key);
47
48
  }
@@ -50,8 +51,10 @@ export class KeyValueStorage implements KeyValueStorageInterface {
50
51
  * This is used to clear the storage
51
52
  * @returns {string} nothing
52
53
  */
53
- async clear() {
54
+ async clear(): Promise<void> {
54
55
  if (!this.storage) throw PlatformNotSupportedError;
55
56
  this.storage.clear();
56
57
  }
57
58
  }
59
+
60
+ export const SessionStorage = new SessionStorageClass();
@@ -11,7 +11,8 @@ import { HttpRequest, HttpResponse } from '../types';
11
11
  export const authenticatedHandler = composeTransferHandler<
12
12
  [UserAgentOptions, RetryOptions<HttpResponse>, SigningOptions],
13
13
  HttpRequest,
14
- HttpResponse
14
+ HttpResponse,
15
+ typeof fetchTransferHandler
15
16
  >(fetchTransferHandler, [
16
17
  userAgentMiddleware,
17
18
  retryMiddleware,
@@ -13,7 +13,7 @@ export const fetchTransferHandler: TransferHandler<
13
13
  HttpRequest,
14
14
  HttpResponse,
15
15
  HttpTransferOptions
16
- > = async ({ url, method, headers, body }, { abortSignal }) => {
16
+ > = async ({ url, method, headers, body }, { abortSignal, cache }) => {
17
17
  let resp: Response;
18
18
  try {
19
19
  resp = await fetch(url, {
@@ -21,6 +21,7 @@ export const fetchTransferHandler: TransferHandler<
21
21
  headers,
22
22
  body: shouldSendBody(method) ? body : undefined,
23
23
  signal: abortSignal,
24
+ cache,
24
25
  });
25
26
  } catch (e) {
26
27
  // TODO: needs to revise error handling in v6
@@ -10,5 +10,6 @@ import { HttpRequest, HttpResponse } from '../types';
10
10
  export const unauthenticatedHandler = composeTransferHandler<
11
11
  [UserAgentOptions, RetryOptions<HttpResponse>],
12
12
  HttpRequest,
13
- HttpResponse
13
+ HttpResponse,
14
+ typeof fetchTransferHandler
14
15
  >(fetchTransferHandler, [userAgentMiddleware, retryMiddleware]);
@@ -29,7 +29,7 @@ export const composeServiceApi = <
29
29
  ServiceClientOptions &
30
30
  Partial<DefaultConfig> &
31
31
  InferEndpointResolverOptionType<DefaultConfig>,
32
- keyof DefaultConfig
32
+ DefaultConfig
33
33
  >,
34
34
  input: Input
35
35
  ) => {
@@ -54,8 +54,15 @@ export const composeServiceApi = <
54
54
  };
55
55
  };
56
56
 
57
- type OptionalizeKey<T, K extends keyof T> = Omit<T, K> & {
58
- [P in K & keyof T]?: T[P];
57
+ type OptionalizeKey<InputType, InputDefaultsType> = {
58
+ [KeyWithDefaultValue in keyof InputDefaultsType]?: KeyWithDefaultValue extends keyof InputType
59
+ ? InputType[KeyWithDefaultValue]
60
+ : never;
61
+ } & {
62
+ [KeyWithoutDefaultValue in keyof Omit<
63
+ InputType,
64
+ keyof InputDefaultsType
65
+ >]: InputType[KeyWithoutDefaultValue];
59
66
  };
60
67
 
61
68
  type InferEndpointResolverOptionType<T> = T extends {
@@ -5,7 +5,10 @@ import { MetadataBearer } from '@aws-sdk/types';
5
5
  import { Endpoint } from './core';
6
6
  import { HttpResponse } from './http';
7
7
 
8
- export type { Credentials, MetadataBearer } from '@aws-sdk/types';
8
+ export type {
9
+ AwsCredentialIdentity as Credentials,
10
+ MetadataBearer,
11
+ } from '@aws-sdk/types';
9
12
 
10
13
  export type SourceData = string | ArrayBuffer | ArrayBufferView;
11
14
 
@@ -26,13 +29,3 @@ export interface ServiceClientOptions {
26
29
  export type ErrorParser = (
27
30
  response?: HttpResponse
28
31
  ) => Promise<(Error & MetadataBearer) | undefined>;
29
-
30
- /**
31
- * Default config options for the `composeServiceApi`.
32
- */
33
- export type DefaultConfigOptions<
34
- TransferHandlerOptions extends Record<string, unknown> = Record<
35
- string,
36
- unknown
37
- >
38
- > = Partial<TransferHandlerOptions & ServiceClientOptions>;
@@ -34,6 +34,14 @@ export interface HttpResponse extends Response {
34
34
 
35
35
  export interface HttpTransferOptions {
36
36
  abortSignal?: AbortSignal;
37
+ /**
38
+ * Cache mode for the request. Note that this is only effective when the underlying HTTP handler is fetch.
39
+ * For XHR handler, or Node.js `"http(s)"` module or running on React Native, this option is ignored.
40
+ * Instead, you can configure the `Cache-Control` headers to achieve similar effects.
41
+ * @default 'default'
42
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/cache}
43
+ */
44
+ cache?: RequestCache;
37
45
  }
38
46
 
39
47
  export type HttpTransferHandler = TransferHandler<
@@ -22,5 +22,4 @@ export {
22
22
  EndpointResolverOptions,
23
23
  ErrorParser,
24
24
  ServiceClientOptions,
25
- DefaultConfigOptions,
26
25
  } from './aws';
package/src/index.ts CHANGED
@@ -50,11 +50,13 @@ export { UserProfile } from './types';
50
50
 
51
51
  // Storage helpers
52
52
  export {
53
+ StorageHelper,
54
+ MemoryStorage,
55
+ LocalStorage,
53
56
  CookieStorage,
54
- defaultStorage,
55
- sessionStorage,
56
- sharedInMemoryStorage,
57
- } from './storage';
57
+ SessionStorage,
58
+ MemoryKeyValueStorage,
59
+ } from './StorageHelper';
58
60
  export { KeyValueStorageInterface } from './types';
59
61
 
60
62
  // Cache exports
@@ -3,12 +3,6 @@
3
3
  import { OAuthConfig } from './singleton/Auth/types';
4
4
  import { ResourcesConfig } from './singleton/types';
5
5
 
6
- const authTypeMapping: Record<any, any> = {
7
- API_KEY: 'apiKey',
8
- AWS_IAM: 'iam',
9
- AMAZON_COGNITO_USER_POOLS: 'jwt',
10
- };
11
-
12
6
  /**
13
7
  * This utility converts the `aws-exports.js` file generated by the Amplify CLI into a {@link ResourcesConfig} object
14
8
  * consumable by Amplify.
@@ -17,15 +11,10 @@ const authTypeMapping: Record<any, any> = {
17
11
  *
18
12
  * @returns A {@link ResourcesConfig} object.
19
13
  */
20
-
21
14
  export const parseAWSExports = (
22
15
  config: Record<string, any> = {}
23
16
  ): ResourcesConfig => {
24
17
  const {
25
- aws_appsync_apiKey,
26
- aws_appsync_authenticationType,
27
- aws_appsync_graphqlEndpoint,
28
- aws_appsync_region,
29
18
  aws_cognito_identity_pool_id,
30
19
  aws_cognito_sign_up_verification_method,
31
20
  aws_mandatory_sign_in,
@@ -51,21 +40,6 @@ export const parseAWSExports = (
51
40
  };
52
41
  }
53
42
 
54
- // TODO: Need to support all API configurations
55
- // API
56
- if (aws_appsync_graphqlEndpoint) {
57
- amplifyConfig.API = {
58
- AppSync: {
59
- defaultAuthMode: {
60
- type: authTypeMapping[aws_appsync_authenticationType],
61
- apiKey: aws_appsync_apiKey,
62
- },
63
- endpoint: aws_appsync_graphqlEndpoint,
64
- region: aws_appsync_region,
65
- },
66
- };
67
- }
68
-
69
43
  // Auth
70
44
  if (aws_cognito_identity_pool_id || aws_user_pools_id) {
71
45
  amplifyConfig.Auth = {