@aws-amplify/core 5.8.2 → 6.0.1-console-preview.7919075.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 (300) hide show
  1. package/README.md +3 -0
  2. package/lib/Amplify.d.ts +18 -17
  3. package/lib/Amplify.js +9 -0
  4. package/lib/AwsClients/CognitoIdentity/base.d.ts +3 -10
  5. package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +3 -17
  6. package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.js +8 -8
  7. package/lib/AwsClients/CognitoIdentity/getId.d.ts +3 -17
  8. package/lib/AwsClients/Pinpoint/base.d.ts +2 -10
  9. package/lib/AwsClients/Pinpoint/getInAppMessages.d.ts +3 -17
  10. package/lib/AwsClients/Pinpoint/getInAppMessages.js +1 -1
  11. package/lib/AwsClients/Pinpoint/putEvents.d.ts +3 -17
  12. package/lib/AwsClients/Pinpoint/putEvents.js +6 -0
  13. package/lib/AwsClients/Pinpoint/updateEndpoint.d.ts +3 -17
  14. package/lib/AwsClients/Pinpoint/updateEndpoint.js +2 -2
  15. package/lib/Cache/AsyncStorageCache.d.ts +154 -0
  16. package/lib/Cache/AsyncStorageCache.js +744 -0
  17. package/lib/Cache/BrowserStorageCache.d.ts +166 -0
  18. package/lib/Cache/BrowserStorageCache.js +469 -0
  19. package/lib/Cache/InMemoryCache.d.ts +129 -0
  20. package/lib/Cache/InMemoryCache.js +349 -0
  21. package/lib/Cache/StorageCache.d.ts +39 -0
  22. package/lib/Cache/StorageCache.js +121 -0
  23. package/lib/Cache/Utils/CacheList.d.ts +89 -0
  24. package/lib/Cache/Utils/CacheList.js +196 -0
  25. package/lib/Cache/Utils/CacheUtils.d.ts +25 -0
  26. package/lib/Cache/Utils/CacheUtils.js +88 -0
  27. package/lib/Cache/Utils/index.d.ts +2 -0
  28. package/lib/Cache/Utils/index.js +16 -0
  29. package/lib/Cache/reactnative.d.ts +3 -0
  30. package/lib/Cache/reactnative.js +8 -0
  31. package/lib/Cache/types/Cache.d.ts +55 -0
  32. package/lib/Cache/types/Cache.js +4 -0
  33. package/lib/Cache/types/index.d.ts +1 -0
  34. package/lib/Cache/types/index.js +19 -0
  35. package/lib/ClientDevice/android.js +3 -2
  36. package/lib/ClientDevice/ios.d.ts +2 -2
  37. package/lib/ClientDevice/ios.js +3 -2
  38. package/lib/ClientDevice/reactnative.js +3 -2
  39. package/lib/Credentials.d.ts +1 -1
  40. package/lib/Credentials.js +2 -1
  41. package/lib/Errors.d.ts +19 -0
  42. package/lib/Errors.js +50 -1
  43. package/lib/Hub.js +1 -0
  44. package/lib/I18n/I18n.d.ts +29 -9
  45. package/lib/I18n/I18n.js +30 -5
  46. package/lib/I18n/index.d.ts +18 -5
  47. package/lib/I18n/index.js +35 -5
  48. package/lib/I18n/types.d.ts +4 -1
  49. package/lib/I18n/types.js +3 -0
  50. package/lib/JS.d.ts +6 -6
  51. package/lib/Logger/ConsoleLogger.d.ts +11 -11
  52. package/lib/OAuthHelper/GoogleOAuth.js +2 -1
  53. package/lib/Platform/detectFramework.js +2 -1
  54. package/lib/Platform/detection/Next.d.ts +1 -1
  55. package/lib/Platform/detection/React.js +1 -0
  56. package/lib/Platform/version.d.ts +1 -1
  57. package/lib/Platform/version.js +1 -1
  58. package/lib/Providers/AWSCloudWatchProvider.d.ts +2 -2
  59. package/lib/Providers/AWSCloudWatchProvider.js +35 -12
  60. package/lib/RNComponents/index.d.ts +1 -1
  61. package/lib/RNComponents/reactnative.js +3 -2
  62. package/lib/ServiceWorker/ServiceWorker.d.ts +4 -4
  63. package/lib/ServiceWorker/ServiceWorker.js +37 -11
  64. package/lib/Signer.d.ts +14 -1
  65. package/lib/StorageHelper/cookieStorage.d.ts +13 -0
  66. package/lib/StorageHelper/cookieStorage.js +167 -0
  67. package/lib/StorageHelper/inMemoryStorage.d.ts +10 -0
  68. package/lib/StorageHelper/inMemoryStorage.js +82 -0
  69. package/lib/StorageHelper/index.d.ts +7 -3
  70. package/lib/StorageHelper/index.js +9 -1
  71. package/lib/StorageHelper/localStorage.d.ts +32 -0
  72. package/lib/StorageHelper/localStorage.js +114 -0
  73. package/lib/StorageHelper/reactnative.d.ts +71 -1
  74. package/lib/StorageHelper/reactnative.js +154 -10
  75. package/lib/StorageHelper/sessionStorage.d.ts +32 -0
  76. package/lib/StorageHelper/sessionStorage.js +114 -0
  77. package/lib/UniversalStorage/index.d.ts +2 -2
  78. package/lib/Util/BackgroundProcessManager.d.ts +2 -2
  79. package/lib/Util/BackgroundProcessManager.js +1 -0
  80. package/lib/Util/DateUtils.d.ts +12 -1
  81. package/lib/Util/Reachability.js +7 -5
  82. package/lib/Util/Reachability.native.d.ts +3 -2
  83. package/lib/Util/StringUtils.js +3 -10
  84. package/lib/Util/errors/AssertError.d.ts +2 -0
  85. package/lib/Util/errors/AssertError.js +11 -0
  86. package/lib/clients/middleware/retry/defaultRetryDecider.d.ts +1 -1
  87. package/lib/clients/middleware/retry/defaultRetryDecider.js +17 -13
  88. package/lib/clients/middleware/retry/isClockSkewError.js +1 -1
  89. package/lib/clients/middleware/retry/middleware.d.ts +1 -1
  90. package/lib/clients/middleware/retry/middleware.js +13 -13
  91. package/lib/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.js +1 -1
  92. package/lib/clients/serde/responseInfo.js +1 -1
  93. package/lib/clients/types/aws.d.ts +4 -0
  94. package/lib/clients/types/index.d.ts +1 -1
  95. package/lib/constants.d.ts +7 -0
  96. package/lib/constants.js +9 -1
  97. package/lib/index.d.ts +18 -4
  98. package/lib/index.js +32 -5
  99. package/lib/parseAWSExports.d.ts +1 -1
  100. package/lib/singleton/Auth/index.d.ts +30 -0
  101. package/lib/singleton/Auth/index.js +133 -0
  102. package/lib/singleton/Auth/types.d.ts +95 -0
  103. package/lib/singleton/Auth/types.js +6 -0
  104. package/lib/singleton/Auth/utils/index.d.ts +5 -0
  105. package/lib/singleton/Auth/utils/index.js +52 -0
  106. package/lib/singleton/Storage/types.d.ts +14 -0
  107. package/lib/singleton/Storage/types.js +4 -0
  108. package/lib/singleton/index.d.ts +46 -0
  109. package/lib/singleton/index.js +160 -0
  110. package/lib/singleton/types.d.ts +21 -0
  111. package/lib/singleton/types.js +4 -0
  112. package/lib/tsconfig.tsbuildinfo +1 -1
  113. package/lib/types/types.d.ts +31 -1
  114. package/lib/types/types.js +2 -0
  115. package/lib-esm/Amplify.d.ts +18 -17
  116. package/lib-esm/Amplify.js +9 -0
  117. package/lib-esm/AwsClients/CognitoIdentity/base.d.ts +3 -10
  118. package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +3 -17
  119. package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.js +8 -8
  120. package/lib-esm/AwsClients/CognitoIdentity/getId.d.ts +3 -17
  121. package/lib-esm/AwsClients/Pinpoint/base.d.ts +2 -10
  122. package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +3 -17
  123. package/lib-esm/AwsClients/Pinpoint/getInAppMessages.js +1 -1
  124. package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +3 -17
  125. package/lib-esm/AwsClients/Pinpoint/putEvents.js +6 -0
  126. package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +3 -17
  127. package/lib-esm/AwsClients/Pinpoint/updateEndpoint.js +2 -2
  128. package/lib-esm/Cache/AsyncStorageCache.d.ts +154 -0
  129. package/lib-esm/Cache/AsyncStorageCache.js +737 -0
  130. package/lib-esm/Cache/BrowserStorageCache.d.ts +166 -0
  131. package/lib-esm/Cache/BrowserStorageCache.js +466 -0
  132. package/lib-esm/Cache/InMemoryCache.d.ts +129 -0
  133. package/lib-esm/Cache/InMemoryCache.js +346 -0
  134. package/lib-esm/Cache/StorageCache.d.ts +39 -0
  135. package/lib-esm/Cache/StorageCache.js +118 -0
  136. package/lib-esm/Cache/Utils/CacheList.d.ts +89 -0
  137. package/lib-esm/Cache/Utils/CacheList.js +194 -0
  138. package/lib-esm/Cache/Utils/CacheUtils.d.ts +25 -0
  139. package/lib-esm/Cache/Utils/CacheUtils.js +81 -0
  140. package/lib-esm/Cache/Utils/index.d.ts +2 -0
  141. package/lib-esm/Cache/Utils/index.js +4 -0
  142. package/lib-esm/Cache/reactnative.d.ts +3 -0
  143. package/lib-esm/Cache/reactnative.js +6 -0
  144. package/lib-esm/Cache/types/Cache.d.ts +55 -0
  145. package/lib-esm/Cache/types/Cache.js +3 -0
  146. package/lib-esm/Cache/types/index.d.ts +1 -0
  147. package/lib-esm/Cache/types/index.js +3 -0
  148. package/lib-esm/ClientDevice/android.js +1 -0
  149. package/lib-esm/ClientDevice/ios.d.ts +2 -2
  150. package/lib-esm/ClientDevice/ios.js +1 -0
  151. package/lib-esm/ClientDevice/reactnative.js +1 -0
  152. package/lib-esm/Credentials.d.ts +1 -1
  153. package/lib-esm/Credentials.js +2 -1
  154. package/lib-esm/Errors.d.ts +19 -0
  155. package/lib-esm/Errors.js +49 -0
  156. package/lib-esm/Hub.js +1 -0
  157. package/lib-esm/I18n/I18n.d.ts +29 -9
  158. package/lib-esm/I18n/I18n.js +30 -5
  159. package/lib-esm/I18n/index.d.ts +18 -5
  160. package/lib-esm/I18n/index.js +35 -5
  161. package/lib-esm/I18n/types.d.ts +4 -1
  162. package/lib-esm/I18n/types.js +3 -0
  163. package/lib-esm/JS.d.ts +6 -6
  164. package/lib-esm/Logger/ConsoleLogger.d.ts +11 -11
  165. package/lib-esm/OAuthHelper/GoogleOAuth.js +2 -1
  166. package/lib-esm/Platform/detectFramework.js +2 -1
  167. package/lib-esm/Platform/detection/Next.d.ts +1 -1
  168. package/lib-esm/Platform/detection/React.js +1 -0
  169. package/lib-esm/Platform/version.d.ts +1 -1
  170. package/lib-esm/Platform/version.js +1 -1
  171. package/lib-esm/Providers/AWSCloudWatchProvider.d.ts +2 -2
  172. package/lib-esm/Providers/AWSCloudWatchProvider.js +33 -10
  173. package/lib-esm/RNComponents/index.d.ts +1 -1
  174. package/lib-esm/RNComponents/reactnative.js +1 -0
  175. package/lib-esm/ServiceWorker/ServiceWorker.d.ts +4 -4
  176. package/lib-esm/ServiceWorker/ServiceWorker.js +37 -11
  177. package/lib-esm/Signer.d.ts +14 -1
  178. package/lib-esm/StorageHelper/cookieStorage.d.ts +13 -0
  179. package/lib-esm/StorageHelper/cookieStorage.js +141 -0
  180. package/lib-esm/StorageHelper/inMemoryStorage.d.ts +10 -0
  181. package/lib-esm/StorageHelper/inMemoryStorage.js +79 -0
  182. package/lib-esm/StorageHelper/index.d.ts +7 -3
  183. package/lib-esm/StorageHelper/index.js +4 -0
  184. package/lib-esm/StorageHelper/localStorage.d.ts +32 -0
  185. package/lib-esm/StorageHelper/localStorage.js +111 -0
  186. package/lib-esm/StorageHelper/reactnative.d.ts +71 -1
  187. package/lib-esm/StorageHelper/reactnative.js +153 -9
  188. package/lib-esm/StorageHelper/sessionStorage.d.ts +32 -0
  189. package/lib-esm/StorageHelper/sessionStorage.js +111 -0
  190. package/lib-esm/UniversalStorage/index.d.ts +2 -2
  191. package/lib-esm/Util/BackgroundProcessManager.d.ts +2 -2
  192. package/lib-esm/Util/BackgroundProcessManager.js +1 -0
  193. package/lib-esm/Util/DateUtils.d.ts +12 -1
  194. package/lib-esm/Util/Reachability.js +5 -3
  195. package/lib-esm/Util/Reachability.native.d.ts +3 -2
  196. package/lib-esm/Util/StringUtils.js +3 -10
  197. package/lib-esm/Util/errors/AssertError.d.ts +2 -0
  198. package/lib-esm/Util/errors/AssertError.js +7 -0
  199. package/lib-esm/clients/middleware/retry/defaultRetryDecider.d.ts +1 -1
  200. package/lib-esm/clients/middleware/retry/defaultRetryDecider.js +17 -13
  201. package/lib-esm/clients/middleware/retry/isClockSkewError.js +1 -1
  202. package/lib-esm/clients/middleware/retry/middleware.d.ts +1 -1
  203. package/lib-esm/clients/middleware/retry/middleware.js +13 -13
  204. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.js +1 -1
  205. package/lib-esm/clients/serde/responseInfo.js +1 -1
  206. package/lib-esm/clients/types/aws.d.ts +4 -0
  207. package/lib-esm/clients/types/index.d.ts +1 -1
  208. package/lib-esm/constants.d.ts +7 -0
  209. package/lib-esm/constants.js +8 -0
  210. package/lib-esm/index.d.ts +18 -4
  211. package/lib-esm/index.js +15 -3
  212. package/lib-esm/parseAWSExports.d.ts +1 -1
  213. package/lib-esm/singleton/Auth/index.d.ts +30 -0
  214. package/lib-esm/singleton/Auth/index.js +129 -0
  215. package/lib-esm/singleton/Auth/types.d.ts +95 -0
  216. package/lib-esm/singleton/Auth/types.js +5 -0
  217. package/lib-esm/singleton/Auth/utils/index.d.ts +5 -0
  218. package/lib-esm/singleton/Auth/utils/index.js +45 -0
  219. package/lib-esm/singleton/Storage/types.d.ts +14 -0
  220. package/lib-esm/singleton/Storage/types.js +3 -0
  221. package/lib-esm/singleton/index.d.ts +46 -0
  222. package/lib-esm/singleton/index.js +156 -0
  223. package/lib-esm/singleton/types.d.ts +21 -0
  224. package/lib-esm/singleton/types.js +3 -0
  225. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  226. package/lib-esm/types/types.d.ts +31 -1
  227. package/lib-esm/types/types.js +2 -0
  228. package/package.json +38 -15
  229. package/src/Amplify.ts +9 -3
  230. package/src/AwsClients/CognitoIdentity/base.ts +2 -1
  231. package/src/AwsClients/CognitoIdentity/getCredentialsForIdentity.ts +13 -6
  232. package/src/AwsClients/Pinpoint/base.ts +6 -2
  233. package/src/AwsClients/Pinpoint/getInAppMessages.ts +1 -1
  234. package/src/AwsClients/Pinpoint/putEvents.ts +6 -0
  235. package/src/AwsClients/Pinpoint/updateEndpoint.ts +2 -2
  236. package/src/Cache/AsyncStorageCache.ts +500 -0
  237. package/src/Cache/BrowserStorageCache.ts +517 -0
  238. package/src/Cache/CHANGELOG.md +1227 -0
  239. package/src/Cache/InMemoryCache.ts +354 -0
  240. package/src/Cache/StorageCache.ts +157 -0
  241. package/src/Cache/Utils/CacheList.ts +198 -0
  242. package/src/Cache/Utils/CacheUtils.ts +92 -0
  243. package/src/Cache/Utils/index.ts +11 -0
  244. package/src/Cache/reactnative.ts +9 -0
  245. package/src/Cache/types/Cache.ts +75 -0
  246. package/src/Cache/types/index.ts +4 -0
  247. package/src/ClientDevice/android.ts +1 -1
  248. package/src/ClientDevice/ios.ts +2 -2
  249. package/src/ClientDevice/reactnative.ts +1 -1
  250. package/src/Credentials.ts +19 -17
  251. package/src/Errors.ts +41 -0
  252. package/src/Hub.ts +1 -0
  253. package/src/I18n/I18n.ts +40 -12
  254. package/src/I18n/index.ts +45 -12
  255. package/src/I18n/types.ts +3 -0
  256. package/src/JS.ts +24 -17
  257. package/src/Logger/ConsoleLogger.ts +10 -10
  258. package/src/OAuthHelper/FacebookOAuth.ts +2 -2
  259. package/src/OAuthHelper/GoogleOAuth.ts +9 -6
  260. package/src/Platform/detectFramework.ts +1 -1
  261. package/src/Platform/detection/React.ts +5 -3
  262. package/src/Platform/version.ts +1 -1
  263. package/src/Providers/AWSCloudWatchProvider.ts +39 -14
  264. package/src/RNComponents/index.ts +1 -1
  265. package/src/RNComponents/reactnative.ts +1 -1
  266. package/src/ServiceWorker/ServiceWorker.ts +58 -18
  267. package/src/Signer.ts +22 -3
  268. package/src/StorageHelper/cookieStorage.ts +99 -0
  269. package/src/StorageHelper/inMemoryStorage.ts +32 -0
  270. package/src/StorageHelper/index.ts +6 -1
  271. package/src/StorageHelper/localStorage.ts +60 -0
  272. package/src/StorageHelper/reactnative.ts +94 -14
  273. package/src/StorageHelper/sessionStorage.ts +60 -0
  274. package/src/Util/BackgroundProcessManager.ts +33 -9
  275. package/src/Util/DateUtils.ts +14 -5
  276. package/src/Util/Reachability.native.ts +3 -2
  277. package/src/Util/Reachability.ts +9 -7
  278. package/src/Util/Retry.ts +2 -1
  279. package/src/Util/StringUtils.ts +3 -10
  280. package/src/Util/errors/AssertError.ts +11 -0
  281. package/src/clients/handlers/fetch.ts +2 -2
  282. package/src/clients/middleware/retry/defaultRetryDecider.ts +12 -6
  283. package/src/clients/middleware/retry/isClockSkewError.ts +1 -1
  284. package/src/clients/middleware/retry/middleware.ts +9 -9
  285. package/src/clients/middleware/signing/middleware.ts +1 -1
  286. package/src/clients/middleware/signing/signer/signatureV4/utils/dataHashHelpers.ts +1 -1
  287. package/src/clients/serde/responseInfo.ts +2 -1
  288. package/src/clients/types/aws.ts +10 -0
  289. package/src/clients/types/index.ts +1 -0
  290. package/src/constants.ts +16 -0
  291. package/src/global.d.ts +11 -0
  292. package/src/index.ts +66 -4
  293. package/src/parseAWSExports.ts +1 -1
  294. package/src/singleton/Auth/index.ts +113 -0
  295. package/src/singleton/Auth/types.ts +129 -0
  296. package/src/singleton/Auth/utils/index.ts +68 -0
  297. package/src/singleton/Storage/types.ts +21 -0
  298. package/src/singleton/index.ts +144 -0
  299. package/src/singleton/types.ts +48 -0
  300. package/src/types/types.ts +38 -1
@@ -0,0 +1,92 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { CacheConfig } from '../types';
5
+ import { StorageHelper } from '../../StorageHelper';
6
+ /**
7
+ * Default cache config
8
+ */
9
+ export const defaultConfig: CacheConfig = {
10
+ keyPrefix: 'aws-amplify-cache',
11
+ capacityInBytes: 1048576, // 1MB
12
+ itemMaxSize: 210000, // about 200kb
13
+ defaultTTL: 259200000, // about 3 days
14
+ defaultPriority: 5,
15
+ warningThreshold: 0.8,
16
+ // the storage helper will check if localStorage exists,
17
+ // if not, will use a in-memory object instead
18
+ storage: new StorageHelper().getStorage(),
19
+ };
20
+
21
+ /**
22
+ * return the byte size of the string
23
+ * @param str
24
+ */
25
+ export function getByteLength(str: string): number {
26
+ let ret: number = 0;
27
+ ret = str.length;
28
+
29
+ for (let i = str.length; i >= 0; i -= 1) {
30
+ const charCode: number = str.charCodeAt(i);
31
+ if (charCode > 0x7f && charCode <= 0x7ff) {
32
+ ret += 1;
33
+ } else if (charCode > 0x7ff && charCode <= 0xffff) {
34
+ ret += 2;
35
+ }
36
+ // trail surrogate
37
+ if (charCode >= 0xdc00 && charCode <= 0xdfff) {
38
+ i -= 1;
39
+ }
40
+ }
41
+
42
+ return ret;
43
+ }
44
+
45
+ /**
46
+ * get current time
47
+ */
48
+ export function getCurrTime(): number {
49
+ const currTime = new Date();
50
+ return currTime.getTime();
51
+ }
52
+
53
+ /**
54
+ * check if passed value is an integer
55
+ */
56
+ export function isInteger(value?: number): boolean {
57
+ if (Number.isInteger) {
58
+ return Number.isInteger(value);
59
+ }
60
+
61
+ return _isInteger(value);
62
+ }
63
+
64
+ function _isInteger(value?: number): boolean {
65
+ return (
66
+ typeof value === 'number' && isFinite(value) && Math.floor(value) === value
67
+ );
68
+ }
69
+
70
+ /**
71
+ * provide an object as the in-memory cache
72
+ */
73
+ let store: Record<string, string> = {};
74
+ export class CacheObject {
75
+ static clear(): void {
76
+ store = {};
77
+ }
78
+
79
+ static getItem(key: string): string | null {
80
+ return store[key] || null;
81
+ }
82
+
83
+ static setItem(key: string, value: string): void {
84
+ store[key] = value;
85
+ }
86
+
87
+ static removeItem(key: string): void {
88
+ delete store[key];
89
+ }
90
+ }
91
+
92
+ export const getCurrSizeKey = (keyPrefix: string) => keyPrefix + 'CurSize';
@@ -0,0 +1,11 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export {
5
+ CacheObject,
6
+ defaultConfig,
7
+ getByteLength,
8
+ getCurrTime,
9
+ isInteger,
10
+ } from './CacheUtils';
11
+ export { default as CacheList } from './CacheList';
@@ -0,0 +1,9 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { Cache, AsyncStorageCache } from './AsyncStorageCache';
5
+
6
+ export { AsyncStorageCache };
7
+
8
+ // Standard `Cache` export to maintain interoperability with React Native
9
+ export { Cache };
@@ -0,0 +1,75 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ /**
5
+ * Cache Interface
6
+ */
7
+ export interface ICache {
8
+ /** Put item into cache */
9
+ setItem(key: string, value: any, options?: CacheItemOptions): void;
10
+
11
+ /** Get item from cache */
12
+ getItem(key: string, options?: CacheItemOptions): any;
13
+
14
+ /** Remove item from cache */
15
+ removeItem(key: string): void;
16
+
17
+ /** Remove all items from cache */
18
+ clear(): void;
19
+
20
+ /** Get all keys form cache */
21
+ getAllKeys(): string[] | Promise<string[]>;
22
+
23
+ /** Get current size of the cache */
24
+ getCacheCurSize(): number | Promise<number>;
25
+
26
+ /** create a new instance with customized config */
27
+ createInstance(config: CacheConfig): ICache;
28
+
29
+ /** change current configuration */
30
+ configure(config: CacheConfig): CacheConfig;
31
+ }
32
+
33
+ /**
34
+ * Cache instance options
35
+ */
36
+ export interface CacheConfig {
37
+ /** Prepend to key to avoid conflicts */
38
+ keyPrefix: string;
39
+
40
+ /** Cache capacity, in bytes */
41
+ capacityInBytes: number;
42
+
43
+ /** Max size of one item */
44
+ itemMaxSize: number;
45
+
46
+ /** Time to live, in milliseconds */
47
+ defaultTTL: number;
48
+
49
+ /** Warn when over threshold percentage of capacity, maximum 1 */
50
+ warningThreshold: number;
51
+
52
+ /** default priority number put on cached items */
53
+ defaultPriority: number;
54
+
55
+ storage?: Storage;
56
+
57
+ Cache?: Cache;
58
+ }
59
+
60
+ export interface CacheItem {
61
+ key: string;
62
+ data: any;
63
+ timestamp: number;
64
+ visitedTime: number;
65
+ priority: number;
66
+ expires: number;
67
+ type: string;
68
+ byteSize: number;
69
+ }
70
+
71
+ export interface CacheItemOptions {
72
+ priority?: number;
73
+ expires?: number;
74
+ callback?: Function;
75
+ }
@@ -0,0 +1,4 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './Cache';
@@ -1,6 +1,6 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
-
3
+ // @ts-ignore: missing type definition
4
4
  import { Platform, Dimensions } from 'react-native';
5
5
  import { ConsoleLogger as Logger } from '../Logger';
6
6
 
@@ -1,6 +1,6 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
-
3
+ // @ts-ignore: missing type definition
4
4
  import { Platform, Dimensions } from 'react-native';
5
5
  import { ConsoleLogger as Logger } from '../Logger';
6
6
 
@@ -21,7 +21,7 @@ export const clientInfo = () => {
21
21
  };
22
22
  };
23
23
 
24
- function dimToMake(dim) {
24
+ function dimToMake(dim:{height:number, width:number;}) {
25
25
  let { height, width } = dim;
26
26
  if (height < width) {
27
27
  const tmp = height;
@@ -1,6 +1,6 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
-
3
+ // @ts-ignore: missing type definition
4
4
  import { Platform } from 'react-native';
5
5
  import { clientInfo as iOSClientInfo } from './ios';
6
6
  import { clientInfo as androidClientInfo } from './android';
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
3
  // SPDX-License-Identifier: Apache-2.0
3
4
  import { ConsoleLogger as Logger } from './Logger';
@@ -35,11 +36,12 @@ export class CredentialsClass {
35
36
  private _config;
36
37
  private _credentials;
37
38
  private _credentials_source;
38
- private _gettingCredPromise = null;
39
+ private _gettingCredPromise: any = null;
39
40
  private _refreshHandlers = {};
40
41
  private _storage;
41
42
  private _storageSync;
42
43
  private _identityId;
44
+ // @ts-ignore
43
45
  private _nextCredentialsRefresh: number;
44
46
 
45
47
  // Allow `Auth` to be injected for SSR, but Auth isn't a required dependency for Credentials
@@ -126,7 +128,7 @@ export class CredentialsClass {
126
128
 
127
129
  // Some use-cases don't require Auth for signing in, but use Credentials for guest users (e.g. Analytics)
128
130
  // Prefer locally scoped `Auth`, but fallback to registered `Amplify.Auth` global otherwise.
129
- const { Auth = Amplify.Auth } = this;
131
+ const { Auth = Amplify.Auth } = this as any;
130
132
 
131
133
  if (!Auth || typeof Auth.currentUserCredentials !== 'function') {
132
134
  // If Auth module is not imported, do a best effort to get guest credentials
@@ -296,10 +298,10 @@ export class CredentialsClass {
296
298
  });
297
299
  return {
298
300
  identityId: this._identityId,
299
- accessKeyId: Credentials.AccessKeyId,
300
- secretAccessKey: Credentials.SecretKey,
301
- sessionToken: Credentials.SessionToken,
302
- expiration: Credentials.Expiration,
301
+ accessKeyId: Credentials!.AccessKeyId,
302
+ secretAccessKey: Credentials!.SecretKey,
303
+ sessionToken: Credentials!.SessionToken,
304
+ expiration: Credentials!.Expiration,
303
305
  };
304
306
  };
305
307
  let credentials = guestCredentialsProvider().catch(async err => {
@@ -334,10 +336,10 @@ export class CredentialsClass {
334
336
 
335
337
  return {
336
338
  identityId: IdentityId,
337
- accessKeyId: Credentials.AccessKeyId,
338
- secretAccessKey: Credentials.SecretKey,
339
- sessionToken: Credentials.SessionToken,
340
- expiration: Credentials.Expiration,
339
+ accessKeyId: Credentials!.AccessKeyId,
340
+ secretAccessKey: Credentials!.SecretKey,
341
+ sessionToken: Credentials!.SessionToken,
342
+ expiration: Credentials!.Expiration,
341
343
  };
342
344
  };
343
345
 
@@ -399,10 +401,10 @@ export class CredentialsClass {
399
401
  });
400
402
  return {
401
403
  identityId: identity_id,
402
- accessKeyId: Credentials.AccessKeyId,
403
- secretAccessKey: Credentials.SecretKey,
404
- sessionToken: Credentials.SessionToken,
405
- expiration: Credentials.Expiration,
404
+ accessKeyId: Credentials!.AccessKeyId,
405
+ secretAccessKey: Credentials!.SecretKey,
406
+ sessionToken: Credentials!.SessionToken,
407
+ expiration: Credentials!.Expiration,
406
408
  };
407
409
  };
408
410
 
@@ -460,10 +462,10 @@ export class CredentialsClass {
460
462
  // single source of truth for the primary identity associated with the logins
461
463
  // only if a guest identity is used for a first-time user, that guest identity will become its primary identity
462
464
  IdentityId: primaryIdentityId,
463
- } = await getCredentialsForIdentity(cognitoConfig, {
465
+ } = (await getCredentialsForIdentity(cognitoConfig, {
464
466
  IdentityId: guestIdentityId || generatedOrRetrievedIdentityId,
465
467
  Logins: logins,
466
- });
468
+ })) as { Credentials: any; IdentityId: string };
467
469
 
468
470
  this._identityId = primaryIdentityId;
469
471
  if (guestIdentityId) {
@@ -576,7 +578,7 @@ export class CredentialsClass {
576
578
  }
577
579
 
578
580
  /* operations on local stored guest identity */
579
- private async _getGuestIdentityId(): Promise<string> {
581
+ private async _getGuestIdentityId(): Promise<string | undefined> {
580
582
  const { identityPoolId } = this._config;
581
583
  try {
582
584
  await this._storageSync;
package/src/Errors.ts CHANGED
@@ -1,9 +1,50 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { ErrorParams } from './types/types';
5
+
4
6
  export function missingConfig(name: string) {
5
7
  return new Error('Missing config value of ' + name);
6
8
  }
7
9
  export function invalidParameter(name: string) {
8
10
  return new Error('Invalid parameter value of ' + name);
9
11
  }
12
+
13
+ export enum AmplifyErrorString {
14
+ UNKNOWN = 'UnknownError',
15
+ PLATFORM_NOT_SUPPORTED_ERROR = 'PlatformNotSupportedError',
16
+ }
17
+ export class AmplifyError extends Error {
18
+ underlyingError?: Error | unknown;
19
+ recoverySuggestion?: string;
20
+ /**
21
+ * Constructs an AmplifyError.
22
+ *
23
+ * @param message text that describes the main problem.
24
+ * @param underlyingError the underlying cause of the error.
25
+ * @param recoverySuggestion suggestion to recover from the error.
26
+ *
27
+ */
28
+ constructor({
29
+ message,
30
+ name,
31
+ recoverySuggestion,
32
+ underlyingError,
33
+ }: ErrorParams) {
34
+ super(message);
35
+
36
+ this.name = name;
37
+ this.underlyingError = underlyingError;
38
+ this.recoverySuggestion = recoverySuggestion;
39
+
40
+ // Hack for making the custom error class work when transpiled to es5
41
+ // TODO: Delete the following 2 lines after we change the build target to >= es2015
42
+ this.constructor = AmplifyError;
43
+ Object.setPrototypeOf(this, AmplifyError.prototype);
44
+ }
45
+ }
46
+
47
+ export const PlatformNotSupportedError = new AmplifyError({
48
+ name: AmplifyErrorString.PLATFORM_NOT_SUPPORTED_ERROR,
49
+ message: 'Function not supported on current platform',
50
+ });
package/src/Hub.ts CHANGED
@@ -1,3 +1,4 @@
1
+ // @ts-nocheck
1
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
3
  // SPDX-License-Identifier: Apache-2.0
3
4
 
package/src/I18n/I18n.ts CHANGED
@@ -1,39 +1,54 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { I18nOptions } from './types';
5
4
  import { ConsoleLogger as Logger } from '../Logger';
5
+ import { AmplifyV6 } from '../singleton';
6
+ import { I18nOptions } from './types';
6
7
 
7
8
  const logger = new Logger('I18n');
8
9
 
9
10
  /**
10
- * Language transition class
11
+ * Language translation utility.
12
+ *
13
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
11
14
  */
12
15
  export class I18n {
13
16
  /**
14
17
  * @private
15
18
  */
16
- _options: I18nOptions = null;
19
+ _options: I18nOptions | null = null;
17
20
 
18
21
  /**
19
22
  * @private
20
23
  */
21
- _lang = null;
24
+ _lang?: string | null = null;
22
25
 
23
26
  /**
24
27
  * @private
25
28
  */
26
- _dict = {};
29
+ _dict: Record<string, any> = {};
27
30
 
28
31
  /**
29
32
  * @constructor
30
33
  * Initialize with configurations
31
34
  * @param {Object} options
35
+ *
36
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
32
37
  */
33
- constructor(options: I18nOptions) {
34
- this._options = Object.assign({}, options);
35
- this._lang = this._options.language;
38
+ constructor() {}
39
+
40
+ /**
41
+ * Sets the default language from the configuration when required.
42
+ *
43
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
44
+ */
45
+ setDefaultLanguage() {
46
+ if (!this._lang) {
47
+ const i18nConfig = AmplifyV6.getConfig().I18n;
48
+ this._lang = i18nConfig?.language;
49
+ }
36
50
 
51
+ // Default to window language if not set in config
37
52
  if (
38
53
  !this._lang &&
39
54
  typeof window !== 'undefined' &&
@@ -50,6 +65,8 @@ export class I18n {
50
65
  * @method
51
66
  * Explicitly setting language
52
67
  * @param {String} lang
68
+ *
69
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
53
70
  */
54
71
  setLanguage(lang: string) {
55
72
  this._lang = lang;
@@ -60,8 +77,10 @@ export class I18n {
60
77
  * Get value
61
78
  * @param {String} key
62
79
  * @param {String} defVal - Default value
80
+ *
81
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
63
82
  */
64
- get(key, defVal = undefined) {
83
+ get(key: string, defVal: string | undefined = undefined) {
65
84
  if (!this._lang) {
66
85
  return typeof defVal !== 'undefined' ? defVal : key;
67
86
  }
@@ -88,8 +107,10 @@ export class I18n {
88
107
  * @param {String} key
89
108
  * @param {String} language - Specified langurage to be used
90
109
  * @param {String} defVal - Default value
110
+ *
111
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
91
112
  */
92
- getByLanguage(key, language, defVal = null) {
113
+ getByLanguage(key: string, language: string, defVal: string | null = null) {
93
114
  if (!language) {
94
115
  return defVal;
95
116
  }
@@ -107,8 +128,13 @@ export class I18n {
107
128
  * Add vocabularies for one language
108
129
  * @param {String} language - Language of the dictionary
109
130
  * @param {Object} vocabularies - Object that has key-value as dictionary entry
131
+ *
132
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
110
133
  */
111
- putVocabulariesForLanguage(language, vocabularies) {
134
+ putVocabulariesForLanguage(
135
+ language: string,
136
+ vocabularies: Record<string, any>
137
+ ) {
112
138
  let lang_dict = this._dict[language];
113
139
  if (!lang_dict) {
114
140
  lang_dict = this._dict[language] = {};
@@ -121,8 +147,10 @@ export class I18n {
121
147
  * Add vocabularies for one language
122
148
  * @param {Object} vocabularies - Object that has language as key,
123
149
  * vocabularies of each language as value
150
+ *
151
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
124
152
  */
125
- putVocabularies(vocabularies) {
153
+ putVocabularies(vocabularies: Record<string, any>) {
126
154
  Object.keys(vocabularies).map(key => {
127
155
  this.putVocabulariesForLanguage(key, vocabularies[key]);
128
156
  });
package/src/I18n/index.ts CHANGED
@@ -4,15 +4,19 @@
4
4
  import { I18n as I18nClass } from './I18n';
5
5
 
6
6
  import { ConsoleLogger as Logger } from '../Logger';
7
- import { Amplify } from '../Amplify';
7
+ import { I18nOptions } from './types';
8
+ import { asserts } from '../Util/errors/AssertError';
9
+ import { I18N_EXCEPTION } from '../constants';
8
10
 
9
11
  const logger = new Logger('I18n');
10
12
 
11
- let _config = null;
12
- let _i18n = null;
13
+ let _config: I18nOptions = { language: null };
14
+ let _i18n: I18nClass | null = null;
13
15
 
14
16
  /**
15
17
  * Export I18n APIs
18
+ *
19
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
16
20
  */
17
21
  export class I18n {
18
22
  /**
@@ -21,7 +25,7 @@ export class I18n {
21
25
  * Configure I18n part
22
26
  * @param {Object} config - Configuration of the I18n
23
27
  */
24
- static configure(config) {
28
+ static configure(config: Record<string, any>) {
25
29
  logger.debug('configure I18n');
26
30
  if (!config) {
27
31
  return _config;
@@ -42,23 +46,30 @@ export class I18n {
42
46
  * @static
43
47
  * @method
44
48
  * Create an instance of I18n for the library
49
+ *
50
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
45
51
  */
46
52
  static createInstance() {
47
53
  logger.debug('create I18n instance');
48
54
  if (_i18n) {
49
55
  return;
50
56
  }
51
- _i18n = new I18nClass(_config);
57
+ _i18n = new I18nClass();
52
58
  }
53
59
 
54
60
  /**
55
61
  * @static @method
56
62
  * Explicitly setting language
57
63
  * @param {String} lang
64
+ *
65
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
58
66
  */
59
- static setLanguage(lang) {
67
+ static setLanguage(lang: string) {
60
68
  I18n.checkConfig();
61
-
69
+ asserts(!!_i18n, {
70
+ name: I18N_EXCEPTION,
71
+ message: 'I18N is not configured',
72
+ });
62
73
  return _i18n.setLanguage(lang);
63
74
  }
64
75
 
@@ -67,11 +78,17 @@ export class I18n {
67
78
  * Get value
68
79
  * @param {String} key
69
80
  * @param {String} defVal - Default value
81
+ *
82
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
70
83
  */
71
- static get(key, defVal?) {
84
+ static get(key: string, defVal?: string) {
72
85
  if (!I18n.checkConfig()) {
73
86
  return typeof defVal === 'undefined' ? key : defVal;
74
87
  }
88
+ asserts(!!_i18n, {
89
+ name: I18N_EXCEPTION,
90
+ message: 'I18N is not configured',
91
+ });
75
92
 
76
93
  return _i18n.get(key, defVal);
77
94
  }
@@ -82,9 +99,18 @@ export class I18n {
82
99
  * Add vocabularies for one language
83
100
  * @param {String} langurage - Language of the dictionary
84
101
  * @param {Object} vocabularies - Object that has key-value as dictionary entry
102
+ *
103
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
85
104
  */
86
- static putVocabulariesForLanguage(language, vocabularies) {
105
+ static putVocabulariesForLanguage(
106
+ language: string,
107
+ vocabularies: Record<string, string>
108
+ ) {
87
109
  I18n.checkConfig();
110
+ asserts(!!_i18n, {
111
+ name: I18N_EXCEPTION,
112
+ message: 'I18N is not configured',
113
+ });
88
114
 
89
115
  return _i18n.putVocabulariesForLanguage(language, vocabularies);
90
116
  }
@@ -95,20 +121,27 @@ export class I18n {
95
121
  * Add vocabularies for one language
96
122
  * @param {Object} vocabularies - Object that has language as key,
97
123
  * vocabularies of each language as value
124
+ *
125
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
98
126
  */
99
- static putVocabularies(vocabularies) {
127
+ static putVocabularies(vocabularies: Record<string, string>) {
100
128
  I18n.checkConfig();
129
+ asserts(!!_i18n, {
130
+ name: I18N_EXCEPTION,
131
+ message: 'I18N is not configured',
132
+ });
101
133
 
102
134
  return _i18n.putVocabularies(vocabularies);
103
135
  }
104
136
 
105
137
  public static checkConfig() {
106
138
  if (!_i18n) {
107
- _i18n = new I18nClass(_config);
139
+ I18n.createInstance();
108
140
  }
109
141
 
110
142
  return true;
111
143
  }
112
144
  }
113
145
 
114
- Amplify.register(I18n);
146
+ // Create an instance of I18n in the static class
147
+ I18n.createInstance();
package/src/I18n/types.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ /**
5
+ * @deprecated The I18n utility is on a deprecation path and will be removed in a future version of Amplify.
6
+ */
4
7
  export class I18nOptions {
5
8
  language = null;
6
9
  }