Skip to content

Commit

Permalink
Fixing secret consumption in app, enabled logging by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
billmote committed Nov 22, 2024
1 parent 2df8752 commit 00b9fab
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
package com.salesforce.marketingcloud.reactnative;

import android.util.Log;

import androidx.annotation.NonNull;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
Expand All @@ -46,16 +44,14 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import com.salesforce.marketingcloud.sfmcsdk.components.identity.Identity;
import com.salesforce.marketingcloud.sfmcsdk.components.logging.LogLevel;
import com.salesforce.marketingcloud.sfmcsdk.components.logging.LogListener;
import com.salesforce.marketingcloud.sfmcsdk.modules.push.PushModuleInterface;
import com.salesforce.marketingcloud.sfmcsdk.modules.ModuleInterface;
import com.salesforce.marketingcloud.sfmcsdk.modules.push.PushModuleInterface;
import com.salesforce.marketingcloud.sfmcsdk.modules.push.PushModuleReadyListener;

import java.util.Map;
import java.util.Set;

import javax.annotation.Nonnull;

@SuppressWarnings({ "unused", "WeakerAccess" })
@SuppressWarnings({"unused", "WeakerAccess"})
public class RNSFMCSdkModule extends ReactContextBaseJavaModule {
public RNSFMCSdkModule(ReactApplicationContext reactContext) {
super(reactContext);
Expand Down Expand Up @@ -315,12 +311,11 @@ public void ready(@NonNull SFMCSdk sfmcSdk) {
public void ready(@NonNull PushModuleInterface pushModuleInterface) {
action.execute(pushModuleInterface);
}

@Override
public void ready(@NonNull ModuleInterface moduleInterface) {
this.ready((PushModuleInterface) moduleInterface);
}

});
}
});
Expand All @@ -346,8 +341,7 @@ private static void log(String tag, String msg) {
abstract class SFMCAction {
abstract void execute(SFMCSdk sdk);

void err() {
}
void err() {}
}

abstract class SFMCPromiseAction extends SFMCAction {
Expand All @@ -365,7 +359,7 @@ final void execute(SFMCSdk sdk) {
@Override
void err() {
promise.reject("SFMCSDK-INIT",
"The MarketingCloudSdk#init method must be called in the Application's onCreate.");
"The MarketingCloudSdk#init method must be called in the Application's onCreate.");
}

abstract void execute(SFMCSdk sdk, @NonNull Promise promise);
Expand All @@ -374,8 +368,7 @@ void err() {
abstract class MCPushAction {
abstract void execute(PushModuleInterface pushSdk);

void err() {
}
void err() {}
}

abstract class MCPushPromiseAction extends MCPushAction {
Expand All @@ -393,7 +386,7 @@ final void execute(PushModuleInterface sdk) {
@Override
void err() {
promise.reject("SFMCSDK-INIT",
"The MarketingCloudSdk#init method must be called in the Application's onCreate.");
"The MarketingCloudSdk#init method must be called in the Application's onCreate.");
}

abstract void execute(PushModuleInterface sdk, @NonNull Promise promise);
Expand All @@ -402,8 +395,7 @@ void err() {
abstract class SFMCIdentityAction {
abstract void execute(Identity identity);

void err() {
}
void err() {}
}

abstract class SFMCIdentityPromiseAction extends SFMCIdentityAction {
Expand All @@ -421,10 +413,9 @@ final void execute(Identity identity) {
@Override
void err() {
promise.reject("SFMCSDK-INIT",
"The SFMCSdk#configure method must be called in the Application's onCreate.");
"The SFMCSdk#configure method must be called in the Application's onCreate.");
}

abstract void execute(Identity sdk, @NonNull Promise promise);
}

}
1 change: 1 addition & 0 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const Push = () => {
useEffect(() => {
updatePushData();
requestNotificationPermission();
MCReactModule.enableLogging();
}, []);

return (
Expand Down
6 changes: 6 additions & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"

resValue "string", "PUSH_APPLICATION_ID", "${System.getenv("PUSH_APP_ID")}"
resValue "string", "PUSH_SENDER_ID", "${System.getenv("PUSH_SENDER_ID")}"
resValue "string", "PUSH_ACCESS_TOKEN", "${System.getenv("PUSH_ACCESS_TOKEN")}"
resValue "string", "PUSH_TSE", "${System.getenv("PUSH_TSE")}"

}
signingConfigs {
debug {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class MainApplication : Application(), ReactApplication, UrlHandler,
MarketingCloudConfig.builder()
.apply {
//Update these details based on your MC config
setApplicationId("{MC_APP_ID}")
setAccessToken("{MC_ACCESS_TOKEN}")
setMarketingCloudServerUrl("{MC_APP_SERVER_URL}")
setSenderId("{FCM_SENDER_ID}")
setApplicationId(this@MainApplication.resources.getString(R.string.PUSH_APPLICATION_ID))
setAccessToken(this@MainApplication.resources.getString(R.string.PUSH_ACCESS_TOKEN))
setSenderId(this@MainApplication.resources.getString(R.string.PUSH_SENDER_ID))
setMarketingCloudServerUrl(this@MainApplication.resources.getString(R.string.PUSH_TSE))
setNotificationCustomizationOptions(
NotificationCustomizationOptions.create(
R.mipmap.ic_launcher,
Expand Down
71 changes: 35 additions & 36 deletions ios/RNSFMCSdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,20 @@
// POSSIBILITY OF SUCH DAMAGE.

#import "RNSFMCSdk.h"
#import <SFMCSDK/SFMCSDK.h>
#import <MarketingCloudSDK/MarketingCloudSDK.h>
#import <SFMCSDK/SFMCSDK.h>
#import "RCTConvert+SFMCEvent.h"

const int LOG_LENGTH = 800;

@implementation RNSFMCSdk

- (instancetype)init
{
- (instancetype)init {
self = [super init];
if (self) {
//Add default tag.
// Add default tag.
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
(void)[mp addTag:@"React"];
(void)[mp addTag:@"React"];
}];
}
return self;
Expand All @@ -56,73 +55,73 @@ + (BOOL)requiresMainQueueSetup {

RCT_EXPORT_MODULE()

- (void)log:(NSString *)msg {
- (void)log:(NSString*)msg {
if (self.logger == nil) {
self.logger = os_log_create("com.salesforce.marketingcloudsdk", "ReactNative");
}
os_log_info(self.logger, "%{public}@", msg);
}

- (void)splitLog:(NSString *)msg {
- (void)splitLog:(NSString*)msg {
NSInteger length = msg.length;
for (int i = 0; i < length; i += LOG_LENGTH) {
NSInteger rangeLength = MIN(length - i, LOG_LENGTH);
[self log:[msg substringWithRange:NSMakeRange((NSUInteger)i, (NSUInteger)rangeLength)]];
}
}

RCT_EXPORT_METHOD(logSdkState) {
[self splitLog:[SFMCSdk state]];
}
RCT_EXPORT_METHOD(logSdkState) { [self splitLog:[SFMCSdk state]]; }

RCT_EXPORT_METHOD(getSystemToken
: (RCTPromiseResolveBlock)resolve rejecter
: (RCTPromiseRejectBlock)reject) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
NSString *deviceToken = [mp deviceToken];
resolve(deviceToken);
NSString* deviceToken = [mp deviceToken];
resolve(deviceToken);
}];
}

RCT_EXPORT_METHOD(enableLogging) {
[SFMCSdk setLoggerWithLogLevel:SFMCSdkLogLevelDebug logOutputter:[[SFMCSdkLogOutputter alloc] init]];
[SFMCSdk setLoggerWithLogLevel:SFMCSdkLogLevelDebug
logOutputter:[[SFMCSdkLogOutputter alloc] init]];
}

RCT_EXPORT_METHOD(disableLogging) {
[SFMCSdk setLoggerWithLogLevel:SFMCSdkLogLevelFault logOutputter:[[SFMCSdkLogOutputter alloc] init]];
[SFMCSdk setLoggerWithLogLevel:SFMCSdkLogLevelFault
logOutputter:[[SFMCSdkLogOutputter alloc] init]];
}

RCT_EXPORT_METHOD(enablePush) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
[mp setPushEnabled:YES];
[mp setPushEnabled:YES];
}];
}

RCT_EXPORT_METHOD(disablePush) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
[mp setPushEnabled:NO];
[mp setPushEnabled:NO];
}];
}

RCT_EXPORT_METHOD(isPushEnabled
: (RCTPromiseResolveBlock)resolve rejecter
: (RCTPromiseRejectBlock)reject) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
BOOL status = [mp pushEnabled];
resolve(@(status));
BOOL status = [mp pushEnabled];
resolve(@(status));
}];
}

RCT_EXPORT_METHOD(getDeviceId
: (RCTPromiseResolveBlock)resolve rejecter
: (RCTPromiseRejectBlock)reject) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
NSString *deviceId = [mp deviceIdentifier];
resolve(deviceId);
NSString* deviceId = [mp deviceIdentifier];
resolve(deviceId);
}];
}

RCT_EXPORT_METHOD(track:(NSDictionary* _Nonnull)eventJson) {
RCT_EXPORT_METHOD(track : (NSDictionary* _Nonnull)eventJson) {
[SFMCSdk trackWithEvent:[RCTConvert SFMCEvent:eventJson]];
}

Expand All @@ -134,34 +133,34 @@ - (void)splitLog:(NSString *)msg {
: (RCTPromiseResolveBlock)resolve rejecter
: (RCTPromiseRejectBlock)reject) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
NSString *contactKey = [mp contactKey];
resolve(contactKey);
NSString* contactKey = [mp contactKey];
resolve(contactKey);
}];
}

RCT_EXPORT_METHOD(addTag : (NSString* _Nonnull)tag) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
[mp addTag:tag];
[mp addTag:tag];
}];
}

RCT_EXPORT_METHOD(removeTag : (NSString* _Nonnull)tag) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
[mp removeTag:tag];
[mp removeTag:tag];
}];
}

RCT_EXPORT_METHOD(getTags
: (RCTPromiseResolveBlock)resolve rejecter
: (RCTPromiseRejectBlock)reject) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
NSArray *tags = [[mp tags] allObjects];
resolve(tags);
NSArray* tags = [[mp tags] allObjects];
resolve(tags);
}];
}

RCT_EXPORT_METHOD(setAttribute : (NSString* _Nonnull)name value : (NSString* _Nonnull)value) {
[[SFMCSdk identity] setProfileAttributes:@{name: value}];
[[SFMCSdk identity] setProfileAttributes:@{name : value}];
}

RCT_EXPORT_METHOD(clearAttribute : (NSString* _Nonnull)name) {
Expand All @@ -172,39 +171,39 @@ - (void)splitLog:(NSString *)msg {
: (RCTPromiseResolveBlock)resolve rejecter
: (RCTPromiseRejectBlock)reject) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
NSDictionary *attributes = [mp attributes];
resolve((attributes != nil) ? attributes : @[]);
NSDictionary* attributes = [mp attributes];
resolve((attributes != nil) ? attributes : @[]);
}];
}

RCT_EXPORT_METHOD(setAnalyticsEnabled : (BOOL)analyticsEnabled) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
[mp setAnalyticsEnabled:analyticsEnabled];
[mp setAnalyticsEnabled:analyticsEnabled];
}];
}

RCT_EXPORT_METHOD(isAnalyticsEnabled
: (RCTPromiseResolveBlock)resolve rejecter
: (RCTPromiseRejectBlock)reject) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
BOOL isEnabled = [mp isAnalyticsEnabled];
resolve(@(isEnabled));
BOOL isEnabled = [mp isAnalyticsEnabled];
resolve(@(isEnabled));
}];
}

// PI Analytics Enablement
RCT_EXPORT_METHOD(setPiAnalyticsEnabled : (BOOL)analyticsEnabled) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
[mp setPiAnalyticsEnabled:analyticsEnabled];
[mp setPiAnalyticsEnabled:analyticsEnabled];
}];
}

RCT_EXPORT_METHOD(isPiAnalyticsEnabled
: (RCTPromiseResolveBlock)resolve rejecter
: (RCTPromiseRejectBlock)reject) {
[SFMCSdk requestPushSdk:^(id<PushInterface> _Nonnull mp) {
BOOL isEnabled = [mp isPiAnalyticsEnabled];
resolve(@(isEnabled));
BOOL isEnabled = [mp isPiAnalyticsEnabled];
resolve(@(isEnabled));
}];
}

Expand Down
Loading

0 comments on commit 00b9fab

Please sign in to comment.