Skip to content

Commit

Permalink
Merge branch 'develop' into feature/sdk-290-configurable-collection-o…
Browse files Browse the repository at this point in the history
…f-deviceid
  • Loading branch information
1abhishekpandey authored Sep 1, 2023
2 parents f05551b + 34644df commit 38bb61e
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 9 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,39 @@ Example Usage:
rudderClient.setAnonymousId(ANONYMOUS_ID);
```

## Database Encryption

To encrypt the database first add the below line to `import` the rudderClient and DBEncryption.

```
import rudderClient, { RUDDER_LOG_LEVEL, DBEncryption } from '@rudderstack/rudder-sdk-react-native';
```

Then open your `app/build.gradle` and add the dependency under `dependencies` as shown below:

```
//sql-cipher
implementation "net.zetetic:android-database-sqlcipher:4.5.4"
implementation "androidx.sqlite:sqlite:2.3.1"
```

Add the following code in your application:

```
const dbEncryption = new DBEncryption('versys', true);
const config = {
dataPlaneUrl: <DATA_PLANE_URL>,
trackAppLifecycleEvents: true,
logLevel: RUDDER_LOG_LEVEL.DEBUG,
dbEncryption: dbEncryption,
};
await rudderClient.setup(<WRITE_KEY>, config);
```

This feature is supported starting from version `1.9.0` of the SDK.

For more details, check out our [documentation](https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-react-native-sdk).

## Contact Us
Expand Down
3 changes: 3 additions & 0 deletions apps/example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.firebase:firebase-messaging:21.0.0'

//sql-cipher
implementation "net.zetetic:android-database-sqlcipher:4.5.4"
implementation "androidx.sqlite:sqlite:2.3.1"

androidTestImplementation(project(path: ":detox"))

Expand Down
4 changes: 0 additions & 4 deletions apps/example/ios/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
572899A5661046CED23B3DC6 /* libPods-Example.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2846C63330CECB73DE262FD5 /* libPods-Example.a */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
8CBF2B652A9E372400A58EFF /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 8CBF2B642A9E372400A58EFF /* GoogleService-Info.plist */; };
FECB4DA94BF95A215192377D /* libPods-Example-ExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CB256E5F615F81481C8756EE /* libPods-Example-ExampleTests.a */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -41,7 +40,6 @@
2846C63330CECB73DE262FD5 /* libPods-Example.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Example.a"; sourceTree = BUILT_PRODUCTS_DIR; };
57C1791C2982A27EC162ADDA /* Pods-Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.release.xcconfig"; path = "Target Support Files/Pods-Example/Pods-Example.release.xcconfig"; sourceTree = "<group>"; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = Example/LaunchScreen.storyboard; sourceTree = "<group>"; };
8CBF2B642A9E372400A58EFF /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
BFB8B5DECB5F049E1E8B8C65 /* Pods-Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Example.debug.xcconfig"; path = "Target Support Files/Pods-Example/Pods-Example.debug.xcconfig"; sourceTree = "<group>"; };
CB256E5F615F81481C8756EE /* libPods-Example-ExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Example-ExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -88,7 +86,6 @@
13B07FAE1A68108700A75B9A /* Example */ = {
isa = PBXGroup;
children = (
8CBF2B642A9E372400A58EFF /* GoogleService-Info.plist */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
13B07FB01A68108700A75B9A /* AppDelegate.mm */,
13B07FB51A68108700A75B9A /* Images.xcassets */,
Expand Down Expand Up @@ -247,7 +244,6 @@
files = (
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
8CBF2B652A9E372400A58EFF /* GoogleService-Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
1 change: 1 addition & 0 deletions apps/example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ target 'Example' do
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.4'
config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = "arm64"
end
end
react_native_post_install(
Expand Down
2 changes: 1 addition & 1 deletion apps/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,6 @@ SPEC CHECKSUMS:
Yoga: 79dd7410de6f8ad73a77c868d3d368843f0c93e0
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 1f734483bc51f36f263f2253ff0038e4adf6734a
PODFILE CHECKSUM: 977a4cd75cd9d6f6ff277b285d4c9cf0b64ae999

COCOAPODS: 1.11.3
5 changes: 4 additions & 1 deletion apps/example/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useEffect } from 'react';
import { Button, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import rc, { RUDDER_LOG_LEVEL } from '@rudderstack/rudder-sdk-react-native';
import rc, { RUDDER_LOG_LEVEL, DBEncryption } from '@rudderstack/rudder-sdk-react-native';
import amplitude from '@rudderstack/rudder-integration-amplitude-react-native';
import appcenter from '@rudderstack/rudder-integration-appcenter-react-native';
import braze from '@rudderstack/rudder-integration-braze-react-native';
Expand Down Expand Up @@ -69,6 +69,8 @@ const initRNAppsFlyerSDK = async () => {
};

const initRudderReactNativeSDK = async () => {
const dbEncryption = new DBEncryption('versys', false);

const config = {
dataPlaneUrl: TEST_DATAPLANE_URL,
autoCollectAdvertId: true,
Expand All @@ -79,6 +81,7 @@ const initRudderReactNativeSDK = async () => {
enableBackgroundMode: true,
trackAppLifecycleEvents: true,
autoSessionTracking: true,
dbEncryption: dbEncryption,
withFactories: [
appsflyer,
amplitude,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.facebook.react.bridge.ReadableMap;
import com.rudderstack.android.sdk.core.RudderConfig;
import com.rudderstack.android.sdk.core.util.Utils;

import java.util.Map;

class RNParamsConfigurator {
private final ReadableMap config;
Expand Down Expand Up @@ -75,6 +78,14 @@ private RudderConfig.Builder buildConfig() {
if (config.hasKey("collectDeviceId")) {
configBuilder.withCollectDeviceId(config.getBoolean("collectDeviceId"));
}
if (config.hasKey("dbEncryption")) {
Map<String, Object> dbEncryption = Utility.convertReadableMapToMap(config.getMap("dbEncryption"));
String key = (String) (Utility.getValueFromMap(dbEncryption, "key", ""));
Boolean enable = (Boolean) (Utility.getValueFromMap(dbEncryption, "enable", false));
if (!Utility.isEmpty(key)) {
configBuilder.withDbEncryption(new RudderConfig.DBEncryption(enable, key));
}
}
return configBuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.List;
import java.util.Map;

import javax.annotation.Nonnull;


public class Utility {
public static Map<String, Object> convertReadableMapToMap(ReadableMap readableMap) {
Expand Down Expand Up @@ -164,4 +166,18 @@ public static WritableArray convertJsonToWriteAbleArray(JSONArray jsonArray) thr
}
return array;
}

@Nonnull
public static Object getValueFromMap(Map<String, Object> map, String key, Object defaultValue) {
if (map == null || key == null) return defaultValue;
if (map.containsKey(key)) {
return map.get(key);
}
return defaultValue;
}

@Nonnull
public static boolean isEmpty(String str) {
return str == null || str.length() == 0;
}
}
8 changes: 8 additions & 0 deletions libs/sdk/ios/RNParamsConfigurator.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ -(RSConfigBuilder*)buildConfig {
if ([config objectForKey:@"collectDeviceId"]) {
[configBuilder withCollectDeviceId:[config[@"collectDeviceId"] boolValue]];
}
if ([config objectForKey:@"dbEncryption"]) {
NSDictionary *dbEncryption = config[@"dbEncryption"];
NSString *key = dbEncryption[@"key"];
BOOL enable = [dbEncryption[@"enable"] boolValue];
if (key != nil && [key length] > 0) {
[configBuilder withDBEncryption:[[RSDBEncryption alloc] initWithKey:key enable:enable]];
}
}
return configBuilder;
}

Expand Down
2 changes: 1 addition & 1 deletion libs/sdk/src/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const AUTO_COLLECT_ADVERT_ID = false;
export const TRACK_LIFECYCLE_EVENTS = true;
export const RECORD_SCREEN_VIEWS = false;
export const LOG_LEVEL = RUDDER_LOG_LEVEL.ERROR;
export const SDK_VERSION = '1.8.0';
export const SDK_VERSION = '1.9.0';
export const AUTO_SESSION_TRACKING = true;
export const SESSION_TIMEOUT = 300000;
export const ENABLE_BACKGROUND_MODE = false;
Expand Down
10 changes: 10 additions & 0 deletions libs/sdk/src/DBEncryption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class DBEncryption {
key: string;
enable: boolean;
constructor(key: string, enable: boolean) {
this.key = key;
this.enable = enable;
}
}

export default DBEncryption;
2 changes: 2 additions & 0 deletions libs/sdk/src/NativeBridge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NativeModules } from 'react-native';
import DBEncryption from './DBEncryption';

export interface Configuration {
dataPlaneUrl?: string;
Expand All @@ -15,6 +16,7 @@ export interface Configuration {
sessionTimeout?: number;
enableBackgroundMode?: boolean;
collectDeviceId?: boolean;
dbEncryption?: DBEncryption;
// eslint-disable-next-line @typescript-eslint/ban-types
withFactories?: Array<Record<string, unknown> | Function>;
}
Expand Down
7 changes: 6 additions & 1 deletion libs/sdk/src/RudderConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const configure = async (
trackAppLifecycleEvents = TRACK_LIFECYCLE_EVENTS,
recordScreenViews = RECORD_SCREEN_VIEWS,
collectDeviceId = COLLECT_DEVICE_ID,
dbEncryption,
withFactories = [],
}: Configuration,
): Promise<Configuration> => {
Expand Down Expand Up @@ -65,5 +66,9 @@ export const configure = async (
collectDeviceId,
};

return { ...config };
if (dbEncryption !== undefined) {
return { ...config, dbEncryption };
}

return config;
};
3 changes: 2 additions & 1 deletion libs/sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import rudderClient from './RudderClient';
import { RUDDER_LOG_LEVEL } from './Logger';
import DBEncryption from './DBEncryption';

export { RUDDER_LOG_LEVEL };
export { RUDDER_LOG_LEVEL, DBEncryption };
export default rudderClient;

0 comments on commit 38bb61e

Please sign in to comment.