@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.
- package/LICENSE.MD +22 -0
- package/README.md +21 -0
- package/dist/cjs/browser/browser-umd.js +20 -0
- package/dist/cjs/browser/browser-umd.js.map +1 -0
- package/dist/cjs/browser/index.js +310 -0
- package/dist/cjs/browser/index.js.map +1 -0
- package/dist/cjs/browser/standalone-analytics.js +60 -0
- package/dist/cjs/browser/standalone-analytics.js.map +1 -0
- package/dist/cjs/browser/standalone.js +83 -0
- package/dist/cjs/browser/standalone.js.map +1 -0
- package/dist/cjs/core/analytics/index.js +544 -0
- package/dist/cjs/core/analytics/index.js.map +1 -0
- package/dist/cjs/core/analytics/interfaces.js +3 -0
- package/dist/cjs/core/analytics/interfaces.js.map +1 -0
- package/dist/cjs/core/arguments-resolver/index.js +106 -0
- package/dist/cjs/core/arguments-resolver/index.js.map +1 -0
- package/dist/cjs/core/auto-track.js +108 -0
- package/dist/cjs/core/auto-track.js.map +1 -0
- package/dist/cjs/core/buffer/index.js +237 -0
- package/dist/cjs/core/buffer/index.js.map +1 -0
- package/dist/cjs/core/buffer/snippet.js +30 -0
- package/dist/cjs/core/buffer/snippet.js.map +1 -0
- package/dist/cjs/core/callback/index.js +7 -0
- package/dist/cjs/core/callback/index.js.map +1 -0
- package/dist/cjs/core/connection/index.js +16 -0
- package/dist/cjs/core/connection/index.js.map +1 -0
- package/dist/cjs/core/context/index.js +19 -0
- package/dist/cjs/core/context/index.js.map +1 -0
- package/dist/cjs/core/environment/index.js +12 -0
- package/dist/cjs/core/environment/index.js.map +1 -0
- package/dist/cjs/core/events/index.js +134 -0
- package/dist/cjs/core/events/index.js.map +1 -0
- package/dist/cjs/core/events/interfaces.js +3 -0
- package/dist/cjs/core/events/interfaces.js.map +1 -0
- package/dist/cjs/core/inspector/index.js +14 -0
- package/dist/cjs/core/inspector/index.js.map +1 -0
- package/dist/cjs/core/plugin/index.js +3 -0
- package/dist/cjs/core/plugin/index.js.map +1 -0
- package/dist/cjs/core/query-string/gracefulDecodeURIComponent.js +20 -0
- package/dist/cjs/core/query-string/gracefulDecodeURIComponent.js.map +1 -0
- package/dist/cjs/core/query-string/index.js +48 -0
- package/dist/cjs/core/query-string/index.js.map +1 -0
- package/dist/cjs/core/query-string/pickPrefix.js +20 -0
- package/dist/cjs/core/query-string/pickPrefix.js.map +1 -0
- package/dist/cjs/core/queue/event-queue.js +15 -0
- package/dist/cjs/core/queue/event-queue.js.map +1 -0
- package/dist/cjs/core/stats/index.js +23 -0
- package/dist/cjs/core/stats/index.js.map +1 -0
- package/dist/cjs/core/stats/remote-metrics.js +107 -0
- package/dist/cjs/core/stats/remote-metrics.js.map +1 -0
- package/dist/cjs/core/user/index.js +422 -0
- package/dist/cjs/core/user/index.js.map +1 -0
- package/dist/cjs/core/user/tld.js +64 -0
- package/dist/cjs/core/user/tld.js.map +1 -0
- package/dist/cjs/generated/version.js +6 -0
- package/dist/cjs/generated/version.js.map +1 -0
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lib/bind-all.js +17 -0
- package/dist/cjs/lib/bind-all.js.map +1 -0
- package/dist/cjs/lib/browser-polyfill.js +22 -0
- package/dist/cjs/lib/browser-polyfill.js.map +1 -0
- package/dist/cjs/lib/create-deferred.js +21 -0
- package/dist/cjs/lib/create-deferred.js.map +1 -0
- package/dist/cjs/lib/csp-detection.js +33 -0
- package/dist/cjs/lib/csp-detection.js.map +1 -0
- package/dist/cjs/lib/embedded-write-key.js +22 -0
- package/dist/cjs/lib/embedded-write-key.js.map +1 -0
- package/dist/cjs/lib/fetch.js +19 -0
- package/dist/cjs/lib/fetch.js.map +1 -0
- package/dist/cjs/lib/get-global.js +21 -0
- package/dist/cjs/lib/get-global.js.map +1 -0
- package/dist/cjs/lib/get-process-env.js +15 -0
- package/dist/cjs/lib/get-process-env.js.map +1 -0
- package/dist/cjs/lib/group-by.js +28 -0
- package/dist/cjs/lib/group-by.js.map +1 -0
- package/dist/cjs/lib/is-plan-event-enabled.js +20 -0
- package/dist/cjs/lib/is-plan-event-enabled.js.map +1 -0
- package/dist/cjs/lib/is-thenable.js +15 -0
- package/dist/cjs/lib/is-thenable.js.map +1 -0
- package/dist/cjs/lib/load-script.js +56 -0
- package/dist/cjs/lib/load-script.js.map +1 -0
- package/dist/cjs/lib/merged-options.js +31 -0
- package/dist/cjs/lib/merged-options.js.map +1 -0
- package/dist/cjs/lib/on-page-leave.js +35 -0
- package/dist/cjs/lib/on-page-leave.js.map +1 -0
- package/dist/cjs/lib/p-while.js +25 -0
- package/dist/cjs/lib/p-while.js.map +1 -0
- package/dist/cjs/lib/parse-cdn.js +79 -0
- package/dist/cjs/lib/parse-cdn.js.map +1 -0
- package/dist/cjs/lib/priority-queue/backoff.js +10 -0
- package/dist/cjs/lib/priority-queue/backoff.js.map +1 -0
- package/dist/cjs/lib/priority-queue/index.js +7 -0
- package/dist/cjs/lib/priority-queue/index.js.map +1 -0
- package/dist/cjs/lib/priority-queue/persisted.js +108 -0
- package/dist/cjs/lib/priority-queue/persisted.js.map +1 -0
- package/dist/cjs/lib/sleep.js +10 -0
- package/dist/cjs/lib/sleep.js.map +1 -0
- package/dist/cjs/lib/to-facade.js +32 -0
- package/dist/cjs/lib/to-facade.js.map +1 -0
- package/dist/cjs/node/index.js +43 -0
- package/dist/cjs/node/index.js.map +1 -0
- package/dist/cjs/node/node.browser.js +13 -0
- package/dist/cjs/node/node.browser.js.map +1 -0
- package/dist/cjs/plugins/ajs-destination/index.js +345 -0
- package/dist/cjs/plugins/ajs-destination/index.js.map +1 -0
- package/dist/cjs/plugins/ajs-destination/loader.js +110 -0
- package/dist/cjs/plugins/ajs-destination/loader.js.map +1 -0
- package/dist/cjs/plugins/ajs-destination/types.js +3 -0
- package/dist/cjs/plugins/ajs-destination/types.js.map +1 -0
- package/dist/cjs/plugins/ajs-destination/utils.js +23 -0
- package/dist/cjs/plugins/ajs-destination/utils.js.map +1 -0
- package/dist/cjs/plugins/analytics-node/index.js +65 -0
- package/dist/cjs/plugins/analytics-node/index.js.map +1 -0
- package/dist/cjs/plugins/customerio/batched-dispatcher.js +102 -0
- package/dist/cjs/plugins/customerio/batched-dispatcher.js.map +1 -0
- package/dist/cjs/plugins/customerio/fetch-dispatcher.js +18 -0
- package/dist/cjs/plugins/customerio/fetch-dispatcher.js.map +1 -0
- package/dist/cjs/plugins/customerio/index.js +97 -0
- package/dist/cjs/plugins/customerio/index.js.map +1 -0
- package/dist/cjs/plugins/customerio/normalize.js +176 -0
- package/dist/cjs/plugins/customerio/normalize.js.map +1 -0
- package/dist/cjs/plugins/customerio/schedule-flush.js +76 -0
- package/dist/cjs/plugins/customerio/schedule-flush.js.map +1 -0
- package/dist/cjs/plugins/legacy-video-plugins/index.js +25 -0
- package/dist/cjs/plugins/legacy-video-plugins/index.js.map +1 -0
- package/dist/cjs/plugins/middleware/index.js +124 -0
- package/dist/cjs/plugins/middleware/index.js.map +1 -0
- package/dist/cjs/plugins/page-enrichment/index.js +98 -0
- package/dist/cjs/plugins/page-enrichment/index.js.map +1 -0
- package/dist/cjs/plugins/remote-loader/index.js +211 -0
- package/dist/cjs/plugins/remote-loader/index.js.map +1 -0
- package/dist/cjs/plugins/remote-middleware/index.js +70 -0
- package/dist/cjs/plugins/remote-middleware/index.js.map +1 -0
- package/dist/cjs/plugins/routing-middleware/index.js +26 -0
- package/dist/cjs/plugins/routing-middleware/index.js.map +1 -0
- package/dist/cjs/plugins/schema-filter/index.js +67 -0
- package/dist/cjs/plugins/schema-filter/index.js.map +1 -0
- package/dist/cjs/plugins/validation/index.js +70 -0
- package/dist/cjs/plugins/validation/index.js.map +1 -0
- package/dist/pkg/browser/browser-umd.js +17 -0
- package/dist/pkg/browser/browser-umd.js.map +1 -0
- package/dist/pkg/browser/index.js +306 -0
- package/dist/pkg/browser/index.js.map +1 -0
- package/dist/pkg/browser/standalone-analytics.js +56 -0
- package/dist/pkg/browser/standalone-analytics.js.map +1 -0
- package/dist/pkg/browser/standalone.js +81 -0
- package/dist/pkg/browser/standalone.js.map +1 -0
- package/dist/pkg/core/analytics/index.js +541 -0
- package/dist/pkg/core/analytics/index.js.map +1 -0
- package/dist/pkg/core/analytics/interfaces.js +2 -0
- package/dist/pkg/core/analytics/interfaces.js.map +1 -0
- package/dist/pkg/core/arguments-resolver/index.js +99 -0
- package/dist/pkg/core/arguments-resolver/index.js.map +1 -0
- package/dist/pkg/core/auto-track.js +103 -0
- package/dist/pkg/core/auto-track.js.map +1 -0
- package/dist/pkg/core/buffer/index.js +231 -0
- package/dist/pkg/core/buffer/index.js.map +1 -0
- package/dist/pkg/core/buffer/snippet.js +25 -0
- package/dist/pkg/core/buffer/snippet.js.map +1 -0
- package/dist/pkg/core/callback/index.js +2 -0
- package/dist/pkg/core/callback/index.js.map +1 -0
- package/dist/pkg/core/connection/index.js +11 -0
- package/dist/pkg/core/connection/index.js.map +1 -0
- package/dist/pkg/core/context/index.js +16 -0
- package/dist/pkg/core/context/index.js.map +1 -0
- package/dist/pkg/core/environment/index.js +7 -0
- package/dist/pkg/core/environment/index.js.map +1 -0
- package/dist/pkg/core/events/index.js +131 -0
- package/dist/pkg/core/events/index.js.map +1 -0
- package/dist/pkg/core/events/interfaces.js +2 -0
- package/dist/pkg/core/events/interfaces.js.map +1 -0
- package/dist/pkg/core/inspector/index.js +10 -0
- package/dist/pkg/core/inspector/index.js.map +1 -0
- package/dist/pkg/core/plugin/index.js +2 -0
- package/dist/pkg/core/plugin/index.js.map +1 -0
- package/dist/pkg/core/query-string/gracefulDecodeURIComponent.js +16 -0
- package/dist/pkg/core/query-string/gracefulDecodeURIComponent.js.map +1 -0
- package/dist/pkg/core/query-string/index.js +44 -0
- package/dist/pkg/core/query-string/index.js.map +1 -0
- package/dist/pkg/core/query-string/pickPrefix.js +16 -0
- package/dist/pkg/core/query-string/pickPrefix.js.map +1 -0
- package/dist/pkg/core/queue/event-queue.js +12 -0
- package/dist/pkg/core/queue/event-queue.js.map +1 -0
- package/dist/pkg/core/stats/index.js +20 -0
- package/dist/pkg/core/stats/index.js.map +1 -0
- package/dist/pkg/core/stats/remote-metrics.js +104 -0
- package/dist/pkg/core/stats/remote-metrics.js.map +1 -0
- package/dist/pkg/core/user/index.js +418 -0
- package/dist/pkg/core/user/index.js.map +1 -0
- package/dist/pkg/core/user/tld.js +59 -0
- package/dist/pkg/core/user/tld.js.map +1 -0
- package/dist/pkg/generated/version.js +3 -0
- package/dist/pkg/generated/version.js.map +1 -0
- package/dist/pkg/index.js +8 -0
- package/dist/pkg/index.js.map +1 -0
- package/dist/pkg/lib/bind-all.js +14 -0
- package/dist/pkg/lib/bind-all.js.map +1 -0
- package/dist/pkg/lib/browser-polyfill.js +18 -0
- package/dist/pkg/lib/browser-polyfill.js.map +1 -0
- package/dist/pkg/lib/create-deferred.js +17 -0
- package/dist/pkg/lib/create-deferred.js.map +1 -0
- package/dist/pkg/lib/csp-detection.js +29 -0
- package/dist/pkg/lib/csp-detection.js.map +1 -0
- package/dist/pkg/lib/embedded-write-key.js +18 -0
- package/dist/pkg/lib/embedded-write-key.js.map +1 -0
- package/dist/pkg/lib/fetch.js +14 -0
- package/dist/pkg/lib/fetch.js.map +1 -0
- package/dist/pkg/lib/get-global.js +17 -0
- package/dist/pkg/lib/get-global.js.map +1 -0
- package/dist/pkg/lib/get-process-env.js +11 -0
- package/dist/pkg/lib/get-process-env.js.map +1 -0
- package/dist/pkg/lib/group-by.js +24 -0
- package/dist/pkg/lib/group-by.js.map +1 -0
- package/dist/pkg/lib/is-plan-event-enabled.js +16 -0
- package/dist/pkg/lib/is-plan-event-enabled.js.map +1 -0
- package/dist/pkg/lib/is-thenable.js +11 -0
- package/dist/pkg/lib/is-thenable.js.map +1 -0
- package/dist/pkg/lib/load-script.js +51 -0
- package/dist/pkg/lib/load-script.js.map +1 -0
- package/dist/pkg/lib/merged-options.js +27 -0
- package/dist/pkg/lib/merged-options.js.map +1 -0
- package/dist/pkg/lib/on-page-leave.js +31 -0
- package/dist/pkg/lib/on-page-leave.js.map +1 -0
- package/dist/pkg/lib/p-while.js +21 -0
- package/dist/pkg/lib/p-while.js.map +1 -0
- package/dist/pkg/lib/parse-cdn.js +72 -0
- package/dist/pkg/lib/parse-cdn.js.map +1 -0
- package/dist/pkg/lib/priority-queue/backoff.js +6 -0
- package/dist/pkg/lib/priority-queue/backoff.js.map +1 -0
- package/dist/pkg/lib/priority-queue/index.js +3 -0
- package/dist/pkg/lib/priority-queue/index.js.map +1 -0
- package/dist/pkg/lib/priority-queue/persisted.js +105 -0
- package/dist/pkg/lib/priority-queue/persisted.js.map +1 -0
- package/dist/pkg/lib/sleep.js +6 -0
- package/dist/pkg/lib/sleep.js.map +1 -0
- package/dist/pkg/lib/to-facade.js +28 -0
- package/dist/pkg/lib/to-facade.js.map +1 -0
- package/dist/pkg/node/index.js +40 -0
- package/dist/pkg/node/index.js.map +1 -0
- package/dist/pkg/node/node.browser.js +10 -0
- package/dist/pkg/node/node.browser.js.map +1 -0
- package/dist/pkg/plugins/ajs-destination/index.js +341 -0
- package/dist/pkg/plugins/ajs-destination/index.js.map +1 -0
- package/dist/pkg/plugins/ajs-destination/loader.js +102 -0
- package/dist/pkg/plugins/ajs-destination/loader.js.map +1 -0
- package/dist/pkg/plugins/ajs-destination/types.js +2 -0
- package/dist/pkg/plugins/ajs-destination/types.js.map +1 -0
- package/dist/pkg/plugins/ajs-destination/utils.js +18 -0
- package/dist/pkg/plugins/ajs-destination/utils.js.map +1 -0
- package/dist/pkg/plugins/analytics-node/index.js +60 -0
- package/dist/pkg/plugins/analytics-node/index.js.map +1 -0
- package/dist/pkg/plugins/customerio/batched-dispatcher.js +99 -0
- package/dist/pkg/plugins/customerio/batched-dispatcher.js.map +1 -0
- package/dist/pkg/plugins/customerio/fetch-dispatcher.js +15 -0
- package/dist/pkg/plugins/customerio/fetch-dispatcher.js.map +1 -0
- package/dist/pkg/plugins/customerio/index.js +93 -0
- package/dist/pkg/plugins/customerio/index.js.map +1 -0
- package/dist/pkg/plugins/customerio/normalize.js +168 -0
- package/dist/pkg/plugins/customerio/normalize.js.map +1 -0
- package/dist/pkg/plugins/customerio/schedule-flush.js +72 -0
- package/dist/pkg/plugins/customerio/schedule-flush.js.map +1 -0
- package/dist/pkg/plugins/legacy-video-plugins/index.js +25 -0
- package/dist/pkg/plugins/legacy-video-plugins/index.js.map +1 -0
- package/dist/pkg/plugins/middleware/index.js +119 -0
- package/dist/pkg/plugins/middleware/index.js.map +1 -0
- package/dist/pkg/plugins/page-enrichment/index.js +93 -0
- package/dist/pkg/plugins/page-enrichment/index.js.map +1 -0
- package/dist/pkg/plugins/remote-loader/index.js +207 -0
- package/dist/pkg/plugins/remote-loader/index.js.map +1 -0
- package/dist/pkg/plugins/remote-middleware/index.js +66 -0
- package/dist/pkg/plugins/remote-middleware/index.js.map +1 -0
- package/dist/pkg/plugins/routing-middleware/index.js +21 -0
- package/dist/pkg/plugins/routing-middleware/index.js.map +1 -0
- package/dist/pkg/plugins/schema-filter/index.js +63 -0
- package/dist/pkg/plugins/schema-filter/index.js.map +1 -0
- package/dist/pkg/plugins/validation/index.js +63 -0
- package/dist/pkg/plugins/validation/index.js.map +1 -0
- package/dist/types/browser/browser-umd.d.ts +2 -0
- package/dist/types/browser/browser-umd.d.ts.map +1 -0
- package/dist/types/browser/index.d.ts +86 -0
- package/dist/types/browser/index.d.ts.map +1 -0
- package/dist/types/browser/standalone-analytics.d.ts +16 -0
- package/dist/types/browser/standalone-analytics.d.ts.map +1 -0
- package/dist/types/browser/standalone.d.ts +2 -0
- package/dist/types/browser/standalone.d.ts.map +1 -0
- package/dist/types/core/analytics/index.d.ts +116 -0
- package/dist/types/core/analytics/index.d.ts.map +1 -0
- package/dist/types/core/analytics/interfaces.d.ts +77 -0
- package/dist/types/core/analytics/interfaces.d.ts.map +1 -0
- package/dist/types/core/arguments-resolver/index.d.ts +34 -0
- package/dist/types/core/arguments-resolver/index.d.ts.map +1 -0
- package/dist/types/core/auto-track.d.ts +10 -0
- package/dist/types/core/auto-track.d.ts.map +1 -0
- package/dist/types/core/buffer/index.d.ts +86 -0
- package/dist/types/core/buffer/index.d.ts.map +1 -0
- package/dist/types/core/buffer/snippet.d.ts +10 -0
- package/dist/types/core/buffer/snippet.d.ts.map +1 -0
- package/dist/types/core/callback/index.d.ts +2 -0
- package/dist/types/core/callback/index.d.ts.map +1 -0
- package/dist/types/core/connection/index.d.ts +3 -0
- package/dist/types/core/connection/index.d.ts.map +1 -0
- package/dist/types/core/context/index.d.ts +9 -0
- package/dist/types/core/context/index.d.ts.map +1 -0
- package/dist/types/core/environment/index.d.ts +3 -0
- package/dist/types/core/environment/index.d.ts.map +1 -0
- package/dist/types/core/events/index.d.ts +21 -0
- package/dist/types/core/events/index.d.ts.map +1 -0
- package/dist/types/core/events/interfaces.d.ts +9 -0
- package/dist/types/core/events/interfaces.d.ts.map +1 -0
- package/dist/types/core/inspector/index.d.ts +3 -0
- package/dist/types/core/inspector/index.d.ts.map +1 -0
- package/dist/types/core/plugin/index.d.ts +11 -0
- package/dist/types/core/plugin/index.d.ts.map +1 -0
- package/dist/types/core/query-string/gracefulDecodeURIComponent.d.ts +9 -0
- package/dist/types/core/query-string/gracefulDecodeURIComponent.d.ts.map +1 -0
- package/dist/types/core/query-string/index.d.ts +7 -0
- package/dist/types/core/query-string/index.d.ts.map +1 -0
- package/dist/types/core/query-string/pickPrefix.d.ts +9 -0
- package/dist/types/core/query-string/pickPrefix.d.ts.map +1 -0
- package/dist/types/core/queue/event-queue.d.ts +8 -0
- package/dist/types/core/queue/event-queue.d.ts.map +1 -0
- package/dist/types/core/stats/index.d.ts +7 -0
- package/dist/types/core/stats/index.d.ts.map +1 -0
- package/dist/types/core/stats/remote-metrics.d.ts +29 -0
- package/dist/types/core/stats/remote-metrics.d.ts.map +1 -0
- package/dist/types/core/user/index.d.ts +128 -0
- package/dist/types/core/user/index.d.ts.map +1 -0
- package/dist/types/core/user/tld.d.ts +2 -0
- package/dist/types/core/user/tld.d.ts.map +1 -0
- package/dist/types/generated/version.d.ts +2 -0
- package/dist/types/generated/version.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/lib/bind-all.d.ts +4 -0
- package/dist/types/lib/bind-all.d.ts.map +1 -0
- package/dist/types/lib/browser-polyfill.d.ts +2 -0
- package/dist/types/lib/browser-polyfill.d.ts.map +1 -0
- package/dist/types/lib/create-deferred.d.ts +9 -0
- package/dist/types/lib/create-deferred.d.ts.map +1 -0
- package/dist/types/lib/csp-detection.d.ts +4 -0
- package/dist/types/lib/csp-detection.d.ts.map +1 -0
- package/dist/types/lib/embedded-write-key.d.ts +7 -0
- package/dist/types/lib/embedded-write-key.d.ts.map +1 -0
- package/dist/types/lib/fetch.d.ts +5 -0
- package/dist/types/lib/fetch.d.ts.map +1 -0
- package/dist/types/lib/get-global.d.ts +2 -0
- package/dist/types/lib/get-global.d.ts.map +1 -0
- package/dist/types/lib/get-process-env.d.ts +8 -0
- package/dist/types/lib/get-process-env.d.ts.map +1 -0
- package/dist/types/lib/group-by.d.ts +4 -0
- package/dist/types/lib/group-by.d.ts.map +1 -0
- package/dist/types/lib/is-plan-event-enabled.d.ts +9 -0
- package/dist/types/lib/is-plan-event-enabled.d.ts.map +1 -0
- package/dist/types/lib/is-thenable.d.ts +6 -0
- package/dist/types/lib/is-thenable.d.ts.map +1 -0
- package/dist/types/lib/load-script.d.ts +3 -0
- package/dist/types/lib/load-script.d.ts.map +1 -0
- package/dist/types/lib/merged-options.d.ts +13 -0
- package/dist/types/lib/merged-options.d.ts.map +1 -0
- package/dist/types/lib/on-page-leave.d.ts +11 -0
- package/dist/types/lib/on-page-leave.d.ts.map +1 -0
- package/dist/types/lib/p-while.d.ts +2 -0
- package/dist/types/lib/p-while.d.ts.map +1 -0
- package/dist/types/lib/parse-cdn.d.ts +10 -0
- package/dist/types/lib/parse-cdn.d.ts.map +1 -0
- package/dist/types/lib/priority-queue/backoff.d.ts +13 -0
- package/dist/types/lib/priority-queue/backoff.d.ts.map +1 -0
- package/dist/types/lib/priority-queue/index.d.ts +3 -0
- package/dist/types/lib/priority-queue/index.d.ts.map +1 -0
- package/dist/types/lib/priority-queue/persisted.d.ts +6 -0
- package/dist/types/lib/priority-queue/persisted.d.ts.map +1 -0
- package/dist/types/lib/sleep.d.ts +2 -0
- package/dist/types/lib/sleep.d.ts.map +1 -0
- package/dist/types/lib/to-facade.d.ts +7 -0
- package/dist/types/lib/to-facade.d.ts.map +1 -0
- package/dist/types/node/index.d.ts +8 -0
- package/dist/types/node/index.d.ts.map +1 -0
- package/dist/types/node/node.browser.d.ts +4 -0
- package/dist/types/node/node.browser.d.ts.map +1 -0
- package/dist/types/plugins/ajs-destination/index.d.ts +42 -0
- package/dist/types/plugins/ajs-destination/index.d.ts.map +1 -0
- package/dist/types/plugins/ajs-destination/loader.d.ts +12 -0
- package/dist/types/plugins/ajs-destination/loader.d.ts.map +1 -0
- package/dist/types/plugins/ajs-destination/types.d.ts +36 -0
- package/dist/types/plugins/ajs-destination/types.d.ts.map +1 -0
- package/dist/types/plugins/ajs-destination/utils.d.ts +5 -0
- package/dist/types/plugins/ajs-destination/utils.d.ts.map +1 -0
- package/dist/types/plugins/analytics-node/index.d.ts +12 -0
- package/dist/types/plugins/analytics-node/index.d.ts.map +1 -0
- package/dist/types/plugins/customerio/batched-dispatcher.d.ts +8 -0
- package/dist/types/plugins/customerio/batched-dispatcher.d.ts.map +1 -0
- package/dist/types/plugins/customerio/fetch-dispatcher.d.ts +8 -0
- package/dist/types/plugins/customerio/fetch-dispatcher.d.ts.map +1 -0
- package/dist/types/plugins/customerio/index.d.ts +26 -0
- package/dist/types/plugins/customerio/index.d.ts.map +1 -0
- package/dist/types/plugins/customerio/normalize.d.ts +12 -0
- package/dist/types/plugins/customerio/normalize.d.ts.map +1 -0
- package/dist/types/plugins/customerio/schedule-flush.d.ts +5 -0
- package/dist/types/plugins/customerio/schedule-flush.d.ts.map +1 -0
- package/dist/types/plugins/legacy-video-plugins/index.d.ts +3 -0
- package/dist/types/plugins/legacy-video-plugins/index.d.ts.map +1 -0
- package/dist/types/plugins/middleware/index.d.ts +18 -0
- package/dist/types/plugins/middleware/index.d.ts.map +1 -0
- package/dist/types/plugins/page-enrichment/index.d.ts +21 -0
- package/dist/types/plugins/page-enrichment/index.d.ts.map +1 -0
- package/dist/types/plugins/remote-loader/index.d.ts +43 -0
- package/dist/types/plugins/remote-loader/index.d.ts.map +1 -0
- package/dist/types/plugins/remote-middleware/index.d.ts +5 -0
- package/dist/types/plugins/remote-middleware/index.d.ts.map +1 -0
- package/dist/types/plugins/routing-middleware/index.d.ts +13 -0
- package/dist/types/plugins/routing-middleware/index.d.ts.map +1 -0
- package/dist/types/plugins/schema-filter/index.d.ts +5 -0
- package/dist/types/plugins/schema-filter/index.d.ts.map +1 -0
- package/dist/types/plugins/validation/index.d.ts +7 -0
- package/dist/types/plugins/validation/index.d.ts.map +1 -0
- package/dist/umd/799.bundle.f804d7b881cf284fbd56.js +1 -0
- package/dist/umd/799.bundle.f804d7b881cf284fbd56.js.gz +0 -0
- package/dist/umd/870.bundle.e0b7bfa4797bb87217c9.js +1 -0
- package/dist/umd/870.bundle.e0b7bfa4797bb87217c9.js.gz +0 -0
- package/dist/umd/ajs-destination.bundle.847bf422720e5616c9d5.js +1 -0
- package/dist/umd/ajs-destination.bundle.847bf422720e5616c9d5.js.gz +0 -0
- package/dist/umd/auto-track.bundle.758629f7a47544af2d44.js +1 -0
- package/dist/umd/auto-track.bundle.758629f7a47544af2d44.js.gz +0 -0
- package/dist/umd/index.js +1 -0
- package/dist/umd/index.js.gz +0 -0
- package/dist/umd/legacyVideos.bundle.d7ac356ab28fab36e111.js +1 -0
- package/dist/umd/legacyVideos.bundle.d7ac356ab28fab36e111.js.gz +0 -0
- package/dist/umd/queryString.bundle.913501e40ce64ef92884.js +1 -0
- package/dist/umd/queryString.bundle.913501e40ce64ef92884.js.gz +0 -0
- package/dist/umd/remoteMiddleware.bundle.3bc569811c4c2c93d90c.js +1 -0
- package/dist/umd/remoteMiddleware.bundle.3bc569811c4c2c93d90c.js.gz +0 -0
- package/dist/umd/schemaFilter.bundle.bb8180ae95843c8f138e.js +1 -0
- package/dist/umd/schemaFilter.bundle.bb8180ae95843c8f138e.js.gz +0 -0
- package/dist/umd/standalone.js +1 -0
- package/dist/umd/standalone.js.gz +0 -0
- package/dist/umd/tsub-middleware.bundle.af0f402084ddd2b605cc.js +1 -0
- package/dist/umd/tsub-middleware.bundle.af0f402084ddd2b605cc.js.gz +0 -0
- package/package.json +103 -0
- package/src/browser/browser-umd.ts +19 -0
- package/src/browser/index.ts +397 -0
- package/src/browser/standalone-analytics.ts +74 -0
- package/src/browser/standalone.ts +78 -0
- package/src/core/analytics/index.ts +567 -0
- package/src/core/analytics/interfaces.ts +100 -0
- package/src/core/arguments-resolver/index.ts +166 -0
- package/src/core/auto-track.ts +152 -0
- package/src/core/buffer/index.ts +289 -0
- package/src/core/buffer/snippet.ts +43 -0
- package/src/core/callback/index.ts +1 -0
- package/src/core/connection/index.ts +13 -0
- package/src/core/context/index.ts +21 -0
- package/src/core/environment/index.ts +7 -0
- package/src/core/events/index.ts +254 -0
- package/src/core/events/interfaces.ts +36 -0
- package/src/core/inspector/index.ts +14 -0
- package/src/core/plugin/index.ts +12 -0
- package/src/core/query-string/gracefulDecodeURIComponent.ts +16 -0
- package/src/core/query-string/index.ts +64 -0
- package/src/core/query-string/pickPrefix.ts +20 -0
- package/src/core/queue/event-queue.ts +11 -0
- package/src/core/stats/index.ts +15 -0
- package/src/core/stats/remote-metrics.ts +137 -0
- package/src/core/user/index.ts +534 -0
- package/src/core/user/tld.ts +65 -0
- package/src/generated/version.ts +2 -0
- package/src/index.ts +10 -0
- package/src/lib/bind-all.ts +19 -0
- package/src/lib/browser-polyfill.ts +23 -0
- package/src/lib/create-deferred.ts +16 -0
- package/src/lib/csp-detection.ts +26 -0
- package/src/lib/embedded-write-key.ts +24 -0
- package/src/lib/fetch.ts +10 -0
- package/src/lib/get-global.ts +16 -0
- package/src/lib/get-process-env.ts +11 -0
- package/src/lib/group-by.ts +30 -0
- package/src/lib/is-plan-event-enabled.ts +20 -0
- package/src/lib/is-thenable.ts +9 -0
- package/src/lib/load-script.ts +66 -0
- package/src/lib/merged-options.ts +46 -0
- package/src/lib/on-page-leave.ts +29 -0
- package/src/lib/p-while.ts +12 -0
- package/src/lib/parse-cdn.ts +85 -0
- package/src/lib/priority-queue/backoff.ts +24 -0
- package/src/lib/priority-queue/index.ts +6 -0
- package/src/lib/priority-queue/persisted.ts +127 -0
- package/src/lib/sleep.ts +4 -0
- package/src/lib/to-facade.ts +53 -0
- package/src/node/index.ts +36 -0
- package/src/node/node.browser.ts +7 -0
- package/src/plugins/ajs-destination/index.ts +388 -0
- package/src/plugins/ajs-destination/loader.ts +127 -0
- package/src/plugins/ajs-destination/types.ts +44 -0
- package/src/plugins/ajs-destination/utils.ts +34 -0
- package/src/plugins/analytics-node/index.ts +64 -0
- package/src/plugins/customerio/batched-dispatcher.ts +115 -0
- package/src/plugins/customerio/fetch-dispatcher.ts +24 -0
- package/src/plugins/customerio/index.ts +142 -0
- package/src/plugins/customerio/normalize.ts +223 -0
- package/src/plugins/customerio/schedule-flush.ts +58 -0
- package/src/plugins/legacy-video-plugins/index.ts +16 -0
- package/src/plugins/middleware/index.ts +131 -0
- package/src/plugins/page-enrichment/index.ts +127 -0
- package/src/plugins/remote-loader/index.ts +240 -0
- package/src/plugins/remote-middleware/index.ts +44 -0
- package/src/plugins/routing-middleware/index.ts +37 -0
- package/src/plugins/schema-filter/index.ts +90 -0
- package/src/plugins/validation/index.ts +80 -0
- package/src/test-helpers/browser-storage.ts +72 -0
- package/src/test-helpers/factories.ts +18 -0
- package/src/test-helpers/fetch-parse.ts +8 -0
- package/src/test-helpers/fixtures/cdn-settings.ts +299 -0
- package/src/test-helpers/fixtures/classic-destination.ts +25 -0
- package/src/test-helpers/fixtures/create-fetch-method.ts +24 -0
- package/src/test-helpers/test-writekeys.ts +5 -0
- 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
|
+
}
|