@aws-amplify/core 6.0.1-api-v6-models.8035dfc.0 → 6.0.1-api-v6-models.3eb7748.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 (341) hide show
  1. package/lib/Cache/StorageCache.d.ts +14 -31
  2. package/lib/Cache/StorageCache.js +97 -102
  3. package/lib/Cache/StorageCache.native.d.ts +19 -0
  4. package/lib/Cache/StorageCache.native.js +164 -0
  5. package/{lib-esm/Cache/AsyncStorageCache.d.ts → lib/Cache/StorageCacheCommon.d.ts} +124 -99
  6. package/lib/Cache/{AsyncStorageCache.js → StorageCacheCommon.js} +494 -432
  7. package/lib/Cache/constants.d.ts +6 -0
  8. package/lib/Cache/constants.js +17 -0
  9. package/lib/Cache/index.d.ts +2 -0
  10. package/lib/Cache/index.js +7 -0
  11. package/lib/Cache/types/cache.d.ts +38 -0
  12. package/lib/Cache/types/index.d.ts +1 -1
  13. package/lib/Cache/types/index.js +1 -1
  14. package/lib/Cache/{Utils → utils}/CacheList.d.ts +1 -1
  15. package/lib/Cache/{Utils → utils}/CacheList.js +2 -1
  16. package/lib/Cache/utils/cacheHelpers.d.ts +14 -0
  17. package/lib/Cache/utils/cacheHelpers.js +51 -0
  18. package/lib/Cache/{Utils → utils}/errorHelpers.d.ts +0 -1
  19. package/lib/Cache/{Utils → utils}/errorHelpers.js +0 -4
  20. package/lib/Cache/utils/index.d.ts +2 -0
  21. package/lib/Cache/utils/index.js +12 -0
  22. package/lib/I18n/I18n.js +1 -6
  23. package/lib/Platform/types.d.ts +18 -8
  24. package/lib/Platform/types.js +10 -2
  25. package/lib/Platform/version.d.ts +1 -1
  26. package/lib/Platform/version.js +1 -1
  27. package/lib/Reachability/Reachability.d.ts +1 -0
  28. package/lib/Reachability/Reachability.js +42 -1
  29. package/lib/ServiceWorker/ServiceWorker.js +69 -17
  30. package/lib/ServiceWorker/index.d.ts +0 -12
  31. package/lib/ServiceWorker/index.js +0 -12
  32. package/lib/Signer/Signer.js +3 -2
  33. package/lib/awsClients/cognitoIdentity/base.js +2 -1
  34. package/lib/awsClients/pinpoint/base.js +2 -1
  35. package/lib/awsClients/pinpoint/getInAppMessages.js +2 -1
  36. package/lib/awsClients/pinpoint/putEvents.js +2 -1
  37. package/lib/awsClients/pinpoint/updateEndpoint.js +2 -1
  38. package/lib/clients/middleware/signing/signer/signatureV4/index.d.ts +0 -1
  39. package/lib/clients/middleware/signing/signer/signatureV4/index.js +0 -1
  40. package/lib/clients/middleware/signing/signer/signatureV4/presignUrl.js +2 -1
  41. package/lib/errors/errorHelpers.d.ts +2 -0
  42. package/lib/errors/errorHelpers.js +20 -0
  43. package/lib/errors/index.d.ts +1 -0
  44. package/lib/errors/index.js +3 -1
  45. package/lib/index.d.ts +4 -4
  46. package/lib/index.js +9 -6
  47. package/lib/libraryUtils.d.ts +8 -7
  48. package/lib/libraryUtils.js +17 -17
  49. package/lib/parseAWSExports.js +34 -19
  50. package/lib/providers/pinpoint/apis/flushEvents.d.ts +2 -2
  51. package/lib/providers/pinpoint/apis/record.d.ts +1 -1
  52. package/lib/providers/pinpoint/apis/record.js +8 -24
  53. package/lib/providers/pinpoint/apis/updateEndpoint.js +6 -6
  54. package/lib/providers/pinpoint/index.d.ts +2 -2
  55. package/lib/providers/pinpoint/index.js +4 -2
  56. package/lib/providers/pinpoint/types/errors.d.ts +9 -0
  57. package/lib/providers/pinpoint/types/errors.js +15 -0
  58. package/lib/providers/pinpoint/types/index.d.ts +1 -0
  59. package/lib/providers/pinpoint/types/index.js +3 -0
  60. package/lib/providers/pinpoint/types/pinpoint.d.ts +3 -3
  61. package/lib/providers/pinpoint/utils/index.d.ts +1 -0
  62. package/lib/providers/pinpoint/utils/index.js +3 -1
  63. package/lib/providers/pinpoint/utils/resolveEndpointId.d.ts +8 -0
  64. package/lib/providers/pinpoint/utils/resolveEndpointId.js +85 -0
  65. package/lib/singleton/Amplify.d.ts +2 -2
  66. package/lib/singleton/Amplify.js +6 -5
  67. package/lib/singleton/Auth/types.d.ts +3 -3
  68. package/lib/singleton/Cache/types.d.ts +18 -0
  69. package/lib/singleton/Cache/types.js +4 -0
  70. package/lib/singleton/Interactions/types.d.ts +21 -0
  71. package/lib/singleton/Interactions/types.js +4 -0
  72. package/lib/singleton/Notifications/PushNotification/types.d.ts +2 -0
  73. package/lib/singleton/Notifications/PushNotification/types.js +4 -0
  74. package/lib/singleton/Notifications/types.d.ts +3 -1
  75. package/lib/singleton/types.d.ts +3 -3
  76. package/lib/storage/CookieStorage.js +8 -5
  77. package/lib/storage/DefaultStorage.js +1 -1
  78. package/lib/storage/utils.d.ts +1 -1
  79. package/lib/storage/utils.js +3 -3
  80. package/lib/tsconfig.tsbuildinfo +1 -1
  81. package/lib/types/errors.d.ts +1 -0
  82. package/lib/types/errors.js +1 -0
  83. package/lib/utils/amplifyUrl/index.d.ts +13 -0
  84. package/lib/utils/amplifyUrl/index.js +10 -0
  85. package/lib/utils/amplifyUrl/polyfill.d.ts +0 -0
  86. package/lib/utils/amplifyUrl/polyfill.js +4 -0
  87. package/lib/utils/amplifyUrl/polyfill.native.d.ts +1 -0
  88. package/lib/utils/amplifyUuid/index.d.ts +3 -0
  89. package/lib/utils/amplifyUuid/index.js +9 -0
  90. package/lib/utils/amplifyUuid/polyfill.d.ts +0 -0
  91. package/lib/utils/amplifyUuid/polyfill.js +4 -0
  92. package/lib/utils/amplifyUuid/polyfill.native.d.ts +1 -0
  93. package/lib/utils/amplifyUuid/polyfill.native.js +6 -0
  94. package/lib/utils/deepFreeze.d.ts +1 -0
  95. package/lib/utils/deepFreeze.js +38 -0
  96. package/lib/{ClientDevice/android.d.ts → utils/getClientInfo/getClientInfo.android.d.ts} +1 -1
  97. package/lib/{ClientDevice/android.js → utils/getClientInfo/getClientInfo.android.js} +4 -4
  98. package/lib/{ClientDevice/browser.d.ts → utils/getClientInfo/getClientInfo.d.ts} +1 -9
  99. package/lib/{ClientDevice/ios.d.ts → utils/getClientInfo/getClientInfo.ios.d.ts} +1 -1
  100. package/lib/{ClientDevice/ios.js → utils/getClientInfo/getClientInfo.ios.js} +4 -4
  101. package/lib/{ClientDevice/browser.js → utils/getClientInfo/getClientInfo.js} +6 -18
  102. package/lib/utils/getClientInfo/index.d.ts +1 -0
  103. package/lib/utils/getClientInfo/index.js +7 -0
  104. package/lib/utils/index.d.ts +2 -0
  105. package/lib/utils/index.js +5 -1
  106. package/lib/utils/sessionListener/SessionListener.d.ts +10 -0
  107. package/lib/utils/sessionListener/SessionListener.js +55 -0
  108. package/lib/utils/sessionListener/SessionListener.native.d.ts +10 -0
  109. package/lib/utils/sessionListener/SessionListener.native.js +54 -0
  110. package/lib/utils/sessionListener/index.d.ts +2 -0
  111. package/lib/utils/sessionListener/index.js +7 -0
  112. package/lib/utils/sessionListener/types.d.ts +6 -0
  113. package/lib/utils/sessionListener/types.js +4 -0
  114. package/lib-esm/Cache/StorageCache.d.ts +14 -31
  115. package/lib-esm/Cache/StorageCache.js +97 -102
  116. package/lib-esm/Cache/StorageCache.native.d.ts +19 -0
  117. package/lib-esm/Cache/StorageCache.native.js +161 -0
  118. package/{lib/Cache/AsyncStorageCache.d.ts → lib-esm/Cache/StorageCacheCommon.d.ts} +124 -99
  119. package/lib-esm/Cache/{AsyncStorageCache.js → StorageCacheCommon.js} +493 -430
  120. package/lib-esm/Cache/constants.d.ts +6 -0
  121. package/lib-esm/Cache/constants.js +14 -0
  122. package/lib-esm/Cache/index.d.ts +2 -0
  123. package/lib-esm/Cache/index.js +4 -0
  124. package/lib-esm/Cache/types/cache.d.ts +38 -0
  125. package/lib-esm/Cache/types/index.d.ts +1 -1
  126. package/lib-esm/Cache/types/index.js +1 -1
  127. package/lib-esm/Cache/{Utils → utils}/CacheList.d.ts +1 -1
  128. package/lib-esm/Cache/{Utils → utils}/CacheList.js +1 -1
  129. package/lib-esm/Cache/utils/cacheHelpers.d.ts +14 -0
  130. package/lib-esm/Cache/utils/cacheHelpers.js +44 -0
  131. package/lib-esm/Cache/{Utils → utils}/errorHelpers.d.ts +0 -1
  132. package/lib-esm/Cache/{Utils → utils}/errorHelpers.js +0 -4
  133. package/lib-esm/Cache/utils/index.d.ts +2 -0
  134. package/lib-esm/Cache/utils/index.js +4 -0
  135. package/lib-esm/I18n/I18n.js +1 -6
  136. package/lib-esm/Platform/types.d.ts +18 -8
  137. package/lib-esm/Platform/types.js +10 -2
  138. package/lib-esm/Platform/version.d.ts +1 -1
  139. package/lib-esm/Platform/version.js +1 -1
  140. package/lib-esm/Reachability/Reachability.d.ts +1 -0
  141. package/lib-esm/Reachability/Reachability.js +43 -2
  142. package/lib-esm/ServiceWorker/ServiceWorker.js +69 -17
  143. package/lib-esm/ServiceWorker/index.d.ts +0 -12
  144. package/lib-esm/ServiceWorker/index.js +0 -12
  145. package/lib-esm/Signer/Signer.js +3 -2
  146. package/lib-esm/awsClients/cognitoIdentity/base.js +2 -1
  147. package/lib-esm/awsClients/pinpoint/base.js +2 -1
  148. package/lib-esm/awsClients/pinpoint/getInAppMessages.js +2 -1
  149. package/lib-esm/awsClients/pinpoint/putEvents.js +2 -1
  150. package/lib-esm/awsClients/pinpoint/updateEndpoint.js +2 -1
  151. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.d.ts +0 -1
  152. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.js +0 -1
  153. package/lib-esm/clients/middleware/signing/signer/signatureV4/presignUrl.js +2 -1
  154. package/lib-esm/errors/errorHelpers.d.ts +2 -0
  155. package/lib-esm/errors/errorHelpers.js +17 -0
  156. package/lib-esm/errors/index.d.ts +1 -0
  157. package/lib-esm/errors/index.js +1 -0
  158. package/lib-esm/index.d.ts +4 -4
  159. package/lib-esm/index.js +5 -4
  160. package/lib-esm/libraryUtils.d.ts +8 -7
  161. package/lib-esm/libraryUtils.js +7 -7
  162. package/lib-esm/parseAWSExports.js +34 -19
  163. package/lib-esm/providers/pinpoint/apis/flushEvents.d.ts +2 -2
  164. package/lib-esm/providers/pinpoint/apis/record.d.ts +1 -1
  165. package/lib-esm/providers/pinpoint/apis/record.js +9 -25
  166. package/lib-esm/providers/pinpoint/apis/updateEndpoint.js +6 -6
  167. package/lib-esm/providers/pinpoint/index.d.ts +2 -2
  168. package/lib-esm/providers/pinpoint/index.js +2 -1
  169. package/lib-esm/providers/pinpoint/types/errors.d.ts +9 -0
  170. package/lib-esm/providers/pinpoint/types/errors.js +12 -0
  171. package/lib-esm/providers/pinpoint/types/index.d.ts +1 -0
  172. package/lib-esm/providers/pinpoint/types/index.js +1 -0
  173. package/lib-esm/providers/pinpoint/types/pinpoint.d.ts +3 -3
  174. package/lib-esm/providers/pinpoint/utils/index.d.ts +1 -0
  175. package/lib-esm/providers/pinpoint/utils/index.js +1 -0
  176. package/lib-esm/providers/pinpoint/utils/resolveEndpointId.d.ts +8 -0
  177. package/lib-esm/providers/pinpoint/utils/resolveEndpointId.js +81 -0
  178. package/lib-esm/singleton/Amplify.d.ts +2 -2
  179. package/lib-esm/singleton/Amplify.js +6 -5
  180. package/lib-esm/singleton/Auth/types.d.ts +3 -3
  181. package/lib-esm/singleton/Cache/types.d.ts +18 -0
  182. package/lib-esm/singleton/Cache/types.js +3 -0
  183. package/lib-esm/singleton/Interactions/types.d.ts +21 -0
  184. package/lib-esm/singleton/Interactions/types.js +3 -0
  185. package/lib-esm/singleton/Notifications/PushNotification/types.d.ts +2 -0
  186. package/lib-esm/singleton/Notifications/PushNotification/types.js +3 -0
  187. package/lib-esm/singleton/Notifications/types.d.ts +3 -1
  188. package/lib-esm/singleton/types.d.ts +3 -3
  189. package/lib-esm/storage/CookieStorage.js +5 -5
  190. package/lib-esm/storage/DefaultStorage.js +2 -2
  191. package/lib-esm/storage/utils.d.ts +1 -1
  192. package/lib-esm/storage/utils.js +1 -1
  193. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  194. package/lib-esm/types/errors.d.ts +1 -0
  195. package/lib-esm/types/errors.js +1 -0
  196. package/lib-esm/utils/amplifyUrl/index.d.ts +13 -0
  197. package/lib-esm/utils/amplifyUrl/index.js +6 -0
  198. package/lib-esm/utils/amplifyUuid/index.d.ts +3 -0
  199. package/lib-esm/utils/amplifyUuid/index.js +6 -0
  200. package/lib-esm/utils/amplifyUuid/polyfill.native.js +4 -0
  201. package/lib-esm/utils/deepFreeze.d.ts +1 -0
  202. package/lib-esm/utils/deepFreeze.js +34 -0
  203. package/lib-esm/{ClientDevice/android.d.ts → utils/getClientInfo/getClientInfo.android.d.ts} +1 -1
  204. package/lib-esm/{ClientDevice/android.js → utils/getClientInfo/getClientInfo.android.js} +2 -2
  205. package/lib-esm/{ClientDevice/browser.d.ts → utils/getClientInfo/getClientInfo.d.ts} +1 -9
  206. package/lib-esm/{ClientDevice/ios.d.ts → utils/getClientInfo/getClientInfo.ios.d.ts} +1 -1
  207. package/lib-esm/{ClientDevice/ios.js → utils/getClientInfo/getClientInfo.ios.js} +2 -2
  208. package/lib-esm/{ClientDevice/browser.js → utils/getClientInfo/getClientInfo.js} +4 -14
  209. package/lib-esm/utils/getClientInfo/index.d.ts +1 -0
  210. package/lib-esm/utils/getClientInfo/index.js +3 -0
  211. package/lib-esm/utils/index.d.ts +2 -0
  212. package/lib-esm/utils/index.js +2 -0
  213. package/lib-esm/utils/sessionListener/SessionListener.d.ts +10 -0
  214. package/lib-esm/utils/sessionListener/SessionListener.js +52 -0
  215. package/lib-esm/utils/sessionListener/SessionListener.native.d.ts +10 -0
  216. package/lib-esm/utils/sessionListener/SessionListener.native.js +51 -0
  217. package/lib-esm/utils/sessionListener/index.d.ts +2 -0
  218. package/lib-esm/utils/sessionListener/index.js +4 -0
  219. package/lib-esm/utils/sessionListener/types.d.ts +6 -0
  220. package/lib-esm/utils/sessionListener/types.js +3 -0
  221. package/package.json +9 -19
  222. package/src/Cache/StorageCache.native.ts +65 -0
  223. package/src/Cache/StorageCache.ts +61 -158
  224. package/src/Cache/StorageCacheCommon.ts +577 -0
  225. package/src/Cache/constants.ts +18 -0
  226. package/src/Cache/index.ts +6 -0
  227. package/src/Cache/types/cache.ts +51 -0
  228. package/src/Cache/types/index.ts +4 -4
  229. package/src/Cache/{Utils → utils}/CacheList.ts +185 -185
  230. package/src/Cache/utils/cacheHelpers.ts +52 -0
  231. package/src/Cache/{Utils → utils}/errorHelpers.ts +0 -4
  232. package/src/Cache/{Utils → utils}/index.ts +4 -5
  233. package/src/I18n/I18n.ts +1 -6
  234. package/src/Platform/types.ts +20 -11
  235. package/src/Platform/version.ts +1 -1
  236. package/src/Reachability/Reachability.ts +22 -2
  237. package/src/ServiceWorker/ServiceWorker.ts +20 -17
  238. package/src/ServiceWorker/index.ts +0 -12
  239. package/src/Signer/Signer.ts +3 -2
  240. package/src/awsClients/cognitoIdentity/base.ts +4 -1
  241. package/src/awsClients/pinpoint/base.ts +2 -1
  242. package/src/awsClients/pinpoint/getInAppMessages.ts +2 -1
  243. package/src/awsClients/pinpoint/putEvents.ts +2 -1
  244. package/src/awsClients/pinpoint/updateEndpoint.ts +2 -1
  245. package/src/clients/middleware/signing/signer/signatureV4/index.ts +0 -2
  246. package/src/clients/middleware/signing/signer/signatureV4/presignUrl.ts +2 -1
  247. package/src/errors/errorHelpers.ts +20 -0
  248. package/src/errors/index.ts +1 -0
  249. package/src/index.ts +8 -4
  250. package/src/libraryUtils.ts +17 -11
  251. package/src/parseAWSExports.ts +28 -9
  252. package/src/providers/pinpoint/apis/flushEvents.ts +2 -2
  253. package/src/providers/pinpoint/apis/record.ts +14 -28
  254. package/src/providers/pinpoint/apis/updateEndpoint.ts +6 -6
  255. package/src/providers/pinpoint/index.ts +6 -2
  256. package/src/providers/pinpoint/types/errors.ts +12 -0
  257. package/src/providers/pinpoint/types/index.ts +1 -0
  258. package/src/providers/pinpoint/types/pinpoint.ts +3 -2
  259. package/src/providers/pinpoint/utils/index.ts +1 -0
  260. package/src/providers/pinpoint/utils/resolveEndpointId.ts +46 -0
  261. package/src/singleton/Amplify.ts +10 -8
  262. package/src/singleton/Auth/types.ts +3 -3
  263. package/src/singleton/Cache/types.ts +27 -0
  264. package/src/singleton/Interactions/types.ts +29 -0
  265. package/src/singleton/Notifications/PushNotification/types.ts +6 -0
  266. package/src/singleton/Notifications/types.ts +3 -1
  267. package/src/singleton/types.ts +3 -5
  268. package/src/storage/CookieStorage.ts +5 -9
  269. package/src/storage/DefaultStorage.ts +2 -2
  270. package/src/storage/utils.ts +1 -1
  271. package/src/types/errors.ts +1 -0
  272. package/src/utils/amplifyUrl/index.ts +9 -0
  273. package/src/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.ts → utils/amplifyUrl/polyfill.native.ts} +1 -0
  274. package/src/utils/amplifyUuid/index.ts +9 -0
  275. package/src/utils/amplifyUuid/polyfill.native.ts +6 -0
  276. package/src/utils/amplifyUuid/polyfill.ts +4 -0
  277. package/src/utils/deepFreeze.ts +16 -0
  278. package/src/{ClientDevice/android.ts → utils/getClientInfo/getClientInfo.android.ts} +2 -2
  279. package/src/{ClientDevice/ios.ts → utils/getClientInfo/getClientInfo.ios.ts} +3 -3
  280. package/src/{ClientDevice/browser.ts → utils/getClientInfo/getClientInfo.ts} +4 -16
  281. package/src/utils/getClientInfo/index.ts +4 -0
  282. package/src/utils/index.ts +2 -0
  283. package/src/utils/sessionListener/SessionListener.native.ts +70 -0
  284. package/src/utils/sessionListener/SessionListener.ts +74 -0
  285. package/src/utils/sessionListener/index.ts +6 -0
  286. package/src/utils/sessionListener/types.ts +11 -0
  287. package/lib/Amplify.d.ts +0 -29
  288. package/lib/Amplify.js +0 -118
  289. package/lib/Cache/BrowserStorageCache.d.ts +0 -166
  290. package/lib/Cache/BrowserStorageCache.js +0 -456
  291. package/lib/Cache/InMemoryCache.d.ts +0 -129
  292. package/lib/Cache/InMemoryCache.js +0 -342
  293. package/lib/Cache/Utils/CacheUtils.d.ts +0 -25
  294. package/lib/Cache/Utils/CacheUtils.js +0 -86
  295. package/lib/Cache/Utils/index.d.ts +0 -2
  296. package/lib/Cache/Utils/index.js +0 -16
  297. package/lib/Cache/reactnative.d.ts +0 -3
  298. package/lib/Cache/reactnative.js +0 -8
  299. package/lib/Cache/types/Cache.d.ts +0 -55
  300. package/lib/ClientDevice/index.d.ts +0 -23
  301. package/lib/ClientDevice/index.js +0 -18
  302. package/lib/ClientDevice/reactnative.d.ts +0 -7
  303. package/lib/ClientDevice/reactnative.js +0 -24
  304. package/lib-esm/Amplify.d.ts +0 -29
  305. package/lib-esm/Amplify.js +0 -115
  306. package/lib-esm/Cache/BrowserStorageCache.d.ts +0 -166
  307. package/lib-esm/Cache/BrowserStorageCache.js +0 -453
  308. package/lib-esm/Cache/InMemoryCache.d.ts +0 -129
  309. package/lib-esm/Cache/InMemoryCache.js +0 -339
  310. package/lib-esm/Cache/Utils/CacheUtils.d.ts +0 -25
  311. package/lib-esm/Cache/Utils/CacheUtils.js +0 -79
  312. package/lib-esm/Cache/Utils/index.d.ts +0 -2
  313. package/lib-esm/Cache/Utils/index.js +0 -4
  314. package/lib-esm/Cache/reactnative.d.ts +0 -3
  315. package/lib-esm/Cache/reactnative.js +0 -6
  316. package/lib-esm/Cache/types/Cache.d.ts +0 -55
  317. package/lib-esm/ClientDevice/index.d.ts +0 -23
  318. package/lib-esm/ClientDevice/index.js +0 -15
  319. package/lib-esm/ClientDevice/reactnative.d.ts +0 -7
  320. package/lib-esm/ClientDevice/reactnative.js +0 -21
  321. package/src/Amplify.ts +0 -106
  322. package/src/Cache/AsyncStorageCache.ts +0 -495
  323. package/src/Cache/BrowserStorageCache.ts +0 -504
  324. package/src/Cache/CHANGELOG.md +0 -1239
  325. package/src/Cache/InMemoryCache.ts +0 -347
  326. package/src/Cache/Utils/CacheUtils.ts +0 -90
  327. package/src/Cache/reactnative.ts +0 -9
  328. package/src/Cache/types/Cache.ts +0 -75
  329. package/src/ClientDevice/index.ts +0 -14
  330. package/src/ClientDevice/reactnative.ts +0 -18
  331. package/lib/Cache/types/{Cache.js → cache.js} +0 -0
  332. package/lib/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.js → utils/amplifyUrl/polyfill.native.js} +1 -1
  333. /package/lib-esm/Cache/types/{Cache.js → cache.js} +0 -0
  334. /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.d.ts → utils/amplifyUrl/polyfill.d.ts} +0 -0
  335. /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.js → utils/amplifyUrl/polyfill.js} +0 -0
  336. /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.d.ts → utils/amplifyUrl/polyfill.native.d.ts} +0 -0
  337. /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.js → utils/amplifyUrl/polyfill.native.js} +0 -0
  338. /package/{lib/clients/middleware/signing/signer/signatureV4/polyfills/index.d.ts → lib-esm/utils/amplifyUuid/polyfill.d.ts} +0 -0
  339. /package/{lib/clients/middleware/signing/signer/signatureV4/polyfills/index.js → lib-esm/utils/amplifyUuid/polyfill.js} +0 -0
  340. /package/{lib/clients/middleware/signing/signer/signatureV4/polyfills/index.native.d.ts → lib-esm/utils/amplifyUuid/polyfill.native.d.ts} +0 -0
  341. /package/src/{clients/middleware/signing/signer/signatureV4/polyfills/index.ts → utils/amplifyUrl/polyfill.ts} +0 -0
@@ -0,0 +1,577 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ConsoleLogger as Logger } from '../Logger';
5
+ import { KeyValueStorageInterface } from '../types';
6
+ import { currentSizeKey, defaultConfig } from './constants';
7
+ import { CacheConfig, CacheItem, CacheItemOptions } from './types';
8
+ import { getCurrentSizeKey, getCurrentTime, getByteLength } from './utils';
9
+ import { assert, CacheErrorCode } from './utils/errorHelpers';
10
+
11
+ const logger = new Logger('StorageCache');
12
+
13
+ /**
14
+ * Initialization of the cache
15
+ *
16
+ */
17
+ export abstract class StorageCacheCommon {
18
+ protected config: CacheConfig;
19
+ protected keyValueStorage: KeyValueStorageInterface;
20
+
21
+ /**
22
+ * Initialize the cache
23
+ *
24
+ * @param config - Custom configuration for this instance.
25
+ */
26
+ constructor({
27
+ config,
28
+ keyValueStorage,
29
+ }: {
30
+ config?: CacheConfig;
31
+ keyValueStorage: KeyValueStorageInterface;
32
+ }) {
33
+ this.config = {
34
+ ...defaultConfig,
35
+ ...config,
36
+ };
37
+ this.keyValueStorage = keyValueStorage;
38
+
39
+ this.sanitizeConfig();
40
+ }
41
+
42
+ protected abstract getAllCacheKeys(options?: {
43
+ omitSizeKey?: boolean;
44
+ }): Promise<string[]>;
45
+
46
+ public getModuleName() {
47
+ return 'Cache';
48
+ }
49
+
50
+ /**
51
+ * Set custom configuration for the cache instance.
52
+ *
53
+ * @param config - customized configuration (without keyPrefix, which can't be changed)
54
+ *
55
+ * @return - the current configuration
56
+ */
57
+ public configure(config?: Omit<CacheConfig, 'keyPrefix'>): CacheConfig {
58
+ if (config) {
59
+ if ((config as CacheConfig).keyPrefix) {
60
+ logger.warn(
61
+ 'keyPrefix can not be re-configured on an existing Cache instance.'
62
+ );
63
+ }
64
+
65
+ this.config = {
66
+ ...this.config,
67
+ ...config,
68
+ };
69
+ }
70
+
71
+ this.sanitizeConfig();
72
+
73
+ return this.config;
74
+ }
75
+
76
+ /**
77
+ * return the current size of the cache
78
+ * @return {Promise}
79
+ */
80
+ public async getCurrentCacheSize() {
81
+ let size = await this.getStorage().getItem(
82
+ getCurrentSizeKey(this.config.keyPrefix)
83
+ );
84
+ if (!size) {
85
+ await this.getStorage().setItem(
86
+ getCurrentSizeKey(this.config.keyPrefix),
87
+ '0'
88
+ );
89
+ size = '0';
90
+ }
91
+ return Number(size);
92
+ }
93
+
94
+ /**
95
+ * Set item into cache. You can put number, string, boolean or object.
96
+ * The cache will first check whether has the same key.
97
+ * If it has, it will delete the old item and then put the new item in
98
+ * The cache will pop out items if it is full
99
+ * You can specify the cache item options. The cache will abort and output a warning:
100
+ * If the key is invalid
101
+ * If the size of the item exceeds itemMaxSize.
102
+ * If the value is undefined
103
+ * If incorrect cache item configuration
104
+ * If error happened with browser storage
105
+ *
106
+ * @param {String} key - the key of the item
107
+ * @param {Object} value - the value of the item
108
+ * @param {Object} [options] - optional, the specified meta-data
109
+ *
110
+ * @return {Promise}
111
+ */
112
+ public async setItem(
113
+ key: string,
114
+ value: any,
115
+ options?: Record<string, any>
116
+ ): Promise<void> {
117
+ logger.debug(
118
+ `Set item: key is ${key}, value is ${value} with options: ${options}`
119
+ );
120
+
121
+ if (!key || key === currentSizeKey) {
122
+ logger.warn(
123
+ `Invalid key: should not be empty or reserved key: '${currentSizeKey}'`
124
+ );
125
+ return;
126
+ }
127
+
128
+ if (typeof value === 'undefined') {
129
+ logger.warn(`The value of item should not be undefined!`);
130
+ return;
131
+ }
132
+
133
+ const cacheItemOptions = {
134
+ priority:
135
+ options?.priority !== undefined
136
+ ? options.priority
137
+ : this.config.defaultPriority,
138
+ expires:
139
+ options?.expires !== undefined
140
+ ? options.expires
141
+ : this.config.defaultTTL + getCurrentTime(),
142
+ };
143
+
144
+ if (cacheItemOptions.priority < 1 || cacheItemOptions.priority > 5) {
145
+ logger.warn(
146
+ `Invalid parameter: priority due to out or range. It should be within 1 and 5.`
147
+ );
148
+ return;
149
+ }
150
+
151
+ const prefixedKey = `${this.config.keyPrefix}${key}`;
152
+ const item = this.fillCacheItem(prefixedKey, value, cacheItemOptions);
153
+
154
+ // check whether this item is too big;
155
+ if (item.byteSize > this.config.itemMaxSize) {
156
+ logger.warn(
157
+ `Item with key: ${key} you are trying to put into is too big!`
158
+ );
159
+ return;
160
+ }
161
+
162
+ try {
163
+ // first look into the storage, if it exists, delete it.
164
+ const val = await this.getStorage().getItem(prefixedKey);
165
+ if (val) {
166
+ await this.removeCacheItem(prefixedKey, JSON.parse(val).byteSize);
167
+ }
168
+
169
+ // check whether the cache is full
170
+ if (await this.isCacheFull(item.byteSize)) {
171
+ const validKeys = await this.clearInvalidAndGetRemainingKeys();
172
+ if (await this.isCacheFull(item.byteSize)) {
173
+ const sizeToPop = await this.sizeToPop(item.byteSize);
174
+ await this.popOutItems(validKeys, sizeToPop);
175
+ }
176
+ }
177
+ // put item in the cache
178
+ return this.setCacheItem(prefixedKey, item);
179
+ } catch (e) {
180
+ logger.warn(`setItem failed! ${e}`);
181
+ }
182
+ }
183
+
184
+ /**
185
+ * Get item from cache. It will return null if item doesn’t exist or it has been expired.
186
+ * If you specified callback function in the options,
187
+ * then the function will be executed if no such item in the cache
188
+ * and finally put the return value into cache.
189
+ * Please make sure the callback function will return the value you want to put into the cache.
190
+ * The cache will abort output a warning:
191
+ * If the key is invalid
192
+ * If error happened with AsyncStorage
193
+ *
194
+ * @param {String} key - the key of the item
195
+ * @param {Object} [options] - the options of callback function
196
+ *
197
+ * @return {Promise} - return a promise resolves to be the value of the item
198
+ */
199
+ public async getItem(
200
+ key: string,
201
+ options?: CacheItemOptions
202
+ ): Promise<CacheItem['data']> {
203
+ logger.debug(`Get item: key is ${key} with options ${options}`);
204
+ let cached;
205
+
206
+ if (!key || key === currentSizeKey) {
207
+ logger.warn(
208
+ `Invalid key: should not be empty or reserved key: '${currentSizeKey}'`
209
+ );
210
+ return null;
211
+ }
212
+
213
+ const prefixedKey = `${this.config.keyPrefix}${key}`;
214
+
215
+ try {
216
+ cached = await this.getStorage().getItem(prefixedKey);
217
+ if (cached != null) {
218
+ if (await this.isExpired(prefixedKey)) {
219
+ // if expired, remove that item and return null
220
+ await this.removeCacheItem(prefixedKey, JSON.parse(cached).byteSize);
221
+ } else {
222
+ // if not expired, update its visitedTime and return the value
223
+ const item = await this.updateVisitedTime(
224
+ JSON.parse(cached),
225
+ prefixedKey
226
+ );
227
+ return item.data;
228
+ }
229
+ }
230
+
231
+ if (options?.callback) {
232
+ const val = options.callback();
233
+ if (val !== null) {
234
+ await this.setItem(key, val, options);
235
+ }
236
+ return val;
237
+ }
238
+ return null;
239
+ } catch (e) {
240
+ logger.warn(`getItem failed! ${e}`);
241
+ return null;
242
+ }
243
+ }
244
+
245
+ /**
246
+ * remove item from the cache
247
+ * The cache will abort output a warning:
248
+ * If error happened with AsyncStorage
249
+ * @param {String} key - the key of the item
250
+ * @return {Promise}
251
+ */
252
+ public async removeItem(key: string): Promise<void> {
253
+ logger.debug(`Remove item: key is ${key}`);
254
+
255
+ if (!key || key === currentSizeKey) {
256
+ logger.warn(
257
+ `Invalid key: should not be empty or reserved key: '${currentSizeKey}'`
258
+ );
259
+ return;
260
+ }
261
+
262
+ const prefixedKey = `${this.config.keyPrefix}${key}`;
263
+
264
+ try {
265
+ const val = await this.getStorage().getItem(prefixedKey);
266
+ if (val) {
267
+ await this.removeCacheItem(prefixedKey, JSON.parse(val).byteSize);
268
+ }
269
+ } catch (e) {
270
+ logger.warn(`removeItem failed! ${e}`);
271
+ }
272
+ }
273
+
274
+ /**
275
+ * Return all the keys owned by this cache.
276
+ * Will return an empty array if error occurred.
277
+ *
278
+ * @return {Promise}
279
+ */
280
+ public async getAllKeys() {
281
+ try {
282
+ return await this.getAllCacheKeys();
283
+ } catch (e) {
284
+ logger.warn(`getAllkeys failed! ${e}`);
285
+ return [];
286
+ }
287
+ }
288
+
289
+ protected getStorage(): KeyValueStorageInterface {
290
+ return this.keyValueStorage;
291
+ }
292
+
293
+ /**
294
+ * check whether item is expired
295
+ *
296
+ * @param key - the key of the item
297
+ *
298
+ * @return true if the item is expired.
299
+ */
300
+ protected async isExpired(key: string): Promise<boolean> {
301
+ const text = await this.getStorage().getItem(key);
302
+ assert(text !== null, CacheErrorCode.NoCacheItem, `Key: ${key}`);
303
+ const item: CacheItem = JSON.parse(text);
304
+ if (getCurrentTime() >= item.expires) {
305
+ return true;
306
+ }
307
+ return false;
308
+ }
309
+
310
+ /**
311
+ * delete item from cache
312
+ *
313
+ * @param prefixedKey - the key of the item
314
+ * @param size - optional, the byte size of the item
315
+ */
316
+ protected async removeCacheItem(
317
+ prefixedKey: string,
318
+ size?: number
319
+ ): Promise<void> {
320
+ const item = await this.getStorage().getItem(prefixedKey);
321
+ assert(item !== null, CacheErrorCode.NoCacheItem, `Key: ${prefixedKey}`);
322
+ const itemSize: number = size ?? JSON.parse(item).byteSize;
323
+ // first try to update the current size of the cache
324
+ await this.decreaseCurrentSizeInBytes(itemSize);
325
+
326
+ // try to remove the item from cache
327
+ try {
328
+ await this.getStorage().removeItem(prefixedKey);
329
+ } catch (removeItemError) {
330
+ // if some error happened, we need to rollback the current size
331
+ await this.increaseCurrentSizeInBytes(itemSize);
332
+ logger.error(`Failed to remove item: ${removeItemError}`);
333
+ }
334
+ }
335
+
336
+ /**
337
+ * produce a JSON object with meta-data and data value
338
+ * @param value - the value of the item
339
+ * @param options - optional, the specified meta-data
340
+ *
341
+ * @return - the item which has the meta-data and the value
342
+ */
343
+ protected fillCacheItem(
344
+ key: string,
345
+ value: object | number | string | boolean,
346
+ options: CacheItemOptions
347
+ ): CacheItem {
348
+ const item: CacheItem = {
349
+ key,
350
+ data: value,
351
+ timestamp: getCurrentTime(),
352
+ visitedTime: getCurrentTime(),
353
+ priority: options.priority ?? 0,
354
+ expires: options.expires ?? 0,
355
+ type: typeof value,
356
+ byteSize: 0,
357
+ };
358
+ // calculate byte size
359
+ item.byteSize = getByteLength(JSON.stringify(item));
360
+ // re-calculate using cache item with updated byteSize property
361
+ item.byteSize = getByteLength(JSON.stringify(item));
362
+ return item;
363
+ }
364
+
365
+ private sanitizeConfig(): void {
366
+ if (this.config.itemMaxSize > this.config.capacityInBytes) {
367
+ logger.error(
368
+ 'Invalid parameter: itemMaxSize. It should be smaller than capacityInBytes. Setting back to default.'
369
+ );
370
+ this.config.itemMaxSize = defaultConfig.itemMaxSize;
371
+ }
372
+
373
+ if (this.config.defaultPriority > 5 || this.config.defaultPriority < 1) {
374
+ logger.error(
375
+ 'Invalid parameter: defaultPriority. It should be between 1 and 5. Setting back to default.'
376
+ );
377
+ this.config.defaultPriority = defaultConfig.defaultPriority;
378
+ }
379
+
380
+ if (
381
+ Number(this.config.warningThreshold) > 1 ||
382
+ Number(this.config.warningThreshold) < 0
383
+ ) {
384
+ logger.error(
385
+ 'Invalid parameter: warningThreshold. It should be between 0 and 1. Setting back to default.'
386
+ );
387
+ this.config.warningThreshold = defaultConfig.warningThreshold;
388
+ }
389
+
390
+ // Set 5MB limit
391
+ const cacheLimit: number = 5 * 1024 * 1024;
392
+ if (this.config.capacityInBytes > cacheLimit) {
393
+ logger.error(
394
+ 'Cache Capacity should be less than 5MB. Setting back to default. Setting back to default.'
395
+ );
396
+ this.config.capacityInBytes = defaultConfig.capacityInBytes;
397
+ }
398
+ }
399
+
400
+ /**
401
+ * increase current size of the cache
402
+ *
403
+ * @param amount - the amount of the cache szie which need to be increased
404
+ */
405
+ private async increaseCurrentSizeInBytes(amount: number): Promise<void> {
406
+ const size = await this.getCurrentCacheSize();
407
+ await this.getStorage().setItem(
408
+ getCurrentSizeKey(this.config.keyPrefix),
409
+ (size + amount).toString()
410
+ );
411
+ }
412
+
413
+ /**
414
+ * decrease current size of the cache
415
+ *
416
+ * @param amount - the amount of the cache size which needs to be decreased
417
+ */
418
+ private async decreaseCurrentSizeInBytes(amount: number): Promise<void> {
419
+ const size = await this.getCurrentCacheSize();
420
+ await this.getStorage().setItem(
421
+ getCurrentSizeKey(this.config.keyPrefix),
422
+ (size - amount).toString()
423
+ );
424
+ }
425
+
426
+ /**
427
+ * update the visited time if item has been visited
428
+ *
429
+ * @param item - the item which need to be updated
430
+ * @param prefixedKey - the key of the item
431
+ *
432
+ * @return the updated item
433
+ */
434
+ private async updateVisitedTime(
435
+ item: CacheItem,
436
+ prefixedKey: string
437
+ ): Promise<CacheItem> {
438
+ item.visitedTime = getCurrentTime();
439
+ await this.getStorage().setItem(prefixedKey, JSON.stringify(item));
440
+ return item;
441
+ }
442
+
443
+ /**
444
+ * put item into cache
445
+ *
446
+ * @param prefixedKey - the key of the item
447
+ * @param itemData - the value of the item
448
+ * @param itemSizeInBytes - the byte size of the item
449
+ */
450
+ private async setCacheItem(
451
+ prefixedKey: string,
452
+ item: CacheItem
453
+ ): Promise<void> {
454
+ // first try to update the current size of the cache.
455
+ await this.increaseCurrentSizeInBytes(item.byteSize);
456
+
457
+ // try to add the item into cache
458
+ try {
459
+ await this.getStorage().setItem(prefixedKey, JSON.stringify(item));
460
+ } catch (setItemErr) {
461
+ // if some error happened, we need to rollback the current size
462
+ await this.decreaseCurrentSizeInBytes(item.byteSize);
463
+ logger.error(`Failed to set item ${setItemErr}`);
464
+ }
465
+ }
466
+
467
+ /**
468
+ * total space needed when poping out items
469
+ *
470
+ * @param itemSize
471
+ *
472
+ * @return total space needed
473
+ */
474
+ private async sizeToPop(itemSize: number): Promise<number> {
475
+ const cur = await this.getCurrentCacheSize();
476
+ const spaceItemNeed = cur + itemSize - this.config.capacityInBytes;
477
+ const cacheThresholdSpace =
478
+ (1 - this.config.warningThreshold) * this.config.capacityInBytes;
479
+ return spaceItemNeed > cacheThresholdSpace
480
+ ? spaceItemNeed
481
+ : cacheThresholdSpace;
482
+ }
483
+
484
+ /**
485
+ * see whether cache is full
486
+ *
487
+ * @param itemSize
488
+ *
489
+ * @return true if cache is full
490
+ */
491
+ private async isCacheFull(itemSize: number): Promise<boolean> {
492
+ const cur = await this.getCurrentCacheSize();
493
+ return itemSize + cur > this.config.capacityInBytes;
494
+ }
495
+
496
+ /**
497
+ * get all the items we have, sort them by their priority,
498
+ * if priority is same, sort them by their last visited time
499
+ * pop out items from the low priority (5 is the lowest)
500
+ * @private
501
+ * @param keys - all the keys in this cache
502
+ * @param sizeToPop - the total size of the items which needed to be poped out
503
+ */
504
+ private async popOutItems(keys: string[], sizeToPop: number): Promise<void> {
505
+ const items: any[] = [];
506
+ let remainedSize = sizeToPop;
507
+ for (let i = 0; i < keys.length; i += 1) {
508
+ const val = await this.getStorage().getItem(keys[i]);
509
+ if (val != null) {
510
+ const item = JSON.parse(val);
511
+ items.push(item);
512
+ }
513
+ }
514
+
515
+ // first compare priority
516
+ // then compare visited time
517
+ items.sort((a, b) => {
518
+ if (a.priority > b.priority) {
519
+ return -1;
520
+ } else if (a.priority < b.priority) {
521
+ return 1;
522
+ } else {
523
+ if (a.visitedTime < b.visitedTime) {
524
+ return -1;
525
+ } else return 1;
526
+ }
527
+ });
528
+
529
+ for (let i = 0; i < items.length; i += 1) {
530
+ // pop out items until we have enough room for new item
531
+ await this.removeCacheItem(items[i].key, items[i].byteSize);
532
+ remainedSize -= items[i].byteSize;
533
+ if (remainedSize <= 0) {
534
+ return;
535
+ }
536
+ }
537
+ }
538
+
539
+ /**
540
+ * Scan the storage and combine the following operations for efficiency
541
+ * 1. Clear out all expired keys owned by this cache, not including the size key.
542
+ * 2. Return the remaining keys.
543
+ *
544
+ * @return The remaining valid keys
545
+ */
546
+ private async clearInvalidAndGetRemainingKeys(): Promise<string[]> {
547
+ const remainingKeys = [];
548
+ const keys = await this.getAllCacheKeys({
549
+ omitSizeKey: true,
550
+ });
551
+ for (const key of keys) {
552
+ if (await this.isExpired(key)) {
553
+ await this.removeCacheItem(key);
554
+ } else {
555
+ remainingKeys.push(key);
556
+ }
557
+ }
558
+ return remainingKeys;
559
+ }
560
+
561
+ /**
562
+ * clear the entire cache
563
+ * The cache will abort and output a warning if error occurs
564
+ * @return {Promise}
565
+ */
566
+ async clear() {
567
+ logger.debug(`Clear Cache`);
568
+ try {
569
+ const keys = await this.getAllKeys();
570
+ for (const key of keys) {
571
+ await this.getStorage().removeItem(key);
572
+ }
573
+ } catch (e) {
574
+ logger.warn(`clear failed! ${e}`);
575
+ }
576
+ }
577
+ }
@@ -0,0 +1,18 @@
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
+
6
+ /**
7
+ * Default cache config
8
+ */
9
+ export const defaultConfig: Omit<CacheConfig, 'storage'> = {
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
+ };
17
+
18
+ export const currentSizeKey = 'CurSize';
@@ -0,0 +1,6 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { StorageCache } from './StorageCache';
5
+
6
+ export const Cache = new StorageCache();
@@ -0,0 +1,51 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { CacheConfig } from '../../singleton/Cache/types';
5
+ export { CacheConfig };
6
+
7
+ /**
8
+ * Cache Interface
9
+ */
10
+ export interface Cache {
11
+ /** Put item into cache */
12
+ setItem(key: string, value: any, options?: CacheItemOptions): Promise<void>;
13
+
14
+ /** Get item from cache */
15
+ getItem(key: string, options?: CacheItemOptions): Promise<CacheItem['data']>;
16
+
17
+ /** Remove item from cache */
18
+ removeItem(key: string): Promise<void>;
19
+
20
+ /** Remove all items from cache */
21
+ clear(): Promise<void>;
22
+
23
+ /** Get all keys form cache */
24
+ getAllKeys(): Promise<string[]>;
25
+
26
+ /** Get current size of the cache */
27
+ getCurrentCacheSize(): Promise<number>;
28
+
29
+ /** create a new instance with customized config */
30
+ createInstance(config: CacheConfig): Cache;
31
+
32
+ /** change current configuration */
33
+ configure(config: CacheConfig): CacheConfig;
34
+ }
35
+
36
+ export interface CacheItem {
37
+ key: string;
38
+ data: any;
39
+ timestamp: number;
40
+ visitedTime: number;
41
+ priority: number;
42
+ expires: number;
43
+ type: string;
44
+ byteSize: number;
45
+ }
46
+
47
+ export interface CacheItemOptions {
48
+ priority?: number;
49
+ expires?: number;
50
+ callback?: Function;
51
+ }
@@ -1,4 +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
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ export * from './cache';