Skip to content

Commit

Permalink
Release Cordova SDK version 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jerielng committed Mar 7, 2023
1 parent 8da387f commit 567c6ec
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 64 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 3.0.0

##### Added
- Added support for the upcoming Braze Feature Flags product with `getFeatureFlag()`, `getAllFeatureFlags()`, `refreshFeatureFlags()`, and `subscribeToFeatureFlagUpdates()`.

##### Changed
- Updated to [Braze Swift SDK 5.11.0](https://github.com/braze-inc/braze-swift-sdk/releases/tag/5.11.0).
- Removed automatic requests for App Tracking Transparency permissions on iOS.

## 2.33.0

##### Breaking
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "appboy-cordova-sdk",
"version": "2.33.0",
"version": "3.0.0",
"main": "www/AppboyPlugin.js"
}
9 changes: 5 additions & 4 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="cordova-plugin-appboy" version="2.33.0">
id="cordova-plugin-appboy" version="3.0.0">
<name>Device</name>
<description>Braze Cordova SDK</description>
<license>MIT</license>
Expand All @@ -19,6 +19,7 @@
</config-file>
<source-file src="src/android/BrazePlugin.kt" target-dir="java/com/braze/cordova" />
<source-file src="src/android/ContentCardUtils.kt" target-dir="java/com/braze/cordova" />
<source-file src="src/android/FeatureFlagUtils.kt" target-dir="java/com/braze/cordova" />
<source-file src="src/android/CordovaInAppMessageViewWrapper.kt" target-dir="java/com/braze/cordova" />
<framework src="src/android/build-extras.gradle" custom="true" type="gradleReference" />
<config-file target="AndroidManifest.xml" parent="/manifest">
Expand Down Expand Up @@ -52,9 +53,9 @@
<source url="https://cdn.cocoapods.org/"/>
</config>
<pods use-frameworks="true">
<pod name="BrazeKit" spec="~> 5.8.1" />
<pod name="BrazeUI" spec="~> 5.8.1" />
<pod name="BrazeLocation" spec="~> 5.8.1" />
<pod name="BrazeKit" spec="~> 5.11.0" />
<pod name="BrazeUI" spec="~> 5.11.0" />
<pod name="BrazeLocation" spec="~> 5.11.0" />
</pods>
</podspec>
</platform>
Expand Down
5 changes: 5 additions & 0 deletions sample-project/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ <h1>Apache Cordova</h1>
<button id="disableSdk">Disables the SDK</button>
<button id="getDeviceId">Gets the Device ID</button>
<button id="requestPushPermission">requestPushPermission()</button>
<input type="text" id="featureFlagInputId" autocorrect="off" autocapitalize="off" />
<button id="getFeatureFlagBtn">Get Feature Flag</button>
<button id="getAllFeatureFlagsBtn">Get All Feature Flags</button>
<button id="refreshFeatureFlagsBtn">Refresh Feature Flags</button>
<button id="subscribeToFeatureFlagsBtn">Subscribe to Feature Flag Updates</button>
</div>
<!-- The snackbar to display messages -->
<div id="snackbar"></div>
Expand Down
37 changes: 37 additions & 0 deletions sample-project/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ bindEvents: function() {
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
document.getElementById("getFeatureFlagBtn").addEventListener("click", getFeatureFlag);
document.getElementById("getAllFeatureFlagsBtn").addEventListener("click", getAllFeatureFlags);
document.getElementById("refreshFeatureFlagsBtn").addEventListener("click", refreshFeatureFlags);
document.getElementById("subscribeToFeatureFlagsBtn").addEventListener("click", subscribeToFeatureFlags)
document.getElementById("changeUserBtn").addEventListener("click", changeUser);
document.getElementById("logCustomEventBtn").addEventListener("click", logCustomEvent);
document.getElementById("logPurchaseBtn").addEventListener("click", logPurchase);
Expand Down Expand Up @@ -92,6 +96,24 @@ function changeUser() {
showTextBubble("Change user called");
}

function getFeatureFlag() {
AppboyPlugin.getFeatureFlag(document.getElementById("featureFlagInputId").value, customPluginSuccessJsonCallback("FeatureFlag: "), customPluginErrorCallback);
}

function getAllFeatureFlags() {
AppboyPlugin.getAllFeatureFlags(customPluginSuccessArrayCallback("GetAllFeatureFlags: "), customPluginErrorCallback);
}

function refreshFeatureFlags() {
AppboyPlugin.refreshFeatureFlags();
showTextBubble("Refresh feature flags");
}

function subscribeToFeatureFlags() {
AppboyPlugin.subscribeToFeatureFlagUpdates(featureFlagsUpdated);
showTextBubble("Subscribed to Feature Flags");
}

function logCustomEvent() {
var properties = {};
properties["One"] = "That's the Way of the World";
Expand Down Expand Up @@ -309,6 +331,13 @@ function customPluginSuccessCallback(bubbleMessage) {
return function(callbackResult) { showTextBubble(bubbleMessage + " " + callbackResult) };
}

/**
* Serves as the success callback for the Appboy Plugin. Displays a text bubble with a message when called.
**/
function customPluginSuccessJsonCallback(bubbleMessage) {
return function(callbackResult) { showTextBubble(bubbleMessage + " JSON: " + JSON.stringify(callbackResult)) };
}

/**
* Serves as the success callback for the Appboy Plugin. Displays a text bubble with a message when called.
**/
Expand All @@ -322,6 +351,14 @@ function customPluginSuccessArrayCallback(bubbleMessage) {
};
}

function featureFlagsUpdated(featureFlags) {
var numElements = featureFlags.length;
showTextBubble("Feature Flags Updated: " + numElements + " objects")
for (var i = 0; i < numElements; i++) {
console.log(" Feature Flag - " + JSON.stringify(featureFlags[i]));
}
}

/**
* Serves as the error callback for the Appboy Plugin. Displays a text bubble with a message when called.
**/
Expand Down
29 changes: 29 additions & 0 deletions src/android/BrazePlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import com.braze.configuration.BrazeConfig
import com.braze.cordova.ContentCardUtils.getCardById
import com.braze.cordova.ContentCardUtils.mapContentCards
import com.braze.cordova.CordovaInAppMessageViewWrapper.CordovaInAppMessageViewWrapperFactory
import com.braze.cordova.FeatureFlagUtils.mapFeatureFlags
import com.braze.enums.BrazeSdkMetadata
import com.braze.events.ContentCardsUpdatedEvent
import com.braze.events.IEventSubscriber
import com.braze.events.FeatureFlagsUpdatedEvent
import com.braze.models.outgoing.BrazeProperties
import com.braze.support.BrazeLogger.Priority.*
import com.braze.support.BrazeLogger.brazelog
Expand All @@ -27,6 +29,7 @@ import com.braze.ui.inappmessage.BrazeInAppMessageManager
import org.apache.cordova.CallbackContext
import org.apache.cordova.CordovaPlugin
import org.apache.cordova.CordovaPreferences
import org.apache.cordova.PluginResult;
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
Expand Down Expand Up @@ -277,6 +280,32 @@ open class BrazePlugin : CordovaPlugin() {
cordova.activity.startActivity(intent)
return true
}
"getFeatureFlag" -> {
callbackContext.success(Braze.getInstance(applicationContext).getFeatureFlag(args.getString(0)).forJsonPut())
return true
}
"getAllFeatureFlags" -> {
callbackContext.success(
mapFeatureFlags(
Braze.getInstance(applicationContext).getAllFeatureFlags()
)
)
return true
}
"refreshFeatureFlags" -> {
runOnBraze { it.refreshFeatureFlags() }
return true
}
"subscribeToFeatureFlagUpdates" -> {
runOnBraze {
it.subscribeToFeatureFlagsUpdates() { event: FeatureFlagsUpdatedEvent ->
val result = PluginResult(PluginResult.Status.OK, mapFeatureFlags(event.featureFlags))
result.setKeepCallback(true)
callbackContext.sendPluginResult(result)
}
}
return true
}
GET_NEWS_FEED_METHOD,
GET_CARD_COUNT_FOR_CATEGORIES_METHOD,
GET_UNREAD_CARD_COUNT_FOR_CATEGORIES_METHOD -> return handleNewsFeedGetters(action, args, callbackContext)
Expand Down
22 changes: 22 additions & 0 deletions src/android/FeatureFlagUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.braze.cordova

import com.braze.models.FeatureFlag
import com.braze.support.BrazeLogger.Priority.E
import com.braze.support.BrazeLogger.brazelog
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject

object FeatureFlagUtils {
fun mapFeatureFlags(ffList: List<FeatureFlag>): JSONArray {
val featureFlags = JSONArray()
for (ff in ffList) {
try {
featureFlags.put(ff.forJsonPut())
} catch (e: JSONException) {
brazelog(E, e) { "Failed to map FeatureFlag to JSON. $ff" }
}
}
return featureFlags
}
}
2 changes: 1 addition & 1 deletion src/android/build-extras.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repositories {
}

dependencies {
implementation 'com.braze:android-sdk-ui:24.1.0'
implementation 'com.braze:android-sdk-ui:24.2.0'
implementation 'com.google.firebase:firebase-messaging:23.0.0'
}

Expand Down
93 changes: 50 additions & 43 deletions src/ios/BrazePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,65 @@

@property Braze *braze;
@property id<BrazeIDFADelegate> idfaDelegate;
@property NSMutableArray<BRZCancellable *> *subscriptions;

/*-------Braze-------*/
- (void) changeUser:(CDVInvokedUrlCommand *)command;
- (void) logCustomEvent:(CDVInvokedUrlCommand *)command;
- (void) logPurchase:(CDVInvokedUrlCommand *)command;
- (void) disableSdk:(CDVInvokedUrlCommand *)command;
- (void) enableSdk:(CDVInvokedUrlCommand *)command;
- (void) wipeData:(CDVInvokedUrlCommand *)command;
- (void) requestImmediateDataFlush:(CDVInvokedUrlCommand *)command;
- (void) getDeviceId:(CDVInvokedUrlCommand *)command;
- (void)changeUser:(CDVInvokedUrlCommand *)command;
- (void)logCustomEvent:(CDVInvokedUrlCommand *)command;
- (void)logPurchase:(CDVInvokedUrlCommand *)command;
- (void)disableSdk:(CDVInvokedUrlCommand *)command;
- (void)enableSdk:(CDVInvokedUrlCommand *)command;
- (void)wipeData:(CDVInvokedUrlCommand *)command;
- (void)requestImmediateDataFlush:(CDVInvokedUrlCommand *)command;
- (void)getDeviceId:(CDVInvokedUrlCommand *)command;

/*-------Braze.User-------*/
- (void) setFirstName:(CDVInvokedUrlCommand *)command;
- (void) setLastName:(CDVInvokedUrlCommand *)command;
- (void) setEmail:(CDVInvokedUrlCommand *)command;
- (void) setGender:(CDVInvokedUrlCommand *)command;
- (void) setDateOfBirth:(CDVInvokedUrlCommand *)command;
- (void) setCountry:(CDVInvokedUrlCommand *)command;
- (void) setHomeCity:(CDVInvokedUrlCommand *)command;
- (void) setPhoneNumber:(CDVInvokedUrlCommand *)command;
- (void) setLanguage:(CDVInvokedUrlCommand *)command;

- (void) setPushNotificationSubscriptionType:(CDVInvokedUrlCommand *)command;
- (void) setEmailNotificationSubscriptionType:(CDVInvokedUrlCommand *)command;

- (void) setBoolCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void) setStringCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void) setDoubleCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void) setDateCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void) setIntCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void) setCustomUserAttributeArray:(CDVInvokedUrlCommand *)command;
- (void) unsetCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void) incrementCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void) addToCustomAttributeArray:(CDVInvokedUrlCommand *)command;
- (void) removeFromCustomAttributeArray:(CDVInvokedUrlCommand *)command;
- (void) addAlias:(CDVInvokedUrlCommand *)command;
- (void)setFirstName:(CDVInvokedUrlCommand *)command;
- (void)setLastName:(CDVInvokedUrlCommand *)command;
- (void)setEmail:(CDVInvokedUrlCommand *)command;
- (void)setGender:(CDVInvokedUrlCommand *)command;
- (void)setDateOfBirth:(CDVInvokedUrlCommand *)command;
- (void)setCountry:(CDVInvokedUrlCommand *)command;
- (void)setHomeCity:(CDVInvokedUrlCommand *)command;
- (void)setPhoneNumber:(CDVInvokedUrlCommand *)command;
- (void)setLanguage:(CDVInvokedUrlCommand *)command;

- (void)setPushNotificationSubscriptionType:(CDVInvokedUrlCommand *)command;
- (void)setEmailNotificationSubscriptionType:(CDVInvokedUrlCommand *)command;

- (void)setBoolCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void)setStringCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void)setDoubleCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void)setDateCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void)setIntCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void)setCustomUserAttributeArray:(CDVInvokedUrlCommand *)command;
- (void)unsetCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void)incrementCustomUserAttribute:(CDVInvokedUrlCommand *)command;
- (void)addToCustomAttributeArray:(CDVInvokedUrlCommand *)command;
- (void)removeFromCustomAttributeArray:(CDVInvokedUrlCommand *)command;
- (void)addAlias:(CDVInvokedUrlCommand *)command;

/*-------BrazeUI-------*/
- (void) launchNewsFeed:(CDVInvokedUrlCommand *)command;
- (void) launchContentCards:(CDVInvokedUrlCommand *)command;
- (void)launchNewsFeed:(CDVInvokedUrlCommand *)command;
- (void)launchContentCards:(CDVInvokedUrlCommand *)command;

/*-------News Feed-------*/
- (void) getCardCountForCategories:(CDVInvokedUrlCommand *)command;
- (void) getUnreadCardCountForCategories:(CDVInvokedUrlCommand *)command;
- (void) getNewsFeed:(CDVInvokedUrlCommand *)command;
- (void)getCardCountForCategories:(CDVInvokedUrlCommand *)command;
- (void)getUnreadCardCountForCategories:(CDVInvokedUrlCommand *)command;
- (void)getNewsFeed:(CDVInvokedUrlCommand *)command;

/*-------Content Cards-------*/
- (void) requestContentCardsRefresh:(CDVInvokedUrlCommand *)command;
- (void) getContentCardsFromServer:(CDVInvokedUrlCommand *)command;
- (void) getContentCardsFromCache:(CDVInvokedUrlCommand *)command;
- (void) logContentCardClicked:(CDVInvokedUrlCommand *)command;
- (void) logContentCardImpression:(CDVInvokedUrlCommand *)command;
- (void) logContentCardDismissed:(CDVInvokedUrlCommand *)command;
- (void)requestContentCardsRefresh:(CDVInvokedUrlCommand *)command;
- (void)getContentCardsFromServer:(CDVInvokedUrlCommand *)command;
- (void)getContentCardsFromCache:(CDVInvokedUrlCommand *)command;
- (void)logContentCardClicked:(CDVInvokedUrlCommand *)command;
- (void)logContentCardImpression:(CDVInvokedUrlCommand *)command;
- (void)logContentCardDismissed:(CDVInvokedUrlCommand *)command;

/*-------Feature Flags-------*/
- (void)getFeatureFlag:(CDVInvokedUrlCommand *)command;
- (void)getAllFeatureFlags:(CDVInvokedUrlCommand *)command;
- (void)refreshFeatureFlags:(CDVInvokedUrlCommand *)command;
- (void)subscribeToFeatureFlagUpdates:(CDVInvokedUrlCommand *)command;

@end
Loading

0 comments on commit 567c6ec

Please sign in to comment.