@braze/react-native-sdk
Advanced tools
Comparing version 6.0.2 to 7.0.0
@@ -5,2 +5,3 @@ const NativeEventEmitter = require('react-native').NativeEventEmitter; | ||
import Braze from '../src/index'; | ||
import { Platform } from 'react-native'; | ||
@@ -19,6 +20,17 @@ console.log = jest.fn(); | ||
Braze.registerAndroidPushToken(token); | ||
expect(NativeBrazeReactModule.registerAndroidPushToken).toBeCalledWith(token); | ||
expect(NativeBrazeReactModule.registerAndroidPushToken).toBeCalledWith(token); | ||
expect(NativeBrazeReactModule.registerPushToken).toBeCalledWith(token); | ||
}); | ||
test('it calls BrazeReactBridge.registerPushToken', () => { | ||
const token = "some_token"; | ||
Braze.registerPushToken(token); | ||
expect(NativeBrazeReactModule.registerPushToken).toBeCalledWith(token); | ||
}); | ||
test('it calls BrazeReactBridge.registerPushToken with null', () => { | ||
const token = null; | ||
Braze.registerPushToken(token); | ||
expect(NativeBrazeReactModule.registerPushToken).toBeCalledWith(token); | ||
}); | ||
test('it calls BrazeReactBridge.setGoogleAdvertisingId', () => { | ||
@@ -110,2 +122,7 @@ const googleAdvertisingId = "some_ga_id"; | ||
test('it calls BrazeReactBridge.getCachedContentCards', () => { | ||
Braze.getCachedContentCards(); | ||
expect(NativeBrazeReactModule.getCachedContentCards).toBeCalled(); | ||
}); | ||
test('it calls BrazeReactBridge.logContentCardClicked', () => { | ||
@@ -169,2 +186,42 @@ const id = "1234"; | ||
test('it calls BrazeReactBridge.setLastKnownLocation', () => { | ||
const latitude = 40.7128; | ||
const longitude = 74.0060; | ||
const altitude = 24.0; | ||
const horizontalAccuracy = 25.0; | ||
const verticalAccuracy = 26.0; | ||
Braze.setLastKnownLocation(latitude, longitude, altitude, horizontalAccuracy, verticalAccuracy); | ||
expect(NativeBrazeReactModule.setLastKnownLocation).toBeCalledWith(latitude, longitude, altitude, horizontalAccuracy, verticalAccuracy); | ||
}); | ||
test('it calls BrazeReactBridge.setLastKnownLocation with 3 null', () => { | ||
const latitude = 40.7128; | ||
const longitude = 74.0060; | ||
const altitude = null; | ||
const horizontalAccuracy = null; | ||
const verticalAccuracy = null; | ||
Braze.setLastKnownLocation(latitude, longitude, altitude, horizontalAccuracy, verticalAccuracy); | ||
expect(NativeBrazeReactModule.setLastKnownLocation).toBeCalledWith(latitude, longitude, altitude, horizontalAccuracy, verticalAccuracy); | ||
}); | ||
test('it calls BrazeReactBridge.setLastKnownLocation with 2 null', () => { | ||
const latitude = 40.7128; | ||
const longitude = 74.0060; | ||
const altitude = null; | ||
const horizontalAccuracy = 25.0; | ||
const verticalAccuracy = null; | ||
Braze.setLastKnownLocation(latitude, longitude, altitude, horizontalAccuracy, verticalAccuracy); | ||
expect(NativeBrazeReactModule.setLastKnownLocation).toBeCalledWith(latitude, longitude, altitude, horizontalAccuracy, verticalAccuracy); | ||
}); | ||
test('it calls BrazeReactBridge.setLastKnownLocation with 1 null', () => { | ||
const latitude = 40.7128; | ||
const longitude = 74.0060; | ||
const altitude = 24.0; | ||
const horizontalAccuracy = 25.0; | ||
const verticalAccuracy = null; | ||
Braze.setLastKnownLocation(latitude, longitude, altitude, horizontalAccuracy, verticalAccuracy); | ||
expect(NativeBrazeReactModule.setLastKnownLocation).toBeCalledWith(latitude, longitude, altitude, horizontalAccuracy, verticalAccuracy); | ||
}); | ||
test('it calls BrazeReactBridge.requestContentCardsRefresh', () => { | ||
@@ -242,2 +299,28 @@ Braze.requestContentCardsRefresh(); | ||
test('it calls BrazeReactBridge.setCustomUserAttributeObjectArray', () => { | ||
const key = "some_key"; | ||
const array = [{'one': 1, 'two': 2, 'three': 3}, {'eight': 8, 'nine': 9}]; | ||
Braze.setCustomUserAttribute(key, array, testCallback); | ||
expect(NativeBrazeReactModule.setCustomUserAttributeObjectArray).toBeCalledWith(key, array, testCallback); | ||
}); | ||
test('it calls BrazeReactBridge.setCustomUserAttributeObject 4 parameters', () => { | ||
const key = "some_key"; | ||
const hash = {'do': 're', 'mi': 'fa'} | ||
const merge = true | ||
Braze.setCustomUserAttribute(key, hash, merge, testCallback); | ||
expect(NativeBrazeReactModule.setCustomUserAttributeObject).toBeCalledWith(key, hash, merge, testCallback); | ||
}); | ||
test('it calls BrazeReactBridge.setCustomUserAttributeObject 3 parameters', () => { | ||
const key = "some_key"; | ||
const hash = {'do': 're', 'mi': 'fa'} | ||
// When not given, merge defaults to 'false' | ||
const merge = false | ||
Braze.setCustomUserAttribute(key, hash, testCallback); | ||
expect(NativeBrazeReactModule.setCustomUserAttributeObject).toBeCalledWith(key, hash, merge, testCallback); | ||
}); | ||
test('it calls BrazeReactBridge.setBoolCustomUserAttribute', () => { | ||
@@ -368,6 +451,8 @@ const key = "some_key"; | ||
test('it calls the callback with null if BrazeReactBridge.getInitialUrl is not defined', () => { | ||
NativeBrazeReactModule.getInitialURL = null; | ||
test('it calls the callback with null if BrazeReactBridge.getInitialUrl is running on Android', () => { | ||
const platform = Platform.OS; | ||
Platform.OS = 'android'; | ||
Braze.getInitialURL(testCallback); | ||
expect(testCallback).toBeCalledWith(null); | ||
Platform.OS = platform; | ||
}); | ||
@@ -547,2 +632,7 @@ | ||
test('it calls BrazeReactBridge.logFeatureFlagImpression', () => { | ||
Braze.logFeatureFlagImpression('test'); | ||
expect(NativeBrazeReactModule.logFeatureFlagImpression).toBeCalled(); | ||
}) | ||
test('it calls BrazeReactBridge.getFeatureFlagBooleanProperty', () => { | ||
@@ -549,0 +639,0 @@ Braze.getFeatureFlagBooleanProperty('id', 'key'); |
@@ -21,2 +21,3 @@ jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter'); | ||
registerAndroidPushToken: jest.fn(), | ||
registerPushToken: jest.fn(), | ||
setGoogleAdvertisingId: jest.fn(), | ||
@@ -43,2 +44,3 @@ setFirstName: jest.fn(), | ||
getContentCards: jest.fn(), | ||
getCachedContentCards: jest.fn(), | ||
logContentCardClicked: jest.fn(), | ||
@@ -54,2 +56,4 @@ logContentCardDismissed: jest.fn(), | ||
setCustomUserAttributeArray: jest.fn(), | ||
setCustomUserAttributeObject: jest.fn(), | ||
setCustomUserAttributeObjectArray: jest.fn(), | ||
setBoolCustomUserAttribute: jest.fn(), | ||
@@ -86,2 +90,3 @@ setStringCustomUserAttribute: jest.fn(), | ||
refreshFeatureFlags: jest.fn(), | ||
logFeatureFlagImpression: jest.fn(), | ||
getFeatureFlagBooleanProperty: jest.fn(), | ||
@@ -88,0 +93,0 @@ getFeatureFlagNumberProperty: jest.fn(), |
{ | ||
"name": "@braze/react-native-sdk", | ||
"version": "6.0.2", | ||
"version": "7.0.0", | ||
"description": "Braze SDK for React Native.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -49,3 +49,3 @@ import { | ||
static getInitialURL(callback) { | ||
if (this.bridge.getInitialURL) { | ||
if (Platform.OS === 'ios') { | ||
this.bridge.getInitialURL((err, res) => { | ||
@@ -163,13 +163,17 @@ if (err) { | ||
/** | ||
* This method posts a token to Braze's servers to associate the token with the current device. | ||
* | ||
* No-op on iOS. | ||
* | ||
* @param {string} token - The device's push token. | ||
* @deprecated This method is deprecated in favor of `registerPushToken`. | ||
*/ | ||
static registerAndroidPushToken(token) { | ||
this.bridge.registerAndroidPushToken(token); | ||
this.bridge.registerPushToken(token); | ||
} | ||
/** | ||
* This method posts a token to Braze's servers to associate the token with the current device. | ||
* @param {string} token - The device's push token. | ||
*/ | ||
static registerPushToken(token) { | ||
this.bridge.registerPushToken(token); | ||
} | ||
/** | ||
* This method sets the Google Advertising ID and associated ad-tracking enabled field for this device. Note that the | ||
@@ -257,3 +261,6 @@ * SDK does not automatically collect this data. | ||
*/ | ||
static setCustomUserAttribute(key, value, callback) { | ||
static setCustomUserAttribute(key, value, thirdParam, fourthParam) { | ||
const merge = typeof thirdParam === 'boolean' ? thirdParam : false; | ||
const callback = typeof thirdParam === 'boolean' ? fourthParam : thirdParam; | ||
var valueType = typeof value; | ||
@@ -267,5 +274,21 @@ if (value instanceof Date) { | ||
} else if (value instanceof Array) { | ||
if (value.every(item => typeof item === 'string')) { | ||
callFunctionWithCallback( | ||
this.bridge.setCustomUserAttributeArray, | ||
[key, value], | ||
callback | ||
); | ||
} else if (value.every(item => typeof item === 'object')) { | ||
callFunctionWithCallback( | ||
this.bridge.setCustomUserAttributeObjectArray, | ||
[key, value], | ||
callback | ||
); | ||
} else { | ||
console.log(`User attribute ${value} was not a valid array. Custom attribute arrays can only contain all strings or all objects.`); | ||
} | ||
} else if (valueType === 'object') { | ||
callFunctionWithCallback( | ||
this.bridge.setCustomUserAttributeArray, | ||
[key, value], | ||
this.bridge.setCustomUserAttributeObject, | ||
[key, value, merge], | ||
callback | ||
@@ -573,2 +596,10 @@ ); | ||
/** | ||
* Returns the most recent Content Cards array from the cache. | ||
* @returns {Promise<ContentCard[]>} | ||
*/ | ||
static getCachedContentCards() { | ||
return this.bridge.getCachedContentCards(); | ||
} | ||
/** | ||
* Manually log a click to Braze for a particular card. | ||
@@ -702,2 +733,16 @@ * The SDK will only log a card click when the card has the url property with a valid value. | ||
/** | ||
* Sets the last known location for the user. For Android, latitude and longitude are required, with altitude and horizontal accuracy being optional parameters, and vertical accuracy being a no-op. | ||
* For iOS, latitude, longitude, and horizontal accuracy are required, with altitude and vertical accuracy being optional parameters. | ||
* Calling this method with invalid parameters for a specific platform is a no-op. Latitude, longitude, and horizontal accuracy are the minimum required parameters to work for all platforms. | ||
* @param {number} latitude - Location latitude. May not be null. | ||
* @param {number} longitude - Location longitude. May not be null. | ||
* @param {number} altitude - Location altitude. May be null for both platforms. | ||
* @param {number} horizontalAccuracy - Location horizontal accuracy. Equivalent to accuracy for Android. May be null for Android only; may not be null for iOS. | ||
* @param {number} verticalAccuracy - Location vertical accuracy. May be null for iOS. No-op for Android. | ||
*/ | ||
static setLastKnownLocation(latitude, longitude, altitude, horizontalAccuracy, verticalAccuracy) { | ||
this.bridge.setLastKnownLocation(latitude, longitude, altitude, horizontalAccuracy, verticalAccuracy); | ||
} | ||
// Refresh Content Cards | ||
@@ -809,2 +854,9 @@ /** | ||
/** | ||
* Logs an impression for the Feature Flag with the provided ID. | ||
*/ | ||
static logFeatureFlagImpression(id) { | ||
this.bridge.logFeatureFlagImpression(id); | ||
} | ||
/** | ||
* Returns the boolean property for the given feature flag ID. | ||
@@ -811,0 +863,0 @@ * @returns {Promise<boolean|null>} |
@@ -158,9 +158,11 @@ // Definitions by: ahanriat <https://github.com/ahanriat> | ||
/** | ||
* @deprecated This method is deprecated in favor of `registerPushToken`. | ||
*/ | ||
export function registerAndroidPushToken(token: string): void; | ||
/** | ||
* This method posts a token to Braze's servers to associate the token with the current device. | ||
* | ||
* No-op on iOS. | ||
* | ||
* @param {string} token - The device's push token. | ||
*/ | ||
export function registerAndroidPushToken(token: string): void; | ||
export function registerPushToken(token: string): void; | ||
@@ -265,4 +267,5 @@ /** | ||
* a $, and can only contain alphanumeric characters and punctuation. | ||
* @param value - Can be numeric, boolean, a Date object, a string, or an array of strings. Strings are limited to | ||
* 255 characters in length, cannot begin with a $, and can only contain alphanumeric characters and punctuation. | ||
* @param value - Can be numeric, boolean, a Date object, a string, an array of strings, an object, or an array of objects. | ||
* Strings are limited to 255 characters in length, cannot begin with a $, and can only contain alphanumeric | ||
* characters and punctuation. | ||
* Passing a null value will remove this custom attribute from the user. | ||
@@ -273,3 +276,3 @@ * @param {function(error, result)} callback - A callback that receives the function call result. | ||
key: string, | ||
value: number | boolean | string | string[] | Date | null, | ||
value: number | boolean | string | string[] | Date | null | object | object[], | ||
callback?: Callback<boolean> | ||
@@ -279,2 +282,21 @@ ): void; | ||
/** | ||
* Sets a custom user attribute. This can be any key/value pair and is used to collect extra information about the | ||
* user. | ||
* @param {string} key - The identifier of the custom attribute. Limited to 255 characters in length, cannot begin with | ||
* a $, and can only contain alphanumeric characters and punctuation. | ||
* @param value - Can be numeric, boolean, a Date object, a string, an array of strings, an object, or an array of objects. | ||
* Strings are limited to 255 characters in length, cannot begin with a $, and can only contain alphanumeric | ||
* characters and punctuation. | ||
* Passing a null value will remove this custom attribute from the user. | ||
* @param merge - If the value is object, this boolean indicates if the value should be merged into the existing key. | ||
* @param {function(error, result)} callback - A callback that receives the function call result. | ||
*/ | ||
export function setCustomUserAttribute( | ||
key: string, | ||
value: number | boolean | string | string[] | Date | null | object | object[], | ||
merge: boolean, | ||
callback?: Callback<boolean> | ||
): void; | ||
/** | ||
* Adds a string to a custom atttribute string array, or creates that array if one doesn't exist. | ||
@@ -488,2 +510,8 @@ * @param {string} key - The identifier of the custom attribute. Limited to 255 characters in length, cannot begin | ||
/** | ||
* Returns the most recent Content Cards array from the cache. | ||
* @returns {Promise<ContentCard[]>} | ||
*/ | ||
export function getCachedContentCards(): Promise<ContentCard[]>; | ||
/** | ||
* @deprecated This method is a no-op on iOS. | ||
@@ -562,2 +590,20 @@ */ | ||
/** | ||
* Sets the last known location for the user. For Android, latitude and longitude are required, with altitude and horizontal accuracy being optional parameters, and vertical accuracy being a no-op. | ||
* For iOS, latitude, longitude, and horizontal accuracy are required, with altitude and vertical accuracy being optional parameters. | ||
* Calling this method with invalid parameters for a specific platform is a no-op. Latitude, longitude, and horizontal accuracy are the minimum required parameters to work for all platforms. | ||
* @param {number} latitude - Location latitude. Required. | ||
* @param {number} longitude - Location longitude. Required. | ||
* @param {number} altitude - Location altitude. May be null for both platforms. | ||
* @param {number} horizontalAccuracy - Location horizontal accuracy. Equivalent to accuracy for Android. May be null for Android only; required for iOS. | ||
* @param {number} verticalAccuracy - Location vertical accuracy. May be null for iOS. No-op for Android. | ||
*/ | ||
export function setLastKnownLocation( | ||
latitude: number, | ||
longitude: number, | ||
altitude?: number | null, | ||
horizontalAccuracy?: number | null, | ||
verticalAccuracy?: number | null | ||
): void; | ||
/** | ||
* Call this method to have the SDK publish an "inAppMessageReceived" event containing the in-app message data to the | ||
@@ -701,2 +747,9 @@ * Javascript layer. You can listen to this event with `Braze.addListener()`. | ||
/** | ||
* Logs an impression for the Feature Flag with the provided ID. | ||
* | ||
* @param id - The ID of the feature flag. | ||
*/ | ||
export function logFeatureFlagImpression(id: string): void; | ||
export class BrazeInAppMessage { | ||
@@ -703,0 +756,0 @@ constructor(_data: string); |
@@ -27,3 +27,3 @@ import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport'; | ||
): void; | ||
registerAndroidPushToken(token: string): void; | ||
registerPushToken(token: string): void; | ||
setGoogleAdvertisingId( | ||
@@ -80,2 +80,13 @@ googleAdvertisingId: string, | ||
): void; | ||
// Sets a dictionary object as a custom user attribute. | ||
// `merge` indicates whether to override the existing value (false) or combine its fields (true). | ||
setCustomUserAttributeObject( | ||
key: string, | ||
value: Object, | ||
merge: boolean, | ||
callback?: ((error?: Object, result?: boolean) => void) | null | ||
): void; | ||
// Sets an array of strings as a custom user attribute. | ||
setCustomUserAttributeArray( | ||
@@ -86,2 +97,9 @@ key: string, | ||
): void; | ||
// Sets an array of objects as a custom user attribute. | ||
setCustomUserAttributeObjectArray( | ||
key: string, | ||
value: object[], | ||
callback?: ((error?: Object, result?: boolean) => void) | null | ||
): void; | ||
setDateCustomUserAttribute( | ||
@@ -127,2 +145,3 @@ key: string, | ||
getContentCards(): Promise<ContentCard[]>; | ||
getCachedContentCards(): Promise<ContentCard[]>; | ||
getCardCountForCategories( | ||
@@ -143,2 +162,9 @@ category: string, | ||
requestGeofences(latitude: number, longitude: number): void; | ||
setLastKnownLocation( | ||
latitude: number, | ||
longitude: number, | ||
altitude: number | null, | ||
horizontalAccuracy: number | null, | ||
verticalAccuracy: number | null | ||
): void; | ||
setLocationCustomAttribute( | ||
@@ -172,2 +198,3 @@ key: string, | ||
refreshFeatureFlags(): void; | ||
logFeatureFlagImpression(flagId: string): void; | ||
@@ -174,0 +201,0 @@ // NativeEventEmitter methods for the New Architecture. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
249051
2820