@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,49 @@
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.updateCachedSession = exports.resolveCachedSession = void 0;
6
+ const core_1 = require("@aws-amplify/core");
7
+ const utils_1 = require("@aws-amplify/core/internals/utils");
8
+ const PERSONALIZE_CACHE_USERID = '_awsct_uid';
9
+ const PERSONALIZE_CACHE_SESSIONID = '_awsct_sid';
10
+ const DEFAULT_CACHE_PREFIX = 'personalize';
11
+ const DELIMITER = '.';
12
+ const CACHE_EXPIRY_IN_DAYS = 7;
13
+ const normalize = (key) => [key, (0, utils_1.isBrowser)() ? window.location.host : DEFAULT_CACHE_PREFIX].join(DELIMITER);
14
+ const getCache = (key) => core_1.Cache.getItem(normalize(key));
15
+ const setCache = (key, value) => {
16
+ const expiredAt = new Date(Date.now() + 3600000 * 24 * CACHE_EXPIRY_IN_DAYS);
17
+ core_1.Cache.setItem(normalize(key), value, {
18
+ expires: expiredAt.getTime(),
19
+ });
20
+ };
21
+ const resolveCachedSession = async () => {
22
+ let sessionId = await getCache(PERSONALIZE_CACHE_SESSIONID);
23
+ if (!sessionId) {
24
+ sessionId = (0, utils_1.amplifyUuid)();
25
+ setCache(PERSONALIZE_CACHE_SESSIONID, sessionId);
26
+ }
27
+ const userId = await getCache(PERSONALIZE_CACHE_USERID);
28
+ return {
29
+ sessionId,
30
+ userId,
31
+ };
32
+ };
33
+ exports.resolveCachedSession = resolveCachedSession;
34
+ const updateCachedSession = (newUserId, currentSessionId, currentUserId) => {
35
+ const isNoCachedSession = !currentSessionId;
36
+ const isSignOutCase = !newUserId && !currentUserId;
37
+ const isSwitchUserCase = !!newUserId && !!currentUserId && newUserId !== currentUserId;
38
+ const isRequireNewSession = isNoCachedSession || isSignOutCase || isSwitchUserCase;
39
+ const isRequireUpdateSession = !!currentSessionId && !currentUserId && !!newUserId;
40
+ if (isRequireNewSession) {
41
+ const newSessionId = (0, utils_1.amplifyUuid)();
42
+ setCache(PERSONALIZE_CACHE_SESSIONID, newSessionId);
43
+ setCache(PERSONALIZE_CACHE_USERID, newUserId);
44
+ }
45
+ else if (isRequireUpdateSession) {
46
+ setCache(PERSONALIZE_CACHE_USERID, newUserId);
47
+ }
48
+ };
49
+ exports.updateCachedSession = updateCachedSession;
@@ -0,0 +1,7 @@
1
+ export declare const DEFAULT_PERSONALIZE_CONFIG: {
2
+ flushSize: number;
3
+ flushInterval: number;
4
+ };
5
+ export declare const PERSONALIZE_FLUSH_SIZE_MAX = 10;
6
+ export declare const IDENTIFY_EVENT_TYPE = "Identify";
7
+ export declare const MEDIA_AUTO_TRACK_EVENT_TYPE = "MediaAutoTrack";
@@ -0,0 +1,12 @@
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.MEDIA_AUTO_TRACK_EVENT_TYPE = exports.IDENTIFY_EVENT_TYPE = exports.PERSONALIZE_FLUSH_SIZE_MAX = exports.DEFAULT_PERSONALIZE_CONFIG = void 0;
6
+ exports.DEFAULT_PERSONALIZE_CONFIG = {
7
+ flushSize: 5,
8
+ flushInterval: 5000,
9
+ };
10
+ exports.PERSONALIZE_FLUSH_SIZE_MAX = 10;
11
+ exports.IDENTIFY_EVENT_TYPE = 'Identify';
12
+ exports.MEDIA_AUTO_TRACK_EVENT_TYPE = 'MediaAutoTrack';
@@ -0,0 +1,3 @@
1
+ import { EventBuffer } from '../../../utils';
2
+ import { PersonalizeBufferConfig, PersonalizeBufferEvent } from '../types';
3
+ export declare const getEventBuffer: ({ region, flushSize, flushInterval, bufferSize, credentials, identityId, userAgentValue, }: PersonalizeBufferConfig) => EventBuffer<PersonalizeBufferEvent>;
@@ -0,0 +1,73 @@
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_personalize_events_1 = require("@aws-sdk/client-personalize-events");
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 DELIMITER = '#';
19
+ const createPutEventsCommand = (ids, events) => {
20
+ const [trackingId, sessionId, userId] = ids.split(DELIMITER);
21
+ return new client_personalize_events_1.PutEventsCommand({
22
+ trackingId,
23
+ sessionId,
24
+ userId,
25
+ eventList: events.map(event => ({
26
+ eventId: event.event.eventId,
27
+ eventType: event.event.eventType,
28
+ properties: JSON.stringify(event.event.properties),
29
+ sentAt: new Date(event.timestamp),
30
+ })),
31
+ });
32
+ };
33
+ const submitEvents = async (events, client) => {
34
+ const groupedByIds = Object.entries((0, utils_1.groupBy)(event => [event.trackingId, event.sessionId, event.userId]
35
+ .filter(id => !!id)
36
+ .join(DELIMITER), events));
37
+ const requests = groupedByIds
38
+ .map(([ids, events]) => createPutEventsCommand(ids, events))
39
+ .map(command => client.send(command));
40
+ await Promise.allSettled(requests);
41
+ return Promise.resolve([]);
42
+ };
43
+ const getEventBuffer = ({ region, flushSize, flushInterval, bufferSize, credentials, identityId, userAgentValue, }) => {
44
+ const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
45
+ if (!eventBufferMap[sessionIdentityKey]) {
46
+ const getClient = () => {
47
+ if (!cachedClients[sessionIdentityKey]) {
48
+ cachedClients[sessionIdentityKey] = new client_personalize_events_1.PersonalizeEventsClient({
49
+ region,
50
+ credentials,
51
+ customUserAgent: userAgentValue,
52
+ });
53
+ }
54
+ return events => submitEvents(events, cachedClients[sessionIdentityKey]);
55
+ };
56
+ eventBufferMap[sessionIdentityKey] =
57
+ new utils_1.EventBuffer({
58
+ bufferSize,
59
+ flushSize,
60
+ flushInterval,
61
+ }, getClient);
62
+ const releaseSessionKeys = Object.keys(eventBufferMap).filter(key => key !== sessionIdentityKey);
63
+ for (const releaseSessionKey of releaseSessionKeys) {
64
+ eventBufferMap[releaseSessionKey].flushAll().finally(() => {
65
+ eventBufferMap[releaseSessionKey].release();
66
+ delete eventBufferMap[releaseSessionKey];
67
+ delete cachedClients[releaseSessionKey];
68
+ });
69
+ }
70
+ }
71
+ return eventBufferMap[sessionIdentityKey];
72
+ };
73
+ exports.getEventBuffer = getEventBuffer;
@@ -0,0 +1,5 @@
1
+ export { getEventBuffer } from './getEventBuffer';
2
+ export { resolveConfig } from './resolveConfig';
3
+ export { autoTrackMedia } from './autoTrackMedia';
4
+ export { resolveCachedSession, updateCachedSession } from './cachedSession';
5
+ export { DEFAULT_PERSONALIZE_CONFIG, PERSONALIZE_FLUSH_SIZE_MAX, } from './constants';
@@ -0,0 +1,17 @@
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.PERSONALIZE_FLUSH_SIZE_MAX = exports.DEFAULT_PERSONALIZE_CONFIG = exports.updateCachedSession = exports.resolveCachedSession = exports.autoTrackMedia = exports.resolveConfig = exports.getEventBuffer = void 0;
6
+ var getEventBuffer_1 = require("./getEventBuffer");
7
+ Object.defineProperty(exports, "getEventBuffer", { enumerable: true, get: function () { return getEventBuffer_1.getEventBuffer; } });
8
+ var resolveConfig_1 = require("./resolveConfig");
9
+ Object.defineProperty(exports, "resolveConfig", { enumerable: true, get: function () { return resolveConfig_1.resolveConfig; } });
10
+ var autoTrackMedia_1 = require("./autoTrackMedia");
11
+ Object.defineProperty(exports, "autoTrackMedia", { enumerable: true, get: function () { return autoTrackMedia_1.autoTrackMedia; } });
12
+ var cachedSession_1 = require("./cachedSession");
13
+ Object.defineProperty(exports, "resolveCachedSession", { enumerable: true, get: function () { return cachedSession_1.resolveCachedSession; } });
14
+ Object.defineProperty(exports, "updateCachedSession", { enumerable: true, get: function () { return cachedSession_1.updateCachedSession; } });
15
+ var constants_1 = require("./constants");
16
+ Object.defineProperty(exports, "DEFAULT_PERSONALIZE_CONFIG", { enumerable: true, get: function () { return constants_1.DEFAULT_PERSONALIZE_CONFIG; } });
17
+ Object.defineProperty(exports, "PERSONALIZE_FLUSH_SIZE_MAX", { enumerable: true, get: function () { return constants_1.PERSONALIZE_FLUSH_SIZE_MAX; } });
@@ -0,0 +1,7 @@
1
+ export declare const resolveConfig: () => {
2
+ region: string;
3
+ trackingId: string;
4
+ bufferSize: number;
5
+ flushSize: number;
6
+ flushInterval: number;
7
+ };
@@ -0,0 +1,26 @@
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 _1 = require("./");
9
+ const resolveConfig = () => {
10
+ const config = core_1.Amplify.getConfig().Analytics?.Personalize;
11
+ const { region, trackingId, flushSize = _1.DEFAULT_PERSONALIZE_CONFIG.flushSize, flushInterval = _1.DEFAULT_PERSONALIZE_CONFIG.flushInterval, } = {
12
+ ..._1.DEFAULT_PERSONALIZE_CONFIG,
13
+ ...config,
14
+ };
15
+ (0, errors_1.assertValidationError)(!!region, errors_1.AnalyticsValidationErrorCode.NoRegion);
16
+ (0, errors_1.assertValidationError)(!!trackingId, errors_1.AnalyticsValidationErrorCode.NoTrackingId);
17
+ (0, errors_1.assertValidationError)(flushSize <= _1.PERSONALIZE_FLUSH_SIZE_MAX, errors_1.AnalyticsValidationErrorCode.InvalidFlushSize, `FlushSize for Personalize should be less or equal than ${_1.PERSONALIZE_FLUSH_SIZE_MAX}`);
18
+ return {
19
+ region,
20
+ trackingId,
21
+ bufferSize: flushSize + 1,
22
+ flushSize,
23
+ flushInterval,
24
+ };
25
+ };
26
+ exports.resolveConfig = resolveConfig;
@@ -0,0 +1,15 @@
1
+ import { ConfigureAutoTrackInput } from '../types';
2
+ /**
3
+ * Configures automatic event tracking for Pinpoint. This API will automatically transmit an analytic event when
4
+ * configured events are detected within your application. This can include: DOM element events (via the `event`
5
+ * tracker), session events (via the `session` tracker), and page view events (via the `pageView` tracker).
6
+ *
7
+ * @remark Only session tracking is currently supported on React Native.
8
+ *
9
+ * @param {ConfigureAutoTrackInput} params The input object to configure auto track behavior.
10
+ *
11
+ * @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.
12
+ * @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library
13
+ * configuration is incorrect.
14
+ */
15
+ export declare const configureAutoTrack: (input: ConfigureAutoTrackInput) => 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.configureAutoTrack = void 0;
6
+ const utils_1 = require("../../../utils");
7
+ const record_1 = require("./record");
8
+ // Configured Tracker instances for Pinpoint
9
+ const configuredTrackers = {};
10
+ // Callback that will emit an appropriate event to Pinpoint when required by the Tracker
11
+ const emitTrackingEvent = (eventName, attributes) => {
12
+ (0, record_1.record)({
13
+ name: eventName,
14
+ attributes,
15
+ });
16
+ };
17
+ /**
18
+ * Configures automatic event tracking for Pinpoint. This API will automatically transmit an analytic event when
19
+ * configured events are detected within your application. This can include: DOM element events (via the `event`
20
+ * tracker), session events (via the `session` tracker), and page view events (via the `pageView` tracker).
21
+ *
22
+ * @remark Only session tracking is currently supported on React Native.
23
+ *
24
+ * @param {ConfigureAutoTrackInput} params The input object to configure auto track behavior.
25
+ *
26
+ * @throws service: {@link UpdateEndpointException} - Thrown when the underlying Pinpoint service returns an error.
27
+ * @throws validation: {@link AnalyticsValidationErrorCode} - Thrown when the provided parameters or library
28
+ * configuration is incorrect.
29
+ */
30
+ const configureAutoTrack = (input) => {
31
+ (0, utils_1.validateTrackerConfiguration)(input);
32
+ // Initialize or update this provider's trackers
33
+ (0, utils_1.updateProviderTrackers)(input, emitTrackingEvent, configuredTrackers);
34
+ };
35
+ exports.configureAutoTrack = configureAutoTrack;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Flushes all buffered Pinpoint 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,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.flushEvents = void 0;
6
+ const utils_1 = require("../utils");
7
+ const pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
8
+ const utils_2 = require("@aws-amplify/core/internals/utils");
9
+ const core_1 = require("@aws-amplify/core");
10
+ const utils_3 = require("../../../utils");
11
+ const logger = new core_1.ConsoleLogger('Analytics');
12
+ /**
13
+ * Flushes all buffered Pinpoint 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 { appId, region } = (0, utils_1.resolveConfig)();
21
+ (0, utils_1.resolveCredentials)()
22
+ .then(({ credentials, identityId }) => (0, pinpoint_1.flushEvents)(appId, region, credentials, identityId, (0, utils_3.getAnalyticsUserAgentString)(utils_2.AnalyticsAction.Record)))
23
+ .catch(e => logger.warn('Failed to flush events', e));
24
+ };
25
+ exports.flushEvents = flushEvents;
@@ -19,8 +19,9 @@ import { IdentifyUserInput } from '../types';
19
19
  * await identifyUser({
20
20
  * userId,
21
21
  * userProfile: {
22
- * attributes: {
23
- * email: [userEmail],
22
+ * email: 'userEmail@example.com'
23
+ * customProperties: {
24
+ * phoneNumber: ['555-555-5555'],
24
25
  * },
25
26
  * }
26
27
  * });
@@ -32,8 +33,9 @@ import { IdentifyUserInput } from '../types';
32
33
  * await identifyUser({
33
34
  * userId,
34
35
  * userProfile: {
35
- * attributes: {
36
- * email: [userEmail],
36
+ * email: 'userEmail@example.com'
37
+ * customProperties: {
38
+ * phoneNumber: ['555-555-5555'],
37
39
  * },
38
40
  * demographic: {
39
41
  * platform: 'ios',
@@ -42,4 +44,4 @@ import { IdentifyUserInput } from '../types';
42
44
  * }
43
45
  * });
44
46
  */
45
- export declare const identifyUser: ({ userId, userProfile, }: IdentifyUserInput) => Promise<void>;
47
+ export declare const identifyUser: ({ userId, userProfile, options, }: IdentifyUserInput) => Promise<void>;
@@ -3,11 +3,10 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.identifyUser = void 0;
6
- var tslib_1 = require("tslib");
7
- var utils_1 = require("@aws-amplify/core/internals/utils");
8
- var pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
9
- var userAgent_1 = require("../../../utils/userAgent");
10
- var utils_2 = require("../utils");
6
+ const utils_1 = require("@aws-amplify/core/internals/utils");
7
+ const pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
8
+ const utils_2 = require("../../../utils");
9
+ const utils_3 = require("../utils");
11
10
  /**
12
11
  * Sends information about a user to Pinpoint. Sending user information allows you to associate a user to their user
13
12
  * profile and activities or actions in your application. Activity can be tracked across devices & platforms by using
@@ -28,8 +27,9 @@ var utils_2 = require("../utils");
28
27
  * await identifyUser({
29
28
  * userId,
30
29
  * userProfile: {
31
- * attributes: {
32
- * email: [userEmail],
30
+ * email: 'userEmail@example.com'
31
+ * customProperties: {
32
+ * phoneNumber: ['555-555-5555'],
33
33
  * },
34
34
  * }
35
35
  * });
@@ -41,8 +41,9 @@ var utils_2 = require("../utils");
41
41
  * await identifyUser({
42
42
  * userId,
43
43
  * userProfile: {
44
- * attributes: {
45
- * email: [userEmail],
44
+ * email: 'userEmail@example.com'
45
+ * customProperties: {
46
+ * phoneNumber: ['555-555-5555'],
46
47
  * },
47
48
  * demographic: {
48
49
  * platform: 'ios',
@@ -51,29 +52,20 @@ var utils_2 = require("../utils");
51
52
  * }
52
53
  * });
53
54
  */
54
- var identifyUser = function (_a) {
55
- var userId = _a.userId, userProfile = _a.userProfile;
56
- return tslib_1.__awaiter(void 0, void 0, void 0, function () {
57
- var _b, credentials, identityId, _c, appId, region;
58
- return tslib_1.__generator(this, function (_d) {
59
- switch (_d.label) {
60
- case 0: return [4 /*yield*/, (0, utils_2.resolveCredentials)()];
61
- case 1:
62
- _b = _d.sent(), credentials = _b.credentials, identityId = _b.identityId;
63
- _c = (0, utils_2.resolveConfig)(), appId = _c.appId, region = _c.region;
64
- (0, pinpoint_1.updateEndpoint)({
65
- appId: appId,
66
- category: 'Analytics',
67
- credentials: credentials,
68
- identityId: identityId,
69
- region: region,
70
- userId: userId,
71
- userProfile: userProfile,
72
- userAgentValue: (0, userAgent_1.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.UpdateEndpoint),
73
- });
74
- return [2 /*return*/];
75
- }
76
- });
55
+ const identifyUser = async ({ userId, userProfile, options, }) => {
56
+ const { credentials, identityId } = await (0, utils_3.resolveCredentials)();
57
+ const { appId, region } = (0, utils_3.resolveConfig)();
58
+ const { userAttributes } = options ?? {};
59
+ (0, pinpoint_1.updateEndpoint)({
60
+ appId,
61
+ category: 'Analytics',
62
+ credentials,
63
+ identityId,
64
+ region,
65
+ userAttributes,
66
+ userId,
67
+ userProfile,
68
+ userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.IdentifyUser),
77
69
  });
78
70
  };
79
71
  exports.identifyUser = identifyUser;
@@ -1,2 +1,4 @@
1
1
  export { record } from './record';
2
2
  export { identifyUser } from './identifyUser';
3
+ export { configureAutoTrack } from './configureAutoTrack';
4
+ export { flushEvents } from './flushEvents';
@@ -2,8 +2,12 @@
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.identifyUser = exports.record = void 0;
5
+ exports.flushEvents = exports.configureAutoTrack = exports.identifyUser = exports.record = void 0;
6
6
  var record_1 = require("./record");
7
7
  Object.defineProperty(exports, "record", { enumerable: true, get: function () { return record_1.record; } });
8
8
  var identifyUser_1 = require("./identifyUser");
9
9
  Object.defineProperty(exports, "identifyUser", { enumerable: true, get: function () { return identifyUser_1.identifyUser; } });
10
+ var configureAutoTrack_1 = require("./configureAutoTrack");
11
+ Object.defineProperty(exports, "configureAutoTrack", { enumerable: true, get: function () { return configureAutoTrack_1.configureAutoTrack; } });
12
+ var flushEvents_1 = require("./flushEvents");
13
+ Object.defineProperty(exports, "flushEvents", { enumerable: true, get: function () { return flushEvents_1.flushEvents; } });
@@ -10,27 +10,21 @@ import { RecordInput } from '../types';
10
10
  * @example
11
11
  * ```ts
12
12
  * // Send an event to Pinpoint
13
- * record({
14
- * event: {
15
- * name: eventName,
16
- * }
17
- * })
13
+ * record({ name: eventName })
18
14
  * ```
19
15
  *
20
16
  * @example
21
17
  * ```ts
22
18
  * // Send an event to Pinpoint with metrics & custom attributes
23
19
  * record({
24
- * event: {
25
- * name: eventName,
26
- * attributes: {
27
- * 'my-attribute': attributeValue
28
- * },
29
- * metrics: {
30
- * 'my-metric': metricValue
31
- * }
20
+ * name: eventName,
21
+ * attributes: {
22
+ * 'my-attribute': attributeValue
23
+ * },
24
+ * metrics: {
25
+ * 'my-metric': metricValue
32
26
  * }
33
27
  * })
34
28
  * ```
35
29
  */
36
- export declare const record: ({ event }: RecordInput) => void;
30
+ export declare const record: (input: RecordInput) => void;
@@ -3,12 +3,13 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.record = void 0;
6
- var utils_1 = require("@aws-amplify/core/internals/utils");
7
- var pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
8
- var errors_1 = require("../../../errors");
9
- var userAgent_1 = require("../../../utils/userAgent");
10
- var utils_2 = require("../utils");
11
- var logger = new utils_1.ConsoleLogger('Analytics');
6
+ const core_1 = require("@aws-amplify/core");
7
+ const utils_1 = require("@aws-amplify/core/internals/utils");
8
+ const pinpoint_1 = require("@aws-amplify/core/internals/providers/pinpoint");
9
+ const errors_1 = require("../../../errors");
10
+ const utils_2 = require("../../../utils");
11
+ const utils_3 = require("../utils");
12
+ const logger = new core_1.ConsoleLogger('Analytics');
12
13
  /**
13
14
  * Records an Analytic event to Pinpoint. Events will be buffered and periodically sent to Pinpoint.
14
15
  *
@@ -20,48 +21,44 @@ var logger = new utils_1.ConsoleLogger('Analytics');
20
21
  * @example
21
22
  * ```ts
22
23
  * // Send an event to Pinpoint
23
- * record({
24
- * event: {
25
- * name: eventName,
26
- * }
27
- * })
24
+ * record({ name: eventName })
28
25
  * ```
29
26
  *
30
27
  * @example
31
28
  * ```ts
32
29
  * // Send an event to Pinpoint with metrics & custom attributes
33
30
  * record({
34
- * event: {
35
- * name: eventName,
36
- * attributes: {
37
- * 'my-attribute': attributeValue
38
- * },
39
- * metrics: {
40
- * 'my-metric': metricValue
41
- * }
31
+ * name: eventName,
32
+ * attributes: {
33
+ * 'my-attribute': attributeValue
34
+ * },
35
+ * metrics: {
36
+ * 'my-metric': metricValue
42
37
  * }
43
38
  * })
44
39
  * ```
45
40
  */
46
- var record = function (_a) {
47
- var event = _a.event;
48
- var _b = (0, utils_2.resolveConfig)(), appId = _b.appId, region = _b.region;
49
- (0, errors_1.assertValidationError)(!!event, errors_1.AnalyticsValidationErrorCode.NoEvent);
50
- (0, errors_1.assertValidationError)(!!event.name, errors_1.AnalyticsValidationErrorCode.NoEventName);
51
- (0, utils_2.resolveCredentials)()
52
- .then(function (_a) {
53
- var credentials = _a.credentials, identityId = _a.identityId;
41
+ const record = (input) => {
42
+ const { appId, region } = (0, utils_3.resolveConfig)();
43
+ if (!(0, utils_2.isAnalyticsEnabled)()) {
44
+ logger.debug('Analytics is disabled, event will not be recorded.');
45
+ return;
46
+ }
47
+ (0, errors_1.assertValidationError)(!!input.name, errors_1.AnalyticsValidationErrorCode.NoEventName);
48
+ (0, utils_3.resolveCredentials)()
49
+ .then(({ credentials, identityId }) => {
50
+ core_1.Hub.dispatch('analytics', { event: 'record', data: input, message: 'Recording Analytics event' }, 'Analytics', utils_1.AMPLIFY_SYMBOL);
54
51
  (0, pinpoint_1.record)({
55
- appId: appId,
52
+ appId,
56
53
  category: 'Analytics',
57
- credentials: credentials,
58
- event: event,
59
- identityId: identityId,
60
- region: region,
61
- userAgentValue: (0, userAgent_1.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),
54
+ credentials,
55
+ event: input,
56
+ identityId,
57
+ region,
58
+ userAgentValue: (0, utils_2.getAnalyticsUserAgentString)(utils_1.AnalyticsAction.Record),
62
59
  });
63
60
  })
64
- .catch(function (e) {
61
+ .catch(e => {
65
62
  // An error occured while fetching credentials or persisting the event to the buffer
66
63
  logger.warn('Failed to record event.', e);
67
64
  });
@@ -1,2 +1,2 @@
1
- export { record, identifyUser } from './apis';
2
- export { RecordInput, IdentifyUserInput } from './types/inputs';
1
+ export { record, identifyUser, flushEvents, configureAutoTrack } from './apis';
2
+ export { RecordInput, IdentifyUserInput, ConfigureAutoTrackInput, } from './types/inputs';
@@ -2,7 +2,9 @@
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.identifyUser = exports.record = void 0;
5
+ exports.configureAutoTrack = exports.flushEvents = exports.identifyUser = exports.record = void 0;
6
6
  var apis_1 = require("./apis");
7
7
  Object.defineProperty(exports, "record", { enumerable: true, get: function () { return apis_1.record; } });
8
8
  Object.defineProperty(exports, "identifyUser", { enumerable: true, get: function () { return apis_1.identifyUser; } });
9
+ Object.defineProperty(exports, "flushEvents", { enumerable: true, get: function () { return apis_1.flushEvents; } });
10
+ Object.defineProperty(exports, "configureAutoTrack", { enumerable: true, get: function () { return apis_1.configureAutoTrack; } });
@@ -1,2 +1,2 @@
1
- export { UpdateEndpointException } from './errors';
2
- export { RecordInput, IdentifyUserInput } from './inputs';
1
+ export { RecordInput, IdentifyUserInput, ConfigureAutoTrackInput, } from './inputs';
2
+ export { IdentifyUserOptions } from './options';
@@ -2,6 +2,3 @@
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.UpdateEndpointException = void 0;
6
- var errors_1 = require("./errors");
7
- Object.defineProperty(exports, "UpdateEndpointException", { enumerable: true, get: function () { return errors_1.UpdateEndpointException; } });
@@ -1,24 +1,15 @@
1
- import { UserProfile } from '@aws-amplify/core';
2
1
  import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pinpoint';
2
+ import { IdentifyUserOptions } from '.';
3
+ import { AnalyticsConfigureAutoTrackInput, AnalyticsIdentifyUserInput } from '../../../types';
3
4
  /**
4
5
  * Input type for Pinpoint record API.
5
6
  */
6
- export type RecordInput = {
7
- /**
8
- * An event to send to the default Analytics provider.
9
- */
10
- event: PinpointAnalyticsEvent;
11
- };
7
+ export type RecordInput = PinpointAnalyticsEvent;
12
8
  /**
13
9
  * Input type for Pinpoint identifyUser API.
14
10
  */
15
- export type IdentifyUserInput = {
16
- /**
17
- * A User ID associated to the current device.
18
- */
19
- userId: string;
20
- /**
21
- * Additional information about the user and their device.
22
- */
23
- userProfile: UserProfile;
24
- };
11
+ export type IdentifyUserInput = AnalyticsIdentifyUserInput<IdentifyUserOptions>;
12
+ /**
13
+ * Input type for Pinpoint configureAutoTrack API.
14
+ */
15
+ export type ConfigureAutoTrackInput = AnalyticsConfigureAutoTrackInput;
@@ -0,0 +1,5 @@
1
+ import { PinpointServiceOptions } from '@aws-amplify/core/internals/providers/pinpoint';
2
+ /**
3
+ * Options specific to Pinpoint identityUser.
4
+ */
5
+ export type IdentifyUserOptions = Pick<PinpointServiceOptions, 'userAttributes'>;