@ht-sdks/events-sdk-react-native-plugin-destination-filters 1.0.5

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 ADDED
@@ -0,0 +1,45 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Hightouch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ ---
24
+
25
+ MIT License
26
+
27
+ Copyright (c) 2020 Segment
28
+
29
+ Permission is hereby granted, free of charge, to any person obtaining a copy
30
+ of this software and associated documentation files (the "Software"), to deal
31
+ in the Software without restriction, including without limitation the rights
32
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
33
+ copies of the Software, and to permit persons to whom the Software is
34
+ furnished to do so, subject to the following conditions:
35
+
36
+ The above copyright notice and this permission notice shall be included in all
37
+ copies or substantial portions of the Software.
38
+
39
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
45
+ SOFTWARE.
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DestinationFiltersPlugin = void 0;
7
+ var _eventsSdkReactNative = require("@ht-sdks/events-sdk-react-native");
8
+ var tsub = _interopRequireWildcard(require("@segment/tsub"));
9
+ var _clone = _interopRequireDefault(require("clone"));
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
+ const WORKSPACE_DESTINATION_FILTER_KEY = '';
14
+
15
+ /**
16
+ * Adds processing for Destination Filters
17
+ * (https://hightouch.com/docs/connections/destinations/destination-filters/)
18
+ * to work on device mode destinations
19
+ */
20
+ class DestinationFiltersPlugin extends _eventsSdkReactNative.UtilityPlugin {
21
+ type = _eventsSdkReactNative.PluginType.before;
22
+ constructor(destination) {
23
+ super();
24
+ this.key = destination;
25
+ }
26
+ addToPlugin = plugin => {
27
+ if (plugin.type === _eventsSdkReactNative.PluginType.destination) {
28
+ const destination = plugin;
29
+ destination.add(new DestinationFiltersPlugin(destination.key));
30
+ }
31
+ };
32
+ configure(analytics) {
33
+ super.configure(analytics);
34
+ if (this.key === undefined) {
35
+ // We watch for new destination plugins being added to inject a
36
+ // destination filter instance for them
37
+ analytics.onPluginLoaded(this.addToPlugin);
38
+ // We also inject an instance for each plugin already loaded
39
+ analytics.getPlugins(_eventsSdkReactNative.PluginType.destination).forEach(this.addToPlugin);
40
+ }
41
+ const key = this.key ?? WORKSPACE_DESTINATION_FILTER_KEY;
42
+ this.filter = analytics.filters.get()?.[key];
43
+ this.filtersUnsubscribe?.();
44
+ this.filtersUnsubscribe = analytics.filters.onChange(filters => {
45
+ this.filter = filters?.[key];
46
+ });
47
+ }
48
+ execute(event) {
49
+ if (this.filter === undefined) {
50
+ return event;
51
+ }
52
+ const {
53
+ matchers,
54
+ transformers
55
+ } = this.filter;
56
+ let transformedEvent;
57
+ for (let i = 0; i < matchers.length; i++) {
58
+ if (tsub.matches(event, matchers[i])) {
59
+ // We have to deep clone the event as the tsub transform modifies the event in place
60
+ if (transformedEvent === undefined) {
61
+ transformedEvent = (0, _clone.default)(event);
62
+ }
63
+ const newEvent = tsub.transform(transformedEvent, transformers[i]);
64
+ if (newEvent === undefined || newEvent === null || !(0, _eventsSdkReactNative.isObject)(newEvent)) {
65
+ return undefined;
66
+ }
67
+ transformedEvent = newEvent;
68
+ }
69
+ }
70
+ return transformedEvent ?? event;
71
+ }
72
+ }
73
+ exports.DestinationFiltersPlugin = DestinationFiltersPlugin;
74
+ //# sourceMappingURL=DestinationFilters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_eventsSdkReactNative","require","tsub","_interopRequireWildcard","_clone","_interopRequireDefault","obj","__esModule","default","_getRequireWildcardCache","e","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","WORKSPACE_DESTINATION_FILTER_KEY","DestinationFiltersPlugin","UtilityPlugin","type","PluginType","before","constructor","destination","key","addToPlugin","plugin","add","configure","analytics","undefined","onPluginLoaded","getPlugins","forEach","filter","filters","filtersUnsubscribe","onChange","execute","event","matchers","transformers","transformedEvent","length","matches","clone","newEvent","transform","isObject","exports"],"sourceRoot":"../../src","sources":["DestinationFilters.ts"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,OAAA;AAWA,IAAAC,IAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,MAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAA0B,SAAAI,uBAAAC,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAP,wBAAAO,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAH,UAAA,SAAAG,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAF,OAAA,EAAAE,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAC,GAAA,CAAAJ,CAAA,UAAAG,CAAA,CAAAE,GAAA,CAAAL,CAAA,OAAAM,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAZ,CAAA,oB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ACU,OAAA,CAAAhC,wBAAA,GAAAA,wBAAA"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "DestinationFiltersPlugin", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _DestinationFilters.DestinationFiltersPlugin;
10
+ }
11
+ });
12
+ var _DestinationFilters = require("./DestinationFilters");
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_DestinationFilters","require"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA"}
@@ -0,0 +1,64 @@
1
+ import { isObject, PluginType, UtilityPlugin } from '@ht-sdks/events-sdk-react-native';
2
+ import * as tsub from '@segment/tsub';
3
+ import clone from 'clone';
4
+ const WORKSPACE_DESTINATION_FILTER_KEY = '';
5
+
6
+ /**
7
+ * Adds processing for Destination Filters
8
+ * (https://hightouch.com/docs/connections/destinations/destination-filters/)
9
+ * to work on device mode destinations
10
+ */
11
+ export class DestinationFiltersPlugin extends UtilityPlugin {
12
+ type = PluginType.before;
13
+ constructor(destination) {
14
+ super();
15
+ this.key = destination;
16
+ }
17
+ addToPlugin = plugin => {
18
+ if (plugin.type === PluginType.destination) {
19
+ const destination = plugin;
20
+ destination.add(new DestinationFiltersPlugin(destination.key));
21
+ }
22
+ };
23
+ configure(analytics) {
24
+ super.configure(analytics);
25
+ if (this.key === undefined) {
26
+ // We watch for new destination plugins being added to inject a
27
+ // destination filter instance for them
28
+ analytics.onPluginLoaded(this.addToPlugin);
29
+ // We also inject an instance for each plugin already loaded
30
+ analytics.getPlugins(PluginType.destination).forEach(this.addToPlugin);
31
+ }
32
+ const key = this.key ?? WORKSPACE_DESTINATION_FILTER_KEY;
33
+ this.filter = analytics.filters.get()?.[key];
34
+ this.filtersUnsubscribe?.();
35
+ this.filtersUnsubscribe = analytics.filters.onChange(filters => {
36
+ this.filter = filters?.[key];
37
+ });
38
+ }
39
+ execute(event) {
40
+ if (this.filter === undefined) {
41
+ return event;
42
+ }
43
+ const {
44
+ matchers,
45
+ transformers
46
+ } = this.filter;
47
+ let transformedEvent;
48
+ for (let i = 0; i < matchers.length; i++) {
49
+ if (tsub.matches(event, matchers[i])) {
50
+ // We have to deep clone the event as the tsub transform modifies the event in place
51
+ if (transformedEvent === undefined) {
52
+ transformedEvent = clone(event);
53
+ }
54
+ const newEvent = tsub.transform(transformedEvent, transformers[i]);
55
+ if (newEvent === undefined || newEvent === null || !isObject(newEvent)) {
56
+ return undefined;
57
+ }
58
+ transformedEvent = newEvent;
59
+ }
60
+ }
61
+ return transformedEvent ?? event;
62
+ }
63
+ }
64
+ //# sourceMappingURL=DestinationFilters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["isObject","PluginType","UtilityPlugin","tsub","clone","WORKSPACE_DESTINATION_FILTER_KEY","DestinationFiltersPlugin","type","before","constructor","destination","key","addToPlugin","plugin","add","configure","analytics","undefined","onPluginLoaded","getPlugins","forEach","filter","filters","get","filtersUnsubscribe","onChange","execute","event","matchers","transformers","transformedEvent","i","length","matches","newEvent","transform"],"sourceRoot":"../../src","sources":["DestinationFilters.ts"],"mappings":"AAAA,SAEEA,QAAQ,EAERC,UAAU,EAIVC,aAAa,QACR,kCAAkC;AAEzC,OAAO,KAAKC,IAAI,MAAM,eAAe;AACrC,OAAOC,KAAK,MAAM,OAAO;AAEzB,MAAMC,gCAAgC,GAAG,EAAE;;AAE3C;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,wBAAwB,SAASJ,aAAa,CAAC;EAC1DK,IAAI,GAAGN,UAAU,CAACO,MAAM;EAKxBC,WAAWA,CAACC,WAAoB,EAAE;IAChC,KAAK,CAAC,CAAC;IACP,IAAI,CAACC,GAAG,GAAGD,WAAW;EACxB;EAEQE,WAAW,GAAIC,MAAc,IAAK;IACxC,IAAIA,MAAM,CAACN,IAAI,KAAKN,UA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ID,gBAAgB,KAAKb,SAAS,EAAE;UAClCa,gBAAgB,GAAG1B,KAAK,CAACuB,KAAK,CAAC;QACjC;QACA,MAAMO,QAAiB,GAAG/B,IAAI,CAACgC,SAAS,CACtCL,gBAAgB,EAChBD,YAAY,CAACE,CAAC,CAChB,CAAC;QACD,IACEG,QAAQ,KAAKjB,SAAS,IACtBiB,QAAQ,KAAK,IAAI,IACjB,CAAClC,QAAQ,CAACkC,QAAQ,CAAC,EACnB;UACA,OAAOjB,SAAS;QAClB;QACAa,gBAAgB,GAAGI,QAAqC;MAC1D;IACF;IACA,OAAOJ,gBAAgB,IAAIH,KAAK;EAClC;AACF"}
@@ -0,0 +1,2 @@
1
+ export { DestinationFiltersPlugin } from './DestinationFilters';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DestinationFiltersPlugin"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,wBAAwB,QAAQ,sBAAsB"}
@@ -0,0 +1,17 @@
1
+ import { PluginType, HightouchClient, HightouchEvent, UtilityPlugin } from '@ht-sdks/events-sdk-react-native';
2
+ /**
3
+ * Adds processing for Destination Filters
4
+ * (https://hightouch.com/docs/connections/destinations/destination-filters/)
5
+ * to work on device mode destinations
6
+ */
7
+ export declare class DestinationFiltersPlugin extends UtilityPlugin {
8
+ type: PluginType;
9
+ private key?;
10
+ private filtersUnsubscribe?;
11
+ private filter?;
12
+ constructor(destination?: string);
13
+ private addToPlugin;
14
+ configure(analytics: HightouchClient): void;
15
+ execute(event: HightouchEvent): HightouchEvent | undefined;
16
+ }
17
+ //# sourceMappingURL=DestinationFilters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DestinationFilters.d.ts","sourceRoot":"","sources":["../../../src/DestinationFilters.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,UAAU,EAEV,eAAe,EACf,cAAc,EACd,aAAa,EACd,MAAM,kCAAkC,CAAC;AAO1C;;;;GAIG;AACH,qBAAa,wBAAyB,SAAQ,aAAa;IACzD,IAAI,aAAqB;IAEzB,OAAO,CAAC,GAAG,CAAC,CAAS;IACrB,OAAO,CAAC,kBAAkB,CAAC,CAAc;IACzC,OAAO,CAAC,MAAM,CAAC,CAAc;gBACjB,WAAW,CAAC,EAAE,MAAM;IAKhC,OAAO,CAAC,WAAW,CAKjB;IAEO,SAAS,CAAC,SAAS,EAAE,eAAe;IAqB7C,OAAO,CAAC,KAAK,EAAE,cAAc;CA6B9B"}
@@ -0,0 +1,2 @@
1
+ export { DestinationFiltersPlugin } from './DestinationFilters';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@ht-sdks/events-sdk-react-native-plugin-destination-filters",
3
+ "version": "1.0.5",
4
+ "description": "The hassle-free way to add Hightouch analytics to your React-Native app.",
5
+ "main": "lib/commonjs/index",
6
+ "module": "lib/module/index",
7
+ "types": "lib/typescript/src/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "android",
14
+ "ios",
15
+ "cpp",
16
+ "hightouch-events-sdk-react-native-plugin-destination-filters.podspec",
17
+ "package.json",
18
+ "!android/build",
19
+ "!ios/build",
20
+ "!**/__tests__",
21
+ "!**/__fixtures__",
22
+ "!**/__mocks__"
23
+ ],
24
+ "scripts": {
25
+ "build": "bob build",
26
+ "test": "jest",
27
+ "typescript": "tsc --noEmit",
28
+ "clean": "rimraf lib node_modules"
29
+ },
30
+ "keywords": [
31
+ "hightouch",
32
+ "react-native",
33
+ "ios",
34
+ "android"
35
+ ],
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/ht-sdks/events-sdk-react-native.git",
39
+ "directory": "packages/plugins/plugin-destination-filters"
40
+ },
41
+ "author": "Hightouch <hello@hightouch.com> (https://hightouch.com/)",
42
+ "license": "MIT",
43
+ "bugs": {
44
+ "url": "https://github.com/ht-sdks/events-sdk-react-native/issues"
45
+ },
46
+ "homepage": "https://github.com/ht-sdks/events-sdk-react-native/tree/master/packages/plugins/plugin-destination-filters#readme",
47
+ "publishConfig": {
48
+ "registry": "https://registry.npmjs.org/"
49
+ },
50
+ "peerDependencies": {
51
+ "@ht-sdks/events-sdk-react-native": "^2.18.2",
52
+ "@ht-sdks/sovran-react-native": "*"
53
+ },
54
+ "dependencies": {
55
+ "@segment/tsub": "^2",
56
+ "clone": "^2.1.2"
57
+ },
58
+ "devDependencies": {
59
+ "@ht-sdks/analytics-rn-shared": "workspace:^",
60
+ "@ht-sdks/events-sdk-react-native": "^2.18.2",
61
+ "@ht-sdks/sovran-react-native": "^1.1.1",
62
+ "@types/clone": "^2.1.1",
63
+ "jest": "^29.7.0",
64
+ "react-native-builder-bob": "^0.23.1",
65
+ "rimraf": "^5.0.5",
66
+ "typescript": "^5.2.2"
67
+ },
68
+ "react-native-builder-bob": {
69
+ "source": "src",
70
+ "output": "lib",
71
+ "targets": [
72
+ "commonjs",
73
+ "module",
74
+ "typescript"
75
+ ]
76
+ }
77
+ }
@@ -0,0 +1,90 @@
1
+ import {
2
+ DestinationPlugin,
3
+ isObject,
4
+ Plugin,
5
+ PluginType,
6
+ RoutingRule,
7
+ HightouchClient,
8
+ HightouchEvent,
9
+ UtilityPlugin,
10
+ } from '@ht-sdks/events-sdk-react-native';
11
+ import type { Unsubscribe } from '@ht-sdks/sovran-react-native';
12
+ import * as tsub from '@segment/tsub';
13
+ import clone from 'clone';
14
+
15
+ const WORKSPACE_DESTINATION_FILTER_KEY = '';
16
+
17
+ /**
18
+ * Adds processing for Destination Filters
19
+ * (https://hightouch.com/docs/connections/destinations/destination-filters/)
20
+ * to work on device mode destinations
21
+ */
22
+ export class DestinationFiltersPlugin extends UtilityPlugin {
23
+ type = PluginType.before;
24
+
25
+ private key?: string;
26
+ private filtersUnsubscribe?: Unsubscribe;
27
+ private filter?: RoutingRule;
28
+ constructor(destination?: string) {
29
+ super();
30
+ this.key = destination;
31
+ }
32
+
33
+ private addToPlugin = (plugin: Plugin) => {
34
+ if (plugin.type === PluginType.destination) {
35
+ const destination: DestinationPlugin = plugin as DestinationPlugin;
36
+ destination.add(new DestinationFiltersPlugin(destination.key));
37
+ }
38
+ };
39
+
40
+ override configure(analytics: HightouchClient) {
41
+ super.configure(analytics);
42
+
43
+ if (this.key === undefined) {
44
+ // We watch for new destination plugins being added to inject a
45
+ // destination filter instance for them
46
+ analytics.onPluginLoaded(this.addToPlugin);
47
+ // We also inject an instance for each plugin already loaded
48
+ analytics.getPlugins(PluginType.destination).forEach(this.addToPlugin);
49
+ }
50
+
51
+ const key = this.key ?? WORKSPACE_DESTINATION_FILTER_KEY;
52
+
53
+ this.filter = analytics.filters.get()?.[key];
54
+
55
+ this.filtersUnsubscribe?.();
56
+ this.filtersUnsubscribe = analytics.filters.onChange((filters) => {
57
+ this.filter = filters?.[key];
58
+ });
59
+ }
60
+
61
+ execute(event: HightouchEvent) {
62
+ if (this.filter === undefined) {
63
+ return event;
64
+ }
65
+
66
+ const { matchers, transformers } = this.filter;
67
+ let transformedEvent: HightouchEvent | undefined;
68
+ for (let i = 0; i < matchers.length; i++) {
69
+ if (tsub.matches(event, matchers[i])) {
70
+ // We have to deep clone the event as the tsub transform modifies the event in place
71
+ if (transformedEvent === undefined) {
72
+ transformedEvent = clone(event);
73
+ }
74
+ const newEvent: unknown = tsub.transform(
75
+ transformedEvent,
76
+ transformers[i]
77
+ );
78
+ if (
79
+ newEvent === undefined ||
80
+ newEvent === null ||
81
+ !isObject(newEvent)
82
+ ) {
83
+ return undefined;
84
+ }
85
+ transformedEvent = newEvent as unknown as HightouchEvent;
86
+ }
87
+ }
88
+ return transformedEvent ?? event;
89
+ }
90
+ }
package/src/index.tsx ADDED
@@ -0,0 +1 @@
1
+ export { DestinationFiltersPlugin } from './DestinationFilters';