@customerio/cdp-analytics-browser 0.0.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 (516) hide show
  1. package/LICENSE.MD +22 -0
  2. package/README.md +21 -0
  3. package/dist/cjs/browser/browser-umd.js +20 -0
  4. package/dist/cjs/browser/browser-umd.js.map +1 -0
  5. package/dist/cjs/browser/index.js +310 -0
  6. package/dist/cjs/browser/index.js.map +1 -0
  7. package/dist/cjs/browser/standalone-analytics.js +60 -0
  8. package/dist/cjs/browser/standalone-analytics.js.map +1 -0
  9. package/dist/cjs/browser/standalone.js +83 -0
  10. package/dist/cjs/browser/standalone.js.map +1 -0
  11. package/dist/cjs/core/analytics/index.js +544 -0
  12. package/dist/cjs/core/analytics/index.js.map +1 -0
  13. package/dist/cjs/core/analytics/interfaces.js +3 -0
  14. package/dist/cjs/core/analytics/interfaces.js.map +1 -0
  15. package/dist/cjs/core/arguments-resolver/index.js +106 -0
  16. package/dist/cjs/core/arguments-resolver/index.js.map +1 -0
  17. package/dist/cjs/core/auto-track.js +108 -0
  18. package/dist/cjs/core/auto-track.js.map +1 -0
  19. package/dist/cjs/core/buffer/index.js +237 -0
  20. package/dist/cjs/core/buffer/index.js.map +1 -0
  21. package/dist/cjs/core/buffer/snippet.js +30 -0
  22. package/dist/cjs/core/buffer/snippet.js.map +1 -0
  23. package/dist/cjs/core/callback/index.js +7 -0
  24. package/dist/cjs/core/callback/index.js.map +1 -0
  25. package/dist/cjs/core/connection/index.js +16 -0
  26. package/dist/cjs/core/connection/index.js.map +1 -0
  27. package/dist/cjs/core/context/index.js +19 -0
  28. package/dist/cjs/core/context/index.js.map +1 -0
  29. package/dist/cjs/core/environment/index.js +12 -0
  30. package/dist/cjs/core/environment/index.js.map +1 -0
  31. package/dist/cjs/core/events/index.js +134 -0
  32. package/dist/cjs/core/events/index.js.map +1 -0
  33. package/dist/cjs/core/events/interfaces.js +3 -0
  34. package/dist/cjs/core/events/interfaces.js.map +1 -0
  35. package/dist/cjs/core/inspector/index.js +14 -0
  36. package/dist/cjs/core/inspector/index.js.map +1 -0
  37. package/dist/cjs/core/plugin/index.js +3 -0
  38. package/dist/cjs/core/plugin/index.js.map +1 -0
  39. package/dist/cjs/core/query-string/gracefulDecodeURIComponent.js +20 -0
  40. package/dist/cjs/core/query-string/gracefulDecodeURIComponent.js.map +1 -0
  41. package/dist/cjs/core/query-string/index.js +48 -0
  42. package/dist/cjs/core/query-string/index.js.map +1 -0
  43. package/dist/cjs/core/query-string/pickPrefix.js +20 -0
  44. package/dist/cjs/core/query-string/pickPrefix.js.map +1 -0
  45. package/dist/cjs/core/queue/event-queue.js +15 -0
  46. package/dist/cjs/core/queue/event-queue.js.map +1 -0
  47. package/dist/cjs/core/stats/index.js +23 -0
  48. package/dist/cjs/core/stats/index.js.map +1 -0
  49. package/dist/cjs/core/stats/remote-metrics.js +107 -0
  50. package/dist/cjs/core/stats/remote-metrics.js.map +1 -0
  51. package/dist/cjs/core/user/index.js +422 -0
  52. package/dist/cjs/core/user/index.js.map +1 -0
  53. package/dist/cjs/core/user/tld.js +64 -0
  54. package/dist/cjs/core/user/tld.js.map +1 -0
  55. package/dist/cjs/generated/version.js +6 -0
  56. package/dist/cjs/generated/version.js.map +1 -0
  57. package/dist/cjs/index.js +11 -0
  58. package/dist/cjs/index.js.map +1 -0
  59. package/dist/cjs/lib/bind-all.js +17 -0
  60. package/dist/cjs/lib/bind-all.js.map +1 -0
  61. package/dist/cjs/lib/browser-polyfill.js +22 -0
  62. package/dist/cjs/lib/browser-polyfill.js.map +1 -0
  63. package/dist/cjs/lib/create-deferred.js +21 -0
  64. package/dist/cjs/lib/create-deferred.js.map +1 -0
  65. package/dist/cjs/lib/csp-detection.js +33 -0
  66. package/dist/cjs/lib/csp-detection.js.map +1 -0
  67. package/dist/cjs/lib/embedded-write-key.js +22 -0
  68. package/dist/cjs/lib/embedded-write-key.js.map +1 -0
  69. package/dist/cjs/lib/fetch.js +19 -0
  70. package/dist/cjs/lib/fetch.js.map +1 -0
  71. package/dist/cjs/lib/get-global.js +21 -0
  72. package/dist/cjs/lib/get-global.js.map +1 -0
  73. package/dist/cjs/lib/get-process-env.js +15 -0
  74. package/dist/cjs/lib/get-process-env.js.map +1 -0
  75. package/dist/cjs/lib/group-by.js +28 -0
  76. package/dist/cjs/lib/group-by.js.map +1 -0
  77. package/dist/cjs/lib/is-plan-event-enabled.js +20 -0
  78. package/dist/cjs/lib/is-plan-event-enabled.js.map +1 -0
  79. package/dist/cjs/lib/is-thenable.js +15 -0
  80. package/dist/cjs/lib/is-thenable.js.map +1 -0
  81. package/dist/cjs/lib/load-script.js +56 -0
  82. package/dist/cjs/lib/load-script.js.map +1 -0
  83. package/dist/cjs/lib/merged-options.js +31 -0
  84. package/dist/cjs/lib/merged-options.js.map +1 -0
  85. package/dist/cjs/lib/on-page-leave.js +35 -0
  86. package/dist/cjs/lib/on-page-leave.js.map +1 -0
  87. package/dist/cjs/lib/p-while.js +25 -0
  88. package/dist/cjs/lib/p-while.js.map +1 -0
  89. package/dist/cjs/lib/parse-cdn.js +79 -0
  90. package/dist/cjs/lib/parse-cdn.js.map +1 -0
  91. package/dist/cjs/lib/priority-queue/backoff.js +10 -0
  92. package/dist/cjs/lib/priority-queue/backoff.js.map +1 -0
  93. package/dist/cjs/lib/priority-queue/index.js +7 -0
  94. package/dist/cjs/lib/priority-queue/index.js.map +1 -0
  95. package/dist/cjs/lib/priority-queue/persisted.js +108 -0
  96. package/dist/cjs/lib/priority-queue/persisted.js.map +1 -0
  97. package/dist/cjs/lib/sleep.js +10 -0
  98. package/dist/cjs/lib/sleep.js.map +1 -0
  99. package/dist/cjs/lib/to-facade.js +32 -0
  100. package/dist/cjs/lib/to-facade.js.map +1 -0
  101. package/dist/cjs/node/index.js +43 -0
  102. package/dist/cjs/node/index.js.map +1 -0
  103. package/dist/cjs/node/node.browser.js +13 -0
  104. package/dist/cjs/node/node.browser.js.map +1 -0
  105. package/dist/cjs/plugins/ajs-destination/index.js +345 -0
  106. package/dist/cjs/plugins/ajs-destination/index.js.map +1 -0
  107. package/dist/cjs/plugins/ajs-destination/loader.js +110 -0
  108. package/dist/cjs/plugins/ajs-destination/loader.js.map +1 -0
  109. package/dist/cjs/plugins/ajs-destination/types.js +3 -0
  110. package/dist/cjs/plugins/ajs-destination/types.js.map +1 -0
  111. package/dist/cjs/plugins/ajs-destination/utils.js +23 -0
  112. package/dist/cjs/plugins/ajs-destination/utils.js.map +1 -0
  113. package/dist/cjs/plugins/analytics-node/index.js +65 -0
  114. package/dist/cjs/plugins/analytics-node/index.js.map +1 -0
  115. package/dist/cjs/plugins/customerio/batched-dispatcher.js +102 -0
  116. package/dist/cjs/plugins/customerio/batched-dispatcher.js.map +1 -0
  117. package/dist/cjs/plugins/customerio/fetch-dispatcher.js +18 -0
  118. package/dist/cjs/plugins/customerio/fetch-dispatcher.js.map +1 -0
  119. package/dist/cjs/plugins/customerio/index.js +97 -0
  120. package/dist/cjs/plugins/customerio/index.js.map +1 -0
  121. package/dist/cjs/plugins/customerio/normalize.js +176 -0
  122. package/dist/cjs/plugins/customerio/normalize.js.map +1 -0
  123. package/dist/cjs/plugins/customerio/schedule-flush.js +76 -0
  124. package/dist/cjs/plugins/customerio/schedule-flush.js.map +1 -0
  125. package/dist/cjs/plugins/legacy-video-plugins/index.js +25 -0
  126. package/dist/cjs/plugins/legacy-video-plugins/index.js.map +1 -0
  127. package/dist/cjs/plugins/middleware/index.js +124 -0
  128. package/dist/cjs/plugins/middleware/index.js.map +1 -0
  129. package/dist/cjs/plugins/page-enrichment/index.js +98 -0
  130. package/dist/cjs/plugins/page-enrichment/index.js.map +1 -0
  131. package/dist/cjs/plugins/remote-loader/index.js +211 -0
  132. package/dist/cjs/plugins/remote-loader/index.js.map +1 -0
  133. package/dist/cjs/plugins/remote-middleware/index.js +70 -0
  134. package/dist/cjs/plugins/remote-middleware/index.js.map +1 -0
  135. package/dist/cjs/plugins/routing-middleware/index.js +26 -0
  136. package/dist/cjs/plugins/routing-middleware/index.js.map +1 -0
  137. package/dist/cjs/plugins/schema-filter/index.js +67 -0
  138. package/dist/cjs/plugins/schema-filter/index.js.map +1 -0
  139. package/dist/cjs/plugins/validation/index.js +70 -0
  140. package/dist/cjs/plugins/validation/index.js.map +1 -0
  141. package/dist/pkg/browser/browser-umd.js +17 -0
  142. package/dist/pkg/browser/browser-umd.js.map +1 -0
  143. package/dist/pkg/browser/index.js +306 -0
  144. package/dist/pkg/browser/index.js.map +1 -0
  145. package/dist/pkg/browser/standalone-analytics.js +56 -0
  146. package/dist/pkg/browser/standalone-analytics.js.map +1 -0
  147. package/dist/pkg/browser/standalone.js +81 -0
  148. package/dist/pkg/browser/standalone.js.map +1 -0
  149. package/dist/pkg/core/analytics/index.js +541 -0
  150. package/dist/pkg/core/analytics/index.js.map +1 -0
  151. package/dist/pkg/core/analytics/interfaces.js +2 -0
  152. package/dist/pkg/core/analytics/interfaces.js.map +1 -0
  153. package/dist/pkg/core/arguments-resolver/index.js +99 -0
  154. package/dist/pkg/core/arguments-resolver/index.js.map +1 -0
  155. package/dist/pkg/core/auto-track.js +103 -0
  156. package/dist/pkg/core/auto-track.js.map +1 -0
  157. package/dist/pkg/core/buffer/index.js +231 -0
  158. package/dist/pkg/core/buffer/index.js.map +1 -0
  159. package/dist/pkg/core/buffer/snippet.js +25 -0
  160. package/dist/pkg/core/buffer/snippet.js.map +1 -0
  161. package/dist/pkg/core/callback/index.js +2 -0
  162. package/dist/pkg/core/callback/index.js.map +1 -0
  163. package/dist/pkg/core/connection/index.js +11 -0
  164. package/dist/pkg/core/connection/index.js.map +1 -0
  165. package/dist/pkg/core/context/index.js +16 -0
  166. package/dist/pkg/core/context/index.js.map +1 -0
  167. package/dist/pkg/core/environment/index.js +7 -0
  168. package/dist/pkg/core/environment/index.js.map +1 -0
  169. package/dist/pkg/core/events/index.js +131 -0
  170. package/dist/pkg/core/events/index.js.map +1 -0
  171. package/dist/pkg/core/events/interfaces.js +2 -0
  172. package/dist/pkg/core/events/interfaces.js.map +1 -0
  173. package/dist/pkg/core/inspector/index.js +10 -0
  174. package/dist/pkg/core/inspector/index.js.map +1 -0
  175. package/dist/pkg/core/plugin/index.js +2 -0
  176. package/dist/pkg/core/plugin/index.js.map +1 -0
  177. package/dist/pkg/core/query-string/gracefulDecodeURIComponent.js +16 -0
  178. package/dist/pkg/core/query-string/gracefulDecodeURIComponent.js.map +1 -0
  179. package/dist/pkg/core/query-string/index.js +44 -0
  180. package/dist/pkg/core/query-string/index.js.map +1 -0
  181. package/dist/pkg/core/query-string/pickPrefix.js +16 -0
  182. package/dist/pkg/core/query-string/pickPrefix.js.map +1 -0
  183. package/dist/pkg/core/queue/event-queue.js +12 -0
  184. package/dist/pkg/core/queue/event-queue.js.map +1 -0
  185. package/dist/pkg/core/stats/index.js +20 -0
  186. package/dist/pkg/core/stats/index.js.map +1 -0
  187. package/dist/pkg/core/stats/remote-metrics.js +104 -0
  188. package/dist/pkg/core/stats/remote-metrics.js.map +1 -0
  189. package/dist/pkg/core/user/index.js +418 -0
  190. package/dist/pkg/core/user/index.js.map +1 -0
  191. package/dist/pkg/core/user/tld.js +59 -0
  192. package/dist/pkg/core/user/tld.js.map +1 -0
  193. package/dist/pkg/generated/version.js +3 -0
  194. package/dist/pkg/generated/version.js.map +1 -0
  195. package/dist/pkg/index.js +8 -0
  196. package/dist/pkg/index.js.map +1 -0
  197. package/dist/pkg/lib/bind-all.js +14 -0
  198. package/dist/pkg/lib/bind-all.js.map +1 -0
  199. package/dist/pkg/lib/browser-polyfill.js +18 -0
  200. package/dist/pkg/lib/browser-polyfill.js.map +1 -0
  201. package/dist/pkg/lib/create-deferred.js +17 -0
  202. package/dist/pkg/lib/create-deferred.js.map +1 -0
  203. package/dist/pkg/lib/csp-detection.js +29 -0
  204. package/dist/pkg/lib/csp-detection.js.map +1 -0
  205. package/dist/pkg/lib/embedded-write-key.js +18 -0
  206. package/dist/pkg/lib/embedded-write-key.js.map +1 -0
  207. package/dist/pkg/lib/fetch.js +14 -0
  208. package/dist/pkg/lib/fetch.js.map +1 -0
  209. package/dist/pkg/lib/get-global.js +17 -0
  210. package/dist/pkg/lib/get-global.js.map +1 -0
  211. package/dist/pkg/lib/get-process-env.js +11 -0
  212. package/dist/pkg/lib/get-process-env.js.map +1 -0
  213. package/dist/pkg/lib/group-by.js +24 -0
  214. package/dist/pkg/lib/group-by.js.map +1 -0
  215. package/dist/pkg/lib/is-plan-event-enabled.js +16 -0
  216. package/dist/pkg/lib/is-plan-event-enabled.js.map +1 -0
  217. package/dist/pkg/lib/is-thenable.js +11 -0
  218. package/dist/pkg/lib/is-thenable.js.map +1 -0
  219. package/dist/pkg/lib/load-script.js +51 -0
  220. package/dist/pkg/lib/load-script.js.map +1 -0
  221. package/dist/pkg/lib/merged-options.js +27 -0
  222. package/dist/pkg/lib/merged-options.js.map +1 -0
  223. package/dist/pkg/lib/on-page-leave.js +31 -0
  224. package/dist/pkg/lib/on-page-leave.js.map +1 -0
  225. package/dist/pkg/lib/p-while.js +21 -0
  226. package/dist/pkg/lib/p-while.js.map +1 -0
  227. package/dist/pkg/lib/parse-cdn.js +72 -0
  228. package/dist/pkg/lib/parse-cdn.js.map +1 -0
  229. package/dist/pkg/lib/priority-queue/backoff.js +6 -0
  230. package/dist/pkg/lib/priority-queue/backoff.js.map +1 -0
  231. package/dist/pkg/lib/priority-queue/index.js +3 -0
  232. package/dist/pkg/lib/priority-queue/index.js.map +1 -0
  233. package/dist/pkg/lib/priority-queue/persisted.js +105 -0
  234. package/dist/pkg/lib/priority-queue/persisted.js.map +1 -0
  235. package/dist/pkg/lib/sleep.js +6 -0
  236. package/dist/pkg/lib/sleep.js.map +1 -0
  237. package/dist/pkg/lib/to-facade.js +28 -0
  238. package/dist/pkg/lib/to-facade.js.map +1 -0
  239. package/dist/pkg/node/index.js +40 -0
  240. package/dist/pkg/node/index.js.map +1 -0
  241. package/dist/pkg/node/node.browser.js +10 -0
  242. package/dist/pkg/node/node.browser.js.map +1 -0
  243. package/dist/pkg/plugins/ajs-destination/index.js +341 -0
  244. package/dist/pkg/plugins/ajs-destination/index.js.map +1 -0
  245. package/dist/pkg/plugins/ajs-destination/loader.js +102 -0
  246. package/dist/pkg/plugins/ajs-destination/loader.js.map +1 -0
  247. package/dist/pkg/plugins/ajs-destination/types.js +2 -0
  248. package/dist/pkg/plugins/ajs-destination/types.js.map +1 -0
  249. package/dist/pkg/plugins/ajs-destination/utils.js +18 -0
  250. package/dist/pkg/plugins/ajs-destination/utils.js.map +1 -0
  251. package/dist/pkg/plugins/analytics-node/index.js +60 -0
  252. package/dist/pkg/plugins/analytics-node/index.js.map +1 -0
  253. package/dist/pkg/plugins/customerio/batched-dispatcher.js +99 -0
  254. package/dist/pkg/plugins/customerio/batched-dispatcher.js.map +1 -0
  255. package/dist/pkg/plugins/customerio/fetch-dispatcher.js +15 -0
  256. package/dist/pkg/plugins/customerio/fetch-dispatcher.js.map +1 -0
  257. package/dist/pkg/plugins/customerio/index.js +93 -0
  258. package/dist/pkg/plugins/customerio/index.js.map +1 -0
  259. package/dist/pkg/plugins/customerio/normalize.js +168 -0
  260. package/dist/pkg/plugins/customerio/normalize.js.map +1 -0
  261. package/dist/pkg/plugins/customerio/schedule-flush.js +72 -0
  262. package/dist/pkg/plugins/customerio/schedule-flush.js.map +1 -0
  263. package/dist/pkg/plugins/legacy-video-plugins/index.js +25 -0
  264. package/dist/pkg/plugins/legacy-video-plugins/index.js.map +1 -0
  265. package/dist/pkg/plugins/middleware/index.js +119 -0
  266. package/dist/pkg/plugins/middleware/index.js.map +1 -0
  267. package/dist/pkg/plugins/page-enrichment/index.js +93 -0
  268. package/dist/pkg/plugins/page-enrichment/index.js.map +1 -0
  269. package/dist/pkg/plugins/remote-loader/index.js +207 -0
  270. package/dist/pkg/plugins/remote-loader/index.js.map +1 -0
  271. package/dist/pkg/plugins/remote-middleware/index.js +66 -0
  272. package/dist/pkg/plugins/remote-middleware/index.js.map +1 -0
  273. package/dist/pkg/plugins/routing-middleware/index.js +21 -0
  274. package/dist/pkg/plugins/routing-middleware/index.js.map +1 -0
  275. package/dist/pkg/plugins/schema-filter/index.js +63 -0
  276. package/dist/pkg/plugins/schema-filter/index.js.map +1 -0
  277. package/dist/pkg/plugins/validation/index.js +63 -0
  278. package/dist/pkg/plugins/validation/index.js.map +1 -0
  279. package/dist/types/browser/browser-umd.d.ts +2 -0
  280. package/dist/types/browser/browser-umd.d.ts.map +1 -0
  281. package/dist/types/browser/index.d.ts +86 -0
  282. package/dist/types/browser/index.d.ts.map +1 -0
  283. package/dist/types/browser/standalone-analytics.d.ts +16 -0
  284. package/dist/types/browser/standalone-analytics.d.ts.map +1 -0
  285. package/dist/types/browser/standalone.d.ts +2 -0
  286. package/dist/types/browser/standalone.d.ts.map +1 -0
  287. package/dist/types/core/analytics/index.d.ts +116 -0
  288. package/dist/types/core/analytics/index.d.ts.map +1 -0
  289. package/dist/types/core/analytics/interfaces.d.ts +77 -0
  290. package/dist/types/core/analytics/interfaces.d.ts.map +1 -0
  291. package/dist/types/core/arguments-resolver/index.d.ts +34 -0
  292. package/dist/types/core/arguments-resolver/index.d.ts.map +1 -0
  293. package/dist/types/core/auto-track.d.ts +10 -0
  294. package/dist/types/core/auto-track.d.ts.map +1 -0
  295. package/dist/types/core/buffer/index.d.ts +86 -0
  296. package/dist/types/core/buffer/index.d.ts.map +1 -0
  297. package/dist/types/core/buffer/snippet.d.ts +10 -0
  298. package/dist/types/core/buffer/snippet.d.ts.map +1 -0
  299. package/dist/types/core/callback/index.d.ts +2 -0
  300. package/dist/types/core/callback/index.d.ts.map +1 -0
  301. package/dist/types/core/connection/index.d.ts +3 -0
  302. package/dist/types/core/connection/index.d.ts.map +1 -0
  303. package/dist/types/core/context/index.d.ts +9 -0
  304. package/dist/types/core/context/index.d.ts.map +1 -0
  305. package/dist/types/core/environment/index.d.ts +3 -0
  306. package/dist/types/core/environment/index.d.ts.map +1 -0
  307. package/dist/types/core/events/index.d.ts +21 -0
  308. package/dist/types/core/events/index.d.ts.map +1 -0
  309. package/dist/types/core/events/interfaces.d.ts +9 -0
  310. package/dist/types/core/events/interfaces.d.ts.map +1 -0
  311. package/dist/types/core/inspector/index.d.ts +3 -0
  312. package/dist/types/core/inspector/index.d.ts.map +1 -0
  313. package/dist/types/core/plugin/index.d.ts +11 -0
  314. package/dist/types/core/plugin/index.d.ts.map +1 -0
  315. package/dist/types/core/query-string/gracefulDecodeURIComponent.d.ts +9 -0
  316. package/dist/types/core/query-string/gracefulDecodeURIComponent.d.ts.map +1 -0
  317. package/dist/types/core/query-string/index.d.ts +7 -0
  318. package/dist/types/core/query-string/index.d.ts.map +1 -0
  319. package/dist/types/core/query-string/pickPrefix.d.ts +9 -0
  320. package/dist/types/core/query-string/pickPrefix.d.ts.map +1 -0
  321. package/dist/types/core/queue/event-queue.d.ts +8 -0
  322. package/dist/types/core/queue/event-queue.d.ts.map +1 -0
  323. package/dist/types/core/stats/index.d.ts +7 -0
  324. package/dist/types/core/stats/index.d.ts.map +1 -0
  325. package/dist/types/core/stats/remote-metrics.d.ts +29 -0
  326. package/dist/types/core/stats/remote-metrics.d.ts.map +1 -0
  327. package/dist/types/core/user/index.d.ts +128 -0
  328. package/dist/types/core/user/index.d.ts.map +1 -0
  329. package/dist/types/core/user/tld.d.ts +2 -0
  330. package/dist/types/core/user/tld.d.ts.map +1 -0
  331. package/dist/types/generated/version.d.ts +2 -0
  332. package/dist/types/generated/version.d.ts.map +1 -0
  333. package/dist/types/index.d.ts +9 -0
  334. package/dist/types/index.d.ts.map +1 -0
  335. package/dist/types/lib/bind-all.d.ts +4 -0
  336. package/dist/types/lib/bind-all.d.ts.map +1 -0
  337. package/dist/types/lib/browser-polyfill.d.ts +2 -0
  338. package/dist/types/lib/browser-polyfill.d.ts.map +1 -0
  339. package/dist/types/lib/create-deferred.d.ts +9 -0
  340. package/dist/types/lib/create-deferred.d.ts.map +1 -0
  341. package/dist/types/lib/csp-detection.d.ts +4 -0
  342. package/dist/types/lib/csp-detection.d.ts.map +1 -0
  343. package/dist/types/lib/embedded-write-key.d.ts +7 -0
  344. package/dist/types/lib/embedded-write-key.d.ts.map +1 -0
  345. package/dist/types/lib/fetch.d.ts +5 -0
  346. package/dist/types/lib/fetch.d.ts.map +1 -0
  347. package/dist/types/lib/get-global.d.ts +2 -0
  348. package/dist/types/lib/get-global.d.ts.map +1 -0
  349. package/dist/types/lib/get-process-env.d.ts +8 -0
  350. package/dist/types/lib/get-process-env.d.ts.map +1 -0
  351. package/dist/types/lib/group-by.d.ts +4 -0
  352. package/dist/types/lib/group-by.d.ts.map +1 -0
  353. package/dist/types/lib/is-plan-event-enabled.d.ts +9 -0
  354. package/dist/types/lib/is-plan-event-enabled.d.ts.map +1 -0
  355. package/dist/types/lib/is-thenable.d.ts +6 -0
  356. package/dist/types/lib/is-thenable.d.ts.map +1 -0
  357. package/dist/types/lib/load-script.d.ts +3 -0
  358. package/dist/types/lib/load-script.d.ts.map +1 -0
  359. package/dist/types/lib/merged-options.d.ts +13 -0
  360. package/dist/types/lib/merged-options.d.ts.map +1 -0
  361. package/dist/types/lib/on-page-leave.d.ts +11 -0
  362. package/dist/types/lib/on-page-leave.d.ts.map +1 -0
  363. package/dist/types/lib/p-while.d.ts +2 -0
  364. package/dist/types/lib/p-while.d.ts.map +1 -0
  365. package/dist/types/lib/parse-cdn.d.ts +10 -0
  366. package/dist/types/lib/parse-cdn.d.ts.map +1 -0
  367. package/dist/types/lib/priority-queue/backoff.d.ts +13 -0
  368. package/dist/types/lib/priority-queue/backoff.d.ts.map +1 -0
  369. package/dist/types/lib/priority-queue/index.d.ts +3 -0
  370. package/dist/types/lib/priority-queue/index.d.ts.map +1 -0
  371. package/dist/types/lib/priority-queue/persisted.d.ts +6 -0
  372. package/dist/types/lib/priority-queue/persisted.d.ts.map +1 -0
  373. package/dist/types/lib/sleep.d.ts +2 -0
  374. package/dist/types/lib/sleep.d.ts.map +1 -0
  375. package/dist/types/lib/to-facade.d.ts +7 -0
  376. package/dist/types/lib/to-facade.d.ts.map +1 -0
  377. package/dist/types/node/index.d.ts +8 -0
  378. package/dist/types/node/index.d.ts.map +1 -0
  379. package/dist/types/node/node.browser.d.ts +4 -0
  380. package/dist/types/node/node.browser.d.ts.map +1 -0
  381. package/dist/types/plugins/ajs-destination/index.d.ts +42 -0
  382. package/dist/types/plugins/ajs-destination/index.d.ts.map +1 -0
  383. package/dist/types/plugins/ajs-destination/loader.d.ts +12 -0
  384. package/dist/types/plugins/ajs-destination/loader.d.ts.map +1 -0
  385. package/dist/types/plugins/ajs-destination/types.d.ts +36 -0
  386. package/dist/types/plugins/ajs-destination/types.d.ts.map +1 -0
  387. package/dist/types/plugins/ajs-destination/utils.d.ts +5 -0
  388. package/dist/types/plugins/ajs-destination/utils.d.ts.map +1 -0
  389. package/dist/types/plugins/analytics-node/index.d.ts +12 -0
  390. package/dist/types/plugins/analytics-node/index.d.ts.map +1 -0
  391. package/dist/types/plugins/customerio/batched-dispatcher.d.ts +8 -0
  392. package/dist/types/plugins/customerio/batched-dispatcher.d.ts.map +1 -0
  393. package/dist/types/plugins/customerio/fetch-dispatcher.d.ts +8 -0
  394. package/dist/types/plugins/customerio/fetch-dispatcher.d.ts.map +1 -0
  395. package/dist/types/plugins/customerio/index.d.ts +26 -0
  396. package/dist/types/plugins/customerio/index.d.ts.map +1 -0
  397. package/dist/types/plugins/customerio/normalize.d.ts +12 -0
  398. package/dist/types/plugins/customerio/normalize.d.ts.map +1 -0
  399. package/dist/types/plugins/customerio/schedule-flush.d.ts +5 -0
  400. package/dist/types/plugins/customerio/schedule-flush.d.ts.map +1 -0
  401. package/dist/types/plugins/legacy-video-plugins/index.d.ts +3 -0
  402. package/dist/types/plugins/legacy-video-plugins/index.d.ts.map +1 -0
  403. package/dist/types/plugins/middleware/index.d.ts +18 -0
  404. package/dist/types/plugins/middleware/index.d.ts.map +1 -0
  405. package/dist/types/plugins/page-enrichment/index.d.ts +21 -0
  406. package/dist/types/plugins/page-enrichment/index.d.ts.map +1 -0
  407. package/dist/types/plugins/remote-loader/index.d.ts +43 -0
  408. package/dist/types/plugins/remote-loader/index.d.ts.map +1 -0
  409. package/dist/types/plugins/remote-middleware/index.d.ts +5 -0
  410. package/dist/types/plugins/remote-middleware/index.d.ts.map +1 -0
  411. package/dist/types/plugins/routing-middleware/index.d.ts +13 -0
  412. package/dist/types/plugins/routing-middleware/index.d.ts.map +1 -0
  413. package/dist/types/plugins/schema-filter/index.d.ts +5 -0
  414. package/dist/types/plugins/schema-filter/index.d.ts.map +1 -0
  415. package/dist/types/plugins/validation/index.d.ts +7 -0
  416. package/dist/types/plugins/validation/index.d.ts.map +1 -0
  417. package/dist/umd/799.bundle.f804d7b881cf284fbd56.js +1 -0
  418. package/dist/umd/799.bundle.f804d7b881cf284fbd56.js.gz +0 -0
  419. package/dist/umd/870.bundle.e0b7bfa4797bb87217c9.js +1 -0
  420. package/dist/umd/870.bundle.e0b7bfa4797bb87217c9.js.gz +0 -0
  421. package/dist/umd/ajs-destination.bundle.847bf422720e5616c9d5.js +1 -0
  422. package/dist/umd/ajs-destination.bundle.847bf422720e5616c9d5.js.gz +0 -0
  423. package/dist/umd/auto-track.bundle.758629f7a47544af2d44.js +1 -0
  424. package/dist/umd/auto-track.bundle.758629f7a47544af2d44.js.gz +0 -0
  425. package/dist/umd/index.js +1 -0
  426. package/dist/umd/index.js.gz +0 -0
  427. package/dist/umd/legacyVideos.bundle.d7ac356ab28fab36e111.js +1 -0
  428. package/dist/umd/legacyVideos.bundle.d7ac356ab28fab36e111.js.gz +0 -0
  429. package/dist/umd/queryString.bundle.913501e40ce64ef92884.js +1 -0
  430. package/dist/umd/queryString.bundle.913501e40ce64ef92884.js.gz +0 -0
  431. package/dist/umd/remoteMiddleware.bundle.3bc569811c4c2c93d90c.js +1 -0
  432. package/dist/umd/remoteMiddleware.bundle.3bc569811c4c2c93d90c.js.gz +0 -0
  433. package/dist/umd/schemaFilter.bundle.bb8180ae95843c8f138e.js +1 -0
  434. package/dist/umd/schemaFilter.bundle.bb8180ae95843c8f138e.js.gz +0 -0
  435. package/dist/umd/standalone.js +1 -0
  436. package/dist/umd/standalone.js.gz +0 -0
  437. package/dist/umd/tsub-middleware.bundle.af0f402084ddd2b605cc.js +1 -0
  438. package/dist/umd/tsub-middleware.bundle.af0f402084ddd2b605cc.js.gz +0 -0
  439. package/package.json +103 -0
  440. package/src/browser/browser-umd.ts +19 -0
  441. package/src/browser/index.ts +397 -0
  442. package/src/browser/standalone-analytics.ts +74 -0
  443. package/src/browser/standalone.ts +78 -0
  444. package/src/core/analytics/index.ts +567 -0
  445. package/src/core/analytics/interfaces.ts +100 -0
  446. package/src/core/arguments-resolver/index.ts +166 -0
  447. package/src/core/auto-track.ts +152 -0
  448. package/src/core/buffer/index.ts +289 -0
  449. package/src/core/buffer/snippet.ts +43 -0
  450. package/src/core/callback/index.ts +1 -0
  451. package/src/core/connection/index.ts +13 -0
  452. package/src/core/context/index.ts +21 -0
  453. package/src/core/environment/index.ts +7 -0
  454. package/src/core/events/index.ts +254 -0
  455. package/src/core/events/interfaces.ts +36 -0
  456. package/src/core/inspector/index.ts +14 -0
  457. package/src/core/plugin/index.ts +12 -0
  458. package/src/core/query-string/gracefulDecodeURIComponent.ts +16 -0
  459. package/src/core/query-string/index.ts +64 -0
  460. package/src/core/query-string/pickPrefix.ts +20 -0
  461. package/src/core/queue/event-queue.ts +11 -0
  462. package/src/core/stats/index.ts +15 -0
  463. package/src/core/stats/remote-metrics.ts +137 -0
  464. package/src/core/user/index.ts +534 -0
  465. package/src/core/user/tld.ts +65 -0
  466. package/src/generated/version.ts +2 -0
  467. package/src/index.ts +10 -0
  468. package/src/lib/bind-all.ts +19 -0
  469. package/src/lib/browser-polyfill.ts +23 -0
  470. package/src/lib/create-deferred.ts +16 -0
  471. package/src/lib/csp-detection.ts +26 -0
  472. package/src/lib/embedded-write-key.ts +24 -0
  473. package/src/lib/fetch.ts +10 -0
  474. package/src/lib/get-global.ts +16 -0
  475. package/src/lib/get-process-env.ts +11 -0
  476. package/src/lib/group-by.ts +30 -0
  477. package/src/lib/is-plan-event-enabled.ts +20 -0
  478. package/src/lib/is-thenable.ts +9 -0
  479. package/src/lib/load-script.ts +66 -0
  480. package/src/lib/merged-options.ts +46 -0
  481. package/src/lib/on-page-leave.ts +29 -0
  482. package/src/lib/p-while.ts +12 -0
  483. package/src/lib/parse-cdn.ts +85 -0
  484. package/src/lib/priority-queue/backoff.ts +24 -0
  485. package/src/lib/priority-queue/index.ts +6 -0
  486. package/src/lib/priority-queue/persisted.ts +127 -0
  487. package/src/lib/sleep.ts +4 -0
  488. package/src/lib/to-facade.ts +53 -0
  489. package/src/node/index.ts +36 -0
  490. package/src/node/node.browser.ts +7 -0
  491. package/src/plugins/ajs-destination/index.ts +388 -0
  492. package/src/plugins/ajs-destination/loader.ts +127 -0
  493. package/src/plugins/ajs-destination/types.ts +44 -0
  494. package/src/plugins/ajs-destination/utils.ts +34 -0
  495. package/src/plugins/analytics-node/index.ts +64 -0
  496. package/src/plugins/customerio/batched-dispatcher.ts +115 -0
  497. package/src/plugins/customerio/fetch-dispatcher.ts +24 -0
  498. package/src/plugins/customerio/index.ts +142 -0
  499. package/src/plugins/customerio/normalize.ts +223 -0
  500. package/src/plugins/customerio/schedule-flush.ts +58 -0
  501. package/src/plugins/legacy-video-plugins/index.ts +16 -0
  502. package/src/plugins/middleware/index.ts +131 -0
  503. package/src/plugins/page-enrichment/index.ts +127 -0
  504. package/src/plugins/remote-loader/index.ts +240 -0
  505. package/src/plugins/remote-middleware/index.ts +44 -0
  506. package/src/plugins/routing-middleware/index.ts +37 -0
  507. package/src/plugins/schema-filter/index.ts +90 -0
  508. package/src/plugins/validation/index.ts +80 -0
  509. package/src/test-helpers/browser-storage.ts +72 -0
  510. package/src/test-helpers/factories.ts +18 -0
  511. package/src/test-helpers/fetch-parse.ts +8 -0
  512. package/src/test-helpers/fixtures/cdn-settings.ts +299 -0
  513. package/src/test-helpers/fixtures/classic-destination.ts +25 -0
  514. package/src/test-helpers/fixtures/create-fetch-method.ts +24 -0
  515. package/src/test-helpers/test-writekeys.ts +5 -0
  516. package/src/test-helpers/type-assertions.ts +11 -0
@@ -0,0 +1,127 @@
1
+ import type { Context } from '../../core/context'
2
+ import type { Plugin } from '../../core/plugin'
3
+
4
+ interface PageDefault {
5
+ [key: string]: unknown
6
+ path: string
7
+ referrer: string
8
+ search: string
9
+ title: string
10
+ url: string
11
+ }
12
+
13
+ /**
14
+ * Get the current page's canonical URL.
15
+ *
16
+ * @return {string|undefined}
17
+ */
18
+ function canonical(): string {
19
+ const tags = document.getElementsByTagName('link')
20
+ let canon: string | null = ''
21
+
22
+ Array.prototype.slice.call(tags).forEach((tag) => {
23
+ if (tag.getAttribute('rel') === 'canonical') {
24
+ canon = tag.getAttribute('href')
25
+ }
26
+ })
27
+
28
+ return canon
29
+ }
30
+
31
+ /**
32
+ * Return the canonical path for the page.
33
+ */
34
+
35
+ function canonicalPath(): string {
36
+ const canon = canonical()
37
+ if (!canon) {
38
+ return window.location.pathname
39
+ }
40
+
41
+ const a = document.createElement('a')
42
+ a.href = canon
43
+ const pathname = !a.pathname.startsWith('/') ? '/' + a.pathname : a.pathname
44
+
45
+ return pathname
46
+ }
47
+
48
+ /**
49
+ * Return the canonical URL for the page concat the given `search`
50
+ * and strip the hash.
51
+ */
52
+
53
+ export function canonicalUrl(search = ''): string {
54
+ const canon = canonical()
55
+ if (canon) {
56
+ return canon.includes('?') ? canon : `${canon}${search}`
57
+ }
58
+ const url = window.location.href
59
+ const i = url.indexOf('#')
60
+ return i === -1 ? url : url.slice(0, i)
61
+ }
62
+
63
+ /**
64
+ * Return a default `options.context.page` object.
65
+ */
66
+
67
+ export function pageDefaults(): PageDefault {
68
+ return {
69
+ path: canonicalPath(),
70
+ referrer: document.referrer,
71
+ search: location.search,
72
+ title: document.title,
73
+ url: canonicalUrl(location.search),
74
+ }
75
+ }
76
+
77
+ function enrichPageContext(ctx: Context): Context {
78
+ const event = ctx.event
79
+ event.context = event.context || {}
80
+ let pageContext = pageDefaults()
81
+ const pageProps = event.properties ?? {}
82
+
83
+ Object.keys(pageContext).forEach((key) => {
84
+ if (pageProps[key]) {
85
+ pageContext[key] = pageProps[key]
86
+ }
87
+ })
88
+
89
+ if (event.context.page) {
90
+ pageContext = Object.assign({}, pageContext, event.context.page)
91
+ }
92
+
93
+ event.context = Object.assign({}, event.context, {
94
+ page: pageContext,
95
+ })
96
+
97
+ ctx.event = event
98
+
99
+ return ctx
100
+ }
101
+
102
+ export const pageEnrichment: Plugin = {
103
+ name: 'Page Enrichment',
104
+ version: '0.1.0',
105
+ isLoaded: () => true,
106
+ load: () => Promise.resolve(),
107
+ type: 'before',
108
+
109
+ page: (ctx) => {
110
+ ctx.event.properties = Object.assign(
111
+ {},
112
+ pageDefaults(),
113
+ ctx.event.properties
114
+ )
115
+
116
+ if (ctx.event.name) {
117
+ ctx.event.properties.name = ctx.event.name
118
+ }
119
+
120
+ return enrichPageContext(ctx)
121
+ },
122
+
123
+ alias: enrichPageContext,
124
+ track: enrichPageContext,
125
+ identify: enrichPageContext,
126
+ group: enrichPageContext,
127
+ }
@@ -0,0 +1,240 @@
1
+ import type { Integrations } from '../../core/events/interfaces'
2
+ import { LegacySettings } from '../../browser'
3
+ import { JSONObject, JSONValue } from '../../core/events'
4
+ import { DestinationPlugin, Plugin } from '../../core/plugin'
5
+ import { loadScript } from '../../lib/load-script'
6
+ import { getCDN } from '../../lib/parse-cdn'
7
+ import {
8
+ applyDestinationMiddleware,
9
+ DestinationMiddlewareFunction,
10
+ } from '../middleware'
11
+ import { Context, ContextCancelation } from '../../core/context'
12
+ import { Analytics } from '../../core/analytics'
13
+
14
+ export interface RemotePlugin {
15
+ /** The name of the remote plugin */
16
+ name: string
17
+ /** The creation name of the remote plugin */
18
+ creationName: string
19
+ /** The url of the javascript file to load */
20
+ url: string
21
+ /** The UMD/global name the plugin uses. Plugins are expected to exist here with the `PluginFactory` method signature */
22
+ libraryName: string
23
+ /** The settings related to this plugin. */
24
+ settings: JSONObject
25
+ }
26
+
27
+ export class ActionDestination implements DestinationPlugin {
28
+ name: string // destination name
29
+ version = '1.0.0'
30
+ type: Plugin['type']
31
+
32
+ alternativeNames: string[] = []
33
+
34
+ middleware: DestinationMiddlewareFunction[] = []
35
+
36
+ action: Plugin
37
+
38
+ constructor(name: string, action: Plugin) {
39
+ this.action = action
40
+ this.name = name
41
+ this.type = action.type
42
+ this.alternativeNames.push(action.name)
43
+ }
44
+
45
+ addMiddleware(...fn: DestinationMiddlewareFunction[]): void {
46
+ if (this.type === 'destination') {
47
+ this.middleware.push(...fn)
48
+ }
49
+ }
50
+
51
+ private async transform(ctx: Context): Promise<Context> {
52
+ const modifiedEvent = await applyDestinationMiddleware(
53
+ this.name,
54
+ ctx.event,
55
+ this.middleware
56
+ )
57
+
58
+ if (modifiedEvent === null) {
59
+ ctx.cancel(
60
+ new ContextCancelation({
61
+ retry: false,
62
+ reason: 'dropped by destination middleware',
63
+ })
64
+ )
65
+ }
66
+
67
+ return new Context(modifiedEvent!)
68
+ }
69
+
70
+ private _createMethod(
71
+ methodName: 'track' | 'page' | 'identify' | 'alias' | 'group' | 'screen'
72
+ ) {
73
+ return async (ctx: Context): Promise<Context> => {
74
+ if (!this.action[methodName]) return ctx
75
+
76
+ let transformedContext: Context = ctx
77
+ // Transformations only allowed for destination plugins. Other plugin types support mutating events.
78
+ if (this.type === 'destination') {
79
+ transformedContext = await this.transform(ctx)
80
+ }
81
+
82
+ await this.action[methodName]!(transformedContext)
83
+
84
+ return ctx
85
+ }
86
+ }
87
+
88
+ alias = this._createMethod('alias')
89
+ group = this._createMethod('group')
90
+ identify = this._createMethod('identify')
91
+ page = this._createMethod('page')
92
+ screen = this._createMethod('screen')
93
+ track = this._createMethod('track')
94
+
95
+ /* --- PASSTHROUGH METHODS --- */
96
+ isLoaded(): boolean {
97
+ return this.action.isLoaded()
98
+ }
99
+
100
+ ready(): Promise<unknown> {
101
+ return this.action.ready ? this.action.ready() : Promise.resolve()
102
+ }
103
+
104
+ load(ctx: Context, analytics: Analytics): Promise<unknown> {
105
+ return this.action.load(ctx, analytics)
106
+ }
107
+
108
+ unload(ctx: Context, analytics: Analytics): Promise<unknown> | unknown {
109
+ return this.action.unload?.(ctx, analytics)
110
+ }
111
+ }
112
+
113
+ type PluginFactory = (
114
+ settings: JSONValue
115
+ ) => Plugin | Plugin[] | Promise<Plugin | Plugin[]>
116
+
117
+ function validate(pluginLike: unknown): pluginLike is Plugin[] {
118
+ if (!Array.isArray(pluginLike)) {
119
+ throw new Error('Not a valid list of plugins')
120
+ }
121
+
122
+ const required = ['load', 'isLoaded', 'name', 'version', 'type']
123
+ pluginLike.forEach((plugin) => {
124
+ required.forEach((method) => {
125
+ if (plugin[method] === undefined) {
126
+ throw new Error(
127
+ `Plugin: ${plugin.name ?? 'unknown'
128
+ } missing required function ${method}`
129
+ )
130
+ }
131
+ })
132
+ })
133
+
134
+ return true
135
+ }
136
+
137
+ function isPluginDisabled(
138
+ userIntegrations: Integrations,
139
+ remotePlugin: RemotePlugin
140
+ ) {
141
+ const creationNameEnabled = userIntegrations[remotePlugin.creationName]
142
+ const currentNameEnabled = userIntegrations[remotePlugin.name]
143
+
144
+ // Check that the plugin isn't explicitly enabled when All: false
145
+ if (
146
+ userIntegrations.All === false &&
147
+ !creationNameEnabled &&
148
+ !currentNameEnabled
149
+ ) {
150
+ return true
151
+ }
152
+
153
+ // Check that the plugin isn't explicitly disabled
154
+ if (creationNameEnabled === false || currentNameEnabled === false) {
155
+ return true
156
+ }
157
+
158
+ return false
159
+ }
160
+
161
+ export async function remoteLoader(
162
+ settings: LegacySettings,
163
+ userIntegrations: Integrations,
164
+ mergedIntegrations: Record<string, JSONObject>,
165
+ obfuscate?: boolean,
166
+ routingMiddleware?: DestinationMiddlewareFunction
167
+ ): Promise<Plugin[]> {
168
+ const allPlugins: Plugin[] = []
169
+ const cdn = getCDN()
170
+
171
+ const routingRules = settings.middlewareSettings?.routingRules ?? []
172
+
173
+ const pluginPromises = (settings.remotePlugins ?? []).map(
174
+ async (remotePlugin) => {
175
+ if (isPluginDisabled(userIntegrations, remotePlugin)) return
176
+ try {
177
+ const defaultCdn = new RegExp('https://cdp.customer.io')
178
+ if (obfuscate) {
179
+ const urlSplit = remotePlugin.url.split('/')
180
+ const name = urlSplit[urlSplit.length - 2]
181
+ const obfuscatedURL = remotePlugin.url.replace(
182
+ name,
183
+ btoa(name).replace(/=/g, '')
184
+ )
185
+ try {
186
+ await loadScript(obfuscatedURL.replace(defaultCdn, cdn))
187
+ } catch (error) {
188
+ // Due to syncing concerns it is possible that the obfuscated action destination (or requested version) might not exist.
189
+ // We should use the unobfuscated version as a fallback.
190
+ await loadScript(remotePlugin.url.replace(defaultCdn, cdn))
191
+ }
192
+ } else {
193
+ await loadScript(remotePlugin.url.replace(defaultCdn, cdn))
194
+ }
195
+
196
+ const libraryName = remotePlugin.libraryName
197
+
198
+ // @ts-expect-error
199
+ if (typeof window[libraryName] === 'function') {
200
+ // @ts-expect-error
201
+ const pluginFactory = window[libraryName] as PluginFactory
202
+ const plugin = await pluginFactory({
203
+ ...remotePlugin.settings,
204
+ ...mergedIntegrations[remotePlugin.name],
205
+ })
206
+ const plugins = Array.isArray(plugin) ? plugin : [plugin]
207
+
208
+ validate(plugins)
209
+
210
+ const routing = routingRules.filter(
211
+ (rule) => rule.destinationName === remotePlugin.creationName
212
+ )
213
+
214
+ plugins.forEach((plugin) => {
215
+ const wrapper = new ActionDestination(
216
+ remotePlugin.creationName,
217
+ plugin
218
+ )
219
+
220
+ /** Make sure we only apply destination filters to actions of the "destination" type to avoid causing issues for hybrid destinations */
221
+ if (
222
+ routing.length &&
223
+ routingMiddleware &&
224
+ plugin.type === 'destination'
225
+ ) {
226
+ wrapper.addMiddleware(routingMiddleware)
227
+ }
228
+
229
+ allPlugins.push(wrapper)
230
+ })
231
+ }
232
+ } catch (error) {
233
+ console.warn('Failed to load Remote Plugin', error)
234
+ }
235
+ }
236
+ )
237
+
238
+ await Promise.all(pluginPromises)
239
+ return allPlugins.filter(Boolean)
240
+ }
@@ -0,0 +1,44 @@
1
+ import { LegacySettings } from '../../browser'
2
+ import { Context } from '../../core/context'
3
+ import { isServer } from '../../core/environment'
4
+ import { loadScript } from '../../lib/load-script'
5
+ import { getNextIntegrationsURL } from '../../lib/parse-cdn'
6
+ import { MiddlewareFunction } from '../middleware'
7
+
8
+ export async function remoteMiddlewares(
9
+ ctx: Context,
10
+ settings: LegacySettings,
11
+ obfuscate?: boolean
12
+ ): Promise<MiddlewareFunction[]> {
13
+ if (isServer()) {
14
+ return []
15
+ }
16
+ const path = getNextIntegrationsURL()
17
+ const remoteMiddleware = settings.enabledMiddleware ?? {}
18
+ const names = Object.entries(remoteMiddleware)
19
+ .filter(([_, enabled]) => enabled)
20
+ .map(([name]) => name)
21
+
22
+ const scripts = names.map(async (name) => {
23
+ const nonNamespaced = name.replace('@segment/', '')
24
+ let bundleName = nonNamespaced
25
+ if (obfuscate) {
26
+ bundleName = btoa(nonNamespaced).replace(/=/g, '')
27
+ }
28
+ const fullPath = `${path}/middleware/${bundleName}/latest/${bundleName}.js.gz`
29
+
30
+ try {
31
+ await loadScript(fullPath)
32
+ // @ts-ignore
33
+ return window[`${nonNamespaced}Middleware`] as MiddlewareFunction
34
+ } catch (error: any) {
35
+ ctx.log('error', error)
36
+ ctx.stats.increment('failed_remote_middleware')
37
+ }
38
+ })
39
+
40
+ let middleware = await Promise.all(scripts)
41
+ middleware = middleware.filter(Boolean)
42
+
43
+ return middleware as MiddlewareFunction[]
44
+ }
@@ -0,0 +1,37 @@
1
+ import * as tsub from '@segment/tsub'
2
+ import { Matcher, Rule } from '@segment/tsub/dist/store'
3
+ import { DestinationMiddlewareFunction } from '../middleware'
4
+
5
+ // TODO: update tsub definition
6
+ type RoutingRuleMatcher = Matcher & {
7
+ config?: {
8
+ expr: string
9
+ }
10
+ }
11
+
12
+ export type RoutingRule = Rule & {
13
+ matchers: RoutingRuleMatcher[]
14
+ }
15
+
16
+ export const tsubMiddleware =
17
+ (rules: RoutingRule[]): DestinationMiddlewareFunction =>
18
+ ({ payload, integration, next }): void => {
19
+ const store = new tsub.Store(rules)
20
+ const rulesToApply = store.getRulesByDestinationName(integration)
21
+
22
+ rulesToApply.forEach((rule) => {
23
+ const { matchers, transformers } = rule
24
+
25
+ for (let i = 0; i < matchers.length; i++) {
26
+ if (tsub.matches(payload.obj, matchers[i])) {
27
+ payload.obj = tsub.transform(payload.obj, transformers[i])
28
+
29
+ if (payload.obj === null) {
30
+ return next(null)
31
+ }
32
+ }
33
+ }
34
+ })
35
+
36
+ next(payload)
37
+ }
@@ -0,0 +1,90 @@
1
+ import { LegacySettings } from '../../browser'
2
+ import { Context } from '../../core/context'
3
+ import { PlanEvent, TrackPlan } from '../../core/events/interfaces'
4
+ import { Plugin } from '../../core/plugin'
5
+ import { isPlanEventEnabled } from '../../lib/is-plan-event-enabled'
6
+ import { RemotePlugin } from '../remote-loader'
7
+
8
+ function disabledActionDestinations(
9
+ plan: PlanEvent | undefined,
10
+ settings: LegacySettings
11
+ ): { [destination: string]: string[] } {
12
+ if (!plan || !Object.keys(plan)) {
13
+ return {}
14
+ }
15
+
16
+ const disabledIntegrations = plan.integrations
17
+ ? Object.keys(plan.integrations).filter(
18
+ (i) => plan.integrations![i] === false
19
+ )
20
+ : []
21
+
22
+ // This accounts for cases like Fullstory, where the settings.integrations
23
+ // contains a "Fullstory" object but settings.remotePlugins contains "Fullstory (Actions)"
24
+ const disabledRemotePlugins: string[] = []
25
+ ; (settings.remotePlugins ?? []).forEach((p: RemotePlugin) => {
26
+ disabledIntegrations.forEach((int) => {
27
+ if (p.name.includes(int) || int.includes(p.name)) {
28
+ disabledRemotePlugins.push(p.name)
29
+ }
30
+ })
31
+ })
32
+
33
+ return (settings.remotePlugins ?? []).reduce((acc, p) => {
34
+ if (p.settings['subscriptions']) {
35
+ if (disabledRemotePlugins.includes(p.name)) {
36
+ // @ts-expect-error element implicitly has an 'any' type because p.settings is a JSONObject
37
+ p.settings['subscriptions'].forEach(
38
+ // @ts-expect-error parameter 'sub' implicitly has an 'any' type
39
+ (sub) => (acc[`${p.name} ${sub.partnerAction}`] = false)
40
+ )
41
+ }
42
+ }
43
+ return acc
44
+ }, {})
45
+ }
46
+
47
+ export function schemaFilter(
48
+ track: TrackPlan | undefined,
49
+ settings: LegacySettings
50
+ ): Plugin {
51
+ function filter(ctx: Context): Context {
52
+ const plan = track
53
+ const ev = ctx.event.event
54
+
55
+ if (plan && ev) {
56
+ const planEvent = plan[ev]
57
+ if (!isPlanEventEnabled(plan, planEvent)) {
58
+ ctx.updateEvent('integrations', {
59
+ ...ctx.event.integrations,
60
+ All: false,
61
+ 'Customer.io Data Pipelines': true,
62
+ })
63
+ return ctx
64
+ } else {
65
+ const disabledActions = disabledActionDestinations(planEvent, settings)
66
+
67
+ ctx.updateEvent('integrations', {
68
+ ...ctx.event.integrations,
69
+ ...planEvent?.integrations,
70
+ ...disabledActions,
71
+ })
72
+ }
73
+ }
74
+
75
+ return ctx
76
+ }
77
+
78
+ return {
79
+ name: 'Schema Filter',
80
+ version: '0.1.0',
81
+ isLoaded: () => true,
82
+ load: () => Promise.resolve(),
83
+ type: 'before',
84
+ page: filter,
85
+ alias: filter,
86
+ track: filter,
87
+ identify: filter,
88
+ group: filter,
89
+ }
90
+ }
@@ -0,0 +1,80 @@
1
+ import type { Plugin } from '../../core/plugin'
2
+ import type { CustomerioEvent } from '../../core/events'
3
+ import type { Context } from '../../core/context'
4
+
5
+ export function isString(obj: unknown): obj is string {
6
+ return typeof obj === 'string'
7
+ }
8
+
9
+ export function isNumber(obj: unknown): obj is number {
10
+ return typeof obj === 'number'
11
+ }
12
+
13
+ export function isFunction(obj: unknown): obj is Function {
14
+ return typeof obj === 'function'
15
+ }
16
+
17
+ export function isPlainObject(obj: unknown): obj is Record<string, any> {
18
+ return (
19
+ Object.prototype.toString.call(obj).slice(8, -1).toLowerCase() === 'object'
20
+ )
21
+ }
22
+
23
+ function hasUser(event: CustomerioEvent): boolean {
24
+ const id =
25
+ event.userId ?? event.anonymousId ?? event.groupId ?? event.previousId
26
+ return isString(id)
27
+ }
28
+
29
+ class ValidationError extends Error {
30
+ field: string
31
+
32
+ constructor(field: string, message: string) {
33
+ super(message)
34
+ this.field = field
35
+ }
36
+ }
37
+
38
+ function validate(ctx: Context): Context {
39
+ const eventType: unknown = ctx && ctx.event && ctx.event.type
40
+ const event = ctx.event
41
+
42
+ if (event === undefined) {
43
+ throw new ValidationError('event', 'Event is missing')
44
+ }
45
+
46
+ if (!isString(eventType)) {
47
+ throw new ValidationError('event', 'Event is not a string')
48
+ }
49
+
50
+ if (eventType === 'track' && !isString(event.event)) {
51
+ throw new ValidationError('event', 'Event is not a string')
52
+ }
53
+
54
+ const props = event.properties ?? event.traits
55
+ if (eventType !== 'alias' && !isPlainObject(props)) {
56
+ throw new ValidationError('properties', 'properties is not an object')
57
+ }
58
+
59
+ if (!hasUser(event)) {
60
+ throw new ValidationError('userId', 'Missing userId or anonymousId')
61
+ }
62
+
63
+ return ctx
64
+ }
65
+
66
+ export const validation: Plugin = {
67
+ name: 'Event Validation',
68
+ type: 'before',
69
+ version: '1.0.0',
70
+
71
+ isLoaded: () => true,
72
+ load: () => Promise.resolve(),
73
+
74
+ track: validate,
75
+ identify: validate,
76
+ page: validate,
77
+ alias: validate,
78
+ group: validate,
79
+ screen: validate,
80
+ }
@@ -0,0 +1,72 @@
1
+ import cookie from 'js-cookie'
2
+
3
+ const ajsCookieNames = [
4
+ 'ajs_user_id',
5
+ 'ajs_anonymous_id',
6
+ 'ajs_group_id',
7
+ ] as const
8
+ const ajsLocalStorageKeys = ['ajs_user_traits', 'ajs_group_properties'] as const
9
+
10
+ export const getAjsBrowserStorage = () => {
11
+ return getBrowserStorage({
12
+ cookieNames: ajsCookieNames,
13
+ localStorageKeys: ajsLocalStorageKeys,
14
+ })
15
+ }
16
+
17
+ export const getAnonId = () => getAjsBrowserStorage().ajs_anonymous_id
18
+
19
+ export const clearAjsBrowserStorage = () => {
20
+ return clearBrowserStorage({
21
+ cookieNames: ajsCookieNames,
22
+ localStorageKeys: ajsLocalStorageKeys,
23
+ })
24
+ }
25
+
26
+ export function getBrowserStorage<
27
+ CookieNames extends string,
28
+ LSKeys extends string
29
+ >({
30
+ cookieNames,
31
+ localStorageKeys,
32
+ }: {
33
+ cookieNames: readonly CookieNames[]
34
+ localStorageKeys: readonly LSKeys[]
35
+ }): Record<CookieNames | LSKeys, string | {}> {
36
+ const result = {} as ReturnType<typeof getBrowserStorage>
37
+
38
+ const cookies = cookie.get()
39
+ cookieNames.forEach((name) => {
40
+ if (name in cookies) {
41
+ result[name] = cookies[name]
42
+ }
43
+ })
44
+
45
+ localStorageKeys.forEach((key) => {
46
+ const value = localStorage.getItem(key)
47
+ if (value !== null && typeof value !== 'undefined') {
48
+ result[key] = JSON.parse(value)
49
+ }
50
+ })
51
+
52
+ return result
53
+ }
54
+
55
+ export function clearBrowserStorage({
56
+ cookieNames,
57
+ localStorageKeys, // if no keys are passed, the entire thing is cleared
58
+ }: {
59
+ cookieNames: string[] | readonly string[]
60
+ localStorageKeys?: string[] | readonly string[]
61
+ }) {
62
+ cookieNames.forEach((name) => {
63
+ cookie.remove(name)
64
+ })
65
+ if (!localStorageKeys) {
66
+ localStorage.clear()
67
+ } else {
68
+ localStorageKeys.forEach((key) => {
69
+ localStorage.removeItem(key)
70
+ })
71
+ }
72
+ }
@@ -0,0 +1,18 @@
1
+ export const createSuccess = (body: any, overrides: Partial<Response> = {}) => {
2
+ return Promise.resolve({
3
+ json: () => Promise.resolve(body),
4
+ ok: true,
5
+ status: 200,
6
+ statusText: 'OK',
7
+ ...overrides,
8
+ }) as Promise<Response>
9
+ }
10
+
11
+ export const createError = (overrides: Partial<Response> = {}) => {
12
+ return Promise.resolve({
13
+ ok: false,
14
+ status: 404,
15
+ statusText: 'Not Found',
16
+ ...overrides,
17
+ }) as Promise<Response>
18
+ }