@aws-amplify/core 6.0.1-console-preview.5f040a2.0 → 6.0.1-console-preview.23dc225.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 (260) 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/Cache/{AsyncStorageCache.d.ts → StorageCacheCommon.d.ts} +124 -99
  6. package/lib/Cache/{AsyncStorageCache.js → StorageCacheCommon.js} +497 -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/Hub/index.d.ts +7 -0
  23. package/lib/Hub/index.js +8 -1
  24. package/lib/Platform/customUserAgent.d.ts +16 -0
  25. package/lib/Platform/customUserAgent.js +70 -0
  26. package/lib/Platform/index.js +10 -1
  27. package/lib/Platform/types.d.ts +33 -1
  28. package/lib/Platform/types.js +1 -0
  29. package/lib/Platform/version.d.ts +1 -1
  30. package/lib/Platform/version.js +1 -1
  31. package/lib/Reachability/Reachability.d.ts +1 -0
  32. package/lib/Reachability/Reachability.js +36 -0
  33. package/lib/Signer/Signer.js +3 -2
  34. package/lib/awsClients/cognitoIdentity/base.js +2 -1
  35. package/lib/awsClients/pinpoint/base.js +2 -1
  36. package/lib/awsClients/pinpoint/getInAppMessages.js +2 -1
  37. package/lib/awsClients/pinpoint/putEvents.js +2 -1
  38. package/lib/awsClients/pinpoint/updateEndpoint.js +2 -1
  39. package/lib/clients/middleware/signing/signer/signatureV4/index.d.ts +0 -1
  40. package/lib/clients/middleware/signing/signer/signatureV4/index.js +0 -1
  41. package/lib/clients/middleware/signing/signer/signatureV4/presignUrl.js +2 -1
  42. package/lib/index.d.ts +2 -5
  43. package/lib/index.js +3 -6
  44. package/lib/libraryUtils.d.ts +7 -5
  45. package/lib/libraryUtils.js +11 -6
  46. package/lib/parseAWSExports.js +75 -14
  47. package/lib/providers/pinpoint/apis/flushEvents.d.ts +2 -2
  48. package/lib/providers/pinpoint/apis/record.js +3 -3
  49. package/lib/providers/pinpoint/apis/updateEndpoint.js +6 -6
  50. package/lib/singleton/API/types.d.ts +4 -3
  51. package/lib/singleton/Amplify.d.ts +2 -2
  52. package/lib/singleton/Amplify.js +6 -5
  53. package/lib/singleton/Auth/types.d.ts +28 -1
  54. package/lib/singleton/Cache/types.d.ts +18 -0
  55. package/lib/singleton/Cache/types.js +4 -0
  56. package/lib/singleton/types.d.ts +3 -1
  57. package/lib/storage/DefaultStorage.js +1 -1
  58. package/lib/storage/utils.d.ts +1 -1
  59. package/lib/storage/utils.js +3 -3
  60. package/lib/tsconfig.tsbuildinfo +1 -1
  61. package/lib/utils/amplifyUrl/index.d.ts +13 -0
  62. package/lib/utils/amplifyUrl/index.js +10 -0
  63. package/lib/utils/amplifyUrl/polyfill.d.ts +0 -0
  64. package/lib/utils/amplifyUrl/polyfill.js +4 -0
  65. package/lib/utils/amplifyUrl/polyfill.native.d.ts +1 -0
  66. package/lib/utils/amplifyUuid/index.d.ts +3 -0
  67. package/lib/utils/amplifyUuid/index.js +9 -0
  68. package/lib/utils/amplifyUuid/polyfill.d.ts +0 -0
  69. package/lib/utils/amplifyUuid/polyfill.js +4 -0
  70. package/lib/utils/amplifyUuid/polyfill.native.d.ts +1 -0
  71. package/lib/utils/amplifyUuid/polyfill.native.js +6 -0
  72. package/lib/utils/deepFreeze.d.ts +1 -0
  73. package/lib/utils/deepFreeze.js +38 -0
  74. package/lib/{ClientDevice/android.d.ts → utils/getClientInfo/getClientInfo.android.d.ts} +1 -1
  75. package/lib/{ClientDevice/android.js → utils/getClientInfo/getClientInfo.android.js} +4 -4
  76. package/lib/{ClientDevice/browser.d.ts → utils/getClientInfo/getClientInfo.d.ts} +1 -9
  77. package/lib/{ClientDevice/ios.d.ts → utils/getClientInfo/getClientInfo.ios.d.ts} +1 -1
  78. package/lib/{ClientDevice/ios.js → utils/getClientInfo/getClientInfo.ios.js} +4 -4
  79. package/lib/{ClientDevice/browser.js → utils/getClientInfo/getClientInfo.js} +6 -18
  80. package/lib/utils/getClientInfo/index.d.ts +1 -0
  81. package/lib/utils/getClientInfo/index.js +7 -0
  82. package/lib/utils/index.d.ts +2 -0
  83. package/lib/utils/index.js +5 -1
  84. package/lib-esm/Cache/StorageCache.d.ts +14 -31
  85. package/lib-esm/Cache/StorageCache.js +97 -102
  86. package/lib-esm/Cache/StorageCache.native.d.ts +19 -0
  87. package/lib-esm/Cache/StorageCache.native.js +161 -0
  88. package/lib-esm/Cache/{AsyncStorageCache.d.ts → StorageCacheCommon.d.ts} +124 -99
  89. package/lib-esm/Cache/{AsyncStorageCache.js → StorageCacheCommon.js} +496 -430
  90. package/lib-esm/Cache/constants.d.ts +6 -0
  91. package/lib-esm/Cache/constants.js +14 -0
  92. package/lib-esm/Cache/index.d.ts +2 -0
  93. package/lib-esm/Cache/index.js +4 -0
  94. package/lib-esm/Cache/types/cache.d.ts +38 -0
  95. package/lib-esm/Cache/types/index.d.ts +1 -1
  96. package/lib-esm/Cache/types/index.js +1 -1
  97. package/lib-esm/Cache/{Utils → utils}/CacheList.d.ts +1 -1
  98. package/lib-esm/Cache/{Utils → utils}/CacheList.js +1 -1
  99. package/lib-esm/Cache/utils/cacheHelpers.d.ts +14 -0
  100. package/lib-esm/Cache/utils/cacheHelpers.js +44 -0
  101. package/lib-esm/Cache/{Utils → utils}/errorHelpers.d.ts +0 -1
  102. package/lib-esm/Cache/{Utils → utils}/errorHelpers.js +0 -4
  103. package/lib-esm/Cache/utils/index.d.ts +2 -0
  104. package/lib-esm/Cache/utils/index.js +4 -0
  105. package/lib-esm/Hub/index.d.ts +7 -0
  106. package/lib-esm/Hub/index.js +7 -0
  107. package/lib-esm/Platform/customUserAgent.d.ts +16 -0
  108. package/lib-esm/Platform/customUserAgent.js +65 -0
  109. package/lib-esm/Platform/index.js +10 -1
  110. package/lib-esm/Platform/types.d.ts +33 -1
  111. package/lib-esm/Platform/types.js +1 -0
  112. package/lib-esm/Platform/version.d.ts +1 -1
  113. package/lib-esm/Platform/version.js +1 -1
  114. package/lib-esm/Reachability/Reachability.d.ts +1 -0
  115. package/lib-esm/Reachability/Reachability.js +36 -0
  116. package/lib-esm/Signer/Signer.js +3 -2
  117. package/lib-esm/awsClients/cognitoIdentity/base.js +2 -1
  118. package/lib-esm/awsClients/pinpoint/base.js +2 -1
  119. package/lib-esm/awsClients/pinpoint/getInAppMessages.js +2 -1
  120. package/lib-esm/awsClients/pinpoint/putEvents.js +2 -1
  121. package/lib-esm/awsClients/pinpoint/updateEndpoint.js +2 -1
  122. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.d.ts +0 -1
  123. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.js +0 -1
  124. package/lib-esm/clients/middleware/signing/signer/signatureV4/presignUrl.js +2 -1
  125. package/lib-esm/index.d.ts +2 -5
  126. package/lib-esm/index.js +1 -4
  127. package/lib-esm/libraryUtils.d.ts +7 -5
  128. package/lib-esm/libraryUtils.js +5 -3
  129. package/lib-esm/parseAWSExports.js +75 -14
  130. package/lib-esm/providers/pinpoint/apis/flushEvents.d.ts +2 -2
  131. package/lib-esm/providers/pinpoint/apis/record.js +3 -3
  132. package/lib-esm/providers/pinpoint/apis/updateEndpoint.js +6 -6
  133. package/lib-esm/singleton/API/types.d.ts +4 -3
  134. package/lib-esm/singleton/Amplify.d.ts +2 -2
  135. package/lib-esm/singleton/Amplify.js +6 -5
  136. package/lib-esm/singleton/Auth/types.d.ts +28 -1
  137. package/lib-esm/singleton/Cache/types.d.ts +18 -0
  138. package/lib-esm/singleton/Cache/types.js +3 -0
  139. package/lib-esm/singleton/types.d.ts +3 -1
  140. package/lib-esm/storage/DefaultStorage.js +2 -2
  141. package/lib-esm/storage/utils.d.ts +1 -1
  142. package/lib-esm/storage/utils.js +1 -1
  143. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  144. package/lib-esm/utils/amplifyUrl/index.d.ts +13 -0
  145. package/lib-esm/utils/amplifyUrl/index.js +6 -0
  146. package/lib-esm/utils/amplifyUuid/index.d.ts +3 -0
  147. package/lib-esm/utils/amplifyUuid/index.js +6 -0
  148. package/lib-esm/utils/amplifyUuid/polyfill.native.js +4 -0
  149. package/lib-esm/utils/deepFreeze.d.ts +1 -0
  150. package/lib-esm/utils/deepFreeze.js +34 -0
  151. package/lib-esm/{ClientDevice/android.d.ts → utils/getClientInfo/getClientInfo.android.d.ts} +1 -1
  152. package/lib-esm/{ClientDevice/android.js → utils/getClientInfo/getClientInfo.android.js} +2 -2
  153. package/lib-esm/{ClientDevice/browser.d.ts → utils/getClientInfo/getClientInfo.d.ts} +1 -9
  154. package/lib-esm/{ClientDevice/ios.d.ts → utils/getClientInfo/getClientInfo.ios.d.ts} +1 -1
  155. package/lib-esm/{ClientDevice/ios.js → utils/getClientInfo/getClientInfo.ios.js} +2 -2
  156. package/lib-esm/{ClientDevice/browser.js → utils/getClientInfo/getClientInfo.js} +4 -14
  157. package/lib-esm/utils/getClientInfo/index.d.ts +1 -0
  158. package/lib-esm/utils/getClientInfo/index.js +3 -0
  159. package/lib-esm/utils/index.d.ts +2 -0
  160. package/lib-esm/utils/index.js +2 -0
  161. package/package.json +7 -17
  162. package/src/Cache/StorageCache.native.ts +65 -0
  163. package/src/Cache/StorageCache.ts +61 -158
  164. package/src/Cache/StorageCacheCommon.ts +581 -0
  165. package/src/Cache/constants.ts +18 -0
  166. package/src/Cache/index.ts +6 -0
  167. package/src/Cache/types/cache.ts +51 -0
  168. package/src/Cache/types/index.ts +1 -1
  169. package/src/Cache/{Utils → utils}/CacheList.ts +185 -185
  170. package/src/Cache/utils/cacheHelpers.ts +52 -0
  171. package/src/Cache/{Utils → utils}/errorHelpers.ts +0 -4
  172. package/src/Cache/{Utils → utils}/index.ts +4 -5
  173. package/src/Hub/index.ts +8 -0
  174. package/src/Platform/customUserAgent.ts +75 -0
  175. package/src/Platform/index.ts +14 -1
  176. package/src/Platform/types.ts +45 -1
  177. package/src/Platform/version.ts +1 -1
  178. package/src/Reachability/Reachability.ts +14 -0
  179. package/src/Signer/Signer.ts +3 -2
  180. package/src/awsClients/cognitoIdentity/base.ts +4 -1
  181. package/src/awsClients/pinpoint/base.ts +2 -1
  182. package/src/awsClients/pinpoint/getInAppMessages.ts +2 -1
  183. package/src/awsClients/pinpoint/putEvents.ts +2 -1
  184. package/src/awsClients/pinpoint/updateEndpoint.ts +2 -1
  185. package/src/clients/middleware/signing/signer/signatureV4/index.ts +0 -2
  186. package/src/clients/middleware/signing/signer/signatureV4/presignUrl.ts +2 -1
  187. package/src/index.ts +3 -4
  188. package/src/libraryUtils.ts +17 -10
  189. package/src/parseAWSExports.ts +76 -13
  190. package/src/providers/pinpoint/apis/flushEvents.ts +2 -2
  191. package/src/providers/pinpoint/apis/record.ts +3 -3
  192. package/src/providers/pinpoint/apis/updateEndpoint.ts +6 -6
  193. package/src/singleton/API/types.ts +4 -3
  194. package/src/singleton/Amplify.ts +10 -8
  195. package/src/singleton/Auth/types.ts +50 -1
  196. package/src/singleton/Cache/types.ts +27 -0
  197. package/src/singleton/types.ts +3 -1
  198. package/src/storage/DefaultStorage.ts +2 -2
  199. package/src/storage/utils.ts +1 -1
  200. package/src/utils/amplifyUrl/index.ts +9 -0
  201. package/src/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.ts → utils/amplifyUrl/polyfill.native.ts} +1 -0
  202. package/src/utils/amplifyUuid/index.ts +9 -0
  203. package/src/utils/amplifyUuid/polyfill.native.ts +6 -0
  204. package/src/utils/amplifyUuid/polyfill.ts +4 -0
  205. package/src/utils/deepFreeze.ts +16 -0
  206. package/src/{ClientDevice/android.ts → utils/getClientInfo/getClientInfo.android.ts} +2 -2
  207. package/src/{ClientDevice/ios.ts → utils/getClientInfo/getClientInfo.ios.ts} +3 -3
  208. package/src/{ClientDevice/browser.ts → utils/getClientInfo/getClientInfo.ts} +4 -16
  209. package/src/utils/getClientInfo/index.ts +4 -0
  210. package/src/utils/index.ts +2 -0
  211. package/lib/Cache/BrowserStorageCache.d.ts +0 -166
  212. package/lib/Cache/BrowserStorageCache.js +0 -456
  213. package/lib/Cache/InMemoryCache.d.ts +0 -129
  214. package/lib/Cache/InMemoryCache.js +0 -342
  215. package/lib/Cache/Utils/CacheUtils.d.ts +0 -25
  216. package/lib/Cache/Utils/CacheUtils.js +0 -86
  217. package/lib/Cache/Utils/index.d.ts +0 -2
  218. package/lib/Cache/Utils/index.js +0 -16
  219. package/lib/Cache/reactnative.d.ts +0 -3
  220. package/lib/Cache/reactnative.js +0 -8
  221. package/lib/Cache/types/Cache.d.ts +0 -55
  222. package/lib/ClientDevice/index.d.ts +0 -23
  223. package/lib/ClientDevice/index.js +0 -18
  224. package/lib/ClientDevice/reactnative.d.ts +0 -7
  225. package/lib/ClientDevice/reactnative.js +0 -24
  226. package/lib-esm/Cache/BrowserStorageCache.d.ts +0 -166
  227. package/lib-esm/Cache/BrowserStorageCache.js +0 -453
  228. package/lib-esm/Cache/InMemoryCache.d.ts +0 -129
  229. package/lib-esm/Cache/InMemoryCache.js +0 -339
  230. package/lib-esm/Cache/Utils/CacheUtils.d.ts +0 -25
  231. package/lib-esm/Cache/Utils/CacheUtils.js +0 -79
  232. package/lib-esm/Cache/Utils/index.d.ts +0 -2
  233. package/lib-esm/Cache/Utils/index.js +0 -4
  234. package/lib-esm/Cache/reactnative.d.ts +0 -3
  235. package/lib-esm/Cache/reactnative.js +0 -6
  236. package/lib-esm/Cache/types/Cache.d.ts +0 -55
  237. package/lib-esm/ClientDevice/index.d.ts +0 -23
  238. package/lib-esm/ClientDevice/index.js +0 -15
  239. package/lib-esm/ClientDevice/reactnative.d.ts +0 -7
  240. package/lib-esm/ClientDevice/reactnative.js +0 -21
  241. package/src/Cache/AsyncStorageCache.ts +0 -495
  242. package/src/Cache/BrowserStorageCache.ts +0 -504
  243. package/src/Cache/CHANGELOG.md +0 -1239
  244. package/src/Cache/InMemoryCache.ts +0 -347
  245. package/src/Cache/Utils/CacheUtils.ts +0 -90
  246. package/src/Cache/reactnative.ts +0 -9
  247. package/src/Cache/types/Cache.ts +0 -75
  248. package/src/ClientDevice/index.ts +0 -14
  249. package/src/ClientDevice/reactnative.ts +0 -18
  250. package/lib/Cache/types/{Cache.js → cache.js} +0 -0
  251. package/lib/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.js → utils/amplifyUrl/polyfill.native.js} +1 -1
  252. /package/lib-esm/Cache/types/{Cache.js → cache.js} +0 -0
  253. /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.d.ts → utils/amplifyUrl/polyfill.d.ts} +0 -0
  254. /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.js → utils/amplifyUrl/polyfill.js} +0 -0
  255. /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.d.ts → utils/amplifyUrl/polyfill.native.d.ts} +0 -0
  256. /package/lib-esm/{clients/middleware/signing/signer/signatureV4/polyfills/index.native.js → utils/amplifyUrl/polyfill.native.js} +0 -0
  257. /package/{lib/clients/middleware/signing/signer/signatureV4/polyfills/index.d.ts → lib-esm/utils/amplifyUuid/polyfill.d.ts} +0 -0
  258. /package/{lib/clients/middleware/signing/signer/signatureV4/polyfills/index.js → lib-esm/utils/amplifyUuid/polyfill.js} +0 -0
  259. /package/{lib/clients/middleware/signing/signer/signatureV4/polyfills/index.native.d.ts → lib-esm/utils/amplifyUuid/polyfill.native.d.ts} +0 -0
  260. /package/src/{clients/middleware/signing/signer/signatureV4/polyfills/index.ts → utils/amplifyUrl/polyfill.ts} +0 -0
@@ -1,185 +1,185 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { assert, CacheErrorCode } from './errorHelpers';
5
-
6
- class DoubleLinkedNode {
7
- key: string;
8
- prevNode: DoubleLinkedNode | null;
9
- nextNode: DoubleLinkedNode | null;
10
-
11
- constructor(keyVal?: string) {
12
- this.key = keyVal ? keyVal : '';
13
- this.prevNode = null;
14
- this.nextNode = null;
15
- }
16
- }
17
-
18
- /**
19
- * double linked list plus a hash table inside
20
- * each key in the cache stored as a node in the list
21
- * recently visited node will be rotated to the head
22
- * so the Last Recently Visited node will be at the tail
23
- *
24
- * @member head - dummy head of the linked list
25
- * @member tail - dummy tail of the linked list
26
- * @member hashtable - the hashtable which maps cache key to list node
27
- * @member length - length of the list
28
- */
29
- export default class CacheList {
30
- private head: DoubleLinkedNode;
31
- private tail: DoubleLinkedNode;
32
- private hashtable: Record<string, any>;
33
- private length: number;
34
-
35
- /**
36
- * initialization
37
- */
38
- constructor() {
39
- this.head = new DoubleLinkedNode();
40
- this.tail = new DoubleLinkedNode();
41
- this.hashtable = {};
42
- this.length = 0;
43
-
44
- this.head.nextNode = this.tail;
45
- this.tail.prevNode = this.head;
46
- }
47
-
48
- /**
49
- * insert node to the head of the list
50
- *
51
- * @param node
52
- */
53
- private insertNodeToHead(node: DoubleLinkedNode) {
54
- const tmp: DoubleLinkedNode | null = this.head.nextNode;
55
- this.head.nextNode = node;
56
- node.nextNode = tmp;
57
- node.prevNode = this.head;
58
- assert(tmp !== null, CacheErrorCode.NullPreviousNode);
59
- tmp.prevNode = node;
60
-
61
- this.length = this.length + 1;
62
- }
63
-
64
- /**
65
- * remove node
66
- *
67
- * @param node
68
- */
69
- private removeNode(node: DoubleLinkedNode): void {
70
- assert(node.prevNode !== null, CacheErrorCode.NullPreviousNode);
71
- assert(node.nextNode !== null, CacheErrorCode.NullNextNode);
72
- node.prevNode.nextNode = node.nextNode;
73
- node.nextNode.prevNode = node.prevNode;
74
-
75
- node.prevNode = null;
76
- node.nextNode = null;
77
-
78
- this.length = this.length - 1;
79
- }
80
-
81
- /**
82
- * @return true if list is empty
83
- */
84
- public isEmpty(): boolean {
85
- return this.length === 0;
86
- }
87
-
88
- /**
89
- * refresh node so it is rotated to the head
90
- *
91
- * @param key - key of the node
92
- */
93
- public refresh(key: string): void {
94
- const node: DoubleLinkedNode = this.hashtable[key];
95
- this.removeNode(node);
96
- this.insertNodeToHead(node);
97
- }
98
-
99
- /**
100
- * insert new node to the head and add it in the hashtable
101
- *
102
- * @param key - the key of the node
103
- */
104
- public insertItem(key: string): void {
105
- const node: DoubleLinkedNode = new DoubleLinkedNode(key);
106
- this.hashtable[key] = node;
107
- this.insertNodeToHead(node);
108
- }
109
-
110
- /**
111
- * @return the LAST Recently Visited key
112
- */
113
- public getLastItem(): string {
114
- assert(this.tail.prevNode !== null, CacheErrorCode.NullPreviousNode);
115
- return this.tail.prevNode.key;
116
- }
117
-
118
- /**
119
- * remove the cache key from the list and hashtable
120
- * @param key - the key of the node
121
- */
122
- public removeItem(key: string): void {
123
- const removedItem: DoubleLinkedNode = this.hashtable[key];
124
- this.removeNode(removedItem);
125
- delete this.hashtable[key];
126
- }
127
-
128
- /**
129
- * @return length of the list
130
- */
131
- public getSize(): number {
132
- return this.length;
133
- }
134
-
135
- /**
136
- * @return true if the key is in the hashtable
137
- * @param key
138
- */
139
- public containsKey(key: string): boolean {
140
- return key in this.hashtable;
141
- }
142
-
143
- /**
144
- * clean up the list and hashtable
145
- */
146
- public clearList(): void {
147
- for (const key of Object.keys(this.hashtable)) {
148
- if (this.hashtable.hasOwnProperty(key)) {
149
- delete this.hashtable[key];
150
- }
151
- }
152
- this.head.nextNode = this.tail;
153
- this.tail.prevNode = this.head;
154
- this.length = 0;
155
- }
156
-
157
- /**
158
- * @return all keys in the hashtable
159
- */
160
- public getKeys(): string[] {
161
- return Object.keys(this.hashtable);
162
- }
163
-
164
- /**
165
- * mainly for test
166
- *
167
- * @param key
168
- * @return true if key is the head node
169
- */
170
- public isHeadNode(key: string): boolean {
171
- const node = this.hashtable[key];
172
- return node.prevNode === this.head;
173
- }
174
-
175
- /**
176
- * mainly for test
177
- *
178
- * @param key
179
- * @return true if key is the tail node
180
- */
181
- public isTailNode(key: string): boolean {
182
- const node = this.hashtable[key];
183
- return node.nextNode === this.tail;
184
- }
185
- }
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { assert, CacheErrorCode } from './errorHelpers';
5
+
6
+ class DoubleLinkedNode {
7
+ key: string;
8
+ prevNode: DoubleLinkedNode | null;
9
+ nextNode: DoubleLinkedNode | null;
10
+
11
+ constructor(keyVal?: string) {
12
+ this.key = keyVal ? keyVal : '';
13
+ this.prevNode = null;
14
+ this.nextNode = null;
15
+ }
16
+ }
17
+
18
+ /**
19
+ * double linked list plus a hash table inside
20
+ * each key in the cache stored as a node in the list
21
+ * recently visited node will be rotated to the head
22
+ * so the Last Recently Visited node will be at the tail
23
+ *
24
+ * @member head - dummy head of the linked list
25
+ * @member tail - dummy tail of the linked list
26
+ * @member hashtable - the hashtable which maps cache key to list node
27
+ * @member length - length of the list
28
+ */
29
+ export class CacheList {
30
+ private head: DoubleLinkedNode;
31
+ private tail: DoubleLinkedNode;
32
+ private hashtable: Record<string, any>;
33
+ private length: number;
34
+
35
+ /**
36
+ * initialization
37
+ */
38
+ constructor() {
39
+ this.head = new DoubleLinkedNode();
40
+ this.tail = new DoubleLinkedNode();
41
+ this.hashtable = {};
42
+ this.length = 0;
43
+
44
+ this.head.nextNode = this.tail;
45
+ this.tail.prevNode = this.head;
46
+ }
47
+
48
+ /**
49
+ * insert node to the head of the list
50
+ *
51
+ * @param node
52
+ */
53
+ private insertNodeToHead(node: DoubleLinkedNode) {
54
+ const tmp: DoubleLinkedNode | null = this.head.nextNode;
55
+ this.head.nextNode = node;
56
+ node.nextNode = tmp;
57
+ node.prevNode = this.head;
58
+ assert(tmp !== null, CacheErrorCode.NullPreviousNode);
59
+ tmp.prevNode = node;
60
+
61
+ this.length = this.length + 1;
62
+ }
63
+
64
+ /**
65
+ * remove node
66
+ *
67
+ * @param node
68
+ */
69
+ private removeNode(node: DoubleLinkedNode): void {
70
+ assert(node.prevNode !== null, CacheErrorCode.NullPreviousNode);
71
+ assert(node.nextNode !== null, CacheErrorCode.NullNextNode);
72
+ node.prevNode.nextNode = node.nextNode;
73
+ node.nextNode.prevNode = node.prevNode;
74
+
75
+ node.prevNode = null;
76
+ node.nextNode = null;
77
+
78
+ this.length = this.length - 1;
79
+ }
80
+
81
+ /**
82
+ * @return true if list is empty
83
+ */
84
+ public isEmpty(): boolean {
85
+ return this.length === 0;
86
+ }
87
+
88
+ /**
89
+ * refresh node so it is rotated to the head
90
+ *
91
+ * @param key - key of the node
92
+ */
93
+ public refresh(key: string): void {
94
+ const node: DoubleLinkedNode = this.hashtable[key];
95
+ this.removeNode(node);
96
+ this.insertNodeToHead(node);
97
+ }
98
+
99
+ /**
100
+ * insert new node to the head and add it in the hashtable
101
+ *
102
+ * @param key - the key of the node
103
+ */
104
+ public insertItem(key: string): void {
105
+ const node: DoubleLinkedNode = new DoubleLinkedNode(key);
106
+ this.hashtable[key] = node;
107
+ this.insertNodeToHead(node);
108
+ }
109
+
110
+ /**
111
+ * @return the LAST Recently Visited key
112
+ */
113
+ public getLastItem(): string {
114
+ assert(this.tail.prevNode !== null, CacheErrorCode.NullPreviousNode);
115
+ return this.tail.prevNode.key;
116
+ }
117
+
118
+ /**
119
+ * remove the cache key from the list and hashtable
120
+ * @param key - the key of the node
121
+ */
122
+ public removeItem(key: string): void {
123
+ const removedItem: DoubleLinkedNode = this.hashtable[key];
124
+ this.removeNode(removedItem);
125
+ delete this.hashtable[key];
126
+ }
127
+
128
+ /**
129
+ * @return length of the list
130
+ */
131
+ public getSize(): number {
132
+ return this.length;
133
+ }
134
+
135
+ /**
136
+ * @return true if the key is in the hashtable
137
+ * @param key
138
+ */
139
+ public containsKey(key: string): boolean {
140
+ return key in this.hashtable;
141
+ }
142
+
143
+ /**
144
+ * clean up the list and hashtable
145
+ */
146
+ public clearList(): void {
147
+ for (const key of Object.keys(this.hashtable)) {
148
+ if (this.hashtable.hasOwnProperty(key)) {
149
+ delete this.hashtable[key];
150
+ }
151
+ }
152
+ this.head.nextNode = this.tail;
153
+ this.tail.prevNode = this.head;
154
+ this.length = 0;
155
+ }
156
+
157
+ /**
158
+ * @return all keys in the hashtable
159
+ */
160
+ public getKeys(): string[] {
161
+ return Object.keys(this.hashtable);
162
+ }
163
+
164
+ /**
165
+ * mainly for test
166
+ *
167
+ * @param key
168
+ * @return true if key is the head node
169
+ */
170
+ public isHeadNode(key: string): boolean {
171
+ const node = this.hashtable[key];
172
+ return node.prevNode === this.head;
173
+ }
174
+
175
+ /**
176
+ * mainly for test
177
+ *
178
+ * @param key
179
+ * @return true if key is the tail node
180
+ */
181
+ public isTailNode(key: string): boolean {
182
+ const node = this.hashtable[key];
183
+ return node.nextNode === this.tail;
184
+ }
185
+ }
@@ -0,0 +1,52 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { currentSizeKey } from '../constants';
5
+
6
+ /**
7
+ * return the byte size of the string
8
+ * @param str
9
+ */
10
+ export function getByteLength(str: string): number {
11
+ let ret: number = 0;
12
+ ret = str.length;
13
+
14
+ for (let i = str.length; i >= 0; i -= 1) {
15
+ const charCode: number = str.charCodeAt(i);
16
+ if (charCode > 0x7f && charCode <= 0x7ff) {
17
+ ret += 1;
18
+ } else if (charCode > 0x7ff && charCode <= 0xffff) {
19
+ ret += 2;
20
+ }
21
+ // trail surrogate
22
+ if (charCode >= 0xdc00 && charCode <= 0xdfff) {
23
+ i -= 1;
24
+ }
25
+ }
26
+
27
+ return ret;
28
+ }
29
+
30
+ /**
31
+ * get current time
32
+ */
33
+ export function getCurrentTime(): number {
34
+ const currentTime = new Date();
35
+ return currentTime.getTime();
36
+ }
37
+
38
+ /**
39
+ * check if passed value is an integer
40
+ */
41
+ export function isInteger(value?: number): boolean {
42
+ if (Number.isInteger) {
43
+ return Number.isInteger(value);
44
+ }
45
+
46
+ return (
47
+ typeof value === 'number' && isFinite(value) && Math.floor(value) === value
48
+ );
49
+ }
50
+
51
+ export const getCurrentSizeKey = (keyPrefix: string) =>
52
+ `${keyPrefix}${currentSizeKey}`;
@@ -6,7 +6,6 @@ import { AmplifyErrorMap, AssertionFunction } from '../../types';
6
6
 
7
7
  export enum CacheErrorCode {
8
8
  NoCacheItem = 'NoCacheItem',
9
- NoCacheStorage = 'NoCacheStorage',
10
9
  NullNextNode = 'NullNextNode',
11
10
  NullPreviousNode = 'NullPreviousNode',
12
11
  }
@@ -15,9 +14,6 @@ const cacheErrorMap: AmplifyErrorMap<CacheErrorCode> = {
15
14
  [CacheErrorCode.NoCacheItem]: {
16
15
  message: 'Item not found in the cache storage.',
17
16
  },
18
- [CacheErrorCode.NoCacheStorage]: {
19
- message: 'Storage is not defined in the cache config.',
20
- },
21
17
  [CacheErrorCode.NullNextNode]: {
22
18
  message: 'Next node is null.',
23
19
  },
@@ -2,10 +2,9 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  export {
5
- CacheObject,
6
- defaultConfig,
7
5
  getByteLength,
8
- getCurrTime,
6
+ getCurrentSizeKey,
7
+ getCurrentTime,
9
8
  isInteger,
10
- } from './CacheUtils';
11
- export { default as CacheList } from './CacheList';
9
+ } from './cacheHelpers';
10
+ export { CacheList } from './CacheList';
package/src/Hub/index.ts CHANGED
@@ -203,3 +203,11 @@ export class HubClass {
203
203
  pseudo Singleton for the main messaging bus, however you can still create
204
204
  your own instance of HubClass() for a separate "private bus" of events.*/
205
205
  export const Hub = new HubClass('__default__');
206
+
207
+ /**
208
+ * @internal
209
+ *
210
+ * Internal hub used for core Amplify functionality. Not intended for use outside of Amplify.
211
+ *
212
+ */
213
+ export const HubInternal = new HubClass('internal-hub');
@@ -0,0 +1,75 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import {
5
+ AdditionalDetails,
6
+ CategoryUserAgentStateMap,
7
+ CustomUserAgentStateMap,
8
+ SetCustomUserAgentInput,
9
+ } from './types';
10
+
11
+ // Maintains custom user-agent state set by external consumers.
12
+ const customUserAgentState: CustomUserAgentStateMap = {};
13
+
14
+ /**
15
+ * Sets custom user agent state which will be appended to applicable requests. Returns a function that can be used to
16
+ * clean up any custom state set with this API.
17
+ *
18
+ * @note
19
+ * This API operates globally. Calling this API multiple times will result in the most recently set values for a
20
+ * particular API being used.
21
+ *
22
+ * @note
23
+ * This utility IS NOT compatible with SSR.
24
+ *
25
+ * @param input - SetCustomUserAgentInput that defines custom state to apply to the specified APIs.
26
+ */
27
+ export const setCustomUserAgent = (
28
+ input: SetCustomUserAgentInput
29
+ ): (() => void) => {
30
+ // Save custom user-agent state & increment reference counter
31
+ // TODO Remove `any` when we upgrade to TypeScript 5.2, see: https://github.com/microsoft/TypeScript/issues/44373
32
+ customUserAgentState[input.category] = (input.apis as any[]).reduce(
33
+ (acc: CategoryUserAgentStateMap, api: string) => ({
34
+ ...acc,
35
+ [api]: {
36
+ refCount: acc[api]?.refCount ? acc[api].refCount + 1 : 1,
37
+ additionalDetails: input.additionalDetails,
38
+ },
39
+ }),
40
+ customUserAgentState[input.category] ?? {}
41
+ );
42
+
43
+ // Callback that cleans up state for APIs recorded by this call
44
+ let cleanUpCallbackCalled = false;
45
+ const cleanUpCallback = () => {
46
+ // Only allow the cleanup callback to be called once
47
+ if (cleanUpCallbackCalled) {
48
+ return;
49
+ }
50
+ cleanUpCallbackCalled = true;
51
+
52
+ input.apis.forEach(api => {
53
+ const apiRefCount = customUserAgentState[input.category][api].refCount;
54
+
55
+ if (apiRefCount > 1) {
56
+ customUserAgentState[input.category][api].refCount = apiRefCount - 1;
57
+ } else {
58
+ delete customUserAgentState[input.category][api];
59
+
60
+ // Clean up category if no more APIs set
61
+ if (!Object.keys(customUserAgentState[input.category]).length) {
62
+ delete customUserAgentState[input.category];
63
+ }
64
+ }
65
+ });
66
+ };
67
+
68
+ return cleanUpCallback;
69
+ };
70
+
71
+ export const getCustomUserAgent = (
72
+ category: string,
73
+ api: string
74
+ ): AdditionalDetails | undefined =>
75
+ customUserAgentState[category]?.[api]?.additionalDetails;
@@ -5,6 +5,7 @@ import { CustomUserAgentDetails, Framework } from './types';
5
5
  import { version } from './version';
6
6
  import { detectFramework, observeFrameworkChanges } from './detectFramework';
7
7
  import { UserAgent as AWSUserAgent } from '@aws-sdk/types';
8
+ import { getCustomUserAgent } from './customUserAgent';
8
9
 
9
10
  const BASE_USER_AGENT = `aws-amplify`;
10
11
 
@@ -39,6 +40,16 @@ export const getAmplifyUserAgentObject = ({
39
40
  }
40
41
  userAgent.push(['framework', detectFramework()]);
41
42
 
43
+ if (category && action) {
44
+ const customState = getCustomUserAgent(category, action);
45
+
46
+ if (customState) {
47
+ customState.forEach(state => {
48
+ userAgent.push(state);
49
+ });
50
+ }
51
+ }
52
+
42
53
  return userAgent;
43
54
  };
44
55
 
@@ -47,7 +58,9 @@ export const getAmplifyUserAgent = (
47
58
  ): string => {
48
59
  const userAgent = getAmplifyUserAgentObject(customUserAgentDetails);
49
60
  const userAgentString = userAgent
50
- .map(([agentKey, agentValue]) => `${agentKey}/${agentValue}`)
61
+ .map(([agentKey, agentValue]) =>
62
+ agentKey && agentValue ? `${agentKey}/${agentValue}` : agentKey
63
+ )
51
64
  .join(' ');
52
65
 
53
66
  return userAgentString;
@@ -88,6 +88,7 @@ export enum GeoAction {
88
88
  export enum InAppMessagingAction {
89
89
  SyncMessages = '1',
90
90
  IdentifyUser = '2',
91
+ DispatchEvent = '3',
91
92
  }
92
93
  export enum InteractionsAction {
93
94
  None = '0',
@@ -110,7 +111,7 @@ export enum StorageAction {
110
111
  Copy = '4',
111
112
  Remove = '5',
112
113
  GetProperties = '6',
113
- GetUrl = '7'
114
+ GetUrl = '7',
114
115
  }
115
116
 
116
117
  type ActionMap = {
@@ -150,3 +151,46 @@ export type CustomUserAgentDetails =
150
151
  | UserAgentDetailsWithCategory<Category.PubSub>
151
152
  | UserAgentDetailsWithCategory<Category.PushNotification>
152
153
  | UserAgentDetailsWithCategory<Category.Storage>;
154
+
155
+ /**
156
+ * `refCount` tracks how many consumers have set state for a particular API to avoid it being cleared before all
157
+ * consumers are done using it.
158
+ *
159
+ * Category -> Action -> Custom State
160
+ */
161
+ export type CategoryUserAgentStateMap = Record<
162
+ string,
163
+ { refCount: number; additionalDetails: AdditionalDetails }
164
+ >;
165
+ export type CustomUserAgentStateMap = Record<string, CategoryUserAgentStateMap>;
166
+
167
+ export type AdditionalDetails = [string, string?][];
168
+
169
+ type StorageUserAgentInput = {
170
+ category: Category.Storage;
171
+ apis: StorageAction[];
172
+ };
173
+
174
+ type AuthUserAgentInput = {
175
+ category: Category.Auth;
176
+ apis: AuthAction[];
177
+ };
178
+
179
+ type InAppMessagingUserAgentInput = {
180
+ category: Category.InAppMessaging;
181
+ apis: InAppMessagingAction[];
182
+ };
183
+
184
+ type GeoUserAgentInput = {
185
+ category: Category.Geo;
186
+ apis: GeoAction[];
187
+ };
188
+
189
+ export type SetCustomUserAgentInput = (
190
+ | StorageUserAgentInput
191
+ | AuthUserAgentInput
192
+ | InAppMessagingUserAgentInput
193
+ | GeoUserAgentInput
194
+ ) & {
195
+ additionalDetails: AdditionalDetails;
196
+ };
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '6.0.1-console-preview.5f040a2.0+5f040a2';
2
+ export const version = '6.0.1-console-preview.23dc225.0+23dc225';
@@ -32,4 +32,18 @@ export class Reachability {
32
32
  };
33
33
  });
34
34
  }
35
+
36
+ // expose observers to simulate offline mode for integration testing
37
+ private static _observerOverride(status: NetworkStatus): void {
38
+ for (const observer of this._observers) {
39
+ if (observer.closed) {
40
+ this._observers = this._observers.filter(
41
+ _observer => _observer !== observer
42
+ );
43
+ continue;
44
+ }
45
+
46
+ observer?.next && observer.next(status);
47
+ }
48
+ }
35
49
  }