File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -96,4 +96,18 @@ describe('#getContext', () => {
96
96
expect ( AnalyticsReactNative . getContextInfo ) . toHaveBeenCalledTimes ( 1 ) ;
97
97
expect ( context ) . toEqual ( { ...contextResult , traits : userTraits } ) ;
98
98
} ) ;
99
+
100
+ it ( 'strip non-required config from native calls' , async ( ) => {
101
+ const { AnalyticsReactNative } = NativeModules ;
102
+ await getContext ( undefined , {
103
+ writeKey : 'notRequiredInNative' ,
104
+ collectDeviceId : true ,
105
+ flushPolicies : [ ] , // Shouldn't get to native as this is RN specific
106
+ } ) ;
107
+
108
+ expect ( AnalyticsReactNative . getContextInfo ) . toHaveBeenCalledTimes ( 1 ) ;
109
+ expect ( AnalyticsReactNative . getContextInfo ) . toHaveBeenCalledWith ( {
110
+ collectDeviceId : true ,
111
+ } ) ;
112
+ } ) ;
99
113
} ) ;
Original file line number Diff line number Diff line change 1
1
import { libraryInfo } from './info' ;
2
2
3
3
import type {
4
+ Config ,
4
5
Context ,
5
6
ContextDevice ,
6
7
NativeContextInfo ,
@@ -10,7 +11,7 @@ import { getNativeModule } from './util';
10
11
import { getUUID } from './uuid' ;
11
12
12
13
interface GetContextConfig {
13
- collectDeviceId ? : boolean ;
14
+ collectDeviceId : boolean ;
14
15
}
15
16
16
17
const defaultContext = {
@@ -35,8 +36,13 @@ const defaultContext = {
35
36
36
37
export const getContext = async (
37
38
userTraits : UserTraits = { } ,
38
- config : GetContextConfig = { }
39
+ config ?: Config
39
40
) : Promise < Context > => {
41
+ // We need to remove all stuff from the config that is not actually required by the native module
42
+ const nativeConfig : GetContextConfig = {
43
+ collectDeviceId : config ?. collectDeviceId ?? false ,
44
+ } ;
45
+
40
46
const {
41
47
appName,
42
48
appVersion,
@@ -56,8 +62,9 @@ export const getContext = async (
56
62
deviceType,
57
63
screenDensity,
58
64
} : NativeContextInfo =
59
- ( await getNativeModule ( 'AnalyticsReactNative' ) ?. getContextInfo ( config ) ) ??
60
- defaultContext ;
65
+ ( await getNativeModule ( 'AnalyticsReactNative' ) ?. getContextInfo (
66
+ nativeConfig
67
+ ) ) ?? defaultContext ;
61
68
62
69
const device : ContextDevice = {
63
70
id : deviceId ,
You can’t perform that action at this time.
0 commit comments