utneque 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.editorconfig +10 -0
- package/.eslintrc.isomorphic.js +26 -0
- package/.eslintrc.js +86 -0
- package/.gitattributes +1 -0
- package/.github/workflows/ci.yml +33 -0
- package/.github/workflows/deploy-browser-cdn-candidate.yml +51 -0
- package/.github/workflows/deploy-releases.yml +178 -0
- package/.nvmrc +1 -0
- package/.prettierrc +7 -0
- package/.vscode/extensions.json +3 -0
- package/.vscode/launch.json +81 -0
- package/.vscode/settings.json +41 -0
- package/.yarn/plugins/@yarnpkg/plugin-constraints.cjs +52 -0
- package/.yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs +546 -0
- package/.yarn/plugins/@yarnpkg/plugin-typescript.cjs +9 -0
- package/.yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs +28 -0
- package/.yarn/releases/yarn-3.4.1.cjs +873 -0
- package/.yarnrc.yml +15 -0
- package/jest.config.js +18 -0
- package/package.json +59 -0
- package/packages/browser/.eslintrc.js +9 -0
- package/packages/browser/.lintstagedrc.js +1 -0
- package/packages/browser/ARCHITECTURE.md +48 -0
- package/packages/browser/LICENSE.MD +45 -0
- package/packages/browser/Makefile +64 -0
- package/packages/browser/README.md +227 -0
- package/packages/browser/e2e-tests/local-server.ts +28 -0
- package/packages/browser/e2e-tests/performance/ajs-perf-browser.test.ts +75 -0
- package/packages/browser/jest.config.js +15 -0
- package/packages/browser/jest.setup.js +10 -0
- package/packages/browser/package.json +106 -0
- package/packages/browser/qa/README.md +41 -0
- package/packages/browser/qa/__fixtures__/snippets.ts +148 -0
- package/packages/browser/qa/__tests__/backwards-compatibility.test.ts +180 -0
- package/packages/browser/qa/__tests__/destinations.test.ts +101 -0
- package/packages/browser/qa/__tests__/smoke.test.ts +170 -0
- package/packages/browser/qa/lib/benchmark.ts +36 -0
- package/packages/browser/qa/lib/browser.ts +28 -0
- package/packages/browser/qa/lib/jest-reporter.js +57 -0
- package/packages/browser/qa/lib/runner.ts +142 -0
- package/packages/browser/qa/lib/schema.ts +59 -0
- package/packages/browser/qa/lib/server.ts +54 -0
- package/packages/browser/qa/lib/stats.ts +52 -0
- package/packages/browser/scripts/build-prep.sh +7 -0
- package/packages/browser/scripts/ci.sh +15 -0
- package/packages/browser/scripts/release.js +121 -0
- package/packages/browser/scripts/release.sh +9 -0
- package/packages/browser/scripts/run.sh +8 -0
- package/packages/browser/src/browser/__tests__/analytics-lazy-init.integration.test.ts +51 -0
- package/packages/browser/src/browser/__tests__/analytics-pre-init.integration.test.ts +440 -0
- package/packages/browser/src/browser/__tests__/anon-id-and-reset.integration.test.ts +73 -0
- package/packages/browser/src/browser/__tests__/cdn.test.ts +53 -0
- package/packages/browser/src/browser/__tests__/csp-detection.test.ts +140 -0
- package/packages/browser/src/browser/__tests__/inspector.integration.test.ts +121 -0
- package/packages/browser/src/browser/__tests__/integration.test.ts +1213 -0
- package/packages/browser/src/browser/__tests__/integrations.integration.test.ts +260 -0
- package/packages/browser/src/browser/__tests__/page-enrichment.integration.test.ts +216 -0
- package/packages/browser/src/browser/__tests__/query-string.integration.test.ts +116 -0
- package/packages/browser/src/browser/__tests__/standalone-analytics.test.ts +303 -0
- package/packages/browser/src/browser/__tests__/standalone-errors.test.ts +136 -0
- package/packages/browser/src/browser/__tests__/standalone.test.ts +97 -0
- package/packages/browser/src/browser/__tests__/typedef-tests/analytics-browser.ts +150 -0
- package/packages/browser/src/browser/__tests__/update-cdn-settings.test.ts +71 -0
- package/packages/browser/src/browser/browser-umd.ts +19 -0
- package/packages/browser/src/browser/index.ts +486 -0
- package/packages/browser/src/browser/standalone-analytics.ts +62 -0
- package/packages/browser/src/browser/standalone-interface.ts +11 -0
- package/packages/browser/src/browser/standalone.ts +92 -0
- package/packages/browser/src/core/__tests__/track-form.test.ts +193 -0
- package/packages/browser/src/core/__tests__/track-link.test.ts +252 -0
- package/packages/browser/src/core/analytics/__tests__/integration.test.ts +334 -0
- package/packages/browser/src/core/analytics/__tests__/test-plugins.ts +94 -0
- package/packages/browser/src/core/analytics/index.ts +672 -0
- package/packages/browser/src/core/analytics/interfaces.ts +100 -0
- package/packages/browser/src/core/arguments-resolver/__tests__/index.test.ts +524 -0
- package/packages/browser/src/core/arguments-resolver/index.ts +200 -0
- package/packages/browser/src/core/auto-track.ts +152 -0
- package/packages/browser/src/core/buffer/__tests__/index.test.ts +455 -0
- package/packages/browser/src/core/buffer/index.ts +371 -0
- package/packages/browser/src/core/callback/index.ts +1 -0
- package/packages/browser/src/core/connection/__tests__/index.test.ts +25 -0
- package/packages/browser/src/core/connection/index.ts +13 -0
- package/packages/browser/src/core/constants/index.ts +1 -0
- package/packages/browser/src/core/context/__tests__/index.test.ts +201 -0
- package/packages/browser/src/core/context/index.ts +21 -0
- package/packages/browser/src/core/environment/index.ts +7 -0
- package/packages/browser/src/core/events/__tests__/index.test.ts +450 -0
- package/packages/browser/src/core/events/index.ts +280 -0
- package/packages/browser/src/core/events/interfaces.ts +36 -0
- package/packages/browser/src/core/inspector/index.ts +14 -0
- package/packages/browser/src/core/page/__tests__/index.test.ts +130 -0
- package/packages/browser/src/core/page/add-page-context.ts +33 -0
- package/packages/browser/src/core/page/get-page-context.ts +140 -0
- package/packages/browser/src/core/page/index.ts +2 -0
- package/packages/browser/src/core/plugin/index.ts +12 -0
- package/packages/browser/src/core/query-string/__tests__/gracefulDecodeURIComponent.test.ts +17 -0
- package/packages/browser/src/core/query-string/__tests__/index.test.ts +149 -0
- package/packages/browser/src/core/query-string/__tests__/pickPrefix.test.ts +31 -0
- package/packages/browser/src/core/query-string/__tests__/useQueryString.test.ts +60 -0
- package/packages/browser/src/core/query-string/gracefulDecodeURIComponent.ts +16 -0
- package/packages/browser/src/core/query-string/index.ts +64 -0
- package/packages/browser/src/core/query-string/pickPrefix.ts +20 -0
- package/packages/browser/src/core/queue/__tests__/event-queue.test.ts +82 -0
- package/packages/browser/src/core/queue/event-queue.ts +22 -0
- package/packages/browser/src/core/session/__tests__/index.test.ts +41 -0
- package/packages/browser/src/core/session/index.ts +107 -0
- package/packages/browser/src/core/stats/__tests__/index.test.ts +15 -0
- package/packages/browser/src/core/stats/__tests__/remote-metrics.test.ts +189 -0
- package/packages/browser/src/core/stats/index.ts +15 -0
- package/packages/browser/src/core/stats/remote-metrics.ts +144 -0
- package/packages/browser/src/core/storage/__tests__/cookieStorage.test.ts +58 -0
- package/packages/browser/src/core/storage/__tests__/localStorage.test.ts +70 -0
- package/packages/browser/src/core/storage/__tests__/test-helpers.ts +26 -0
- package/packages/browser/src/core/storage/__tests__/universalStorage.test.ts +167 -0
- package/packages/browser/src/core/storage/cookieStorage.ts +80 -0
- package/packages/browser/src/core/storage/index.ts +64 -0
- package/packages/browser/src/core/storage/localStorage.ts +45 -0
- package/packages/browser/src/core/storage/memoryStorage.ts +22 -0
- package/packages/browser/src/core/storage/settings.ts +23 -0
- package/packages/browser/src/core/storage/types.ts +49 -0
- package/packages/browser/src/core/storage/universalStorage.ts +78 -0
- package/packages/browser/src/core/user/__tests__/index.test.ts +922 -0
- package/packages/browser/src/core/user/__tests__/migrate.test.ts +101 -0
- package/packages/browser/src/core/user/__tests__/session.test.ts +136 -0
- package/packages/browser/src/core/user/__tests__/tld.test.ts +36 -0
- package/packages/browser/src/core/user/index.ts +399 -0
- package/packages/browser/src/core/user/migrate.ts +126 -0
- package/packages/browser/src/core/user/tld.ts +65 -0
- package/packages/browser/src/core/user/vendor/crypto-es/LICENSE +53 -0
- package/packages/browser/src/core/user/vendor/crypto-es/lib/aes.ts +302 -0
- package/packages/browser/src/core/user/vendor/crypto-es/lib/cipher-core.ts +922 -0
- package/packages/browser/src/core/user/vendor/crypto-es/lib/core.ts +806 -0
- package/packages/browser/src/core/user/vendor/crypto-es/lib/enc-base64.ts +110 -0
- package/packages/browser/src/core/user/vendor/crypto-es/lib/evpkdf.ts +110 -0
- package/packages/browser/src/core/user/vendor/crypto-es/lib/md5.ts +238 -0
- package/packages/browser/src/core/user/vendor/readme.md +7 -0
- package/packages/browser/src/generated/__tests__/version.test.ts +18 -0
- package/packages/browser/src/generated/version.ts +2 -0
- package/packages/browser/src/index.ts +13 -0
- package/packages/browser/src/lib/__tests__/embedded-write-key.test.ts +15 -0
- package/packages/browser/src/lib/__tests__/fetch.test.ts +35 -0
- package/packages/browser/src/lib/__tests__/get-process-env.test.ts +5 -0
- package/packages/browser/src/lib/__tests__/group-by.test.ts +96 -0
- package/packages/browser/src/lib/__tests__/is-plan-event-enabled.test.ts +36 -0
- package/packages/browser/src/lib/__tests__/is-thenable.test.ts +39 -0
- package/packages/browser/src/lib/__tests__/merged-options.test.ts +123 -0
- package/packages/browser/src/lib/__tests__/on-page-change.test.ts +74 -0
- package/packages/browser/src/lib/__tests__/parse-cdn.test.ts +88 -0
- package/packages/browser/src/lib/__tests__/pick.test.ts +34 -0
- package/packages/browser/src/lib/__tests__/pick.typedef.ts +39 -0
- package/packages/browser/src/lib/bind-all.ts +19 -0
- package/packages/browser/src/lib/browser-polyfill.ts +23 -0
- package/packages/browser/src/lib/client-hints/__tests__/index.test.ts +66 -0
- package/packages/browser/src/lib/client-hints/index.ts +16 -0
- package/packages/browser/src/lib/client-hints/interfaces.ts +42 -0
- package/packages/browser/src/lib/create-deferred.ts +16 -0
- package/packages/browser/src/lib/csp-detection.ts +8 -0
- package/packages/browser/src/lib/embedded-write-key.ts +24 -0
- package/packages/browser/src/lib/fetch.ts +10 -0
- package/packages/browser/src/lib/get-global.ts +16 -0
- package/packages/browser/src/lib/get-process-env.ts +11 -0
- package/packages/browser/src/lib/global-analytics-helper.ts +31 -0
- package/packages/browser/src/lib/group-by.ts +30 -0
- package/packages/browser/src/lib/is-plan-event-enabled.ts +20 -0
- package/packages/browser/src/lib/is-thenable.ts +9 -0
- package/packages/browser/src/lib/load-script.ts +66 -0
- package/packages/browser/src/lib/merged-options.ts +46 -0
- package/packages/browser/src/lib/on-page-change.ts +29 -0
- package/packages/browser/src/lib/p-while.ts +12 -0
- package/packages/browser/src/lib/parse-cdn.ts +56 -0
- package/packages/browser/src/lib/pick.ts +28 -0
- package/packages/browser/src/lib/priority-queue/__tests__/backoff.test.ts +23 -0
- package/packages/browser/src/lib/priority-queue/__tests__/index.test.ts +158 -0
- package/packages/browser/src/lib/priority-queue/__tests__/persisted.test.ts +228 -0
- package/packages/browser/src/lib/priority-queue/backoff.ts +24 -0
- package/packages/browser/src/lib/priority-queue/index.ts +6 -0
- package/packages/browser/src/lib/priority-queue/persisted.ts +127 -0
- package/packages/browser/src/lib/sleep.ts +4 -0
- package/packages/browser/src/lib/to-facade.ts +53 -0
- package/packages/browser/src/lib/version-type.ts +10 -0
- package/packages/browser/src/node/__tests__/node-integration.test.ts +19 -0
- package/packages/browser/src/node/index.ts +36 -0
- package/packages/browser/src/node/node.browser.ts +7 -0
- package/packages/browser/src/plugins/ajs-destination/__tests__/index.test.ts +834 -0
- package/packages/browser/src/plugins/ajs-destination/index.ts +392 -0
- package/packages/browser/src/plugins/ajs-destination/loader.ts +129 -0
- package/packages/browser/src/plugins/ajs-destination/types.ts +44 -0
- package/packages/browser/src/plugins/ajs-destination/utils.ts +32 -0
- package/packages/browser/src/plugins/analytics-node/__tests__/index.test.ts +69 -0
- package/packages/browser/src/plugins/analytics-node/index.ts +67 -0
- package/packages/browser/src/plugins/env-enrichment/__tests__/index.test.ts +421 -0
- package/packages/browser/src/plugins/env-enrichment/index.ts +208 -0
- package/packages/browser/src/plugins/hightouchio/__tests__/batched-dispatcher.test.ts +299 -0
- package/packages/browser/src/plugins/hightouchio/__tests__/index.test.ts +317 -0
- package/packages/browser/src/plugins/hightouchio/__tests__/normalize.test.ts +181 -0
- package/packages/browser/src/plugins/hightouchio/__tests__/retries.test.ts +82 -0
- package/packages/browser/src/plugins/hightouchio/batched-dispatcher.ts +127 -0
- package/packages/browser/src/plugins/hightouchio/fetch-dispatcher.ts +27 -0
- package/packages/browser/src/plugins/hightouchio/index.ts +147 -0
- package/packages/browser/src/plugins/hightouchio/normalize.ts +71 -0
- package/packages/browser/src/plugins/hightouchio/schedule-flush.ts +58 -0
- package/packages/browser/src/plugins/legacy-video-plugins/__tests__/index.test.ts +48 -0
- package/packages/browser/src/plugins/legacy-video-plugins/index.ts +16 -0
- package/packages/browser/src/plugins/middleware/__tests__/index.test.ts +268 -0
- package/packages/browser/src/plugins/middleware/index.ts +131 -0
- package/packages/browser/src/plugins/remote-loader/__tests__/index.test.ts +943 -0
- package/packages/browser/src/plugins/remote-loader/index.ts +256 -0
- package/packages/browser/src/plugins/remote-middleware/__tests__/index.test.ts +116 -0
- package/packages/browser/src/plugins/remote-middleware/index.ts +44 -0
- package/packages/browser/src/plugins/routing-middleware/__tests__/index.test.ts +64 -0
- package/packages/browser/src/plugins/routing-middleware/index.ts +37 -0
- package/packages/browser/src/plugins/schema-filter/__tests__/index.test.ts +520 -0
- package/packages/browser/src/plugins/schema-filter/index.ts +90 -0
- package/packages/browser/src/plugins/validation/__tests__/index.test.ts +78 -0
- package/packages/browser/src/plugins/validation/index.ts +44 -0
- package/packages/browser/src/test-helpers/browser-storage.ts +75 -0
- package/packages/browser/src/test-helpers/factories.ts +18 -0
- package/packages/browser/src/test-helpers/fetch-parse.ts +8 -0
- package/packages/browser/src/test-helpers/fixtures/cdn-settings.ts +301 -0
- package/packages/browser/src/test-helpers/fixtures/classic-destination.ts +25 -0
- package/packages/browser/src/test-helpers/fixtures/client-hints.ts +28 -0
- package/packages/browser/src/test-helpers/fixtures/create-fetch-method.ts +30 -0
- package/packages/browser/src/test-helpers/fixtures/index.ts +4 -0
- package/packages/browser/src/test-helpers/fixtures/page-context.ts +11 -0
- package/packages/browser/src/test-helpers/test-writekeys.ts +5 -0
- package/packages/browser/src/test-helpers/type-assertions.ts +11 -0
- package/packages/browser/src/tester/__fixtures__/hightouch-snippet.ts +64 -0
- package/packages/browser/src/tester/__fixtures__/index.html +8 -0
- package/packages/browser/src/tester/ajs-perf.ts +30 -0
- package/packages/browser/src/tester/ajs-tester.ts +119 -0
- package/packages/browser/src/tester/server.js +16 -0
- package/packages/browser/tsconfig.build.json +9 -0
- package/packages/browser/tsconfig.json +13 -0
- package/packages/browser/webpack.config.js +106 -0
- package/packages/config/package.json +10 -0
- package/packages/config/src/index.js +4 -0
- package/packages/config/src/jest/config.js +50 -0
- package/packages/config/src/jest/get-module-map.js +34 -0
- package/packages/config/src/lint-staged/config.js +4 -0
- package/packages/config-webpack/package.json +20 -0
- package/packages/config-webpack/webpack.config.common.js +75 -0
- package/packages/consent/consent-tools/.eslintrc.js +7 -0
- package/packages/consent/consent-tools/.lintstagedrc.js +1 -0
- package/packages/consent/consent-tools/LICENSE +45 -0
- package/packages/consent/consent-tools/README.md +104 -0
- package/packages/consent/consent-tools/jest.config.js +6 -0
- package/packages/consent/consent-tools/jest.setup.js +4 -0
- package/packages/consent/consent-tools/package.json +48 -0
- package/packages/consent/consent-tools/src/domain/__tests__/assertions/integrations-assertions.ts +37 -0
- package/packages/consent/consent-tools/src/domain/__tests__/consent-stamping.test.ts +45 -0
- package/packages/consent/consent-tools/src/domain/__tests__/create-wrapper.test.ts +816 -0
- package/packages/consent/consent-tools/src/domain/__tests__/typedef-tests.ts +21 -0
- package/packages/consent/consent-tools/src/domain/consent-changed.ts +51 -0
- package/packages/consent/consent-tools/src/domain/consent-stamping.ts +19 -0
- package/packages/consent/consent-tools/src/domain/create-wrapper.ts +238 -0
- package/packages/consent/consent-tools/src/domain/get-initialized-analytics.ts +25 -0
- package/packages/consent/consent-tools/src/domain/load-cancellation.ts +31 -0
- package/packages/consent/consent-tools/src/domain/validation/__tests__/options-validators.test.ts +77 -0
- package/packages/consent/consent-tools/src/domain/validation/__tests__/validation-error.test.ts +15 -0
- package/packages/consent/consent-tools/src/domain/validation/common-validators.ts +19 -0
- package/packages/consent/consent-tools/src/domain/validation/index.ts +1 -0
- package/packages/consent/consent-tools/src/domain/validation/options-validators.ts +74 -0
- package/packages/consent/consent-tools/src/domain/validation/validation-error.ts +11 -0
- package/packages/consent/consent-tools/src/index.ts +16 -0
- package/packages/consent/consent-tools/src/types/errors.ts +14 -0
- package/packages/consent/consent-tools/src/types/index.ts +3 -0
- package/packages/consent/consent-tools/src/types/settings.ts +121 -0
- package/packages/consent/consent-tools/src/types/wrapper.ts +107 -0
- package/packages/consent/consent-tools/src/utils/index.ts +4 -0
- package/packages/consent/consent-tools/src/utils/pick.ts +18 -0
- package/packages/consent/consent-tools/src/utils/pipe.ts +14 -0
- package/packages/consent/consent-tools/src/utils/resolve-when.ts +32 -0
- package/packages/consent/consent-tools/src/utils/uniq.ts +4 -0
- package/packages/consent/consent-tools/tsconfig.build.json +9 -0
- package/packages/consent/consent-tools/tsconfig.json +12 -0
- package/packages/consent/consent-wrapper-onetrust/.eslintrc.js +7 -0
- package/packages/consent/consent-wrapper-onetrust/.lintstagedrc.js +1 -0
- package/packages/consent/consent-wrapper-onetrust/LICENSE +45 -0
- package/packages/consent/consent-wrapper-onetrust/README.md +125 -0
- package/packages/consent/consent-wrapper-onetrust/img/onetrust-cat-id.jpg +0 -0
- package/packages/consent/consent-wrapper-onetrust/img/onetrust-popup.jpg +0 -0
- package/packages/consent/consent-wrapper-onetrust/jest.config.js +6 -0
- package/packages/consent/consent-wrapper-onetrust/jest.setup.js +4 -0
- package/packages/consent/consent-wrapper-onetrust/package.json +60 -0
- package/packages/consent/consent-wrapper-onetrust/src/domain/__tests__/wrapper.test.ts +151 -0
- package/packages/consent/consent-wrapper-onetrust/src/domain/wrapper.ts +61 -0
- package/packages/consent/consent-wrapper-onetrust/src/index.ts +6 -0
- package/packages/consent/consent-wrapper-onetrust/src/index.umd.ts +11 -0
- package/packages/consent/consent-wrapper-onetrust/src/lib/__tests__/onetrust-api.test.ts +181 -0
- package/packages/consent/consent-wrapper-onetrust/src/lib/onetrust-api.ts +155 -0
- package/packages/consent/consent-wrapper-onetrust/src/lib/validation/index.ts +1 -0
- package/packages/consent/consent-wrapper-onetrust/src/lib/validation/onetrust-api-error.ts +11 -0
- package/packages/consent/consent-wrapper-onetrust/src/test-helpers/mocks.ts +23 -0
- package/packages/consent/consent-wrapper-onetrust/src/test-helpers/onetrust-globals.d.ts +11 -0
- package/packages/consent/consent-wrapper-onetrust/src/test-helpers/utils.ts +3 -0
- package/packages/consent/consent-wrapper-onetrust/tsconfig.build.json +9 -0
- package/packages/consent/consent-wrapper-onetrust/tsconfig.json +11 -0
- package/packages/consent/consent-wrapper-onetrust/webpack.config.js +25 -0
- package/packages/core/.eslintrc.js +4 -0
- package/packages/core/.lintstagedrc.js +1 -0
- package/packages/core/LICENSE.MD +45 -0
- package/packages/core/README.md +3 -0
- package/packages/core/jest.config.js +5 -0
- package/packages/core/jest.setup.js +10 -0
- package/packages/core/package.json +40 -0
- package/packages/core/src/analytics/__tests__/dispatch.test.ts +95 -0
- package/packages/core/src/analytics/dispatch.ts +58 -0
- package/packages/core/src/analytics/index.ts +11 -0
- package/packages/core/src/callback/__tests__/index.test.ts +85 -0
- package/packages/core/src/callback/index.ts +51 -0
- package/packages/core/src/context/index.ts +123 -0
- package/packages/core/src/emitter/__tests__/emitter.test.ts +74 -0
- package/packages/core/src/emitter/index.ts +65 -0
- package/packages/core/src/emitter/interface.ts +31 -0
- package/packages/core/src/events/__tests__/index.test.ts +394 -0
- package/packages/core/src/events/index.ts +280 -0
- package/packages/core/src/events/interfaces.ts +475 -0
- package/packages/core/src/index.ts +19 -0
- package/packages/core/src/logger/__tests__/index.test.ts +66 -0
- package/packages/core/src/logger/index.ts +74 -0
- package/packages/core/src/plugins/index.ts +43 -0
- package/packages/core/src/priority-queue/__tests__/backoff.test.ts +23 -0
- package/packages/core/src/priority-queue/__tests__/index.test.ts +158 -0
- package/packages/core/src/priority-queue/backoff.ts +24 -0
- package/packages/core/src/priority-queue/index.ts +103 -0
- package/packages/core/src/queue/__tests__/event-queue.test.ts +678 -0
- package/packages/core/src/queue/__tests__/extension-flushing.test.ts +416 -0
- package/packages/core/src/queue/delivery.ts +73 -0
- package/packages/core/src/queue/event-queue.ts +318 -0
- package/packages/core/src/stats/__tests__/index.test.ts +103 -0
- package/packages/core/src/stats/index.ts +88 -0
- package/packages/core/src/task/__tests__/task-group.test.ts +26 -0
- package/packages/core/src/task/task-group.ts +31 -0
- package/packages/core/src/user/index.ts +7 -0
- package/packages/core/src/utils/__tests__/group-by.test.ts +96 -0
- package/packages/core/src/utils/__tests__/is-plain-object.test.ts +27 -0
- package/packages/core/src/utils/__tests__/is-thenable.test.ts +39 -0
- package/packages/core/src/utils/bind-all.ts +19 -0
- package/packages/core/src/utils/get-global.ts +17 -0
- package/packages/core/src/utils/group-by.ts +30 -0
- package/packages/core/src/utils/has-properties.ts +7 -0
- package/packages/core/src/utils/is-plain-object.ts +26 -0
- package/packages/core/src/utils/is-thenable.ts +9 -0
- package/packages/core/src/utils/p-while.ts +12 -0
- package/packages/core/src/utils/pick.ts +8 -0
- package/packages/core/src/utils/ts-helpers.ts +13 -0
- package/packages/core/src/validation/__tests__/assertions.test.ts +155 -0
- package/packages/core/src/validation/assertions.ts +72 -0
- package/packages/core/src/validation/errors.ts +8 -0
- package/packages/core/src/validation/helpers.ts +23 -0
- package/packages/core/test-helpers/index.ts +2 -0
- package/packages/core/test-helpers/test-ctx.ts +7 -0
- package/packages/core/test-helpers/test-event-queue.ts +7 -0
- package/packages/core/tsconfig.build.json +9 -0
- package/packages/core/tsconfig.json +11 -0
- package/packages/node/.eslintrc.js +7 -0
- package/packages/node/.lintstagedrc.js +1 -0
- package/packages/node/LICENSE +45 -0
- package/packages/node/README.md +138 -0
- package/packages/node/jest.config.js +5 -0
- package/packages/node/jest.setup.js +4 -0
- package/packages/node/package.json +50 -0
- package/packages/node/scripts/version.sh +11 -0
- package/packages/node/src/__tests__/callback.test.ts +47 -0
- package/packages/node/src/__tests__/disable.integration.test.ts +42 -0
- package/packages/node/src/__tests__/emitter.integration.test.ts +45 -0
- package/packages/node/src/__tests__/graceful-shutdown-integration.test.ts +244 -0
- package/packages/node/src/__tests__/http-client.integration.test.ts +69 -0
- package/packages/node/src/__tests__/http-integration.test.ts +362 -0
- package/packages/node/src/__tests__/integration.test.ts +357 -0
- package/packages/node/src/__tests__/plugins.test.ts +16 -0
- package/packages/node/src/__tests__/settings.test.ts +9 -0
- package/packages/node/src/__tests__/test-helpers/assert-shape/http-request-event.ts +13 -0
- package/packages/node/src/__tests__/test-helpers/assert-shape/index.ts +2 -0
- package/packages/node/src/__tests__/test-helpers/assert-shape/segment-http-api.ts +43 -0
- package/packages/node/src/__tests__/test-helpers/create-test-analytics.ts +42 -0
- package/packages/node/src/__tests__/test-helpers/factories.ts +17 -0
- package/packages/node/src/__tests__/test-helpers/is-valid-date.ts +6 -0
- package/packages/node/src/__tests__/test-helpers/resolve-ctx.ts +19 -0
- package/packages/node/src/__tests__/test-helpers/resolve-emitter.ts +11 -0
- package/packages/node/src/__tests__/test-helpers/sleep.ts +3 -0
- package/packages/node/src/__tests__/test-helpers/test-plugin.ts +16 -0
- package/packages/node/src/__tests__/typedef-tests.ts +120 -0
- package/packages/node/src/app/analytics-node.ts +299 -0
- package/packages/node/src/app/context.ts +11 -0
- package/packages/node/src/app/dispatch-emit.ts +42 -0
- package/packages/node/src/app/emitter.ts +23 -0
- package/packages/node/src/app/event-factory.ts +20 -0
- package/packages/node/src/app/event-queue.ts +23 -0
- package/packages/node/src/app/settings.ts +49 -0
- package/packages/node/src/app/types/index.ts +3 -0
- package/packages/node/src/app/types/params.ts +76 -0
- package/packages/node/src/app/types/plugin.ts +5 -0
- package/packages/node/src/app/types/segment-event.ts +7 -0
- package/packages/node/src/generated/version.ts +2 -0
- package/packages/node/src/index.ts +26 -0
- package/packages/node/src/lib/__tests__/abort.test.ts +54 -0
- package/packages/node/src/lib/__tests__/create-url.test.ts +35 -0
- package/packages/node/src/lib/__tests__/env.test.ts +52 -0
- package/packages/node/src/lib/__tests__/get-message-id.test.ts +21 -0
- package/packages/node/src/lib/abort.ts +77 -0
- package/packages/node/src/lib/base-64-encode.ts +8 -0
- package/packages/node/src/lib/create-url.ts +11 -0
- package/packages/node/src/lib/env.ts +45 -0
- package/packages/node/src/lib/extract-promise-parts.ts +21 -0
- package/packages/node/src/lib/fetch.ts +16 -0
- package/packages/node/src/lib/get-message-id.ts +10 -0
- package/packages/node/src/lib/http-client.ts +95 -0
- package/packages/node/src/lib/uuid.ts +1 -0
- package/packages/node/src/plugins/segmentio/__tests__/methods.test.ts +223 -0
- package/packages/node/src/plugins/segmentio/__tests__/publisher.test.ts +411 -0
- package/packages/node/src/plugins/segmentio/context-batch.ts +71 -0
- package/packages/node/src/plugins/segmentio/index.ts +66 -0
- package/packages/node/src/plugins/segmentio/publisher.ts +265 -0
- package/packages/node/tsconfig.build.json +9 -0
- package/packages/node/tsconfig.json +10 -0
- package/packages/test-helpers/.eslintrc.js +7 -0
- package/packages/test-helpers/.lintstagedrc.js +1 -0
- package/packages/test-helpers/jest.config.js +3 -0
- package/packages/test-helpers/package.json +26 -0
- package/packages/test-helpers/src/analytics/cdn-settings-builder.ts +79 -0
- package/packages/test-helpers/src/analytics/index.ts +1 -0
- package/packages/test-helpers/src/index.ts +2 -0
- package/packages/test-helpers/src/utils/index.ts +1 -0
- package/packages/test-helpers/src/utils/sleep.ts +4 -0
- package/packages/test-helpers/tsconfig.build.json +9 -0
- package/packages/test-helpers/tsconfig.json +11 -0
- package/tsconfig.json +21 -0
- package/turbo.json +39 -0
- package/typings/get-monorepo-packages.d.ts +9 -0
- package/typings/spawn.d.ts +10 -0
@@ -0,0 +1,943 @@
|
|
1
|
+
import braze from '@segment/analytics-browser-actions-braze'
|
2
|
+
|
3
|
+
import * as loader from '../../../lib/load-script'
|
4
|
+
import { ActionDestination, PluginFactory, remoteLoader } from '..'
|
5
|
+
import { HtEventsBrowser, LegacySettings } from '../../../browser'
|
6
|
+
import { InitOptions } from '../../../core/analytics'
|
7
|
+
import { Context } from '../../../core/context'
|
8
|
+
import { tsubMiddleware } from '../../routing-middleware'
|
9
|
+
|
10
|
+
const pluginFactory = jest.fn()
|
11
|
+
|
12
|
+
describe('Remote Loader', () => {
|
13
|
+
const window = global.window as any
|
14
|
+
|
15
|
+
beforeEach(() => {
|
16
|
+
jest.resetAllMocks()
|
17
|
+
jest.spyOn(console, 'warn').mockImplementation()
|
18
|
+
|
19
|
+
// @ts-expect-error skipping the actual script injection part
|
20
|
+
jest.spyOn(loader, 'loadScript').mockImplementation(() => {
|
21
|
+
window.testPlugin = pluginFactory
|
22
|
+
return Promise.resolve(true)
|
23
|
+
})
|
24
|
+
})
|
25
|
+
|
26
|
+
it('should attempt to load a script from the url of each remotePlugin', async () => {
|
27
|
+
await remoteLoader(
|
28
|
+
{
|
29
|
+
integrations: {},
|
30
|
+
remotePlugins: [
|
31
|
+
{
|
32
|
+
name: 'remote plugin',
|
33
|
+
creationName: 'remote plugin',
|
34
|
+
url: 'cdn/path/to/file.js',
|
35
|
+
libraryName: 'testPlugin',
|
36
|
+
settings: {},
|
37
|
+
},
|
38
|
+
],
|
39
|
+
},
|
40
|
+
{},
|
41
|
+
{}
|
42
|
+
)
|
43
|
+
|
44
|
+
expect(loader.loadScript).toHaveBeenCalledWith('cdn/path/to/file.js')
|
45
|
+
})
|
46
|
+
|
47
|
+
it('should attempt to load a script from the obfuscated url of each remotePlugin', async () => {
|
48
|
+
await remoteLoader(
|
49
|
+
{
|
50
|
+
integrations: {},
|
51
|
+
remotePlugins: [
|
52
|
+
{
|
53
|
+
name: 'remote plugin',
|
54
|
+
creationName: 'remote plugin',
|
55
|
+
url: 'cdn/path/to/file.js',
|
56
|
+
libraryName: 'testPlugin',
|
57
|
+
settings: {},
|
58
|
+
},
|
59
|
+
],
|
60
|
+
},
|
61
|
+
{},
|
62
|
+
{},
|
63
|
+
true
|
64
|
+
)
|
65
|
+
const btoaName = btoa('to').replace(/=/g, '')
|
66
|
+
expect(loader.loadScript).toHaveBeenCalledWith(
|
67
|
+
`cdn/path/${btoaName}/file.js`
|
68
|
+
)
|
69
|
+
})
|
70
|
+
|
71
|
+
it('should attempt to load a script from a custom CDN', async () => {
|
72
|
+
window.htevents = {}
|
73
|
+
window.htevents._cdn = 'foo.com'
|
74
|
+
await remoteLoader(
|
75
|
+
{
|
76
|
+
integrations: {},
|
77
|
+
remotePlugins: [
|
78
|
+
{
|
79
|
+
name: 'remote plugin',
|
80
|
+
creationName: 'remote plugin',
|
81
|
+
url: 'https://cdn.hightouch-events.com/actions/file.js',
|
82
|
+
libraryName: 'testPlugin',
|
83
|
+
settings: {},
|
84
|
+
},
|
85
|
+
],
|
86
|
+
},
|
87
|
+
{},
|
88
|
+
{}
|
89
|
+
)
|
90
|
+
|
91
|
+
expect(loader.loadScript).toHaveBeenCalledWith('foo.com/actions/file.js')
|
92
|
+
})
|
93
|
+
|
94
|
+
it('should work if the cdn is staging', async () => {
|
95
|
+
const stagingURL = 'https://cdn.hightouch-events.build/actions/foo.js'
|
96
|
+
|
97
|
+
window.htevents = {}
|
98
|
+
window.htevents._cdn = 'foo.com'
|
99
|
+
await remoteLoader(
|
100
|
+
{
|
101
|
+
integrations: {},
|
102
|
+
remotePlugins: [
|
103
|
+
{
|
104
|
+
name: 'remote plugin',
|
105
|
+
creationName: 'remote plugin',
|
106
|
+
url: stagingURL,
|
107
|
+
libraryName: 'testPlugin',
|
108
|
+
settings: {},
|
109
|
+
},
|
110
|
+
],
|
111
|
+
},
|
112
|
+
{},
|
113
|
+
{}
|
114
|
+
)
|
115
|
+
|
116
|
+
expect(loader.loadScript).toHaveBeenCalledWith('foo.com/actions/foo.js')
|
117
|
+
})
|
118
|
+
|
119
|
+
it('should attempt calling the library', async () => {
|
120
|
+
await remoteLoader(
|
121
|
+
{
|
122
|
+
integrations: {},
|
123
|
+
remotePlugins: [
|
124
|
+
{
|
125
|
+
name: 'remote plugin',
|
126
|
+
creationName: 'remote plugin',
|
127
|
+
url: 'cdn/path/to/file.js',
|
128
|
+
libraryName: 'testPlugin',
|
129
|
+
settings: {
|
130
|
+
name: 'Charlie Brown',
|
131
|
+
},
|
132
|
+
},
|
133
|
+
],
|
134
|
+
},
|
135
|
+
{},
|
136
|
+
{}
|
137
|
+
)
|
138
|
+
|
139
|
+
expect(pluginFactory).toHaveBeenCalledTimes(1)
|
140
|
+
expect(pluginFactory).toHaveBeenCalledWith(
|
141
|
+
expect.objectContaining({
|
142
|
+
name: 'Charlie Brown',
|
143
|
+
})
|
144
|
+
)
|
145
|
+
})
|
146
|
+
|
147
|
+
it('should load from given plugin sources before loading from CDN', async () => {
|
148
|
+
const brazeSpy = jest.spyOn({ braze }, 'braze')
|
149
|
+
;(brazeSpy as any).pluginName = braze.pluginName
|
150
|
+
|
151
|
+
await remoteLoader(
|
152
|
+
{
|
153
|
+
integrations: {},
|
154
|
+
remotePlugins: [
|
155
|
+
{
|
156
|
+
name: 'Braze Web Mode (Actions)',
|
157
|
+
creationName: 'Braze Web Mode (Actions)',
|
158
|
+
libraryName: 'brazeDestination',
|
159
|
+
url: 'https://cdn.hightouch-events.com/next-integrations/actions/braze/a6f95f5869852b848386.js',
|
160
|
+
settings: {
|
161
|
+
api_key: 'test-api-key',
|
162
|
+
versionSettings: {
|
163
|
+
componentTypes: [],
|
164
|
+
},
|
165
|
+
subscriptions: [
|
166
|
+
{
|
167
|
+
id: '3thVuvYKBcEGKEZA185Tbs',
|
168
|
+
name: 'Track Calls',
|
169
|
+
enabled: true,
|
170
|
+
partnerAction: 'trackEvent',
|
171
|
+
subscribe: 'type = "track" and event != "Order Completed"',
|
172
|
+
mapping: {
|
173
|
+
eventName: {
|
174
|
+
'@path': '$.event',
|
175
|
+
},
|
176
|
+
eventProperties: {
|
177
|
+
'@path': '$.properties',
|
178
|
+
},
|
179
|
+
},
|
180
|
+
},
|
181
|
+
],
|
182
|
+
},
|
183
|
+
},
|
184
|
+
],
|
185
|
+
},
|
186
|
+
{},
|
187
|
+
{},
|
188
|
+
false,
|
189
|
+
undefined,
|
190
|
+
[brazeSpy as unknown as PluginFactory]
|
191
|
+
)
|
192
|
+
|
193
|
+
expect(brazeSpy).toHaveBeenCalledTimes(1)
|
194
|
+
expect(brazeSpy).toHaveBeenCalledWith(
|
195
|
+
expect.objectContaining({
|
196
|
+
api_key: 'test-api-key',
|
197
|
+
})
|
198
|
+
)
|
199
|
+
})
|
200
|
+
|
201
|
+
it('should not load remote plugins when integrations object contains all: false', async () => {
|
202
|
+
await remoteLoader(
|
203
|
+
{
|
204
|
+
integrations: {},
|
205
|
+
remotePlugins: [
|
206
|
+
{
|
207
|
+
name: 'remote plugin',
|
208
|
+
creationName: 'remote plugin',
|
209
|
+
url: 'cdn/path/to/file.js',
|
210
|
+
libraryName: 'testPlugin',
|
211
|
+
settings: {
|
212
|
+
name: 'Charlie Brown',
|
213
|
+
},
|
214
|
+
},
|
215
|
+
],
|
216
|
+
},
|
217
|
+
{ All: false },
|
218
|
+
{}
|
219
|
+
)
|
220
|
+
|
221
|
+
expect(pluginFactory).toHaveBeenCalledTimes(0)
|
222
|
+
})
|
223
|
+
|
224
|
+
it('should load remote plugins when integrations object contains all: false but plugin: true', async () => {
|
225
|
+
await remoteLoader(
|
226
|
+
{
|
227
|
+
integrations: {},
|
228
|
+
remotePlugins: [
|
229
|
+
{
|
230
|
+
name: 'remote plugin',
|
231
|
+
creationName: 'remote plugin',
|
232
|
+
url: 'cdn/path/to/file.js',
|
233
|
+
libraryName: 'testPlugin',
|
234
|
+
settings: {
|
235
|
+
name: 'Charlie Brown',
|
236
|
+
},
|
237
|
+
},
|
238
|
+
],
|
239
|
+
},
|
240
|
+
{ All: false, 'remote plugin': true },
|
241
|
+
{}
|
242
|
+
)
|
243
|
+
|
244
|
+
expect(pluginFactory).toHaveBeenCalledTimes(1)
|
245
|
+
expect(pluginFactory).toHaveBeenCalledWith(
|
246
|
+
expect.objectContaining({
|
247
|
+
name: 'Charlie Brown',
|
248
|
+
})
|
249
|
+
)
|
250
|
+
})
|
251
|
+
|
252
|
+
it('should load remote plugin when integrations object contains plugin: false', async () => {
|
253
|
+
await remoteLoader(
|
254
|
+
{
|
255
|
+
integrations: {},
|
256
|
+
remotePlugins: [
|
257
|
+
{
|
258
|
+
name: 'remote plugin',
|
259
|
+
creationName: 'remote plugin',
|
260
|
+
url: 'cdn/path/to/file.js',
|
261
|
+
libraryName: 'testPlugin',
|
262
|
+
settings: {
|
263
|
+
name: 'Charlie Brown',
|
264
|
+
},
|
265
|
+
},
|
266
|
+
],
|
267
|
+
},
|
268
|
+
{ 'remote plugin': false },
|
269
|
+
{}
|
270
|
+
)
|
271
|
+
|
272
|
+
expect(pluginFactory).toHaveBeenCalledTimes(0)
|
273
|
+
})
|
274
|
+
|
275
|
+
it('should skip remote plugins that arent callable functions', async () => {
|
276
|
+
const plugins = await remoteLoader(
|
277
|
+
{
|
278
|
+
integrations: {},
|
279
|
+
remotePlugins: [
|
280
|
+
{
|
281
|
+
name: 'remote plugin',
|
282
|
+
creationName: 'remote plugin',
|
283
|
+
url: 'cdn/path/to/file.js',
|
284
|
+
libraryName: 'this wont resolve',
|
285
|
+
settings: {},
|
286
|
+
},
|
287
|
+
],
|
288
|
+
},
|
289
|
+
{},
|
290
|
+
{}
|
291
|
+
)
|
292
|
+
|
293
|
+
expect(pluginFactory).not.toHaveBeenCalled()
|
294
|
+
expect(plugins).toHaveLength(0)
|
295
|
+
})
|
296
|
+
|
297
|
+
it('should return all plugins resolved remotely', async () => {
|
298
|
+
const one = {
|
299
|
+
name: 'one',
|
300
|
+
version: '1.0.0',
|
301
|
+
type: 'before',
|
302
|
+
load: () => {},
|
303
|
+
isLoaded: () => true,
|
304
|
+
}
|
305
|
+
const two = {
|
306
|
+
name: 'two',
|
307
|
+
version: '1.0.0',
|
308
|
+
type: 'before',
|
309
|
+
load: () => {},
|
310
|
+
isLoaded: () => true,
|
311
|
+
}
|
312
|
+
const three = {
|
313
|
+
name: 'three',
|
314
|
+
version: '1.0.0',
|
315
|
+
type: 'enrichment',
|
316
|
+
load: () => {},
|
317
|
+
isLoaded: () => true,
|
318
|
+
}
|
319
|
+
|
320
|
+
const multiPluginFactory = jest.fn().mockImplementation(() => [one, two])
|
321
|
+
const singlePluginFactory = jest.fn().mockImplementation(() => three)
|
322
|
+
|
323
|
+
// @ts-expect-error not gonna return a script tag sorry
|
324
|
+
jest.spyOn(loader, 'loadScript').mockImplementation((url: string) => {
|
325
|
+
if (url === 'multiple-plugins.js') {
|
326
|
+
window['multiple-plugins'] = multiPluginFactory
|
327
|
+
} else {
|
328
|
+
window['single-plugin'] = singlePluginFactory
|
329
|
+
}
|
330
|
+
return Promise.resolve(true)
|
331
|
+
})
|
332
|
+
|
333
|
+
const plugins = await remoteLoader(
|
334
|
+
{
|
335
|
+
integrations: {},
|
336
|
+
remotePlugins: [
|
337
|
+
{
|
338
|
+
name: 'multiple plugins',
|
339
|
+
creationName: 'multiple plugins',
|
340
|
+
url: 'multiple-plugins.js',
|
341
|
+
libraryName: 'multiple-plugins',
|
342
|
+
settings: { foo: true },
|
343
|
+
},
|
344
|
+
{
|
345
|
+
name: 'single plugin',
|
346
|
+
creationName: 'single plugin',
|
347
|
+
url: 'single-plugin.js',
|
348
|
+
libraryName: 'single-plugin',
|
349
|
+
settings: { bar: false },
|
350
|
+
},
|
351
|
+
],
|
352
|
+
},
|
353
|
+
{},
|
354
|
+
{}
|
355
|
+
)
|
356
|
+
|
357
|
+
expect(plugins).toHaveLength(3)
|
358
|
+
expect(plugins).toEqual(
|
359
|
+
expect.arrayContaining([
|
360
|
+
{
|
361
|
+
action: one,
|
362
|
+
name: 'multiple plugins',
|
363
|
+
version: '1.0.0',
|
364
|
+
type: 'before',
|
365
|
+
alternativeNames: ['one'],
|
366
|
+
middleware: [],
|
367
|
+
track: expect.any(Function),
|
368
|
+
alias: expect.any(Function),
|
369
|
+
group: expect.any(Function),
|
370
|
+
identify: expect.any(Function),
|
371
|
+
page: expect.any(Function),
|
372
|
+
screen: expect.any(Function),
|
373
|
+
},
|
374
|
+
{
|
375
|
+
action: two,
|
376
|
+
name: 'multiple plugins',
|
377
|
+
version: '1.0.0',
|
378
|
+
type: 'before',
|
379
|
+
alternativeNames: ['two'],
|
380
|
+
middleware: [],
|
381
|
+
track: expect.any(Function),
|
382
|
+
alias: expect.any(Function),
|
383
|
+
group: expect.any(Function),
|
384
|
+
identify: expect.any(Function),
|
385
|
+
page: expect.any(Function),
|
386
|
+
screen: expect.any(Function),
|
387
|
+
},
|
388
|
+
{
|
389
|
+
action: three,
|
390
|
+
name: 'single plugin',
|
391
|
+
version: '1.0.0',
|
392
|
+
type: 'enrichment',
|
393
|
+
alternativeNames: ['three'],
|
394
|
+
middleware: [],
|
395
|
+
track: expect.any(Function),
|
396
|
+
alias: expect.any(Function),
|
397
|
+
group: expect.any(Function),
|
398
|
+
identify: expect.any(Function),
|
399
|
+
page: expect.any(Function),
|
400
|
+
screen: expect.any(Function),
|
401
|
+
},
|
402
|
+
])
|
403
|
+
)
|
404
|
+
expect(multiPluginFactory).toHaveBeenCalledWith({ foo: true })
|
405
|
+
expect(singlePluginFactory).toHaveBeenCalledWith({ bar: false })
|
406
|
+
})
|
407
|
+
|
408
|
+
it('should ignore plugins that fail to initialize', async () => {
|
409
|
+
// @ts-expect-error not gonna return a script tag sorry
|
410
|
+
jest.spyOn(loader, 'loadScript').mockImplementation((url: string) => {
|
411
|
+
window['flaky'] = (): never => {
|
412
|
+
throw Error('aaay')
|
413
|
+
}
|
414
|
+
|
415
|
+
window['asyncFlaky'] = async (): Promise<never> => {
|
416
|
+
throw Error('aaay')
|
417
|
+
}
|
418
|
+
|
419
|
+
return Promise.resolve(true)
|
420
|
+
})
|
421
|
+
|
422
|
+
const plugins = await remoteLoader(
|
423
|
+
{
|
424
|
+
integrations: {},
|
425
|
+
remotePlugins: [
|
426
|
+
{
|
427
|
+
name: 'flaky plugin',
|
428
|
+
creationName: 'flaky plugin',
|
429
|
+
url: 'cdn/path/to/flaky.js',
|
430
|
+
libraryName: 'flaky',
|
431
|
+
settings: {},
|
432
|
+
},
|
433
|
+
{
|
434
|
+
name: 'async flaky plugin',
|
435
|
+
creationName: 'async flaky plugin',
|
436
|
+
url: 'cdn/path/to/asyncFlaky.js',
|
437
|
+
libraryName: 'asyncFlaky',
|
438
|
+
settings: {},
|
439
|
+
},
|
440
|
+
],
|
441
|
+
},
|
442
|
+
{},
|
443
|
+
{}
|
444
|
+
)
|
445
|
+
|
446
|
+
expect(pluginFactory).not.toHaveBeenCalled()
|
447
|
+
expect(plugins).toHaveLength(0)
|
448
|
+
expect(console.warn).toHaveBeenCalledTimes(2)
|
449
|
+
})
|
450
|
+
|
451
|
+
it('ignores invalid plugins', async () => {
|
452
|
+
const invalidPlugin = {
|
453
|
+
name: 'invalid',
|
454
|
+
version: '1.0.0',
|
455
|
+
}
|
456
|
+
|
457
|
+
const validPlugin = {
|
458
|
+
name: 'valid',
|
459
|
+
version: '1.0.0',
|
460
|
+
type: 'enrichment',
|
461
|
+
load: () => {},
|
462
|
+
isLoaded: () => true,
|
463
|
+
}
|
464
|
+
|
465
|
+
// @ts-expect-error not gonna return a script tag sorry
|
466
|
+
jest.spyOn(loader, 'loadScript').mockImplementation((url: string) => {
|
467
|
+
if (url === 'valid') {
|
468
|
+
window['valid'] = jest.fn().mockImplementation(() => validPlugin)
|
469
|
+
} else {
|
470
|
+
window['invalid'] = jest.fn().mockImplementation(() => invalidPlugin)
|
471
|
+
}
|
472
|
+
|
473
|
+
return Promise.resolve(true)
|
474
|
+
})
|
475
|
+
|
476
|
+
const plugins = await remoteLoader(
|
477
|
+
{
|
478
|
+
integrations: {},
|
479
|
+
remotePlugins: [
|
480
|
+
{
|
481
|
+
name: 'valid plugin',
|
482
|
+
creationName: 'valid plugin',
|
483
|
+
url: 'valid',
|
484
|
+
libraryName: 'valid',
|
485
|
+
settings: { foo: true },
|
486
|
+
},
|
487
|
+
{
|
488
|
+
name: 'invalid plugin',
|
489
|
+
creationName: 'invalid plugin',
|
490
|
+
url: 'invalid',
|
491
|
+
libraryName: 'invalid',
|
492
|
+
settings: { bar: false },
|
493
|
+
},
|
494
|
+
],
|
495
|
+
},
|
496
|
+
{},
|
497
|
+
{}
|
498
|
+
)
|
499
|
+
|
500
|
+
expect(plugins).toHaveLength(1)
|
501
|
+
expect(plugins).toEqual(
|
502
|
+
expect.arrayContaining([
|
503
|
+
{
|
504
|
+
action: validPlugin,
|
505
|
+
name: 'valid plugin',
|
506
|
+
version: '1.0.0',
|
507
|
+
type: 'enrichment',
|
508
|
+
alternativeNames: ['valid'],
|
509
|
+
middleware: [],
|
510
|
+
track: expect.any(Function),
|
511
|
+
alias: expect.any(Function),
|
512
|
+
group: expect.any(Function),
|
513
|
+
identify: expect.any(Function),
|
514
|
+
page: expect.any(Function),
|
515
|
+
screen: expect.any(Function),
|
516
|
+
},
|
517
|
+
])
|
518
|
+
)
|
519
|
+
expect(console.warn).toHaveBeenCalledTimes(1)
|
520
|
+
})
|
521
|
+
|
522
|
+
it('accepts settings overrides from merged integrations', async () => {
|
523
|
+
const cdnSettings: LegacySettings = {
|
524
|
+
integrations: {
|
525
|
+
remotePlugin: {
|
526
|
+
name: 'Charlie Brown',
|
527
|
+
version: '1.0',
|
528
|
+
},
|
529
|
+
},
|
530
|
+
remotePlugins: [
|
531
|
+
{
|
532
|
+
name: 'remotePlugin',
|
533
|
+
creationName: 'remotePlugin',
|
534
|
+
libraryName: 'testPlugin',
|
535
|
+
url: 'cdn/path/to/file.js',
|
536
|
+
settings: {
|
537
|
+
name: 'Charlie Brown',
|
538
|
+
version: '1.0',
|
539
|
+
subscriptions: [],
|
540
|
+
},
|
541
|
+
},
|
542
|
+
],
|
543
|
+
}
|
544
|
+
|
545
|
+
const userOverrides = {
|
546
|
+
remotePlugin: {
|
547
|
+
name: 'Chris Radek',
|
548
|
+
},
|
549
|
+
}
|
550
|
+
|
551
|
+
await remoteLoader(cdnSettings, userOverrides, {
|
552
|
+
remotePlugin: {
|
553
|
+
...cdnSettings.integrations.remotePlugin,
|
554
|
+
...userOverrides.remotePlugin,
|
555
|
+
},
|
556
|
+
})
|
557
|
+
|
558
|
+
expect(pluginFactory).toHaveBeenCalledTimes(1)
|
559
|
+
expect(pluginFactory).toHaveBeenCalledWith(
|
560
|
+
expect.objectContaining({
|
561
|
+
name: 'Chris Radek',
|
562
|
+
version: '1.0',
|
563
|
+
subscriptions: [],
|
564
|
+
})
|
565
|
+
)
|
566
|
+
})
|
567
|
+
|
568
|
+
it('accepts settings overrides from options (HtEventsBrowser)', async () => {
|
569
|
+
const cdnSettings = {
|
570
|
+
integrations: {
|
571
|
+
remotePlugin: {
|
572
|
+
name: 'Charlie Brown',
|
573
|
+
version: '1.0',
|
574
|
+
},
|
575
|
+
},
|
576
|
+
remotePlugins: [
|
577
|
+
{
|
578
|
+
name: 'remotePlugin',
|
579
|
+
creationName: 'remotePlugin',
|
580
|
+
libraryName: 'testPlugin',
|
581
|
+
url: 'cdn/path/to/file.js',
|
582
|
+
settings: {
|
583
|
+
name: 'Charlie Brown',
|
584
|
+
version: '1.0',
|
585
|
+
subscriptions: [],
|
586
|
+
},
|
587
|
+
},
|
588
|
+
],
|
589
|
+
}
|
590
|
+
|
591
|
+
const initOptions: InitOptions = {
|
592
|
+
integrations: {
|
593
|
+
remotePlugin: {
|
594
|
+
name: 'Chris Radek',
|
595
|
+
},
|
596
|
+
},
|
597
|
+
}
|
598
|
+
|
599
|
+
await HtEventsBrowser.load(
|
600
|
+
{
|
601
|
+
writeKey: 'key',
|
602
|
+
cdnSettings,
|
603
|
+
},
|
604
|
+
initOptions
|
605
|
+
)
|
606
|
+
|
607
|
+
expect(pluginFactory).toHaveBeenCalledTimes(1)
|
608
|
+
expect(pluginFactory).toHaveBeenCalledWith(
|
609
|
+
expect.objectContaining({
|
610
|
+
name: 'Chris Radek',
|
611
|
+
version: '1.0',
|
612
|
+
subscriptions: [],
|
613
|
+
})
|
614
|
+
)
|
615
|
+
})
|
616
|
+
|
617
|
+
// Action destinations should be toggled using the `integration` name which matches the `creationName`
|
618
|
+
// Most action destinations have the same value for creationName and name, but a few (Amplitude) do not.
|
619
|
+
// Continue to support toggling with plugin.name for backwards compatibility.
|
620
|
+
it('loads destinations when `All: false` but is enabled (pluginName)', async () => {
|
621
|
+
const cdnSettings = {
|
622
|
+
integrations: {
|
623
|
+
oldValidName: {
|
624
|
+
versionSettings: {
|
625
|
+
componentTypes: [],
|
626
|
+
},
|
627
|
+
},
|
628
|
+
},
|
629
|
+
remotePlugins: [
|
630
|
+
{
|
631
|
+
name: 'valid',
|
632
|
+
creationName: 'oldValidName',
|
633
|
+
url: 'cdn/path/to/file.js',
|
634
|
+
libraryName: 'testPlugin',
|
635
|
+
settings: {
|
636
|
+
subscriptions: [],
|
637
|
+
versionSettings: {
|
638
|
+
componentTypes: [],
|
639
|
+
},
|
640
|
+
},
|
641
|
+
},
|
642
|
+
],
|
643
|
+
}
|
644
|
+
|
645
|
+
await HtEventsBrowser.load(
|
646
|
+
{ writeKey: '', cdnSettings },
|
647
|
+
{
|
648
|
+
integrations: {
|
649
|
+
All: false,
|
650
|
+
valid: true,
|
651
|
+
},
|
652
|
+
}
|
653
|
+
)
|
654
|
+
|
655
|
+
expect(pluginFactory).toHaveBeenCalledTimes(1)
|
656
|
+
expect(pluginFactory).toHaveBeenCalledWith(
|
657
|
+
expect.objectContaining(cdnSettings.remotePlugins[0].settings)
|
658
|
+
)
|
659
|
+
})
|
660
|
+
|
661
|
+
it('loads destinations when `All: false` but is enabled (creationName)', async () => {
|
662
|
+
const cdnSettings = {
|
663
|
+
integrations: {
|
664
|
+
oldValidName: {
|
665
|
+
versionSettings: {
|
666
|
+
componentTypes: [],
|
667
|
+
},
|
668
|
+
},
|
669
|
+
},
|
670
|
+
remotePlugins: [
|
671
|
+
{
|
672
|
+
name: 'valid',
|
673
|
+
creationName: 'oldValidName',
|
674
|
+
url: 'cdn/path/to/file.js',
|
675
|
+
libraryName: 'testPlugin',
|
676
|
+
settings: {
|
677
|
+
subscriptions: [],
|
678
|
+
versionSettings: {
|
679
|
+
componentTypes: [],
|
680
|
+
},
|
681
|
+
},
|
682
|
+
},
|
683
|
+
],
|
684
|
+
}
|
685
|
+
|
686
|
+
await HtEventsBrowser.load(
|
687
|
+
{ writeKey: '', cdnSettings },
|
688
|
+
{
|
689
|
+
integrations: {
|
690
|
+
All: false,
|
691
|
+
oldValidName: true,
|
692
|
+
},
|
693
|
+
}
|
694
|
+
)
|
695
|
+
|
696
|
+
expect(pluginFactory).toHaveBeenCalledTimes(1)
|
697
|
+
expect(pluginFactory).toHaveBeenCalledWith(
|
698
|
+
expect.objectContaining(cdnSettings.remotePlugins[0].settings)
|
699
|
+
)
|
700
|
+
})
|
701
|
+
|
702
|
+
it('does not load destinations when disabled via pluginName', async () => {
|
703
|
+
const cdnSettings = {
|
704
|
+
integrations: {
|
705
|
+
oldValidName: {
|
706
|
+
versionSettings: {
|
707
|
+
componentTypes: [],
|
708
|
+
},
|
709
|
+
},
|
710
|
+
},
|
711
|
+
remotePlugins: [
|
712
|
+
{
|
713
|
+
name: 'valid',
|
714
|
+
creationName: 'oldValidName',
|
715
|
+
url: 'cdn/path/to/file.js',
|
716
|
+
libraryName: 'testPlugin',
|
717
|
+
settings: {
|
718
|
+
subscriptions: [],
|
719
|
+
versionSettings: {
|
720
|
+
componentTypes: [],
|
721
|
+
},
|
722
|
+
},
|
723
|
+
},
|
724
|
+
],
|
725
|
+
}
|
726
|
+
|
727
|
+
await HtEventsBrowser.load(
|
728
|
+
{ writeKey: '', cdnSettings },
|
729
|
+
{
|
730
|
+
integrations: {
|
731
|
+
All: true,
|
732
|
+
valid: false,
|
733
|
+
},
|
734
|
+
}
|
735
|
+
)
|
736
|
+
|
737
|
+
expect(pluginFactory).toHaveBeenCalledTimes(0)
|
738
|
+
})
|
739
|
+
|
740
|
+
it('does not load destinations when disabled via creationName', async () => {
|
741
|
+
const cdnSettings = {
|
742
|
+
integrations: {
|
743
|
+
oldValidName: {
|
744
|
+
versionSettings: {
|
745
|
+
componentTypes: [],
|
746
|
+
},
|
747
|
+
},
|
748
|
+
},
|
749
|
+
remotePlugins: [
|
750
|
+
{
|
751
|
+
name: 'valid',
|
752
|
+
creationName: 'oldValidName',
|
753
|
+
url: 'cdn/path/to/file.js',
|
754
|
+
libraryName: 'testPlugin',
|
755
|
+
settings: {
|
756
|
+
subscriptions: [],
|
757
|
+
versionSettings: {
|
758
|
+
componentTypes: [],
|
759
|
+
},
|
760
|
+
},
|
761
|
+
},
|
762
|
+
],
|
763
|
+
}
|
764
|
+
|
765
|
+
await HtEventsBrowser.load(
|
766
|
+
{ writeKey: '', cdnSettings },
|
767
|
+
{
|
768
|
+
integrations: {
|
769
|
+
All: true,
|
770
|
+
oldValidName: false,
|
771
|
+
},
|
772
|
+
}
|
773
|
+
)
|
774
|
+
|
775
|
+
expect(pluginFactory).toHaveBeenCalledTimes(0)
|
776
|
+
})
|
777
|
+
|
778
|
+
it('applies remote routing rules based on creation name', async () => {
|
779
|
+
const validPlugin = {
|
780
|
+
name: 'valid',
|
781
|
+
version: '1.0.0',
|
782
|
+
type: 'destination',
|
783
|
+
load: () => {},
|
784
|
+
isLoaded: () => true,
|
785
|
+
track: (ctx: Context) => ctx,
|
786
|
+
}
|
787
|
+
|
788
|
+
const cdnSettings: LegacySettings = {
|
789
|
+
integrations: {},
|
790
|
+
middlewareSettings: {
|
791
|
+
routingRules: [
|
792
|
+
{
|
793
|
+
matchers: [
|
794
|
+
{
|
795
|
+
ir: '["=","event",{"value":"Item Impression"}]',
|
796
|
+
type: 'fql',
|
797
|
+
},
|
798
|
+
],
|
799
|
+
scope: 'destinations',
|
800
|
+
target_type: 'workspace::project::destination::config',
|
801
|
+
transformers: [[{ type: 'drop' }]],
|
802
|
+
destinationName: 'oldValidName',
|
803
|
+
},
|
804
|
+
],
|
805
|
+
},
|
806
|
+
remotePlugins: [
|
807
|
+
{
|
808
|
+
name: 'valid',
|
809
|
+
creationName: 'oldValidName',
|
810
|
+
url: 'valid',
|
811
|
+
libraryName: 'valid',
|
812
|
+
settings: { foo: true },
|
813
|
+
},
|
814
|
+
],
|
815
|
+
}
|
816
|
+
|
817
|
+
// @ts-expect-error not gonna return a script tag sorry
|
818
|
+
jest.spyOn(loader, 'loadScript').mockImplementation((url: string) => {
|
819
|
+
if (url === 'valid') {
|
820
|
+
window['valid'] = jest.fn().mockImplementation(() => validPlugin)
|
821
|
+
}
|
822
|
+
|
823
|
+
return Promise.resolve(true)
|
824
|
+
})
|
825
|
+
|
826
|
+
const middleware = tsubMiddleware(
|
827
|
+
cdnSettings.middlewareSettings!.routingRules
|
828
|
+
)
|
829
|
+
|
830
|
+
const plugins = await remoteLoader(cdnSettings, {}, {}, false, middleware)
|
831
|
+
const plugin = plugins[0]
|
832
|
+
await expect(() =>
|
833
|
+
plugin.track!(new Context({ type: 'track', event: 'Item Impression' }))
|
834
|
+
).rejects.toMatchInlineSnapshot(`
|
835
|
+
ContextCancelation {
|
836
|
+
"reason": "dropped by destination middleware",
|
837
|
+
"retry": false,
|
838
|
+
"type": "plugin Error",
|
839
|
+
}
|
840
|
+
`)
|
841
|
+
})
|
842
|
+
|
843
|
+
it('only applies destination middleware to destination actions', async () => {
|
844
|
+
const validPlugin = {
|
845
|
+
name: 'valid',
|
846
|
+
version: '1.0.0',
|
847
|
+
type: 'enrichment',
|
848
|
+
load: () => {},
|
849
|
+
isLoaded: () => true,
|
850
|
+
track: (ctx: Context) => ctx,
|
851
|
+
}
|
852
|
+
|
853
|
+
const cdnSettings: LegacySettings = {
|
854
|
+
integrations: {},
|
855
|
+
middlewareSettings: {
|
856
|
+
routingRules: [
|
857
|
+
{
|
858
|
+
matchers: [
|
859
|
+
{
|
860
|
+
ir: '["=","event",{"value":"Item Impression"}]',
|
861
|
+
type: 'fql',
|
862
|
+
},
|
863
|
+
],
|
864
|
+
scope: 'destinations',
|
865
|
+
target_type: 'workspace::project::destination::config',
|
866
|
+
transformers: [[{ type: 'drop' }]],
|
867
|
+
destinationName: 'oldValidName',
|
868
|
+
},
|
869
|
+
],
|
870
|
+
},
|
871
|
+
remotePlugins: [
|
872
|
+
{
|
873
|
+
name: 'valid',
|
874
|
+
creationName: 'oldValidName',
|
875
|
+
url: 'valid',
|
876
|
+
libraryName: 'valid',
|
877
|
+
settings: { foo: true },
|
878
|
+
},
|
879
|
+
],
|
880
|
+
}
|
881
|
+
|
882
|
+
// @ts-expect-error not gonna return a script tag sorry
|
883
|
+
jest.spyOn(loader, 'loadScript').mockImplementation((url: string) => {
|
884
|
+
if (url === 'valid') {
|
885
|
+
window['valid'] = jest.fn().mockImplementation(() => validPlugin)
|
886
|
+
}
|
887
|
+
|
888
|
+
return Promise.resolve(true)
|
889
|
+
})
|
890
|
+
|
891
|
+
const middleware = jest.fn().mockImplementation(() => true)
|
892
|
+
|
893
|
+
const plugins = await remoteLoader(cdnSettings, {}, {}, false, middleware)
|
894
|
+
const plugin = plugins[0] as ActionDestination
|
895
|
+
plugin.addMiddleware(middleware)
|
896
|
+
await plugin.track(new Context({ type: 'track' }))
|
897
|
+
expect(middleware).not.toHaveBeenCalled()
|
898
|
+
})
|
899
|
+
|
900
|
+
it('non destination type plugins can modify the context', async () => {
|
901
|
+
const validPlugin = {
|
902
|
+
name: 'valid',
|
903
|
+
version: '1.0.0',
|
904
|
+
type: 'enrichment',
|
905
|
+
load: () => {},
|
906
|
+
isLoaded: () => true,
|
907
|
+
track: (ctx: Context) => {
|
908
|
+
ctx.event.name += 'bar'
|
909
|
+
return ctx
|
910
|
+
},
|
911
|
+
}
|
912
|
+
|
913
|
+
const cdnSettings: LegacySettings = {
|
914
|
+
integrations: {},
|
915
|
+
remotePlugins: [
|
916
|
+
{
|
917
|
+
name: 'valid',
|
918
|
+
creationName: 'valid',
|
919
|
+
url: 'valid',
|
920
|
+
libraryName: 'valid',
|
921
|
+
settings: { foo: true },
|
922
|
+
},
|
923
|
+
],
|
924
|
+
}
|
925
|
+
|
926
|
+
// @ts-expect-error not gonna return a script tag sorry
|
927
|
+
jest.spyOn(loader, 'loadScript').mockImplementation((url: string) => {
|
928
|
+
if (url === 'valid') {
|
929
|
+
window['valid'] = jest.fn().mockImplementation(() => validPlugin)
|
930
|
+
}
|
931
|
+
|
932
|
+
return Promise.resolve(true)
|
933
|
+
})
|
934
|
+
|
935
|
+
const plugins = await remoteLoader(cdnSettings, {}, {}, false)
|
936
|
+
const plugin = plugins[0] as ActionDestination
|
937
|
+
const newCtx = await plugin.track(
|
938
|
+
new Context({ type: 'track', name: 'foo' })
|
939
|
+
)
|
940
|
+
|
941
|
+
expect(newCtx.event.name).toEqual('foobar')
|
942
|
+
})
|
943
|
+
})
|