@aws-amplify/analytics 7.0.1-preview-testing.be90020.0 → 7.0.1-ssr-api.df60e41.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 (372) hide show
  1. package/kinesis/package.json +7 -0
  2. package/kinesis-firehose/package.json +7 -0
  3. package/lib/apis/disable.d.ts +8 -0
  4. package/lib/apis/disable.js +14 -0
  5. package/lib/apis/enable.d.ts +7 -0
  6. package/lib/apis/enable.js +13 -0
  7. package/lib/apis/index.d.ts +2 -0
  8. package/lib/apis/index.js +9 -0
  9. package/lib/errors/AnalyticsError.d.ts +2 -2
  10. package/lib/errors/AnalyticsError.js +7 -11
  11. package/lib/errors/assertValidationError.d.ts +1 -1
  12. package/lib/errors/assertValidationError.js +9 -5
  13. package/lib/errors/validation.d.ts +5 -2
  14. package/lib/errors/validation.js +22 -11
  15. package/lib/index.d.ts +2 -1
  16. package/lib/index.js +6 -1
  17. package/lib/providers/kinesis/apis/flushEvents.d.ts +8 -0
  18. package/lib/providers/kinesis/apis/flushEvents.js +35 -0
  19. package/lib/providers/kinesis/apis/index.d.ts +2 -0
  20. package/lib/providers/kinesis/apis/index.js +9 -0
  21. package/lib/providers/kinesis/apis/record.d.ts +2 -0
  22. package/lib/providers/kinesis/apis/record.js +46 -0
  23. package/lib/providers/kinesis/index.d.ts +1 -0
  24. package/lib/providers/kinesis/index.js +8 -0
  25. package/lib/providers/kinesis/types/buffer.d.ts +15 -0
  26. package/lib/providers/kinesis/types/buffer.js +4 -0
  27. package/lib/providers/kinesis/types/index.d.ts +2 -0
  28. package/lib/providers/kinesis/types/index.js +4 -0
  29. package/lib/providers/kinesis/types/inputs.d.ts +6 -0
  30. package/lib/providers/kinesis/types/inputs.js +4 -0
  31. package/lib/providers/kinesis/utils/constants.d.ts +6 -0
  32. package/lib/providers/kinesis/utils/constants.js +11 -0
  33. package/lib/providers/kinesis/utils/getEventBuffer.d.ts +3 -0
  34. package/lib/providers/kinesis/utils/getEventBuffer.js +72 -0
  35. package/lib/providers/kinesis/utils/resolveConfig.d.ts +7 -0
  36. package/lib/providers/kinesis/utils/resolveConfig.js +25 -0
  37. package/lib/providers/kinesis-firehose/apis/flushEvents.d.ts +8 -0
  38. package/lib/providers/kinesis-firehose/apis/flushEvents.js +34 -0
  39. package/lib/providers/kinesis-firehose/apis/index.d.ts +2 -0
  40. package/lib/providers/kinesis-firehose/apis/index.js +9 -0
  41. package/lib/providers/kinesis-firehose/apis/record.d.ts +2 -0
  42. package/lib/providers/kinesis-firehose/apis/record.js +43 -0
  43. package/lib/providers/kinesis-firehose/index.d.ts +1 -0
  44. package/lib/providers/kinesis-firehose/index.js +8 -0
  45. package/lib/providers/kinesis-firehose/types/buffer.d.ts +15 -0
  46. package/lib/providers/kinesis-firehose/types/index.d.ts +2 -0
  47. package/lib/providers/kinesis-firehose/types/index.js +4 -0
  48. package/lib/providers/kinesis-firehose/types/inputs.d.ts +5 -0
  49. package/lib/providers/kinesis-firehose/types/inputs.js +4 -0
  50. package/lib/providers/kinesis-firehose/utils/constants.d.ts +6 -0
  51. package/lib/providers/kinesis-firehose/utils/constants.js +11 -0
  52. package/lib/providers/kinesis-firehose/utils/getEventBuffer.d.ts +3 -0
  53. package/lib/providers/kinesis-firehose/utils/getEventBuffer.js +71 -0
  54. package/lib/providers/kinesis-firehose/utils/index.d.ts +2 -0
  55. package/lib/providers/kinesis-firehose/utils/index.js +9 -0
  56. package/lib/providers/kinesis-firehose/utils/resolveConfig.d.ts +7 -0
  57. package/lib/providers/kinesis-firehose/utils/resolveConfig.js +25 -0
  58. package/lib/providers/personalize/apis/flushEvents.d.ts +8 -0
  59. package/lib/providers/personalize/apis/flushEvents.js +33 -0
  60. package/lib/providers/personalize/apis/index.d.ts +2 -0
  61. package/lib/providers/personalize/apis/index.js +9 -0
  62. package/lib/providers/personalize/apis/record.d.ts +2 -0
  63. package/lib/providers/personalize/apis/record.js +71 -0
  64. package/lib/providers/personalize/index.d.ts +1 -0
  65. package/lib/providers/personalize/index.js +8 -0
  66. package/lib/providers/personalize/types/buffer.d.ts +16 -0
  67. package/lib/providers/personalize/types/buffer.js +4 -0
  68. package/lib/providers/personalize/types/index.d.ts +2 -0
  69. package/lib/providers/personalize/types/index.js +4 -0
  70. package/lib/providers/personalize/types/inputs.d.ts +7 -0
  71. package/lib/providers/personalize/types/inputs.js +4 -0
  72. package/lib/providers/personalize/utils/autoTrackMedia.d.ts +10 -0
  73. package/lib/providers/personalize/utils/autoTrackMedia.js +181 -0
  74. package/lib/providers/personalize/utils/cachedSession.d.ts +5 -0
  75. package/lib/providers/personalize/utils/cachedSession.js +49 -0
  76. package/lib/providers/personalize/utils/constants.d.ts +7 -0
  77. package/lib/providers/personalize/utils/constants.js +12 -0
  78. package/lib/providers/personalize/utils/getEventBuffer.d.ts +3 -0
  79. package/lib/providers/personalize/utils/getEventBuffer.js +73 -0
  80. package/lib/providers/personalize/utils/index.d.ts +5 -0
  81. package/lib/providers/personalize/utils/index.js +17 -0
  82. package/lib/providers/personalize/utils/resolveConfig.d.ts +7 -0
  83. package/lib/providers/personalize/utils/resolveConfig.js +26 -0
  84. package/lib/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
  85. package/lib/providers/pinpoint/apis/configureAutoTrack.js +35 -0
  86. package/lib/providers/pinpoint/apis/flushEvents.d.ts +8 -0
  87. package/lib/providers/pinpoint/apis/flushEvents.js +25 -0
  88. package/lib/providers/pinpoint/apis/identifyUser.d.ts +7 -5
  89. package/lib/providers/pinpoint/apis/identifyUser.js +24 -32
  90. package/lib/providers/pinpoint/apis/index.d.ts +2 -0
  91. package/lib/providers/pinpoint/apis/index.js +5 -1
  92. package/lib/providers/pinpoint/apis/record.d.ts +8 -14
  93. package/lib/providers/pinpoint/apis/record.js +31 -34
  94. package/lib/providers/pinpoint/index.d.ts +2 -2
  95. package/lib/providers/pinpoint/index.js +3 -1
  96. package/lib/providers/pinpoint/types/index.d.ts +2 -2
  97. package/lib/providers/pinpoint/types/index.js +0 -3
  98. package/lib/providers/pinpoint/types/inputs.d.ts +8 -17
  99. package/lib/providers/pinpoint/types/options.d.ts +5 -0
  100. package/lib/providers/pinpoint/types/options.js +4 -0
  101. package/lib/providers/pinpoint/utils/resolveConfig.js +5 -6
  102. package/lib/providers/pinpoint/utils/resolveCredentials.d.ts +1 -6
  103. package/lib/providers/pinpoint/utils/resolveCredentials.js +7 -15
  104. package/lib/setupTests.js +1 -1
  105. package/lib/trackers/EventTracker.d.ts +10 -0
  106. package/lib/trackers/EventTracker.js +98 -0
  107. package/lib/trackers/PageViewTracker.d.ts +18 -0
  108. package/lib/trackers/PageViewTracker.js +112 -0
  109. package/lib/trackers/SessionTracker.d.ts +13 -0
  110. package/lib/trackers/SessionTracker.js +67 -0
  111. package/lib/trackers/SessionTracker.native.d.ts +13 -0
  112. package/lib/trackers/SessionTracker.native.js +67 -0
  113. package/lib/trackers/index.d.ts +3 -0
  114. package/lib/trackers/index.js +11 -0
  115. package/lib/tsconfig.tsbuildinfo +1 -1
  116. package/lib/types/index.d.ts +3 -1
  117. package/lib/types/index.js +0 -2
  118. package/lib/types/inputs.d.ts +35 -0
  119. package/lib/types/inputs.js +4 -0
  120. package/lib/types/kinesis.d.ts +8 -0
  121. package/lib/types/kinesis.js +4 -0
  122. package/lib/types/options.d.ts +4 -0
  123. package/lib/types/options.js +4 -0
  124. package/lib/types/trackers.d.ts +22 -0
  125. package/lib/types/trackers.js +4 -0
  126. package/lib/utils/eventBuffer/EventBuffer.d.ts +16 -0
  127. package/lib/utils/eventBuffer/EventBuffer.js +63 -0
  128. package/lib/utils/eventBuffer/index.d.ts +2 -0
  129. package/lib/utils/eventBuffer/index.js +7 -0
  130. package/lib/utils/eventBuffer/types.d.ts +8 -0
  131. package/lib/utils/eventBuffer/types.js +4 -0
  132. package/lib/utils/groupBy.d.ts +1 -0
  133. package/lib/utils/groupBy.js +12 -0
  134. package/lib/utils/index.d.ts +7 -0
  135. package/lib/utils/index.js +22 -0
  136. package/lib/utils/resolveCredentials.d.ts +4 -0
  137. package/lib/utils/resolveCredentials.js +13 -0
  138. package/lib/utils/statusHelpers.d.ts +6 -0
  139. package/lib/utils/statusHelpers.js +19 -0
  140. package/lib/utils/trackerConfigHelpers.d.ts +5 -0
  141. package/lib/utils/trackerConfigHelpers.js +15 -0
  142. package/lib/utils/trackerConfigHelpers.native.d.ts +5 -0
  143. package/lib/utils/trackerConfigHelpers.native.js +14 -0
  144. package/lib/utils/trackerHelpers.d.ts +9 -0
  145. package/lib/utils/trackerHelpers.js +44 -0
  146. package/lib/utils/userAgent.js +3 -3
  147. package/lib-esm/apis/disable.d.ts +8 -0
  148. package/lib-esm/apis/disable.js +11 -0
  149. package/lib-esm/apis/enable.d.ts +7 -0
  150. package/lib-esm/apis/enable.js +10 -0
  151. package/lib-esm/apis/index.d.ts +2 -0
  152. package/lib-esm/apis/index.js +4 -0
  153. package/lib-esm/errors/AnalyticsError.d.ts +2 -2
  154. package/lib-esm/errors/AnalyticsError.js +7 -12
  155. package/lib-esm/errors/assertValidationError.d.ts +1 -1
  156. package/lib-esm/errors/assertValidationError.js +7 -3
  157. package/lib-esm/errors/validation.d.ts +5 -2
  158. package/lib-esm/errors/validation.js +22 -11
  159. package/lib-esm/index.d.ts +2 -1
  160. package/lib-esm/index.js +2 -1
  161. package/lib-esm/providers/kinesis/apis/flushEvents.d.ts +8 -0
  162. package/lib-esm/providers/kinesis/apis/flushEvents.js +31 -0
  163. package/lib-esm/providers/kinesis/apis/index.d.ts +2 -0
  164. package/lib-esm/providers/kinesis/apis/index.js +4 -0
  165. package/lib-esm/providers/kinesis/apis/record.d.ts +2 -0
  166. package/lib-esm/providers/kinesis/apis/record.js +42 -0
  167. package/lib-esm/providers/kinesis/index.d.ts +1 -0
  168. package/lib-esm/providers/kinesis/index.js +3 -0
  169. package/lib-esm/providers/kinesis/types/buffer.d.ts +15 -0
  170. package/lib-esm/providers/kinesis/types/buffer.js +3 -0
  171. package/lib-esm/providers/kinesis/types/index.d.ts +2 -0
  172. package/lib-esm/providers/kinesis/types/index.js +3 -0
  173. package/lib-esm/providers/kinesis/types/inputs.d.ts +6 -0
  174. package/lib-esm/providers/kinesis/types/inputs.js +3 -0
  175. package/lib-esm/providers/kinesis/utils/constants.d.ts +6 -0
  176. package/lib-esm/providers/kinesis/utils/constants.js +8 -0
  177. package/lib-esm/providers/kinesis/utils/getEventBuffer.d.ts +3 -0
  178. package/lib-esm/providers/kinesis/utils/getEventBuffer.js +68 -0
  179. package/lib-esm/providers/kinesis/utils/resolveConfig.d.ts +7 -0
  180. package/lib-esm/providers/kinesis/utils/resolveConfig.js +21 -0
  181. package/lib-esm/providers/kinesis-firehose/apis/flushEvents.d.ts +8 -0
  182. package/lib-esm/providers/kinesis-firehose/apis/flushEvents.js +30 -0
  183. package/lib-esm/providers/kinesis-firehose/apis/index.d.ts +2 -0
  184. package/lib-esm/providers/kinesis-firehose/apis/index.js +4 -0
  185. package/lib-esm/providers/kinesis-firehose/apis/record.d.ts +2 -0
  186. package/lib-esm/providers/kinesis-firehose/apis/record.js +39 -0
  187. package/lib-esm/providers/kinesis-firehose/index.d.ts +1 -0
  188. package/lib-esm/providers/kinesis-firehose/index.js +3 -0
  189. package/lib-esm/providers/kinesis-firehose/types/buffer.d.ts +15 -0
  190. package/lib-esm/providers/kinesis-firehose/types/index.d.ts +2 -0
  191. package/lib-esm/providers/kinesis-firehose/types/index.js +3 -0
  192. package/lib-esm/providers/kinesis-firehose/types/inputs.d.ts +5 -0
  193. package/lib-esm/providers/kinesis-firehose/types/inputs.js +3 -0
  194. package/lib-esm/providers/kinesis-firehose/utils/constants.d.ts +6 -0
  195. package/lib-esm/providers/kinesis-firehose/utils/constants.js +8 -0
  196. package/lib-esm/providers/kinesis-firehose/utils/getEventBuffer.d.ts +3 -0
  197. package/lib-esm/providers/kinesis-firehose/utils/getEventBuffer.js +67 -0
  198. package/lib-esm/providers/kinesis-firehose/utils/index.d.ts +2 -0
  199. package/lib-esm/providers/kinesis-firehose/utils/index.js +4 -0
  200. package/lib-esm/providers/kinesis-firehose/utils/resolveConfig.d.ts +7 -0
  201. package/lib-esm/providers/kinesis-firehose/utils/resolveConfig.js +21 -0
  202. package/lib-esm/providers/personalize/apis/flushEvents.d.ts +8 -0
  203. package/lib-esm/providers/personalize/apis/flushEvents.js +29 -0
  204. package/lib-esm/providers/personalize/apis/index.d.ts +2 -0
  205. package/lib-esm/providers/personalize/apis/index.js +4 -0
  206. package/lib-esm/providers/personalize/apis/record.d.ts +2 -0
  207. package/lib-esm/providers/personalize/apis/record.js +67 -0
  208. package/lib-esm/providers/personalize/index.d.ts +1 -0
  209. package/lib-esm/providers/personalize/index.js +3 -0
  210. package/lib-esm/providers/personalize/types/buffer.d.ts +16 -0
  211. package/lib-esm/providers/personalize/types/buffer.js +3 -0
  212. package/lib-esm/providers/personalize/types/index.d.ts +2 -0
  213. package/lib-esm/providers/personalize/types/index.js +3 -0
  214. package/lib-esm/providers/personalize/types/inputs.d.ts +7 -0
  215. package/lib-esm/providers/personalize/types/inputs.js +3 -0
  216. package/lib-esm/providers/personalize/utils/autoTrackMedia.d.ts +10 -0
  217. package/lib-esm/providers/personalize/utils/autoTrackMedia.js +177 -0
  218. package/lib-esm/providers/personalize/utils/cachedSession.d.ts +5 -0
  219. package/lib-esm/providers/personalize/utils/cachedSession.js +44 -0
  220. package/lib-esm/providers/personalize/utils/constants.d.ts +7 -0
  221. package/lib-esm/providers/personalize/utils/constants.js +9 -0
  222. package/lib-esm/providers/personalize/utils/getEventBuffer.d.ts +3 -0
  223. package/lib-esm/providers/personalize/utils/getEventBuffer.js +69 -0
  224. package/lib-esm/providers/personalize/utils/index.d.ts +5 -0
  225. package/lib-esm/providers/personalize/utils/index.js +7 -0
  226. package/lib-esm/providers/personalize/utils/resolveConfig.d.ts +7 -0
  227. package/lib-esm/providers/personalize/utils/resolveConfig.js +22 -0
  228. package/lib-esm/providers/pinpoint/apis/configureAutoTrack.d.ts +15 -0
  229. package/lib-esm/providers/pinpoint/apis/configureAutoTrack.js +31 -0
  230. package/lib-esm/providers/pinpoint/apis/flushEvents.d.ts +8 -0
  231. package/lib-esm/providers/pinpoint/apis/flushEvents.js +21 -0
  232. package/lib-esm/providers/pinpoint/apis/identifyUser.d.ts +7 -5
  233. package/lib-esm/providers/pinpoint/apis/identifyUser.js +22 -30
  234. package/lib-esm/providers/pinpoint/apis/index.d.ts +2 -0
  235. package/lib-esm/providers/pinpoint/apis/index.js +2 -0
  236. package/lib-esm/providers/pinpoint/apis/record.d.ts +8 -14
  237. package/lib-esm/providers/pinpoint/apis/record.js +26 -29
  238. package/lib-esm/providers/pinpoint/index.d.ts +2 -2
  239. package/lib-esm/providers/pinpoint/index.js +1 -1
  240. package/lib-esm/providers/pinpoint/types/index.d.ts +2 -2
  241. package/lib-esm/providers/pinpoint/types/index.js +1 -1
  242. package/lib-esm/providers/pinpoint/types/inputs.d.ts +8 -17
  243. package/lib-esm/providers/pinpoint/types/options.d.ts +5 -0
  244. package/lib-esm/providers/pinpoint/types/options.js +3 -0
  245. package/lib-esm/providers/pinpoint/utils/resolveConfig.js +3 -4
  246. package/lib-esm/providers/pinpoint/utils/resolveCredentials.d.ts +1 -6
  247. package/lib-esm/providers/pinpoint/utils/resolveCredentials.js +5 -13
  248. package/lib-esm/setupTests.js +1 -1
  249. package/lib-esm/trackers/EventTracker.d.ts +10 -0
  250. package/lib-esm/trackers/EventTracker.js +94 -0
  251. package/lib-esm/trackers/PageViewTracker.d.ts +18 -0
  252. package/lib-esm/trackers/PageViewTracker.js +108 -0
  253. package/lib-esm/trackers/SessionTracker.d.ts +13 -0
  254. package/lib-esm/trackers/SessionTracker.js +63 -0
  255. package/lib-esm/trackers/SessionTracker.native.d.ts +13 -0
  256. package/lib-esm/trackers/SessionTracker.native.js +63 -0
  257. package/lib-esm/trackers/index.d.ts +3 -0
  258. package/lib-esm/trackers/index.js +5 -0
  259. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  260. package/lib-esm/types/index.d.ts +3 -1
  261. package/lib-esm/types/index.js +1 -1
  262. package/lib-esm/types/inputs.d.ts +35 -0
  263. package/lib-esm/types/inputs.js +3 -0
  264. package/lib-esm/types/kinesis.d.ts +8 -0
  265. package/lib-esm/types/kinesis.js +3 -0
  266. package/lib-esm/types/options.d.ts +4 -0
  267. package/lib-esm/types/options.js +3 -0
  268. package/lib-esm/types/trackers.d.ts +22 -0
  269. package/lib-esm/types/trackers.js +3 -0
  270. package/lib-esm/utils/eventBuffer/EventBuffer.d.ts +16 -0
  271. package/lib-esm/utils/eventBuffer/EventBuffer.js +59 -0
  272. package/lib-esm/utils/eventBuffer/index.d.ts +2 -0
  273. package/lib-esm/utils/eventBuffer/index.js +3 -0
  274. package/lib-esm/utils/eventBuffer/types.d.ts +8 -0
  275. package/lib-esm/utils/eventBuffer/types.js +3 -0
  276. package/lib-esm/utils/groupBy.d.ts +1 -0
  277. package/lib-esm/utils/groupBy.js +8 -0
  278. package/lib-esm/utils/index.d.ts +7 -0
  279. package/lib-esm/utils/index.js +9 -0
  280. package/lib-esm/utils/resolveCredentials.d.ts +4 -0
  281. package/lib-esm/utils/resolveCredentials.js +9 -0
  282. package/lib-esm/utils/statusHelpers.d.ts +6 -0
  283. package/lib-esm/utils/statusHelpers.js +13 -0
  284. package/lib-esm/utils/trackerConfigHelpers.d.ts +5 -0
  285. package/lib-esm/utils/trackerConfigHelpers.js +11 -0
  286. package/lib-esm/utils/trackerConfigHelpers.native.d.ts +5 -0
  287. package/lib-esm/utils/trackerConfigHelpers.native.js +10 -0
  288. package/lib-esm/utils/trackerHelpers.d.ts +9 -0
  289. package/lib-esm/utils/trackerHelpers.js +40 -0
  290. package/lib-esm/utils/userAgent.js +2 -2
  291. package/package.json +39 -12
  292. package/personalize/package.json +7 -0
  293. package/src/apis/disable.ts +13 -0
  294. package/src/apis/enable.ts +12 -0
  295. package/src/apis/index.ts +5 -0
  296. package/src/errors/AnalyticsError.ts +5 -2
  297. package/src/errors/assertValidationError.ts +9 -3
  298. package/src/errors/validation.ts +16 -4
  299. package/src/index.ts +4 -0
  300. package/src/providers/kinesis/apis/flushEvents.ts +40 -0
  301. package/src/providers/kinesis/apis/index.ts +5 -0
  302. package/src/providers/kinesis/apis/record.ts +58 -0
  303. package/src/providers/kinesis/index.ts +4 -0
  304. package/src/providers/kinesis/types/buffer.ts +20 -0
  305. package/src/providers/kinesis/types/index.ts +5 -0
  306. package/src/providers/kinesis/types/inputs.ts +10 -0
  307. package/src/providers/kinesis/utils/constants.ts +9 -0
  308. package/src/providers/kinesis/utils/getEventBuffer.ts +109 -0
  309. package/src/providers/kinesis/utils/resolveConfig.ts +36 -0
  310. package/src/providers/kinesis-firehose/apis/flushEvents.ts +39 -0
  311. package/src/providers/kinesis-firehose/apis/index.ts +5 -0
  312. package/src/providers/kinesis-firehose/apis/record.ts +51 -0
  313. package/src/providers/kinesis-firehose/index.ts +4 -0
  314. package/src/providers/kinesis-firehose/types/buffer.ts +20 -0
  315. package/src/providers/kinesis-firehose/types/index.ts +9 -0
  316. package/src/providers/kinesis-firehose/types/inputs.ts +9 -0
  317. package/src/providers/kinesis-firehose/utils/constants.ts +9 -0
  318. package/src/providers/kinesis-firehose/utils/getEventBuffer.ts +117 -0
  319. package/src/providers/kinesis-firehose/utils/index.ts +5 -0
  320. package/src/providers/kinesis-firehose/utils/resolveConfig.ts +36 -0
  321. package/src/providers/personalize/apis/flushEvents.ts +37 -0
  322. package/src/providers/personalize/apis/index.ts +5 -0
  323. package/src/providers/personalize/apis/record.ts +102 -0
  324. package/src/providers/personalize/index.ts +4 -0
  325. package/src/providers/personalize/types/buffer.ts +21 -0
  326. package/src/providers/personalize/types/index.ts +5 -0
  327. package/src/providers/personalize/types/inputs.ts +11 -0
  328. package/src/providers/personalize/utils/autoTrackMedia.ts +232 -0
  329. package/src/providers/personalize/utils/cachedSession.ts +68 -0
  330. package/src/providers/personalize/utils/constants.ts +12 -0
  331. package/src/providers/personalize/utils/getEventBuffer.ts +110 -0
  332. package/src/providers/personalize/utils/index.ts +11 -0
  333. package/src/providers/personalize/utils/resolveConfig.ts +41 -0
  334. package/src/providers/pinpoint/apis/configureAutoTrack.ts +49 -0
  335. package/src/providers/pinpoint/apis/flushEvents.ts +32 -0
  336. package/src/providers/pinpoint/apis/identifyUser.ts +20 -12
  337. package/src/providers/pinpoint/apis/index.ts +2 -0
  338. package/src/providers/pinpoint/apis/record.ts +31 -23
  339. package/src/providers/pinpoint/index.ts +6 -2
  340. package/src/providers/pinpoint/types/index.ts +6 -2
  341. package/src/providers/pinpoint/types/inputs.ts +11 -17
  342. package/src/providers/pinpoint/types/options.ts +12 -0
  343. package/src/trackers/EventTracker.ts +135 -0
  344. package/src/trackers/PageViewTracker.ts +160 -0
  345. package/src/trackers/SessionTracker.native.ts +105 -0
  346. package/src/trackers/SessionTracker.ts +105 -0
  347. package/src/trackers/index.ts +6 -0
  348. package/src/types/index.ts +8 -1
  349. package/src/types/inputs.ts +52 -0
  350. package/src/types/kinesis.ts +13 -0
  351. package/src/types/options.ts +7 -0
  352. package/src/types/trackers.ts +35 -0
  353. package/src/utils/eventBuffer/EventBuffer.ts +84 -0
  354. package/src/utils/eventBuffer/index.ts +5 -0
  355. package/src/utils/eventBuffer/types.ts +12 -0
  356. package/src/utils/groupBy.ts +12 -0
  357. package/src/utils/index.ts +21 -0
  358. package/src/utils/resolveCredentials.ts +14 -0
  359. package/src/utils/statusHelpers.ts +17 -0
  360. package/src/utils/trackerConfigHelpers.native.ts +18 -0
  361. package/src/utils/trackerConfigHelpers.ts +19 -0
  362. package/src/utils/trackerHelpers.ts +57 -0
  363. package/lib/providers/pinpoint/types/errors.d.ts +0 -9
  364. package/lib/providers/pinpoint/types/errors.js +0 -15
  365. package/lib/types/analytics.d.ts +0 -50
  366. package/lib-esm/providers/pinpoint/types/errors.d.ts +0 -9
  367. package/lib-esm/providers/pinpoint/types/errors.js +0 -12
  368. package/lib-esm/types/analytics.d.ts +0 -50
  369. package/src/providers/pinpoint/types/errors.ts +0 -12
  370. package/src/types/analytics.ts +0 -70
  371. /package/lib/{types/analytics.js → providers/kinesis-firehose/types/buffer.js} +0 -0
  372. /package/lib-esm/{types/analytics.js → providers/kinesis-firehose/types/buffer.js} +0 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@aws-amplify/analytics/kinesis",
3
+ "main": "../lib/providers/kinesis/index.js",
4
+ "browser": "../lib-esm/providers/kinesis/index.js",
5
+ "module": "../lib-esm/providers/kinesis/index.js",
6
+ "typings": "../lib-esm/providers/kinesis/index.d.ts"
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@aws-amplify/analytics/kinesis-firehose",
3
+ "main": "../lib/providers/kinesis-firehose/index.js",
4
+ "browser": "../lib-esm/providers/kinesis-firehose/index.js",
5
+ "module": "../lib-esm/providers/kinesis-firehose/index.js",
6
+ "typings": "../lib-esm/providers/kinesis-firehose/index.d.ts"
7
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Disables the Analytics category.
3
+ *
4
+ * @note
5
+ * When Analytics is disabled events will not be buffered or transmitted to your selected service. Any auto-tracking
6
+ * behavior that you have configured via `configureAutoTrack` will not have any effect while Analytics is disabled.
7
+ */
8
+ export declare const disable: () => void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.disable = void 0;
6
+ const utils_1 = require("../utils");
7
+ /**
8
+ * Disables the Analytics category.
9
+ *
10
+ * @note
11
+ * When Analytics is disabled events will not be buffered or transmitted to your selected service. Any auto-tracking
12
+ * behavior that you have configured via `configureAutoTrack` will not have any effect while Analytics is disabled.
13
+ */
14
+ exports.disable = utils_1.disableAnalytics;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Enables the Analytics category to permit the transmission of events.
3
+ *
4
+ * @note
5
+ * Analytics is enabled by default. You do not need to call this API unless you have disabled Analytics.
6
+ */
7
+ export declare const enable: () => void;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.enable = void 0;
6
+ const utils_1 = require("../utils");
7
+ /**
8
+ * Enables the Analytics category to permit the transmission of events.
9
+ *
10
+ * @note
11
+ * Analytics is enabled by default. You do not need to call this API unless you have disabled Analytics.
12
+ */
13
+ exports.enable = utils_1.enableAnalytics;
@@ -0,0 +1,2 @@
1
+ export { enable } from './enable';
2
+ export { disable } from './disable';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.disable = exports.enable = void 0;
6
+ var enable_1 = require("./enable");
7
+ Object.defineProperty(exports, "enable", { enumerable: true, get: function () { return enable_1.enable; } });
8
+ var disable_1 = require("./disable");
9
+ Object.defineProperty(exports, "disable", { enumerable: true, get: function () { return disable_1.disable; } });
@@ -1,7 +1,7 @@
1
- import { AmplifyError, ErrorParams } from '@aws-amplify/core/internals/utils';
1
+ import { AmplifyError, AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
2
2
  /**
3
3
  * @internal
4
4
  */
5
5
  export declare class AnalyticsError extends AmplifyError {
6
- constructor(params: ErrorParams);
6
+ constructor(params: AmplifyErrorParams);
7
7
  }
@@ -3,21 +3,17 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.AnalyticsError = void 0;
6
- var tslib_1 = require("tslib");
7
- var utils_1 = require("@aws-amplify/core/internals/utils");
6
+ const utils_1 = require("@aws-amplify/core/internals/utils");
8
7
  /**
9
8
  * @internal
10
9
  */
11
- var AnalyticsError = /** @class */ (function (_super) {
12
- tslib_1.__extends(AnalyticsError, _super);
13
- function AnalyticsError(params) {
14
- var _this = _super.call(this, params) || this;
10
+ class AnalyticsError extends utils_1.AmplifyError {
11
+ constructor(params) {
12
+ super(params);
15
13
  // Hack for making the custom error class work when transpiled to es5
16
14
  // TODO: Delete the following 2 lines after we change the build target to >= es2015
17
- _this.constructor = AnalyticsError;
18
- Object.setPrototypeOf(_this, AnalyticsError.prototype);
19
- return _this;
15
+ this.constructor = AnalyticsError;
16
+ Object.setPrototypeOf(this, AnalyticsError.prototype);
20
17
  }
21
- return AnalyticsError;
22
- }(utils_1.AmplifyError));
18
+ }
23
19
  exports.AnalyticsError = AnalyticsError;
@@ -2,4 +2,4 @@ import { AnalyticsValidationErrorCode } from './validation';
2
2
  /**
3
3
  * @internal
4
4
  */
5
- export declare function assertValidationError(assertion: boolean, name: AnalyticsValidationErrorCode): asserts assertion;
5
+ export declare function assertValidationError(assertion: boolean, name: AnalyticsValidationErrorCode, message?: string): asserts assertion;
@@ -3,15 +3,19 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.assertValidationError = void 0;
6
- var AnalyticsError_1 = require("./AnalyticsError");
7
- var validation_1 = require("./validation");
6
+ const AnalyticsError_1 = require("./AnalyticsError");
7
+ const validation_1 = require("./validation");
8
8
  /**
9
9
  * @internal
10
10
  */
11
- function assertValidationError(assertion, name) {
12
- var _a = validation_1.validationErrorMap[name], message = _a.message, recoverySuggestion = _a.recoverySuggestion;
11
+ function assertValidationError(assertion, name, message) {
12
+ const { message: defaultMessage, recoverySuggestion } = validation_1.validationErrorMap[name];
13
13
  if (!assertion) {
14
- throw new AnalyticsError_1.AnalyticsError({ name: name, message: message, recoverySuggestion: recoverySuggestion });
14
+ throw new AnalyticsError_1.AnalyticsError({
15
+ name,
16
+ message: message ?? defaultMessage,
17
+ recoverySuggestion,
18
+ });
15
19
  }
16
20
  }
17
21
  exports.assertValidationError = assertValidationError;
@@ -2,8 +2,11 @@ import { AmplifyErrorMap } from '@aws-amplify/core/internals/utils';
2
2
  export declare enum AnalyticsValidationErrorCode {
3
3
  NoAppId = "NoAppId",
4
4
  NoCredentials = "NoCredentials",
5
- NoEvent = "NoEvent",
6
5
  NoEventName = "NoEventName",
7
- NoRegion = "NoRegion"
6
+ NoRegion = "NoRegion",
7
+ InvalidTracker = "InvalidTracker",
8
+ UnsupportedPlatform = "UnsupportedPlatform",
9
+ NoTrackingId = "NoTrackingId",
10
+ InvalidFlushSize = "InvalidFlushSize"
8
11
  }
9
12
  export declare const validationErrorMap: AmplifyErrorMap<AnalyticsValidationErrorCode>;
@@ -1,31 +1,42 @@
1
1
  "use strict";
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
- var _a;
5
4
  Object.defineProperty(exports, "__esModule", { value: true });
6
5
  exports.validationErrorMap = exports.AnalyticsValidationErrorCode = void 0;
7
6
  var AnalyticsValidationErrorCode;
8
7
  (function (AnalyticsValidationErrorCode) {
9
8
  AnalyticsValidationErrorCode["NoAppId"] = "NoAppId";
10
9
  AnalyticsValidationErrorCode["NoCredentials"] = "NoCredentials";
11
- AnalyticsValidationErrorCode["NoEvent"] = "NoEvent";
12
10
  AnalyticsValidationErrorCode["NoEventName"] = "NoEventName";
13
11
  AnalyticsValidationErrorCode["NoRegion"] = "NoRegion";
12
+ AnalyticsValidationErrorCode["InvalidTracker"] = "InvalidTracker";
13
+ AnalyticsValidationErrorCode["UnsupportedPlatform"] = "UnsupportedPlatform";
14
+ AnalyticsValidationErrorCode["NoTrackingId"] = "NoTrackingId";
15
+ AnalyticsValidationErrorCode["InvalidFlushSize"] = "InvalidFlushSize";
14
16
  })(AnalyticsValidationErrorCode = exports.AnalyticsValidationErrorCode || (exports.AnalyticsValidationErrorCode = {}));
15
- exports.validationErrorMap = (_a = {},
16
- _a[AnalyticsValidationErrorCode.NoAppId] = {
17
+ exports.validationErrorMap = {
18
+ [AnalyticsValidationErrorCode.NoAppId]: {
17
19
  message: 'Missing application id.',
18
20
  },
19
- _a[AnalyticsValidationErrorCode.NoCredentials] = {
21
+ [AnalyticsValidationErrorCode.NoCredentials]: {
20
22
  message: 'Credentials should not be empty.',
21
23
  },
22
- _a[AnalyticsValidationErrorCode.NoEvent] = {
23
- message: 'An event is required to record.',
24
- },
25
- _a[AnalyticsValidationErrorCode.NoEventName] = {
24
+ [AnalyticsValidationErrorCode.NoEventName]: {
26
25
  message: 'Events must specify a name.',
27
26
  },
28
- _a[AnalyticsValidationErrorCode.NoRegion] = {
27
+ [AnalyticsValidationErrorCode.NoRegion]: {
29
28
  message: 'Missing region.',
30
29
  },
31
- _a);
30
+ [AnalyticsValidationErrorCode.InvalidTracker]: {
31
+ message: 'Invalid tracker type specified.',
32
+ },
33
+ [AnalyticsValidationErrorCode.UnsupportedPlatform]: {
34
+ message: 'Only session tracking is supported on React Native.',
35
+ },
36
+ [AnalyticsValidationErrorCode.InvalidFlushSize]: {
37
+ message: 'Invalid FlushSize, it should be smaller than BufferSize',
38
+ },
39
+ [AnalyticsValidationErrorCode.NoTrackingId]: {
40
+ message: 'A trackingId is required to use Amazon Personalize',
41
+ },
42
+ };
package/lib/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export { record, identifyUser, RecordInput, IdentifyUserInput, } from './providers/pinpoint';
1
+ export { record, identifyUser, configureAutoTrack, flushEvents, RecordInput, IdentifyUserInput, ConfigureAutoTrackInput, } from './providers/pinpoint';
2
+ export { enable, disable } from './apis';
2
3
  export { AnalyticsError } from './errors';
package/lib/index.js CHANGED
@@ -2,9 +2,14 @@
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.AnalyticsError = exports.identifyUser = exports.record = void 0;
5
+ exports.AnalyticsError = exports.disable = exports.enable = exports.flushEvents = exports.configureAutoTrack = exports.identifyUser = exports.record = void 0;
6
6
  var pinpoint_1 = require("./providers/pinpoint");
7
7
  Object.defineProperty(exports, "record", { enumerable: true, get: function () { return pinpoint_1.record; } });
8
8
  Object.defineProperty(exports, "identifyUser", { enumerable: true, get: function () { return pinpoint_1.identifyUser; } });
9
+ Object.defineProperty(exports, "configureAutoTrack", { enumerable: true, get: function () { return pinpoint_1.configureAutoTrack; } });
10
+ Object.defineProperty(exports, "flushEvents", { enumerable: true, get: function () { return pinpoint_1.flushEvents; } });
11
+ var apis_1 = require("./apis");
12
+ Object.defineProperty(exports, "enable", { enumerable: true, get: function () { return apis_1.enable; } });
13
+ Object.defineProperty(exports, "disable", { enumerable: true, get: function () { return apis_1.disable; } });
9
14
  var errors_1 = require("./errors");
10
15
  Object.defineProperty(exports, "AnalyticsError", { enumerable: true, get: function () { return errors_1.AnalyticsError; } });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Flushes all buffered Kinesis events to the service.
3
+ *
4
+ * @note
5
+ * This API will make a best-effort attempt to flush events from the buffer. Events recorded immediately after invoking
6
+ * this API may not be included in the flush.
7
+ */
8
+ export declare const flushEvents: () => void;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.flushEvents = void 0;
6
+ const resolveConfig_1 = require("../utils/resolveConfig");
7
+ const utils_1 = require("../../../utils");
8
+ const getEventBuffer_1 = require("../utils/getEventBuffer");
9
+ const utils_2 = require("@aws-amplify/core/internals/utils");
10
+ const core_1 = require("@aws-amplify/core");
11
+ const logger = new core_1.ConsoleLogger('Kinesis');
12
+ /**
13
+ * Flushes all buffered Kinesis events to the service.
14
+ *
15
+ * @note
16
+ * This API will make a best-effort attempt to flush events from the buffer. Events recorded immediately after invoking
17
+ * this API may not be included in the flush.
18
+ */
19
+ const flushEvents = () => {
20
+ const { region, flushSize, flushInterval, bufferSize, resendLimit } = (0, resolveConfig_1.resolveConfig)();
21
+ (0, utils_1.resolveCredentials)()
22
+ .then(({ credentials, identityId }) => (0, getEventBuffer_1.getEventBuffer)({
23
+ region,
24
+ flushSize,
25
+ flushInterval,
26
+ bufferSize,
27
+ credentials,
28
+ identityId,
29
+ resendLimit,
30
+ userAgentValue: (0, utils_1.getAnalyticsUserAgentString)(utils_2.AnalyticsAction.Record),
31
+ }))
32
+ .then(eventBuffer => eventBuffer.flushAll())
33
+ .catch(e => logger.warn('Failed to flush events.', e));
34
+ };
35
+ exports.flushEvents = flushEvents;
@@ -0,0 +1,2 @@
1
+ export { record } from './record';
2
+ export { flushEvents } from './flushEvents';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.flushEvents = exports.record = void 0;
6
+ var record_1 = require("./record");
7
+ Object.defineProperty(exports, "record", { enumerable: true, get: function () { return record_1.record; } });
8
+ var flushEvents_1 = require("./flushEvents");
9
+ Object.defineProperty(exports, "flushEvents", { enumerable: true, get: function () { return flushEvents_1.flushEvents; } });
@@ -0,0 +1,2 @@
1
+ import { RecordInput } from '../types';
2
+ export declare const record: ({ streamName, partitionKey, data, }: RecordInput) => void;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.record = void 0;
6
+ const getEventBuffer_1 = require("../utils/getEventBuffer");
7
+ const resolveConfig_1 = require("../utils/resolveConfig");
8
+ const utils_1 = require("../../../utils");
9
+ const util_utf8_1 = require("@smithy/util-utf8");
10
+ const utils_2 = require("@aws-amplify/core/internals/utils");
11
+ const core_1 = require("@aws-amplify/core");
12
+ const logger = new core_1.ConsoleLogger('Kinesis');
13
+ const record = ({ streamName, partitionKey, data, }) => {
14
+ if (!(0, utils_1.isAnalyticsEnabled)()) {
15
+ logger.debug('Analytics is disabled, event will not be recorded.');
16
+ return;
17
+ }
18
+ const timestamp = Date.now();
19
+ const { region, bufferSize, flushSize, flushInterval, resendLimit } = (0, resolveConfig_1.resolveConfig)();
20
+ (0, utils_1.resolveCredentials)()
21
+ .then(({ credentials, identityId }) => {
22
+ const buffer = (0, getEventBuffer_1.getEventBuffer)({
23
+ region,
24
+ bufferSize,
25
+ flushSize,
26
+ flushInterval,
27
+ credentials,
28
+ identityId,
29
+ resendLimit,
30
+ userAgentValue: (0, utils_1.getAnalyticsUserAgentString)(utils_2.AnalyticsAction.Record),
31
+ });
32
+ buffer.append({
33
+ region,
34
+ streamName,
35
+ partitionKey,
36
+ event: ArrayBuffer.isView(data) ? data : (0, util_utf8_1.fromUtf8)(JSON.stringify(data)),
37
+ timestamp,
38
+ retryCount: 0,
39
+ });
40
+ })
41
+ .catch(e => {
42
+ // An error occured while fetching credentials or persisting the event to the buffer
43
+ logger.warn('Failed to record event.', e);
44
+ });
45
+ };
46
+ exports.record = record;
@@ -0,0 +1 @@
1
+ export { record, flushEvents } from './apis';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.flushEvents = exports.record = void 0;
6
+ var apis_1 = require("./apis");
7
+ Object.defineProperty(exports, "record", { enumerable: true, get: function () { return apis_1.record; } });
8
+ Object.defineProperty(exports, "flushEvents", { enumerable: true, get: function () { return apis_1.flushEvents; } });
@@ -0,0 +1,15 @@
1
+ import { AWSCredentials } from '@aws-amplify/core/internals/utils';
2
+ import { EventBufferConfig } from '../../../utils';
3
+ import { KinesisShard } from '../../../types';
4
+ export type KinesisBufferEvent = KinesisShard & {
5
+ event: Uint8Array;
6
+ timestamp: number;
7
+ retryCount: number;
8
+ };
9
+ export type KinesisEventBufferConfig = EventBufferConfig & {
10
+ region: string;
11
+ credentials: AWSCredentials;
12
+ identityId?: string;
13
+ resendLimit?: number;
14
+ userAgentValue?: string;
15
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export { RecordInput } from './inputs';
2
+ export { KinesisBufferEvent, KinesisEventBufferConfig } from './buffer';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { KinesisEventData } from '../../../types';
2
+ export type RecordInput = {
3
+ streamName: string;
4
+ partitionKey: string;
5
+ data: KinesisEventData;
6
+ };
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ export declare const DEFAULT_KINESIS_CONFIG: {
2
+ bufferSize: number;
3
+ flushSize: number;
4
+ flushInterval: number;
5
+ resendLimit: number;
6
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.DEFAULT_KINESIS_CONFIG = void 0;
6
+ exports.DEFAULT_KINESIS_CONFIG = {
7
+ bufferSize: 1000,
8
+ flushSize: 100,
9
+ flushInterval: 5000,
10
+ resendLimit: 5,
11
+ };
@@ -0,0 +1,3 @@
1
+ import { KinesisBufferEvent, KinesisEventBufferConfig } from '../types';
2
+ import { EventBuffer } from '../../../utils';
3
+ export declare const getEventBuffer: ({ region, flushInterval, flushSize, bufferSize, credentials, identityId, resendLimit, userAgentValue, }: KinesisEventBufferConfig) => EventBuffer<KinesisBufferEvent>;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.getEventBuffer = void 0;
6
+ const utils_1 = require("../../../utils");
7
+ const client_kinesis_1 = require("@aws-sdk/client-kinesis");
8
+ /**
9
+ * These Records hold cached event buffers and AWS clients.
10
+ * The hash key is determined by the region and session,
11
+ * consisting of a combined value comprising [region, sessionToken, identityId].
12
+ *
13
+ * Only one active session should exist at any given moment.
14
+ * When a new session is initiated, the previous ones should be released.
15
+ * */
16
+ const eventBufferMap = {};
17
+ const cachedClients = {};
18
+ const createKinesisPutRecordsCommand = (streamName, events) => new client_kinesis_1.PutRecordsCommand({
19
+ StreamName: streamName,
20
+ Records: events.map(event => ({
21
+ PartitionKey: event.partitionKey,
22
+ Data: event.event,
23
+ })),
24
+ });
25
+ const submitEvents = async (events, client, resendLimit) => {
26
+ const groupedByStreamName = Object.entries((0, utils_1.groupBy)(event => event.streamName, events));
27
+ const requests = groupedByStreamName
28
+ .map(([streamName, events]) => createKinesisPutRecordsCommand(streamName, events))
29
+ .map(command => client.send(command));
30
+ const responses = await Promise.allSettled(requests);
31
+ const failedEvents = responses
32
+ .map((response, i) => response.status === 'rejected' ? groupedByStreamName[i][1] : [])
33
+ .flat();
34
+ return resendLimit
35
+ ? failedEvents
36
+ .filter(event => event.retryCount < resendLimit)
37
+ .map(event => ({ ...event, retryCount: event.retryCount + 1 }))
38
+ .sort((a, b) => a.timestamp - b.timestamp)
39
+ : [];
40
+ };
41
+ const getEventBuffer = ({ region, flushInterval, flushSize, bufferSize, credentials, identityId, resendLimit, userAgentValue, }) => {
42
+ const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
43
+ if (!eventBufferMap[sessionIdentityKey]) {
44
+ const getKinesisClient = () => {
45
+ if (!cachedClients[sessionIdentityKey]) {
46
+ cachedClients[sessionIdentityKey] = new client_kinesis_1.KinesisClient({
47
+ credentials,
48
+ region,
49
+ customUserAgent: userAgentValue,
50
+ });
51
+ }
52
+ return events => submitEvents(events, cachedClients[sessionIdentityKey], resendLimit);
53
+ };
54
+ // create new session
55
+ eventBufferMap[sessionIdentityKey] = new utils_1.EventBuffer({
56
+ flushInterval,
57
+ flushSize,
58
+ bufferSize,
59
+ }, getKinesisClient);
60
+ // release other sessions
61
+ const releaseSessionKeys = Object.keys(eventBufferMap).filter(x => x !== sessionIdentityKey);
62
+ for (const releaseSessionKey of releaseSessionKeys) {
63
+ eventBufferMap[releaseSessionKey].flushAll().finally(() => {
64
+ eventBufferMap[releaseSessionKey].release();
65
+ delete eventBufferMap[releaseSessionKey];
66
+ delete cachedClients[releaseSessionKey];
67
+ });
68
+ }
69
+ }
70
+ return eventBufferMap[sessionIdentityKey];
71
+ };
72
+ exports.getEventBuffer = getEventBuffer;
@@ -0,0 +1,7 @@
1
+ export declare const resolveConfig: () => {
2
+ region: string;
3
+ bufferSize: number;
4
+ flushSize: number;
5
+ flushInterval: number;
6
+ resendLimit: number;
7
+ };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.resolveConfig = void 0;
6
+ const core_1 = require("@aws-amplify/core");
7
+ const errors_1 = require("../../../errors");
8
+ const constants_1 = require("./constants");
9
+ const resolveConfig = () => {
10
+ const config = core_1.Amplify.getConfig().Analytics?.Kinesis;
11
+ const { region, bufferSize = constants_1.DEFAULT_KINESIS_CONFIG.bufferSize, flushSize = constants_1.DEFAULT_KINESIS_CONFIG.flushSize, flushInterval = constants_1.DEFAULT_KINESIS_CONFIG.flushInterval, resendLimit, } = {
12
+ ...constants_1.DEFAULT_KINESIS_CONFIG,
13
+ ...config,
14
+ };
15
+ (0, errors_1.assertValidationError)(!!region, errors_1.AnalyticsValidationErrorCode.NoRegion);
16
+ (0, errors_1.assertValidationError)(flushSize < bufferSize, errors_1.AnalyticsValidationErrorCode.InvalidFlushSize);
17
+ return {
18
+ region,
19
+ bufferSize,
20
+ flushSize,
21
+ flushInterval,
22
+ resendLimit,
23
+ };
24
+ };
25
+ exports.resolveConfig = resolveConfig;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Flushes all buffered Kinesis events to the service.
3
+ *
4
+ * @note
5
+ * This API will make a best-effort attempt to flush events from the buffer. Events recorded immediately after invoking
6
+ * this API may not be included in the flush.
7
+ */
8
+ export declare const flushEvents: () => void;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.flushEvents = void 0;
6
+ const utils_1 = require("../utils");
7
+ const utils_2 = require("../../../utils");
8
+ const utils_3 = require("@aws-amplify/core/internals/utils");
9
+ const core_1 = require("@aws-amplify/core");
10
+ const logger = new core_1.ConsoleLogger('KinesisFirehose');
11
+ /**
12
+ * Flushes all buffered Kinesis events to the service.
13
+ *
14
+ * @note
15
+ * This API will make a best-effort attempt to flush events from the buffer. Events recorded immediately after invoking
16
+ * this API may not be included in the flush.
17
+ */
18
+ const flushEvents = () => {
19
+ const { region, flushSize, flushInterval, bufferSize, resendLimit } = (0, utils_1.resolveConfig)();
20
+ (0, utils_2.resolveCredentials)()
21
+ .then(({ credentials, identityId }) => (0, utils_1.getEventBuffer)({
22
+ region,
23
+ flushSize,
24
+ flushInterval,
25
+ bufferSize,
26
+ credentials,
27
+ identityId,
28
+ resendLimit,
29
+ userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_3.AnalyticsAction.Record),
30
+ }))
31
+ .then(eventBuffer => eventBuffer.flushAll())
32
+ .catch(e => logger.warn('Failed to flush events.', e));
33
+ };
34
+ exports.flushEvents = flushEvents;
@@ -0,0 +1,2 @@
1
+ export { record } from './record';
2
+ export { flushEvents } from './flushEvents';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.flushEvents = exports.record = void 0;
6
+ var record_1 = require("./record");
7
+ Object.defineProperty(exports, "record", { enumerable: true, get: function () { return record_1.record; } });
8
+ var flushEvents_1 = require("./flushEvents");
9
+ Object.defineProperty(exports, "flushEvents", { enumerable: true, get: function () { return flushEvents_1.flushEvents; } });
@@ -0,0 +1,2 @@
1
+ import { RecordInput } from '../types';
2
+ export declare const record: ({ streamName, data }: RecordInput) => void;