@amplitude/analytics-core 2.5.6 → 2.6.1

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 (389) hide show
  1. package/lib/cjs/analytics-connector.d.ts +5 -0
  2. package/lib/cjs/analytics-connector.d.ts.map +1 -0
  3. package/lib/cjs/analytics-connector.js +20 -0
  4. package/lib/cjs/analytics-connector.js.map +1 -0
  5. package/lib/cjs/config.d.ts +107 -3
  6. package/lib/cjs/config.d.ts.map +1 -1
  7. package/lib/cjs/config.js +3 -3
  8. package/lib/cjs/config.js.map +1 -1
  9. package/lib/cjs/cookie-name.d.ts +3 -0
  10. package/lib/cjs/cookie-name.d.ts.map +1 -0
  11. package/lib/cjs/cookie-name.js +15 -0
  12. package/lib/cjs/cookie-name.js.map +1 -0
  13. package/lib/cjs/core-client.d.ts +154 -14
  14. package/lib/cjs/core-client.d.ts.map +1 -1
  15. package/lib/cjs/core-client.js +1 -1
  16. package/lib/cjs/core-client.js.map +1 -1
  17. package/lib/cjs/event-bridge/event-bridge-channel.d.ts +4 -3
  18. package/lib/cjs/event-bridge/event-bridge-channel.d.ts.map +1 -1
  19. package/lib/cjs/event-bridge/event-bridge-channel.js.map +1 -1
  20. package/lib/cjs/event-bridge/event-bridge-container.d.ts +1 -1
  21. package/lib/cjs/event-bridge/event-bridge-container.d.ts.map +1 -1
  22. package/lib/cjs/event-bridge/event-bridge-container.js.map +1 -1
  23. package/lib/cjs/event-bridge/event-bridge.d.ts +9 -2
  24. package/lib/cjs/event-bridge/event-bridge.d.ts.map +1 -1
  25. package/lib/cjs/event-bridge/event-bridge.js.map +1 -1
  26. package/lib/cjs/global-scope.d.ts +2 -0
  27. package/lib/cjs/global-scope.d.ts.map +1 -0
  28. package/lib/cjs/global-scope.js +28 -0
  29. package/lib/cjs/global-scope.js.map +1 -0
  30. package/lib/cjs/identify.d.ts +48 -1
  31. package/lib/cjs/identify.d.ts.map +1 -1
  32. package/lib/cjs/identify.js +32 -16
  33. package/lib/cjs/identify.js.map +1 -1
  34. package/lib/cjs/index.d.ts +37 -8
  35. package/lib/cjs/index.d.ts.map +1 -1
  36. package/lib/cjs/index.js +45 -6
  37. package/lib/cjs/index.js.map +1 -1
  38. package/lib/cjs/language.d.ts +2 -0
  39. package/lib/cjs/language.d.ts.map +1 -0
  40. package/lib/cjs/language.js +13 -0
  41. package/lib/cjs/language.js.map +1 -0
  42. package/lib/cjs/logger.d.ts +27 -1
  43. package/lib/cjs/logger.d.ts.map +1 -1
  44. package/lib/cjs/logger.js +8 -8
  45. package/lib/cjs/logger.js.map +1 -1
  46. package/lib/cjs/plugins/destination.d.ts +14 -3
  47. package/lib/cjs/plugins/destination.d.ts.map +1 -1
  48. package/lib/cjs/plugins/destination.js +8 -8
  49. package/lib/cjs/plugins/destination.js.map +1 -1
  50. package/lib/cjs/plugins/identity.d.ts +11 -0
  51. package/lib/cjs/plugins/identity.d.ts.map +1 -0
  52. package/lib/cjs/plugins/identity.js +37 -0
  53. package/lib/cjs/plugins/identity.js.map +1 -0
  54. package/lib/cjs/query-params.d.ts +3 -0
  55. package/lib/cjs/query-params.d.ts.map +1 -0
  56. package/lib/cjs/query-params.js +36 -0
  57. package/lib/cjs/query-params.js.map +1 -0
  58. package/lib/cjs/revenue.d.ts +43 -1
  59. package/lib/cjs/revenue.d.ts.map +1 -1
  60. package/lib/cjs/revenue.js +28 -8
  61. package/lib/cjs/revenue.js.map +1 -1
  62. package/lib/cjs/session.d.ts +2 -0
  63. package/lib/cjs/session.d.ts.map +1 -0
  64. package/lib/cjs/session.js +11 -0
  65. package/lib/cjs/session.js.map +1 -0
  66. package/lib/cjs/storage/cookie.d.ts +13 -0
  67. package/lib/cjs/storage/cookie.d.ts.map +1 -0
  68. package/lib/cjs/storage/cookie.js +172 -0
  69. package/lib/cjs/storage/cookie.js.map +1 -0
  70. package/lib/cjs/storage/helpers.d.ts +2 -0
  71. package/lib/cjs/storage/helpers.d.ts.map +1 -0
  72. package/lib/cjs/storage/helpers.js +11 -0
  73. package/lib/cjs/storage/helpers.js.map +1 -0
  74. package/lib/cjs/storage/memory.d.ts +1 -1
  75. package/lib/cjs/storage/memory.d.ts.map +1 -1
  76. package/lib/cjs/storage/memory.js.map +1 -1
  77. package/lib/cjs/timeline.d.ts +8 -3
  78. package/lib/cjs/timeline.d.ts.map +1 -1
  79. package/lib/cjs/timeline.js.map +1 -1
  80. package/lib/cjs/transports/base.d.ts +4 -1
  81. package/lib/cjs/transports/base.d.ts.map +1 -1
  82. package/lib/cjs/transports/base.js +13 -16
  83. package/lib/cjs/transports/base.js.map +1 -1
  84. package/lib/cjs/transports/fetch.d.ts +8 -0
  85. package/lib/cjs/transports/fetch.d.ts.map +1 -0
  86. package/lib/cjs/transports/fetch.js +50 -0
  87. package/lib/cjs/transports/fetch.js.map +1 -0
  88. package/lib/cjs/types/browser-client.d.ts +131 -0
  89. package/lib/cjs/types/browser-client.d.ts.map +1 -0
  90. package/lib/cjs/types/browser-client.js +3 -0
  91. package/lib/cjs/types/browser-client.js.map +1 -0
  92. package/lib/cjs/types/browser-config.d.ts +217 -0
  93. package/lib/cjs/types/browser-config.d.ts.map +1 -0
  94. package/lib/cjs/types/browser-config.js +3 -0
  95. package/lib/cjs/types/browser-config.js.map +1 -0
  96. package/lib/cjs/types/constants.d.ts.map +1 -0
  97. package/lib/cjs/types/constants.js.map +1 -0
  98. package/lib/cjs/types/element-interactions.d.ts +73 -0
  99. package/lib/cjs/types/element-interactions.d.ts.map +1 -0
  100. package/lib/cjs/types/element-interactions.js +34 -0
  101. package/lib/cjs/types/element-interactions.js.map +1 -0
  102. package/lib/cjs/types/event/base-event.d.ts +64 -0
  103. package/lib/cjs/types/event/base-event.d.ts.map +1 -0
  104. package/lib/cjs/types/event/base-event.js +3 -0
  105. package/lib/cjs/types/event/base-event.js.map +1 -0
  106. package/lib/cjs/types/event/event.d.ts +68 -0
  107. package/lib/cjs/types/event/event.d.ts.map +1 -0
  108. package/lib/cjs/types/event/event.js +31 -0
  109. package/lib/cjs/types/event/event.js.map +1 -0
  110. package/lib/cjs/types/event/ingestion-metadata.d.ts +19 -0
  111. package/lib/cjs/types/event/ingestion-metadata.d.ts.map +1 -0
  112. package/lib/cjs/types/event/ingestion-metadata.js +3 -0
  113. package/lib/cjs/types/event/ingestion-metadata.js.map +1 -0
  114. package/lib/cjs/types/event/plan.d.ts +14 -0
  115. package/lib/cjs/types/event/plan.d.ts.map +1 -0
  116. package/lib/cjs/types/event/plan.js +3 -0
  117. package/lib/cjs/types/event/plan.js.map +1 -0
  118. package/lib/cjs/types/event-callback.d.ts +3 -0
  119. package/lib/cjs/types/event-callback.d.ts.map +1 -0
  120. package/lib/cjs/types/event-callback.js +3 -0
  121. package/lib/cjs/types/event-callback.js.map +1 -0
  122. package/lib/cjs/types/loglevel.d.ts +8 -0
  123. package/lib/cjs/types/loglevel.d.ts.map +1 -0
  124. package/lib/cjs/types/loglevel.js +12 -0
  125. package/lib/cjs/types/loglevel.js.map +1 -0
  126. package/lib/cjs/types/messages.d.ts.map +1 -0
  127. package/lib/cjs/types/messages.js.map +1 -0
  128. package/lib/cjs/types/offline.d.ts +2 -0
  129. package/lib/cjs/types/offline.d.ts.map +1 -0
  130. package/lib/cjs/types/offline.js +5 -0
  131. package/lib/cjs/types/offline.js.map +1 -0
  132. package/lib/cjs/types/page-view-tracking.d.ts +9 -0
  133. package/lib/cjs/types/page-view-tracking.d.ts.map +1 -0
  134. package/lib/cjs/types/page-view-tracking.js +3 -0
  135. package/lib/cjs/types/page-view-tracking.js.map +1 -0
  136. package/lib/cjs/types/payload.d.ts +13 -0
  137. package/lib/cjs/types/payload.d.ts.map +1 -0
  138. package/lib/cjs/types/payload.js +3 -0
  139. package/lib/cjs/types/payload.js.map +1 -0
  140. package/lib/cjs/types/plugin.d.ts +30 -0
  141. package/lib/cjs/types/plugin.d.ts.map +1 -0
  142. package/lib/cjs/types/plugin.js +3 -0
  143. package/lib/cjs/types/plugin.js.map +1 -0
  144. package/lib/cjs/types/response.d.ts +81 -0
  145. package/lib/cjs/types/response.d.ts.map +1 -0
  146. package/lib/cjs/types/response.js +3 -0
  147. package/lib/cjs/types/response.js.map +1 -0
  148. package/lib/cjs/types/result.d.ts +7 -0
  149. package/lib/cjs/types/result.d.ts.map +1 -0
  150. package/lib/cjs/types/result.js +3 -0
  151. package/lib/cjs/types/result.js.map +1 -0
  152. package/lib/cjs/types/server-zone.d.ts +9 -0
  153. package/lib/cjs/types/server-zone.d.ts.map +1 -0
  154. package/lib/cjs/types/server-zone.js +12 -0
  155. package/lib/cjs/types/server-zone.js.map +1 -0
  156. package/lib/cjs/types/status.d.ts +22 -0
  157. package/lib/cjs/types/status.d.ts.map +1 -0
  158. package/lib/cjs/types/status.js +26 -0
  159. package/lib/cjs/types/status.js.map +1 -0
  160. package/lib/cjs/types/storage.d.ts +16 -0
  161. package/lib/cjs/types/storage.d.ts.map +1 -0
  162. package/lib/cjs/types/storage.js +3 -0
  163. package/lib/cjs/types/storage.js.map +1 -0
  164. package/lib/cjs/types/transport.d.ts +7 -0
  165. package/lib/cjs/types/transport.d.ts.map +1 -0
  166. package/lib/cjs/types/transport.js +3 -0
  167. package/lib/cjs/types/transport.js.map +1 -0
  168. package/lib/cjs/types/user-session.d.ts +11 -0
  169. package/lib/cjs/types/user-session.d.ts.map +1 -0
  170. package/lib/cjs/types/user-session.js +3 -0
  171. package/lib/cjs/types/user-session.js.map +1 -0
  172. package/lib/cjs/utils/debug.d.ts +1 -1
  173. package/lib/cjs/utils/debug.d.ts.map +1 -1
  174. package/lib/cjs/utils/debug.js +2 -6
  175. package/lib/cjs/utils/debug.js.map +1 -1
  176. package/lib/cjs/utils/event-builder.d.ts +5 -2
  177. package/lib/cjs/utils/event-builder.d.ts.map +1 -1
  178. package/lib/cjs/utils/event-builder.js +5 -5
  179. package/lib/cjs/utils/event-builder.js.map +1 -1
  180. package/lib/cjs/utils/result-builder.d.ts +2 -1
  181. package/lib/cjs/utils/result-builder.d.ts.map +1 -1
  182. package/lib/cjs/utils/result-builder.js +2 -2
  183. package/lib/cjs/utils/result-builder.js.map +1 -1
  184. package/lib/cjs/utils/return-wrapper.d.ts +3 -1
  185. package/lib/cjs/utils/return-wrapper.d.ts.map +1 -1
  186. package/lib/cjs/utils/return-wrapper.js.map +1 -1
  187. package/lib/esm/analytics-connector.d.ts +5 -0
  188. package/lib/esm/analytics-connector.d.ts.map +1 -0
  189. package/lib/esm/analytics-connector.js +14 -0
  190. package/lib/esm/analytics-connector.js.map +1 -0
  191. package/lib/esm/config.d.ts +107 -3
  192. package/lib/esm/config.d.ts.map +1 -1
  193. package/lib/esm/config.js +2 -2
  194. package/lib/esm/config.js.map +1 -1
  195. package/lib/esm/cookie-name.d.ts +3 -0
  196. package/lib/esm/cookie-name.d.ts.map +1 -0
  197. package/lib/esm/cookie-name.js +10 -0
  198. package/lib/esm/cookie-name.js.map +1 -0
  199. package/lib/esm/core-client.d.ts +154 -14
  200. package/lib/esm/core-client.d.ts.map +1 -1
  201. package/lib/esm/core-client.js +1 -1
  202. package/lib/esm/core-client.js.map +1 -1
  203. package/lib/esm/event-bridge/event-bridge-channel.d.ts +4 -3
  204. package/lib/esm/event-bridge/event-bridge-channel.d.ts.map +1 -1
  205. package/lib/esm/event-bridge/event-bridge-channel.js.map +1 -1
  206. package/lib/esm/event-bridge/event-bridge-container.d.ts +1 -1
  207. package/lib/esm/event-bridge/event-bridge-container.d.ts.map +1 -1
  208. package/lib/esm/event-bridge/event-bridge-container.js.map +1 -1
  209. package/lib/esm/event-bridge/event-bridge.d.ts +9 -2
  210. package/lib/esm/event-bridge/event-bridge.d.ts.map +1 -1
  211. package/lib/esm/event-bridge/event-bridge.js.map +1 -1
  212. package/lib/esm/global-scope.d.ts +2 -0
  213. package/lib/esm/global-scope.d.ts.map +1 -0
  214. package/lib/esm/global-scope.js +24 -0
  215. package/lib/esm/global-scope.js.map +1 -0
  216. package/lib/esm/identify.d.ts +48 -1
  217. package/lib/esm/identify.d.ts.map +1 -1
  218. package/lib/esm/identify.js +18 -2
  219. package/lib/esm/identify.js.map +1 -1
  220. package/lib/esm/index.d.ts +37 -8
  221. package/lib/esm/index.d.ts.map +1 -1
  222. package/lib/esm/index.js +19 -3
  223. package/lib/esm/index.js.map +1 -1
  224. package/lib/esm/language.d.ts +2 -0
  225. package/lib/esm/language.d.ts.map +1 -0
  226. package/lib/esm/language.js +9 -0
  227. package/lib/esm/language.js.map +1 -0
  228. package/lib/esm/logger.d.ts +27 -1
  229. package/lib/esm/logger.d.ts.map +1 -1
  230. package/lib/esm/logger.js +1 -1
  231. package/lib/esm/logger.js.map +1 -1
  232. package/lib/esm/plugins/destination.d.ts +14 -3
  233. package/lib/esm/plugins/destination.d.ts.map +1 -1
  234. package/lib/esm/plugins/destination.js +3 -3
  235. package/lib/esm/plugins/destination.js.map +1 -1
  236. package/lib/esm/plugins/identity.d.ts +11 -0
  237. package/lib/esm/plugins/identity.d.ts.map +1 -0
  238. package/lib/esm/plugins/identity.js +34 -0
  239. package/lib/esm/plugins/identity.js.map +1 -0
  240. package/lib/esm/query-params.d.ts +3 -0
  241. package/lib/esm/query-params.d.ts.map +1 -0
  242. package/lib/esm/query-params.js +31 -0
  243. package/lib/esm/query-params.js.map +1 -0
  244. package/lib/esm/revenue.d.ts +43 -1
  245. package/lib/esm/revenue.d.ts.map +1 -1
  246. package/lib/esm/revenue.js +21 -1
  247. package/lib/esm/revenue.js.map +1 -1
  248. package/lib/esm/session.d.ts +2 -0
  249. package/lib/esm/session.d.ts.map +1 -0
  250. package/lib/esm/session.js +7 -0
  251. package/lib/esm/session.js.map +1 -0
  252. package/lib/esm/storage/cookie.d.ts +13 -0
  253. package/lib/esm/storage/cookie.d.ts.map +1 -0
  254. package/lib/esm/storage/cookie.js +169 -0
  255. package/lib/esm/storage/cookie.js.map +1 -0
  256. package/lib/esm/storage/helpers.d.ts +2 -0
  257. package/lib/esm/storage/helpers.d.ts.map +1 -0
  258. package/lib/esm/storage/helpers.js +7 -0
  259. package/lib/esm/storage/helpers.js.map +1 -0
  260. package/lib/esm/storage/memory.d.ts +1 -1
  261. package/lib/esm/storage/memory.d.ts.map +1 -1
  262. package/lib/esm/storage/memory.js.map +1 -1
  263. package/lib/esm/timeline.d.ts +8 -3
  264. package/lib/esm/timeline.d.ts.map +1 -1
  265. package/lib/esm/timeline.js.map +1 -1
  266. package/lib/esm/transports/base.d.ts +4 -1
  267. package/lib/esm/transports/base.d.ts.map +1 -1
  268. package/lib/esm/transports/base.js +1 -4
  269. package/lib/esm/transports/base.js.map +1 -1
  270. package/lib/esm/transports/fetch.d.ts +8 -0
  271. package/lib/esm/transports/fetch.d.ts.map +1 -0
  272. package/lib/esm/transports/fetch.js +47 -0
  273. package/lib/esm/transports/fetch.js.map +1 -0
  274. package/lib/esm/types/browser-client.d.ts +131 -0
  275. package/lib/esm/types/browser-client.d.ts.map +1 -0
  276. package/lib/esm/types/browser-client.js +2 -0
  277. package/lib/esm/types/browser-client.js.map +1 -0
  278. package/lib/esm/types/browser-config.d.ts +217 -0
  279. package/lib/esm/types/browser-config.d.ts.map +1 -0
  280. package/lib/esm/types/browser-config.js +2 -0
  281. package/lib/esm/types/browser-config.js.map +1 -0
  282. package/lib/esm/types/constants.d.ts.map +1 -0
  283. package/lib/esm/types/constants.js.map +1 -0
  284. package/lib/esm/types/element-interactions.d.ts +73 -0
  285. package/lib/esm/types/element-interactions.d.ts.map +1 -0
  286. package/lib/esm/types/element-interactions.js +31 -0
  287. package/lib/esm/types/element-interactions.js.map +1 -0
  288. package/lib/esm/types/event/base-event.d.ts +64 -0
  289. package/lib/esm/types/event/base-event.d.ts.map +1 -0
  290. package/lib/esm/types/event/base-event.js +2 -0
  291. package/lib/esm/types/event/base-event.js.map +1 -0
  292. package/lib/esm/types/event/event.d.ts +68 -0
  293. package/lib/esm/types/event/event.d.ts.map +1 -0
  294. package/lib/esm/types/event/event.js +28 -0
  295. package/lib/esm/types/event/event.js.map +1 -0
  296. package/lib/esm/types/event/ingestion-metadata.d.ts +19 -0
  297. package/lib/esm/types/event/ingestion-metadata.d.ts.map +1 -0
  298. package/lib/esm/types/event/ingestion-metadata.js +2 -0
  299. package/lib/esm/types/event/ingestion-metadata.js.map +1 -0
  300. package/lib/esm/types/event/plan.d.ts +14 -0
  301. package/lib/esm/types/event/plan.d.ts.map +1 -0
  302. package/lib/esm/types/event/plan.js +2 -0
  303. package/lib/esm/types/event/plan.js.map +1 -0
  304. package/lib/esm/types/event-callback.d.ts +3 -0
  305. package/lib/esm/types/event-callback.d.ts.map +1 -0
  306. package/lib/esm/types/event-callback.js +2 -0
  307. package/lib/esm/types/event-callback.js.map +1 -0
  308. package/lib/esm/types/loglevel.d.ts +8 -0
  309. package/lib/esm/types/loglevel.d.ts.map +1 -0
  310. package/lib/esm/types/loglevel.js +9 -0
  311. package/lib/esm/types/loglevel.js.map +1 -0
  312. package/lib/esm/types/messages.d.ts.map +1 -0
  313. package/lib/esm/types/messages.js.map +1 -0
  314. package/lib/esm/types/offline.d.ts +2 -0
  315. package/lib/esm/types/offline.d.ts.map +1 -0
  316. package/lib/esm/types/offline.js +2 -0
  317. package/lib/esm/types/offline.js.map +1 -0
  318. package/lib/esm/types/page-view-tracking.d.ts +9 -0
  319. package/lib/esm/types/page-view-tracking.d.ts.map +1 -0
  320. package/lib/esm/types/page-view-tracking.js +2 -0
  321. package/lib/esm/types/page-view-tracking.js.map +1 -0
  322. package/lib/esm/types/payload.d.ts +13 -0
  323. package/lib/esm/types/payload.d.ts.map +1 -0
  324. package/lib/esm/types/payload.js +2 -0
  325. package/lib/esm/types/payload.js.map +1 -0
  326. package/lib/esm/types/plugin.d.ts +30 -0
  327. package/lib/esm/types/plugin.d.ts.map +1 -0
  328. package/lib/esm/types/plugin.js +2 -0
  329. package/lib/esm/types/plugin.js.map +1 -0
  330. package/lib/esm/types/response.d.ts +81 -0
  331. package/lib/esm/types/response.d.ts.map +1 -0
  332. package/lib/esm/types/response.js +2 -0
  333. package/lib/esm/types/response.js.map +1 -0
  334. package/lib/esm/types/result.d.ts +7 -0
  335. package/lib/esm/types/result.d.ts.map +1 -0
  336. package/lib/esm/types/result.js +2 -0
  337. package/lib/esm/types/result.js.map +1 -0
  338. package/lib/esm/types/server-zone.d.ts +9 -0
  339. package/lib/esm/types/server-zone.d.ts.map +1 -0
  340. package/lib/esm/types/server-zone.js +9 -0
  341. package/lib/esm/types/server-zone.js.map +1 -0
  342. package/lib/esm/types/status.d.ts +22 -0
  343. package/lib/esm/types/status.d.ts.map +1 -0
  344. package/lib/esm/types/status.js +23 -0
  345. package/lib/esm/types/status.js.map +1 -0
  346. package/lib/esm/types/storage.d.ts +16 -0
  347. package/lib/esm/types/storage.d.ts.map +1 -0
  348. package/lib/esm/types/storage.js +2 -0
  349. package/lib/esm/types/storage.js.map +1 -0
  350. package/lib/esm/types/transport.d.ts +7 -0
  351. package/lib/esm/types/transport.d.ts.map +1 -0
  352. package/lib/esm/types/transport.js +2 -0
  353. package/lib/esm/types/transport.js.map +1 -0
  354. package/lib/esm/types/user-session.d.ts +11 -0
  355. package/lib/esm/types/user-session.d.ts.map +1 -0
  356. package/lib/esm/types/user-session.js +2 -0
  357. package/lib/esm/types/user-session.js.map +1 -0
  358. package/lib/esm/utils/debug.d.ts +1 -1
  359. package/lib/esm/utils/debug.d.ts.map +1 -1
  360. package/lib/esm/utils/debug.js +1 -5
  361. package/lib/esm/utils/debug.js.map +1 -1
  362. package/lib/esm/utils/event-builder.d.ts +5 -2
  363. package/lib/esm/utils/event-builder.d.ts.map +1 -1
  364. package/lib/esm/utils/event-builder.js +1 -1
  365. package/lib/esm/utils/event-builder.js.map +1 -1
  366. package/lib/esm/utils/result-builder.d.ts +2 -1
  367. package/lib/esm/utils/result-builder.d.ts.map +1 -1
  368. package/lib/esm/utils/result-builder.js +1 -1
  369. package/lib/esm/utils/result-builder.js.map +1 -1
  370. package/lib/esm/utils/return-wrapper.d.ts +3 -1
  371. package/lib/esm/utils/return-wrapper.d.ts.map +1 -1
  372. package/lib/esm/utils/return-wrapper.js.map +1 -1
  373. package/package.json +2 -3
  374. package/lib/cjs/constants.d.ts.map +0 -1
  375. package/lib/cjs/constants.js.map +0 -1
  376. package/lib/cjs/messages.d.ts.map +0 -1
  377. package/lib/cjs/messages.js.map +0 -1
  378. package/lib/esm/constants.d.ts.map +0 -1
  379. package/lib/esm/constants.js.map +0 -1
  380. package/lib/esm/messages.d.ts.map +0 -1
  381. package/lib/esm/messages.js.map +0 -1
  382. /package/lib/cjs/{constants.d.ts → types/constants.d.ts} +0 -0
  383. /package/lib/cjs/{constants.js → types/constants.js} +0 -0
  384. /package/lib/cjs/{messages.d.ts → types/messages.d.ts} +0 -0
  385. /package/lib/cjs/{messages.js → types/messages.js} +0 -0
  386. /package/lib/esm/{constants.d.ts → types/constants.d.ts} +0 -0
  387. /package/lib/esm/{constants.js → types/constants.js} +0 -0
  388. /package/lib/esm/{messages.d.ts → types/messages.d.ts} +0 -0
  389. /package/lib/esm/{messages.js → types/messages.js} +0 -0
@@ -0,0 +1,169 @@
1
+ import { __assign, __awaiter, __generator } from "tslib";
2
+ import { getGlobalScope } from '../global-scope';
3
+ var CookieStorage = /** @class */ (function () {
4
+ function CookieStorage(options) {
5
+ this.options = __assign({}, options);
6
+ }
7
+ CookieStorage.prototype.isEnabled = function () {
8
+ return __awaiter(this, void 0, void 0, function () {
9
+ var testStrorage, testKey, value, _a;
10
+ return __generator(this, function (_b) {
11
+ switch (_b.label) {
12
+ case 0:
13
+ /* istanbul ignore if */
14
+ if (!getGlobalScope()) {
15
+ return [2 /*return*/, false];
16
+ }
17
+ CookieStorage.testValue = String(Date.now());
18
+ testStrorage = new CookieStorage(this.options);
19
+ testKey = 'AMP_TEST';
20
+ _b.label = 1;
21
+ case 1:
22
+ _b.trys.push([1, 4, 5, 7]);
23
+ return [4 /*yield*/, testStrorage.set(testKey, CookieStorage.testValue)];
24
+ case 2:
25
+ _b.sent();
26
+ return [4 /*yield*/, testStrorage.get(testKey)];
27
+ case 3:
28
+ value = _b.sent();
29
+ return [2 /*return*/, value === CookieStorage.testValue];
30
+ case 4:
31
+ _a = _b.sent();
32
+ /* istanbul ignore next */
33
+ return [2 /*return*/, false];
34
+ case 5: return [4 /*yield*/, testStrorage.remove(testKey)];
35
+ case 6:
36
+ _b.sent();
37
+ return [7 /*endfinally*/];
38
+ case 7: return [2 /*return*/];
39
+ }
40
+ });
41
+ });
42
+ };
43
+ CookieStorage.prototype.get = function (key) {
44
+ var _a;
45
+ return __awaiter(this, void 0, void 0, function () {
46
+ var value, decodedValue;
47
+ return __generator(this, function (_b) {
48
+ switch (_b.label) {
49
+ case 0: return [4 /*yield*/, this.getRaw(key)];
50
+ case 1:
51
+ value = _b.sent();
52
+ if (!value) {
53
+ return [2 /*return*/, undefined];
54
+ }
55
+ try {
56
+ decodedValue = (_a = decodeCookiesAsDefault(value)) !== null && _a !== void 0 ? _a : decodeCookiesWithDoubleUrlEncoding(value);
57
+ if (decodedValue === undefined) {
58
+ console.error("Amplitude Logger [Error]: Failed to decode cookie value for key: ".concat(key, ", value: ").concat(value));
59
+ return [2 /*return*/, undefined];
60
+ }
61
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
62
+ return [2 /*return*/, JSON.parse(decodedValue)];
63
+ }
64
+ catch (_c) {
65
+ console.error("Amplitude Logger [Error]: Failed to parse cookie value for key: ".concat(key, ", value: ").concat(value));
66
+ return [2 /*return*/, undefined];
67
+ }
68
+ return [2 /*return*/];
69
+ }
70
+ });
71
+ });
72
+ };
73
+ CookieStorage.prototype.getRaw = function (key) {
74
+ var _a, _b;
75
+ return __awaiter(this, void 0, void 0, function () {
76
+ var globalScope, cookie, match;
77
+ return __generator(this, function (_c) {
78
+ globalScope = getGlobalScope();
79
+ cookie = (_b = (_a = globalScope === null || globalScope === void 0 ? void 0 : globalScope.document) === null || _a === void 0 ? void 0 : _a.cookie.split('; ')) !== null && _b !== void 0 ? _b : [];
80
+ match = cookie.find(function (c) { return c.indexOf(key + '=') === 0; });
81
+ if (!match) {
82
+ return [2 /*return*/, undefined];
83
+ }
84
+ return [2 /*return*/, match.substring(key.length + 1)];
85
+ });
86
+ });
87
+ };
88
+ CookieStorage.prototype.set = function (key, value) {
89
+ var _a;
90
+ return __awaiter(this, void 0, void 0, function () {
91
+ var expirationDays, expires, expireDate, date, str, globalScope, errorMessage;
92
+ return __generator(this, function (_b) {
93
+ try {
94
+ expirationDays = (_a = this.options.expirationDays) !== null && _a !== void 0 ? _a : 0;
95
+ expires = value !== null ? expirationDays : -1;
96
+ expireDate = undefined;
97
+ if (expires) {
98
+ date = new Date();
99
+ date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);
100
+ expireDate = date;
101
+ }
102
+ str = "".concat(key, "=").concat(btoa(encodeURIComponent(JSON.stringify(value))));
103
+ if (expireDate) {
104
+ str += "; expires=".concat(expireDate.toUTCString());
105
+ }
106
+ str += '; path=/';
107
+ if (this.options.domain) {
108
+ str += "; domain=".concat(this.options.domain);
109
+ }
110
+ if (this.options.secure) {
111
+ str += '; Secure';
112
+ }
113
+ if (this.options.sameSite) {
114
+ str += "; SameSite=".concat(this.options.sameSite);
115
+ }
116
+ globalScope = getGlobalScope();
117
+ if (globalScope) {
118
+ globalScope.document.cookie = str;
119
+ }
120
+ }
121
+ catch (error) {
122
+ errorMessage = error instanceof Error ? error.message : String(error);
123
+ console.error("Amplitude Logger [Error]: Failed to set cookie for key: ".concat(key, ". Error: ").concat(errorMessage));
124
+ }
125
+ return [2 /*return*/];
126
+ });
127
+ });
128
+ };
129
+ CookieStorage.prototype.remove = function (key) {
130
+ return __awaiter(this, void 0, void 0, function () {
131
+ return __generator(this, function (_a) {
132
+ switch (_a.label) {
133
+ case 0: return [4 /*yield*/, this.set(key, null)];
134
+ case 1:
135
+ _a.sent();
136
+ return [2 /*return*/];
137
+ }
138
+ });
139
+ });
140
+ };
141
+ CookieStorage.prototype.reset = function () {
142
+ return __awaiter(this, void 0, void 0, function () {
143
+ return __generator(this, function (_a) {
144
+ return [2 /*return*/];
145
+ });
146
+ });
147
+ };
148
+ return CookieStorage;
149
+ }());
150
+ export { CookieStorage };
151
+ var decodeCookiesAsDefault = function (value) {
152
+ try {
153
+ return decodeURIComponent(atob(value));
154
+ }
155
+ catch (_a) {
156
+ return undefined;
157
+ }
158
+ };
159
+ var decodeCookiesWithDoubleUrlEncoding = function (value) {
160
+ // Modern Ruby (v7+) automatically encodes cookies with URL encoding by
161
+ // https://api.rubyonrails.org/classes/ActionDispatch/Cookies.html
162
+ try {
163
+ return decodeURIComponent(atob(decodeURIComponent(value)));
164
+ }
165
+ catch (_a) {
166
+ return undefined;
167
+ }
168
+ };
169
+ //# sourceMappingURL=cookie.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie.js","sourceRoot":"","sources":["../../../src/storage/cookie.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD;IAIE,uBAAY,OAA8B;QACxC,IAAI,CAAC,OAAO,gBAAQ,OAAO,CAAE,CAAC;IAChC,CAAC;IAEK,iCAAS,GAAf;;;;;;wBACE,wBAAwB;wBACxB,IAAI,CAAC,cAAc,EAAE,EAAE;4BACrB,sBAAO,KAAK,EAAC;yBACd;wBAED,aAAa,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;wBACvC,YAAY,GAAG,IAAI,aAAa,CAAS,IAAI,CAAC,OAAO,CAAC,CAAC;wBACvD,OAAO,GAAG,UAAU,CAAC;;;;wBAEzB,qBAAM,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,SAAS,CAAC,EAAA;;wBAAxD,SAAwD,CAAC;wBAC3C,qBAAM,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,EAAA;;wBAAvC,KAAK,GAAG,SAA+B;wBAC7C,sBAAO,KAAK,KAAK,aAAa,CAAC,SAAS,EAAC;;;wBAEzC,0BAA0B;wBAC1B,sBAAO,KAAK,EAAC;4BAEb,q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C;iBACF;gBAAC,OAAO,KAAK,EAAE;oBACR,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC5E,OAAO,CAAC,KAAK,CAAC,kEAA2D,GAAG,sBAAY,YAAY,CAAE,CAAC,CAAC;iBACzG;;;;KACF;IAEK,8BAAM,GAAZ,UAAa,GAAW;;;;4BACtB,qBAAM,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,EAAA;;wBAAzB,SAAyB,CAAC;;;;;KAC3B;IAEK,6BAAK,GAAX;;;gBACE,sBAAO;;;KACR;IACH,oBAAC;AAAD,CAAC,AAnGD,IAmGC;;AAED,IAAM,sBAAsB,GAAG,UAAC,KAAa;IAC3C,IAAI;QACF,OAAO,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;KACxC;IAAC,WAAM;QACN,OAAO,SAAS,CAAC;KAClB;AACH,CAAC,CAAC;AAEF,IAAM,kCAAkC,GAAG,UAAC,KAAa;IACvD,uEAAuE;IACvE,kEAAkE;IAClE,IAAI;QACF,OAAO,kBAAkB,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAC5D;IAAC,WAAM;QACN,OAAO,SAAS,CAAC;KAClB;AACH,CAAC,CAAC","sourcesContent":["import { Storage, CookieStorageOptions } from '../types/storage';\nimport { getGlobalScope } from '../global-scope';\n\nexport class CookieStorage<T> implements Storage<T> {\n options: CookieStorageOptions;\n private static testValue: undefined | string;\n\n constructor(options?: CookieStorageOptions) {\n this.options = { ...options };\n }\n\n async isEnabled(): Promise<boolean> {\n /* istanbul ignore if */\n if (!getGlobalScope()) {\n return false;\n }\n\n CookieStorage.testValue = String(Date.now());\n const testStrorage = new CookieStorage<string>(this.options);\n const testKey = 'AMP_TEST';\n try {\n await testStrorage.set(testKey, CookieStorage.testValue);\n const value = await testStrorage.get(testKey);\n return value === CookieStorage.testValue;\n } catch {\n /* istanbul ignore next */\n return false;\n } finally {\n await testStrorage.remove(testKey);\n }\n }\n\n async get(key: string): Promise<T | undefined> {\n const value = await this.getRaw(key);\n if (!value) {\n return undefined;\n }\n try {\n const decodedValue = decodeCookiesAsDefault(value) ?? decodeCookiesWithDoubleUrlEncoding(value);\n if (decodedValue === undefined) {\n console.error(`Amplitude Logger [Error]: Failed to decode cookie value for key: ${key}, value: ${value}`);\n return undefined;\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return JSON.parse(decodedValue);\n } catch {\n console.error(`Amplitude Logger [Error]: Failed to parse cookie value for key: ${key}, value: ${value}`);\n return undefined;\n }\n }\n\n async getRaw(key: string): Promise<string | undefined> {\n const globalScope = getGlobalScope();\n const cookie = globalScope?.document?.cookie.split('; ') ?? [];\n const match = cookie.find((c) => c.indexOf(key + '=') === 0);\n if (!match) {\n return undefined;\n }\n return match.substring(key.length + 1);\n }\n\n async set(key: string, value: T | null): Promise<void> {\n try {\n const expirationDays = this.options.expirationDays ?? 0;\n const expires = value !== null ? expirationDays : -1;\n let expireDate: Date | undefined = undefined;\n if (expires) {\n const date = new Date();\n date.setTime(date.getTime() + expires * 24 * 60 * 60 * 1000);\n expireDate = date;\n }\n let str = `${key}=${btoa(encodeURIComponent(JSON.stringify(value)))}`;\n if (expireDate) {\n str += `; expires=${expireDate.toUTCString()}`;\n }\n str += '; path=/';\n if (this.options.domain) {\n str += `; domain=${this.options.domain}`;\n }\n if (this.options.secure) {\n str += '; Secure';\n }\n if (this.options.sameSite) {\n str += `; SameSite=${this.options.sameSite}`;\n }\n const globalScope = getGlobalScope();\n if (globalScope) {\n globalScope.document.cookie = str;\n }\n } catch (error) {\n const errorMessage = error instanceof Error ? error.message : String(error);\n console.error(`Amplitude Logger [Error]: Failed to set cookie for key: ${key}. Error: ${errorMessage}`);\n }\n }\n\n async remove(key: string): Promise<void> {\n await this.set(key, null);\n }\n\n async reset(): Promise<void> {\n return;\n }\n}\n\nconst decodeCookiesAsDefault = (value: string): string | undefined => {\n try {\n return decodeURIComponent(atob(value));\n } catch {\n return undefined;\n }\n};\n\nconst decodeCookiesWithDoubleUrlEncoding = (value: string): string | undefined => {\n // Modern Ruby (v7+) automatically encodes cookies with URL encoding by\n // https://api.rubyonrails.org/classes/ActionDispatch/Cookies.html\n try {\n return decodeURIComponent(atob(decodeURIComponent(value)));\n } catch {\n return undefined;\n }\n};\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const getStorageKey: (apiKey: string, postKey?: string, limit?: number) => string;
2
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/storage/helpers.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,WAAY,MAAM,6CAE3C,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { AMPLITUDE_PREFIX } from '../types/constants';
2
+ export var getStorageKey = function (apiKey, postKey, limit) {
3
+ if (postKey === void 0) { postKey = ''; }
4
+ if (limit === void 0) { limit = 10; }
5
+ return [AMPLITUDE_PREFIX, postKey, apiKey.substring(0, limit)].filter(Boolean).join('_');
6
+ };
7
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/storage/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,CAAC,IAAM,aAAa,GAAG,UAAC,MAAc,EAAE,OAAY,EAAE,KAAU;IAAxB,wBAAA,EAAA,YAAY;IAAE,sBAAA,EAAA,UAAU;IACpE,OAAO,CAAC,gBAAgB,EAAE,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3F,CAAC,CAAC","sourcesContent":["import { AMPLITUDE_PREFIX } from '../types/constants';\n\nexport const getStorageKey = (apiKey: string, postKey = '', limit = 10) => {\n return [AMPLITUDE_PREFIX, postKey, apiKey.substring(0, limit)].filter(Boolean).join('_');\n};\n"]}
@@ -1,4 +1,4 @@
1
- import { Storage } from '@amplitude/analytics-types';
1
+ import { Storage } from '../types/storage';
2
2
  export declare class MemoryStorage<T> implements Storage<T> {
3
3
  memoryStorage: Map<string, T>;
4
4
  isEnabled(): Promise<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/storage/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,OAAO,CAAC,CAAC,CAAC;IACjD,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAa;IAEpC,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAI7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAIxC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAKhD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../../src/storage/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,OAAO,CAAC,CAAC,CAAC;IACjD,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CA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X;;;gBACE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;;;;KAC5B;IACH,oBAAC;AAAD,CAAC,AA3BD,IA2BC","sourcesContent":["import { Storage } from '@amplitude/analytics-types';\n\nexport class MemoryStorage<T> implements Storage<T> {\n memoryStorage: Map<string, T> = new Map();\n\n async isEnabled(): Promise<boolean> {\n return true;\n }\n\n async get(key: string): Promise<T | undefined> {\n return this.memoryStorage.get(key);\n }\n\n async getRaw(key: string): Promise<string | undefined> {\n const value = await this.get(key);\n return value ? JSON.stringify(value) : undefined;\n }\n\n async set(key: string, value: T): Promise<void> {\n this.memoryStorage.set(key, value);\n }\n\n async remove(key: string): Promise<void> {\n this.memoryStorage.delete(key);\n }\n\n async reset(): Promise<void> {\n this.memoryStorage.clear();\n }\n}\n"]}
1
+ {"version":3,"file":"memory.js","sourceRoot":"","sources":["../../../src/storage/memory.ts"],"names":[],"mappings":";AAEA;IAAA;QACE,kBAAa,GAAmB,IAAI,GAAG,EAAE,CAAC;IA0B5C,CAAC;IAxBO,iCAAS,GAAf;;;gBACE,sBAAO,IAAI,EAAC;;;KACb;IAEK,2BAAG,GAAT,UAAU,GAAW;;;gBACnB,sBAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,EAAC;;;KACpC;IAEK,8BAAM,GAAZ,UAAa,GAAW;;;;;4BACR,qBAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAA;;wBAA3B,KAAK,GAAG,SAAmB;wBACjC,sBAAO,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,EAAC;;;;KAClD;IAEK,2BAAG,GAAT,UAAU,GAAW,EAAE,KAAQ;;;gBAC7B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;;;;KACpC;IAEK,8BAAM,GAAZ,UAAa,GAAW;;;gBACtB,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;;;;KAChC;IAEK,6BAAK,GAAX;;;gBACE,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;;;;KAC5B;IACH,oBAAC;AAAD,CAAC,AA3BD,IA2BC","sourcesContent":["import { Storage } from '../types/storage';\n\nexport class MemoryStorage<T> implements Storage<T> {\n memoryStorage: Map<string, T> = new Map();\n\n async isEnabled(): Promise<boolean> {\n return true;\n }\n\n async get(key: string): Promise<T | undefined> {\n return this.memoryStorage.get(key);\n }\n\n async getRaw(key: string): Promise<string | undefined> {\n const value = await this.get(key);\n return value ? JSON.stringify(value) : undefined;\n }\n\n async set(key: string, value: T): Promise<void> {\n this.memoryStorage.set(key, value);\n }\n\n async remove(key: string): Promise<void> {\n this.memoryStorage.delete(key);\n }\n\n async reset(): Promise<void> {\n this.memoryStorage.clear();\n }\n}\n"]}
@@ -1,12 +1,17 @@
1
- import { Config, CoreClient, Event, EventCallback, Plugin, Result } from '@amplitude/analytics-types';
1
+ import { Plugin } from './types/plugin';
2
+ import { CoreClient } from './core-client';
3
+ import { IConfig } from './config';
4
+ import { EventCallback } from './types/event-callback';
5
+ import { Event } from './types/event/event';
6
+ import { Result } from './types/result';
2
7
  export declare class Timeline {
3
8
  private client;
4
9
  queue: [Event, EventCallback][];
5
10
  applying: boolean;
6
11
  plugins: Plugin[];
7
12
  constructor(client: CoreClient);
8
- register(plugin: Plugin, config: Config): Promise<void>;
9
- deregister(pluginName: string, config: Config): Promise<void>;
13
+ register(plugin: Plugin, config: IConfig): Promise<void>;
14
+ deregister(pluginName: string, config: IConfig): Promise<void>;
10
15
  reset(client: CoreClient): void;
11
16
  push(event: Event): Promise<Result>;
12
17
  scheduleApply(timeout: number): void;
@@ -1 +1 @@
1
- {"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EACN,UAAU,EAGV,KAAK,EACL,aAAa,EACb,MAAM,E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C,GAAG,CAAC,mBAAmB,CAAC,CAAC,IAAI,CAAC,UAAC,EAAQ;gCAAR,KAAA,aAAQ,EAAP,MAAM,QAAA;4BACjD,IAAM,aAAa,GACjB,MAAM,IAAI,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE,2DAA2D,CAAC,CAAC;4BACjG,OAAO,CAAC,aAAa,CAAC,CAAC;wBACzB,CAAC,CAAC,CAAC;wBAEH,sBAAO;;;;KACR;IAEK,wBAAK,GAAX;;;;;;;wBACQ,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;wBACzB,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;wBAEhB,qBAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,UAAC,IAAI,IAAK,OAAA,KAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAhB,CAAgB,CAAC,CAAC,EAAA;;wBAAxD,SAAwD,CAAC;wBAEnD,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CACrC,UAAC,MAAc,IAAkC,OAAA,MAAM,CAAC,IAAI,KAAK,aAAa,EAA7B,CAA6B,CAC/E,CAAC;wBAEI,mBAAmB,GAAG,WAAW,CAAC,GAAG,CAAC,UAAC,MAAM;4BACjD,OAAO,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;wBACxC,CAAC,CAAC,CAAC;wBAEH,qBAAM,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAA;;wBAAtC,SAAsC,CAAC;;;;;KACxC;IACH,eAAC;AAAD,CAAC,AApJD,IAoJC","sourcesContent":["import {\n BeforePlugin,\n Config,\n CoreClient,\n DestinationPlugin,\n EnrichmentPlugin,\n Event,\n EventCallback,\n Plugin,\n Result,\n} from '@amplitude/analytics-types';\nimport { buildResult } from './utils/result-builder';\nimport { UUID } from './utils/uuid';\n\nexport class Timeline {\n queue: [Event, EventCallback][] = [];\n // Flag to guarantee one schedule apply is running\n applying = false;\n // Flag indicates whether timeline is ready to process event\n // Events collected before timeline is ready will stay in the queue to be processed later\n plugins: Plugin[] = [];\n\n constructor(private client: CoreClient) {}\n\n async register(plugin: Plugin, config: Config) {\n if (this.plugins.some((existingPlugin) => existingPlugin.name === plugin.name)) {\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n config.loggerProvider.warn(`Plugin with name ${plugin.name} already exists, skipping registration`);\n return;\n }\n\n if (plugin.name === undefined) {\n plugin.name = UUID();\n config.loggerProvider.warn(`Plugin name is undefined. \n Generating a random UUID for plugin name: ${plugin.name}. \n Set a name for the plugin to prevent it from being added multiple times.`);\n }\n\n plugin.type = plugin.type ?? 'enrichment';\n await plugin.setup?.(config, this.client);\n this.plugins.push(plugin);\n }\n\n async deregister(pluginName: string, config: Config) {\n const index = this.plugins.findIndex((plugin) => plugin.name === pluginName);\n if (index === -1) {\n config.loggerProvider.warn(`Plugin with name ${pluginName} does not exist, skipping deregistration`);\n return;\n }\n const plugin = this.plugins[index];\n this.plugins.splice(index, 1);\n await plugin.teardown?.();\n }\n\n reset(client: CoreClient) {\n this.applying = false;\n const plugins = this.plugins;\n plugins.map((plugin) => plugin.teardown?.());\n this.plugins = [];\n this.client = client;\n }\n\n push(event: Event) {\n return new Promise<Result>((resolve) => {\n this.queue.push([event, resolve]);\n this.scheduleApply(0);\n });\n }\n\n scheduleApply(timeout: number) {\n if (this.applying) return;\n this.applying = true;\n setTimeout(() => {\n void this.apply(this.queue.shift()).then(() => {\n this.applying = false;\n if (this.queue.length > 0) {\n this.scheduleApply(0);\n }\n });\n }, timeout);\n }\n\n async apply(item: [Event, EventCallback] | undefined) {\n if (!item) {\n return;\n }\n\n let [event] = item;\n const [, resolve] = item;\n\n const before = this.plugins.filter<BeforePlugin>(\n (plugin: Plugin): plugin is BeforePlugin => plugin.type === 'before',\n );\n\n for (const plugin of before) {\n /* istanbul ignore if */\n if (!plugin.execute) {\n // do nothing\n continue;\n }\n const e = await plugin.execute({ ...event });\n if (e === null) {\n resolve({ event, code: 0, message: '' });\n return;\n } else {\n event = e;\n }\n }\n\n const enrichment = this.plugins.filter<EnrichmentPlugin>(\n (plugin: Plugin): plugin is EnrichmentPlugin => plugin.type === 'enrichment' || plugin.type === undefined,\n );\n\n for (const plugin of enrichment) {\n /* istanbul ignore if */\n if (!plugin.execute) {\n // do nothing\n continue;\n }\n const e = await plugin.execute({ ...event });\n if (e === null) {\n resolve({ event, code: 0, message: '' });\n return;\n } else {\n event = e;\n }\n }\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === 'destination',\n );\n\n const executeDestinations = destination.map((plugin) => {\n const eventClone = { ...event };\n return plugin.execute(eventClone).catch((e) => buildResult(eventClone, 0, String(e)));\n });\n\n void Promise.all(executeDestinations).then(([result]) => {\n const resolveResult =\n result || buildResult(event, 100, 'Event not tracked, no destination plugins on the instance');\n resolve(resolveResult);\n });\n\n return;\n }\n\n async flush() {\n const queue = this.queue;\n this.queue = [];\n\n await Promise.all(queue.map((item) => this.apply(item)));\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === 'destination',\n );\n\n const executeDestinations = destination.map((plugin) => {\n return plugin.flush && plugin.flush();\n });\n\n await Promise.all(executeDestinations);\n }\n}\n"]}
1
+ {"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":";AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC;IAQE,kBAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAPtC,UAAK,GAA6B,EAAE,CAAC;QACrC,kDAAkD;QAClD,aAAQ,GAAG,KAAK,CAAC;QACjB,4DAA4D;QAC5D,yFAAyF;QACzF,YAAO,GAAa,EAAE,CAAC;IAEkB,CAAC;IAEpC,2BAAQ,GAAd,UAAe,MAAc,EAAE,MA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,CAAC,IAAI,KAAK,aAAa,EAA7B,CAA6B,CAC/E,CAAC;wBAEI,mBAAmB,GAAG,WAAW,CAAC,GAAG,CAAC,UAAC,MAAM;4BACjD,OAAO,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;wBACxC,CAAC,CAAC,CAAC;wBAEH,qBAAM,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAA;;wBAAtC,SAAsC,CAAC;;;;;KACxC;IACH,eAAC;AAAD,CAAC,AApJD,IAoJC","sourcesContent":["import { BeforePlugin, DestinationPlugin, EnrichmentPlugin, Plugin } from './types/plugin';\nimport { CoreClient } from './core-client';\nimport { IConfig } from './config';\nimport { EventCallback } from './types/event-callback';\nimport { Event } from './types/event/event';\nimport { Result } from './types/result';\nimport { buildResult } from './utils/result-builder';\nimport { UUID } from './utils/uuid';\n\nexport class Timeline {\n queue: [Event, EventCallback][] = [];\n // Flag to guarantee one schedule apply is running\n applying = false;\n // Flag indicates whether timeline is ready to process event\n // Events collected before timeline is ready will stay in the queue to be processed later\n plugins: Plugin[] = [];\n\n constructor(private client: CoreClient) {}\n\n async register(plugin: Plugin, config: IConfig) {\n if (this.plugins.some((existingPlugin) => existingPlugin.name === plugin.name)) {\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\n config.loggerProvider.warn(`Plugin with name ${plugin.name} already exists, skipping registration`);\n return;\n }\n\n if (plugin.name === undefined) {\n plugin.name = UUID();\n config.loggerProvider.warn(`Plugin name is undefined. \n Generating a random UUID for plugin name: ${plugin.name}. \n Set a name for the plugin to prevent it from being added multiple times.`);\n }\n\n plugin.type = plugin.type ?? 'enrichment';\n await plugin.setup?.(config, this.client);\n this.plugins.push(plugin);\n }\n\n async deregister(pluginName: string, config: IConfig) {\n const index = this.plugins.findIndex((plugin) => plugin.name === pluginName);\n if (index === -1) {\n config.loggerProvider.warn(`Plugin with name ${pluginName} does not exist, skipping deregistration`);\n return;\n }\n const plugin = this.plugins[index];\n this.plugins.splice(index, 1);\n await plugin.teardown?.();\n }\n\n reset(client: CoreClient) {\n this.applying = false;\n const plugins = this.plugins;\n plugins.map((plugin) => plugin.teardown?.());\n this.plugins = [];\n this.client = client;\n }\n\n push(event: Event) {\n return new Promise<Result>((resolve) => {\n this.queue.push([event, resolve]);\n this.scheduleApply(0);\n });\n }\n\n scheduleApply(timeout: number) {\n if (this.applying) return;\n this.applying = true;\n setTimeout(() => {\n void this.apply(this.queue.shift()).then(() => {\n this.applying = false;\n if (this.queue.length > 0) {\n this.scheduleApply(0);\n }\n });\n }, timeout);\n }\n\n async apply(item: [Event, EventCallback] | undefined) {\n if (!item) {\n return;\n }\n\n let [event] = item;\n const [, resolve] = item;\n\n const before = this.plugins.filter<BeforePlugin>(\n (plugin: Plugin): plugin is BeforePlugin => plugin.type === 'before',\n );\n\n for (const plugin of before) {\n /* istanbul ignore if */\n if (!plugin.execute) {\n // do nothing\n continue;\n }\n const e = await plugin.execute({ ...event });\n if (e === null) {\n resolve({ event, code: 0, message: '' });\n return;\n } else {\n event = e;\n }\n }\n\n const enrichment = this.plugins.filter<EnrichmentPlugin>(\n (plugin: Plugin): plugin is EnrichmentPlugin => plugin.type === 'enrichment' || plugin.type === undefined,\n );\n\n for (const plugin of enrichment) {\n /* istanbul ignore if */\n if (!plugin.execute) {\n // do nothing\n continue;\n }\n const e = await plugin.execute({ ...event });\n if (e === null) {\n resolve({ event, code: 0, message: '' });\n return;\n } else {\n event = e;\n }\n }\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === 'destination',\n );\n\n const executeDestinations = destination.map((plugin) => {\n const eventClone = { ...event };\n return plugin.execute(eventClone).catch((e) => buildResult(eventClone, 0, String(e)));\n });\n\n void Promise.all(executeDestinations).then(([result]) => {\n const resolveResult =\n result || buildResult(event, 100, 'Event not tracked, no destination plugins on the instance');\n resolve(resolveResult);\n });\n\n return;\n }\n\n async flush() {\n const queue = this.queue;\n this.queue = [];\n\n await Promise.all(queue.map((item) => this.apply(item)));\n\n const destination = this.plugins.filter<DestinationPlugin>(\n (plugin: Plugin): plugin is DestinationPlugin => plugin.type === 'destination',\n );\n\n const executeDestinations = destination.map((plugin) => {\n return plugin.flush && plugin.flush();\n });\n\n await Promise.all(executeDestinations);\n }\n}\n"]}
@@ -1,4 +1,7 @@
1
- import { Payload, Response, Status, Transport } from '@amplitude/analytics-types';
1
+ import { Transport } from '../types/transport';
2
+ import { Status } from '../types/status';
3
+ import { Payload } from '../types/payload';
4
+ import { Response } from '../types/response';
2
5
  export declare class BaseTransport implements Transport {
3
6
  send(_serverUrl: string, _payload: Payload): Promise<Response | null>;
4
7
  buildResponse(responseJSON: Record<string, any>): Response | null;
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/transports/base.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAElF,qBAAa,aAAc,YAAW,SAAS;IAC7C,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAIrE,aAAa,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,QAAQ,GAAG,IAAI;IAqEjE,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CA2BlC"}
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/transports/base.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,qBAAa,aAAc,YAAW,SAAS;IAC7C,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAIrE,aAAa,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,QAAQ,GAAG,IAAI;IAqEjE,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CA2BlC"}
@@ -1,7 +1,4 @@
1
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
2
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
- /* eslint-disable @typescript-eslint/no-unsafe-call */
4
- import { Status } from '@amplitude/analytics-types';
1
+ import { Status } from '../types/status';
5
2
  var BaseTransport = /** @class */ (function () {
6
3
  function BaseTransport() {
7
4
  }
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/transports/base.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,4DAA4D;AAC5D,sDAAsD;AACtD,OAAO,EAAqB,MAAM,EAAa,MAAM,4BAA4B,CAAC;AAElF;IAAA;IAqGA,CAAC;IApGC,4BAAI,GAAJ,UAAK,UAAkB,EAAE,QAAiB;QACxC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,qCAAa,GAAb,UAAc,YAAiC;;QAC7C,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;YACpC,OAAO,IAAI,CAAC;SACb;QAED,IAAM,UAAU,GAAG,YAAY,CAAC,IAAI,IAAI,CAAC,CAAC;QAC1C,IAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAE5C,QAAQ,MAAM,EAAE;YACd,KAAK,MAAM,CAAC,OAAO;gBACjB,OAAO;oBACL,MAAM,QAAA;oBACN,UAAU,YAAA;oBACV,IAAI,EAAE;wBACJ,cAAc,EAAE,MAAA,YAAY,CAAC,eAAe,mCAAI,CAAC;wBACjD,gBAAgB,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C/B,YAAY,EAAE,MAAA,YAAY,CAAC,aAAa,mCAAI,CAAC;wBAC7C,gBAAgB,EAAE,MAAA,YAAY,CAAC,iBAAiB,mCAAI,EAAE;wBACtD,cAAc,EAAE,MAAA,YAAY,CAAC,eAAe,mCAAI,EAAE;wBAClD,yBAAyB,EAAE,MAAA,YAAY,CAAC,4BAA4B,mCAAI,EAAE;wBAC1E,uBAAuB,EAAE,MAAA,YAAY,CAAC,0BAA0B,mCAAI,EAAE;wBACtE,eAAe,EAAE,MAAA,YAAY,CAAC,gBAAgB,mCAAI,EAAE;qBACrD;iBACF,CAAC;YACJ,KAAK,MAAM,CAAC,OAAO,CAAC;YACpB;gBACE,OAAO;oBACL,MAAM,QAAA;oBACN,UAAU,YAAA;iBACX,CAAC;SACL;IACH,CAAC;IAED,mCAAW,GAAX,UAAY,IAAY;QACtB,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,GAAG,GAAG,EAAE;YAC7B,OAAO,MAAM,CAAC,OAAO,CAAC;SACvB;QAED,IAAI,IAAI,KAAK,GAAG,EAAE;YAChB,OAAO,MAAM,CAAC,SAAS,CAAC;SACzB;QAED,IAAI,IAAI,KAAK,GAAG,EAAE;YAChB,OAAO,MAAM,CAAC,eAAe,CAAC;SAC/B;QAED,IAAI,IAAI,KAAK,GAAG,EAAE;YAChB,OAAO,MAAM,CAAC,OAAO,CAAC;SACvB;QAED,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,GAAG,GAAG,EAAE;YAC7B,OAAO,MAAM,CAAC,OAAO,CAAC;SACvB;QAED,IAAI,IAAI,IAAI,GAAG,EAAE;YACf,OAAO,MAAM,CAAC,MAAM,CAAC;SACtB;QAED,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;IACH,oBAAC;AAAD,CAAC,AArGD,IAqGC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\nimport { Payload, Response, Status, Transport } from '@amplitude/analytics-types';\n\nexport class BaseTransport implements Transport {\n send(_serverUrl: string, _payload: Payload): Promise<Response | null> {\n return Promise.resolve(null);\n }\n\n buildResponse(responseJSON: Record<string, any>): Response | null {\n if (typeof responseJSON !== 'object') {\n return null;\n }\n\n const statusCode = responseJSON.code || 0;\n const status = this.buildStatus(statusCode);\n\n switch (status) {\n case Status.Success:\n return {\n status,\n statusCode,\n body: {\n eventsIngested: responseJSON.events_ingested ?? 0,\n payloadSizeBytes: responseJSON.payload_size_bytes ?? 0,\n serverUploadTime: responseJSON.server_upload_time ?? 0,\n },\n };\n\n case Status.Invalid:\n return {\n status,\n statusCode,\n body: {\n error: responseJSON.error ?? '',\n missingField: responseJSON.missing_field ?? '',\n eventsWithInvalidFields: responseJSON.events_with_invalid_fields ?? {},\n eventsWithMissingFields: responseJSON.events_with_missing_fields ?? {},\n eventsWithInvalidIdLengths: responseJSON.events_with_invalid_id_lengths ?? {},\n epsThreshold: responseJSON.eps_threshold ?? 0,\n exceededDailyQuotaDevices: responseJSON.exceeded_daily_quota_devices ?? {},\n silencedDevices: responseJSON.silenced_devices ?? [],\n silencedEvents: responseJSON.silenced_events ?? [],\n throttledDevices: responseJSON.throttled_devices ?? {},\n throttledEvents: responseJSON.throttled_events ?? [],\n },\n };\n case Status.PayloadTooLarge:\n return {\n status,\n statusCode,\n body: {\n error: responseJSON.error ?? '',\n },\n };\n case Status.RateLimit:\n return {\n status,\n statusCode,\n body: {\n error: responseJSON.error ?? '',\n epsThreshold: responseJSON.eps_threshold ?? 0,\n throttledDevices: responseJSON.throttled_devices ?? {},\n throttledUsers: responseJSON.throttled_users ?? {},\n exceededDailyQuotaDevices: responseJSON.exceeded_daily_quota_devices ?? {},\n exceededDailyQuotaUsers: responseJSON.exceeded_daily_quota_users ?? {},\n throttledEvents: responseJSON.throttled_events ?? [],\n },\n };\n case Status.Timeout:\n default:\n return {\n status,\n statusCode,\n };\n }\n }\n\n buildStatus(code: number): Status {\n if (code >= 200 && code < 300) {\n return Status.Success;\n }\n\n if (code === 429) {\n return Status.RateLimit;\n }\n\n if (code === 413) {\n return Status.PayloadTooLarge;\n }\n\n if (code === 408) {\n return Status.Timeout;\n }\n\n if (code >= 400 && code < 500) {\n return Status.Invalid;\n }\n\n if (code >= 500) {\n return Status.Failed;\n }\n\n return Status.Unknown;\n }\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/transports/base.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAIzC;IAAA;IAqGA,CAAC;IApGC,4BAAI,GAAJ,UAAK,UAAkB,EAAE,QAAiB;QACxC,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,qCAAa,GAAb,UAAc,YAAiC;;QAC7C,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE;YACpC,OAAO,IAAI,CAAC;SACb;QAED,IAAM,UAAU,GAAG,YAAY,CAAC,IAAI,IAAI,CAAC,CAAC;QAC1C,IAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAE5C,QAAQ,MAAM,EAAE;YACd,KAAK,MAAM,CAAC,OAAO;gBACjB,OAAO;oBACL,MAAM,QAAA;oBACN,UAAU,YAAA;oBACV,IAAI,EAAE;wBACJ,cAAc,EAAE,MAAA,YAAY,CAAC,eAAe,mCAAI,CAAC;wBACjD,gBAAgB,EAAE,MAAA,YAAY,CAAC,kBAAkB,mCAAI,CAAC;wBACtD,gBAAgB,EAAE,MAAA,YAAY,CAAC,kBAAkB,mCAAI,CAAC;qBACvD;iBACF,CAAC;YAEJ,KAAK,MAAM,CAAC,OAAO;gBACjB,OAAO;oBACL,MAAM,QAAA;oBACN,UAAU,YAAA;oBACV,IAAI,EAAE;wBACJ,KAAK,EAAE,MAAA,YAAY,CAAC,KAAK,mCAAI,EAAE;wBAC/B,YAAY,EAAE,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E,eAAe,EAAE,MAAA,YAAY,CAAC,gBAAgB,mCAAI,EAAE;qBACrD;iBACF,CAAC;YACJ,KAAK,MAAM,CAAC,OAAO,CAAC;YACpB;gBACE,OAAO;oBACL,MAAM,QAAA;oBACN,UAAU,YAAA;iBACX,CAAC;SACL;IACH,CAAC;IAED,mCAAW,GAAX,UAAY,IAAY;QACtB,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,GAAG,GAAG,EAAE;YAC7B,OAAO,MAAM,CAAC,OAAO,CAAC;SACvB;QAED,IAAI,IAAI,KAAK,GAAG,EAAE;YAChB,OAAO,MAAM,CAAC,SAAS,CAAC;SACzB;QAED,IAAI,IAAI,KAAK,GAAG,EAAE;YAChB,OAAO,MAAM,CAAC,eAAe,CAAC;SAC/B;QAED,IAAI,IAAI,KAAK,GAAG,EAAE;YAChB,OAAO,MAAM,CAAC,OAAO,CAAC;SACvB;QAED,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,GAAG,GAAG,EAAE;YAC7B,OAAO,MAAM,CAAC,OAAO,CAAC;SACvB;QAED,IAAI,IAAI,IAAI,GAAG,EAAE;YACf,OAAO,MAAM,CAAC,MAAM,CAAC;SACtB;QAED,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;IACH,oBAAC;AAAD,CAAC,AArGD,IAqGC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\n/* eslint-disable @typescript-eslint/no-unsafe-call */\nimport { Transport } from '../types/transport';\nimport { Status } from '../types/status';\nimport { Payload } from '../types/payload';\nimport { Response } from '../types/response';\n\nexport class BaseTransport implements Transport {\n send(_serverUrl: string, _payload: Payload): Promise<Response | null> {\n return Promise.resolve(null);\n }\n\n buildResponse(responseJSON: Record<string, any>): Response | null {\n if (typeof responseJSON !== 'object') {\n return null;\n }\n\n const statusCode = responseJSON.code || 0;\n const status = this.buildStatus(statusCode);\n\n switch (status) {\n case Status.Success:\n return {\n status,\n statusCode,\n body: {\n eventsIngested: responseJSON.events_ingested ?? 0,\n payloadSizeBytes: responseJSON.payload_size_bytes ?? 0,\n serverUploadTime: responseJSON.server_upload_time ?? 0,\n },\n };\n\n case Status.Invalid:\n return {\n status,\n statusCode,\n body: {\n error: responseJSON.error ?? '',\n missingField: responseJSON.missing_field ?? '',\n eventsWithInvalidFields: responseJSON.events_with_invalid_fields ?? {},\n eventsWithMissingFields: responseJSON.events_with_missing_fields ?? {},\n eventsWithInvalidIdLengths: responseJSON.events_with_invalid_id_lengths ?? {},\n epsThreshold: responseJSON.eps_threshold ?? 0,\n exceededDailyQuotaDevices: responseJSON.exceeded_daily_quota_devices ?? {},\n silencedDevices: responseJSON.silenced_devices ?? [],\n silencedEvents: responseJSON.silenced_events ?? [],\n throttledDevices: responseJSON.throttled_devices ?? {},\n throttledEvents: responseJSON.throttled_events ?? [],\n },\n };\n case Status.PayloadTooLarge:\n return {\n status,\n statusCode,\n body: {\n error: responseJSON.error ?? '',\n },\n };\n case Status.RateLimit:\n return {\n status,\n statusCode,\n body: {\n error: responseJSON.error ?? '',\n epsThreshold: responseJSON.eps_threshold ?? 0,\n throttledDevices: responseJSON.throttled_devices ?? {},\n throttledUsers: responseJSON.throttled_users ?? {},\n exceededDailyQuotaDevices: responseJSON.exceeded_daily_quota_devices ?? {},\n exceededDailyQuotaUsers: responseJSON.exceeded_daily_quota_users ?? {},\n throttledEvents: responseJSON.throttled_events ?? [],\n },\n };\n case Status.Timeout:\n default:\n return {\n status,\n statusCode,\n };\n }\n }\n\n buildStatus(code: number): Status {\n if (code >= 200 && code < 300) {\n return Status.Success;\n }\n\n if (code === 429) {\n return Status.RateLimit;\n }\n\n if (code === 413) {\n return Status.PayloadTooLarge;\n }\n\n if (code === 408) {\n return Status.Timeout;\n }\n\n if (code >= 400 && code < 500) {\n return Status.Invalid;\n }\n\n if (code >= 500) {\n return Status.Failed;\n }\n\n return Status.Unknown;\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { BaseTransport } from './base';
2
+ import { Transport } from '../types/transport';
3
+ import { Payload } from '../types/payload';
4
+ import { Response } from '../types/response';
5
+ export declare class FetchTransport extends BaseTransport implements Transport {
6
+ send(serverUrl: string, payload: Payload): Promise<Response | null>;
7
+ }
8
+ //# sourceMappingURL=fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/transports/fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,qBAAa,cAAe,SAAQ,aAAc,YAAW,SAAS;IAC9D,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;CAsB1E"}
@@ -0,0 +1,47 @@
1
+ import { __awaiter, __extends, __generator } from "tslib";
2
+ import { BaseTransport } from './base';
3
+ var FetchTransport = /** @class */ (function (_super) {
4
+ __extends(FetchTransport, _super);
5
+ function FetchTransport() {
6
+ return _super !== null && _super.apply(this, arguments) || this;
7
+ }
8
+ FetchTransport.prototype.send = function (serverUrl, payload) {
9
+ return __awaiter(this, void 0, void 0, function () {
10
+ var options, response, responseText;
11
+ return __generator(this, function (_a) {
12
+ switch (_a.label) {
13
+ case 0:
14
+ /* istanbul ignore if */
15
+ if (typeof fetch === 'undefined') {
16
+ throw new Error('FetchTransport is not supported');
17
+ }
18
+ options = {
19
+ headers: {
20
+ 'Content-Type': 'application/json',
21
+ Accept: '*/*',
22
+ },
23
+ body: JSON.stringify(payload),
24
+ method: 'POST',
25
+ };
26
+ return [4 /*yield*/, fetch(serverUrl, options)];
27
+ case 1:
28
+ response = _a.sent();
29
+ return [4 /*yield*/, response.text()];
30
+ case 2:
31
+ responseText = _a.sent();
32
+ try {
33
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
34
+ return [2 /*return*/, this.buildResponse(JSON.parse(responseText))];
35
+ }
36
+ catch (_b) {
37
+ return [2 /*return*/, this.buildResponse({ code: response.status })];
38
+ }
39
+ return [2 /*return*/];
40
+ }
41
+ });
42
+ });
43
+ };
44
+ return FetchTransport;
45
+ }(BaseTransport));
46
+ export { FetchTransport };
47
+ //# sourceMappingURL=fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../../src/transports/fetch.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAKvC;IAAoC,kCAAa;IAAjD;;IAuBA,CAAC;IAtBO,6BAAI,GAAV,UAAW,SAAiB,EAAE,OAAgB;;;;;;wBAC5C,wBAAwB;wBACxB,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;4BAChC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;yBACpD;wBACK,OAAO,GAAgB;4BAC3B,OAAO,EAAE;gCACP,cAAc,EAAE,kBAAkB;gCAClC,MAAM,EAAE,KAAK;6BACd;4BACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;4BAC7B,MAAM,EAAE,MAAM;yBACf,CAAC;wBACe,qBAAM,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,EAAA;;wBAA1C,QAAQ,GAAG,SAA+B;wBAC3B,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;;wBAApC,YAAY,GAAG,SAAqB;wBAC1C,IAAI;4BACF,iEAAiE;4BACjE,sBAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,EAAC;yBACrD;wBAAC,WAAM;4BACN,sBAAO,IAAI,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAC;yBACtD;;;;;KACF;IACH,qBAAC;AAAD,CAAC,AAvBD,CAAoC,aAAa,GAuBhD","sourcesContent":["import { BaseTransport } from './base';\nimport { Transport } from '../types/transport';\nimport { Payload } from '../types/payload';\nimport { Response } from '../types/response';\n\nexport class FetchTransport extends BaseTransport implements Transport {\n async send(serverUrl: string, payload: Payload): Promise<Response | null> {\n /* istanbul ignore if */\n if (typeof fetch === 'undefined') {\n throw new Error('FetchTransport is not supported');\n }\n const options: RequestInit = {\n headers: {\n 'Content-Type': 'application/json',\n Accept: '*/*',\n },\n body: JSON.stringify(payload),\n method: 'POST',\n };\n const response = await fetch(serverUrl, options);\n const responseText = await response.text();\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return this.buildResponse(JSON.parse(responseText));\n } catch {\n return this.buildResponse({ code: response.status });\n }\n }\n}\n"]}
@@ -0,0 +1,131 @@
1
+ import { TransportType } from './transport';
2
+ import { CoreClient } from '../core-client';
3
+ import { Plugin } from './plugin';
4
+ import { AmplitudeReturn } from '../utils/return-wrapper';
5
+ import { BrowserConfig, BrowserOptions } from './browser-config';
6
+ interface Client extends CoreClient {
7
+ /**
8
+ * Returns current user ID.
9
+ *
10
+ * ```typescript
11
+ * const userId = getUserId();
12
+ * ```
13
+ */
14
+ getUserId(): string | undefined;
15
+ /**
16
+ * Sets a new user ID.
17
+ *
18
+ * ```typescript
19
+ * setUserId('userId');
20
+ * ```
21
+ */
22
+ setUserId(userId: string | undefined): void;
23
+ /**
24
+ * Returns current device ID.
25
+ *
26
+ * ```typescript
27
+ * const deviceId = getDeviceId();
28
+ * ```
29
+ */
30
+ getDeviceId(): string | undefined;
31
+ /**
32
+ * Sets a new device ID.
33
+ * When setting a custom device ID, make sure the value is sufficiently unique.
34
+ * A uuid is recommended.
35
+ *
36
+ * ```typescript
37
+ * setDeviceId('deviceId');
38
+ * ```
39
+ */
40
+ setDeviceId(deviceId: string): void;
41
+ /**
42
+ * Returns current session ID.
43
+ *
44
+ * ```typescript
45
+ * const sessionId = getSessionId();
46
+ * ```
47
+ */
48
+ getSessionId(): number | undefined;
49
+ /**
50
+ * Sets a new session ID.
51
+ * When setting a custom session ID, make sure the value is in milliseconds since epoch (Unix Timestamp).
52
+ *
53
+ * ```typescript
54
+ * setSessionId(Date.now());
55
+ * ```
56
+ */
57
+ setSessionId(sessionId: number): void;
58
+ /**
59
+ * Extends the current session (advanced)
60
+ *
61
+ * Normally sessions are extended automatically by track()'ing events. If you want to extend the session without
62
+ * tracking and event, this will set the last user interaction to the current time.
63
+ *
64
+ * ```typescript
65
+ * extendSession();
66
+ * ```
67
+ */
68
+ extendSession(): void;
69
+ /**
70
+ * Anonymizes users after they log out, by:
71
+ *
72
+ * * setting userId to undefined
73
+ * * setting deviceId to a new uuid value
74
+ *
75
+ * With an undefined userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
76
+ *
77
+ * ```typescript
78
+ * import { reset } from '@amplitude/analytics-browser';
79
+ *
80
+ * reset();
81
+ * ```
82
+ */
83
+ reset(): void;
84
+ }
85
+ export interface BrowserClient extends Client {
86
+ /**
87
+ * Initializes the Amplitude SDK with your apiKey, optional configurations.
88
+ * This method must be called before any other operations.
89
+ *
90
+ * ```typescript
91
+ * await init(API_KEY, options).promise;
92
+ * ```
93
+ */
94
+ init(apiKey: string, options?: BrowserOptions): AmplitudeReturn<void>;
95
+ init(apiKey: string, userId?: string, options?: BrowserOptions): AmplitudeReturn<void>;
96
+ /**
97
+ * Sets the network transport type for events.
98
+ *
99
+ * ```typescript
100
+ * // Use Fetch API
101
+ * setTransport('fetch');
102
+ *
103
+ * // Use XMLHttpRequest API
104
+ * setTransport('xhr');
105
+ *
106
+ * // Use navigator.sendBeacon API
107
+ * setTransport('beacon');
108
+ * ```
109
+ */
110
+ setTransport(transport: TransportType): void;
111
+ /**
112
+ * Adds a new plugin.
113
+ *
114
+ * ```typescript
115
+ * const plugin = {
116
+ * name: 'my-plugin',
117
+ * type: 'enrichment',
118
+ * async setup(config: BrowserConfig, amplitude: BrowserClient) {
119
+ * return;
120
+ * },
121
+ * async execute(event: Event) {
122
+ * return event;
123
+ * },
124
+ * };
125
+ * amplitude.add(plugin);
126
+ * ```
127
+ */
128
+ add(plugin: Plugin<BrowserClient, BrowserConfig>): AmplitudeReturn<void>;
129
+ }
130
+ export {};
131
+ //# sourceMappingURL=browser-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-client.d.ts","sourceRoot":"","sources":["../../../src/types/browser-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEjE,UAAU,MAAO,SAAQ,UAAU;IACjC;;;;;;OAMG;IACH,SAAS,IAAI,MAAM,GAAG,SAAS,CAAC;IAEhC;;;;;;OAMG;IACH,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAE5C;;;;;;OAMG;IACH,WAAW,IAAI,MAAM,GAAG,SAAS,CAAC;IAElC;;;;;;;;OAQG;IACH,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAEpC;;;;;;OAMG;IACH,YAAY,IAAI,MAAM,GAAG,SAAS,CAAC;IAEnC;;;;;;;OAOG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC;;;;;;;;;OASG;IACH,aAAa,IAAI,IAAI,CAAC;IAEtB;;;;;;;;;;;;;OAaG;IACH,KAAK,IAAI,IAAI,CAAC;CACf;AAED,MAAM,WAAW,aAAc,SAAQ,MAAM;IAC3C;;;;;;;OAOG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAEtE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAEvF;;;;;;;;;;;;;OAaG;IACH,YAAY,CAAC,SAAS,EAAE,aAAa,GAAG,IAAI,CAAC;IAE7C;;;;;;;;;;;;;;;;OAgBG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,aAAa,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;CAC1E"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=browser-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-client.js","sourceRoot":"","sources":["../../../src/types/browser-client.ts"],"names":[],"mappings":"","sourcesContent":["import { TransportType } from './transport';\nimport { CoreClient } from '../core-client';\nimport { Plugin } from './plugin';\nimport { AmplitudeReturn } from '../utils/return-wrapper';\nimport { BrowserConfig, BrowserOptions } from './browser-config';\n\ninterface Client extends CoreClient {\n /**\n * Returns current user ID.\n *\n * ```typescript\n * const userId = getUserId();\n * ```\n */\n getUserId(): string | undefined;\n\n /**\n * Sets a new user ID.\n *\n * ```typescript\n * setUserId('userId');\n * ```\n */\n setUserId(userId: string | undefined): void;\n\n /**\n * Returns current device ID.\n *\n * ```typescript\n * const deviceId = getDeviceId();\n * ```\n */\n getDeviceId(): string | undefined;\n\n /**\n * Sets a new device ID.\n * When setting a custom device ID, make sure the value is sufficiently unique.\n * A uuid is recommended.\n *\n * ```typescript\n * setDeviceId('deviceId');\n * ```\n */\n setDeviceId(deviceId: string): void;\n\n /**\n * Returns current session ID.\n *\n * ```typescript\n * const sessionId = getSessionId();\n * ```\n */\n getSessionId(): number | undefined;\n\n /**\n * Sets a new session ID.\n * When setting a custom session ID, make sure the value is in milliseconds since epoch (Unix Timestamp).\n *\n * ```typescript\n * setSessionId(Date.now());\n * ```\n */\n setSessionId(sessionId: number): void;\n\n /**\n * Extends the current session (advanced)\n *\n * Normally sessions are extended automatically by track()'ing events. If you want to extend the session without\n * tracking and event, this will set the last user interaction to the current time.\n *\n * ```typescript\n * extendSession();\n * ```\n */\n extendSession(): void;\n\n /**\n * Anonymizes users after they log out, by:\n *\n * * setting userId to undefined\n * * setting deviceId to a new uuid value\n *\n * With an undefined userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.\n *\n * ```typescript\n * import { reset } from '@amplitude/analytics-browser';\n *\n * reset();\n * ```\n */\n reset(): void;\n}\n\nexport interface BrowserClient extends Client {\n /**\n * Initializes the Amplitude SDK with your apiKey, optional configurations.\n * This method must be called before any other operations.\n *\n * ```typescript\n * await init(API_KEY, options).promise;\n * ```\n */\n init(apiKey: string, options?: BrowserOptions): AmplitudeReturn<void>;\n\n init(apiKey: string, userId?: string, options?: BrowserOptions): AmplitudeReturn<void>;\n\n /**\n * Sets the network transport type for events.\n *\n * ```typescript\n * // Use Fetch API\n * setTransport('fetch');\n *\n * // Use XMLHttpRequest API\n * setTransport('xhr');\n *\n * // Use navigator.sendBeacon API\n * setTransport('beacon');\n * ```\n */\n setTransport(transport: TransportType): void;\n\n /**\n * Adds a new plugin.\n *\n * ```typescript\n * const plugin = {\n * name: 'my-plugin',\n * type: 'enrichment',\n * async setup(config: BrowserConfig, amplitude: BrowserClient) {\n * return;\n * },\n * async execute(event: Event) {\n * return event;\n * },\n * };\n * amplitude.add(plugin);\n * ```\n */\n add(plugin: Plugin<BrowserClient, BrowserConfig>): AmplitudeReturn<void>;\n}\n"]}