@braze/react-native-sdk
Advanced tools
Comparing version 13.0.0 to 13.1.0
@@ -12,2 +12,24 @@ const NativeEventEmitter = require('react-native').NativeEventEmitter; | ||
const testPushPayloadJson = { | ||
"use_webview": false, | ||
"is_silent": false, | ||
"ios": { | ||
"aps": { | ||
"alert": { | ||
"title": "Test Message", | ||
"body": "Hello World" | ||
}, | ||
"interruption-level": "active" | ||
}, | ||
"action_identifier": "com.apple.UNNotificationDefaultActionIdentifier" | ||
}, | ||
"payload_type": "push_opened", | ||
"title": "Test Message", | ||
"braze_properties": {}, | ||
"is_braze_internal": false, | ||
"body": "Hello World", | ||
"timestamp": 1728060077, | ||
"url": "www.braze.com" | ||
}; | ||
afterEach(() => { | ||
@@ -474,9 +496,18 @@ jest.clearAllMocks(); | ||
NativeBrazeReactModule.getInitialURL.mockImplementation((callback) => { | ||
callback(null, "some_data"); | ||
callback(null, testPushPayloadJson["url"]); | ||
}); | ||
Braze.getInitialURL(testCallback); | ||
expect(NativeBrazeReactModule.getInitialURL).toBeCalled(); | ||
expect(testCallback).toBeCalledWith("some_data"); | ||
expect(testCallback).toBeCalledWith(testPushPayloadJson["url"]); | ||
}); | ||
test('it calls BrazeReactBridge.getInitialPushPayload if defined', () => { | ||
NativeBrazeReactModule.getInitialPushPayload.mockImplementation((callback) => { | ||
callback(null, testPushPayloadJson); | ||
}); | ||
Braze.getInitialPushPayload(testCallback); | ||
expect(NativeBrazeReactModule.getInitialPushPayload).toBeCalled(); | ||
expect(testCallback).toBeCalledWith(testPushPayloadJson); | ||
}); | ||
test('it calls BrazeReactBridge.getDeviceId', () => { | ||
@@ -501,2 +532,12 @@ NativeBrazeReactModule.getDeviceId.mockImplementation((callback) => { | ||
test('it calls the callback with null and logs the error if BrazeReactBridge.getInitialPushPayload returns an error', () => { | ||
NativeBrazeReactModule.getInitialPushPayload.mockImplementation((callback) => { | ||
callback("error", null); | ||
}); | ||
Braze.getInitialPushPayload(testCallback); | ||
expect(NativeBrazeReactModule.getInitialPushPayload).toBeCalled(); | ||
expect(testCallback).toBeCalledWith(null); | ||
expect(console.log).toBeCalledWith("error"); | ||
}); | ||
test('it calls the callback with null if BrazeReactBridge.getInitialUrl is running on Android', () => { | ||
@@ -510,2 +551,10 @@ const platform = Platform.OS; | ||
test('it calls the callback with null if BrazeReactBridge.getInitialPushPayload is running on Android', () => { | ||
const platform = Platform.OS; | ||
Platform.OS = 'android'; | ||
Braze.getInitialPushPayload(testCallback); | ||
expect(testCallback).toBeCalledWith(null); | ||
Platform.OS = platform; | ||
}); | ||
test('it calls BrazeReactBridge.subscribeToInAppMessage', () => { | ||
@@ -512,0 +561,0 @@ Braze.subscribeToInAppMessage(true, testCallback); |
@@ -73,2 +73,3 @@ jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter'); | ||
getInitialURL: jest.fn(), | ||
getInitialPushPayload: jest.fn(), | ||
getDeviceId: jest.fn(), | ||
@@ -75,0 +76,0 @@ requestLocationInitialization: jest.fn(), |
{ | ||
"name": "@braze/react-native-sdk", | ||
"version": "13.0.0", | ||
"version": "13.1.0", | ||
"description": "Braze SDK for React Native.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -43,12 +43,34 @@ import { | ||
/** | ||
* @deprecated This method is deprecated in favor of `getInitialPushPayload`. | ||
* | ||
* To get the initial URL, call `getInitialPushPayload` and get the `url` key from the payload object. | ||
*/ | ||
static getInitialURL(callback) { | ||
if (Platform.OS === 'ios') { | ||
this.bridge.getInitialURL((err, res) => { | ||
if (err) { | ||
console.log(err); | ||
callback(null); | ||
} else { | ||
callback(res); | ||
} | ||
}); | ||
} else { | ||
// BrazeReactBridge.getInitialUrl not implemented on Android | ||
callback(null); | ||
} | ||
} | ||
/** | ||
* When launching an iOS application that has previously been force closed, React Native's Linking API doesn't | ||
* support handling deep links embedded in push notifications. This is due to a race condition on startup between | ||
* support handling push notifications and deep links in the payload. This is due to a race condition on startup between | ||
* the native call to RCTLinkingManager and React's loading of its JavaScript. This function provides a workaround: | ||
* If an application is launched from a push notification click, we return any Braze deep links in the push payload. | ||
* @param {function(string)} callback - A callback that retuns the deep link as a string. If there is no deep link, returns null. | ||
* If an application is launched from a push notification click, we return the full push payload. | ||
* @param {function(string)} callback - A callback that retuns the push notification as an Object. If there is no push payload, | ||
* returns null. | ||
*/ | ||
static getInitialURL(callback) { | ||
static getInitialPushPayload(callback) { | ||
if (Platform.OS === 'ios') { | ||
this.bridge.getInitialURL((err, res) => { | ||
this.bridge.getInitialPushPayload((err, res) => { | ||
if (err) { | ||
@@ -62,3 +84,3 @@ console.log(err); | ||
} else { | ||
// BrazeReactBridge.getInitialUrl not implemented on Android | ||
// BrazeReactBridge.getInitialPushPayload not implemented on Android | ||
callback(null); | ||
@@ -65,0 +87,0 @@ } |
@@ -7,8 +7,5 @@ // Definitions by: ahanriat <https://github.com/ahanriat> | ||
/** | ||
* When launching an iOS application that has previously been force closed, React Native's Linking API doesn't | ||
* support handling deep links embedded in push notifications. This is due to a race condition on startup between | ||
* the native call to RCTLinkingManager and React's loading of its JavaScript. This function provides a workaround: | ||
* If an application is launched from a push notification click, we return any Braze deep links in the push payload. | ||
* @param {function(string)} callback - A callback that retuns the deep link as a string. If there is no deep link, | ||
* returns null. | ||
* @deprecated This method is deprecated in favor of `getInitialPushPayload`. | ||
* | ||
* To get the initial URL, call `getInitialPushPayload` and get the `url` key from the payload object. | ||
*/ | ||
@@ -18,2 +15,12 @@ export function getInitialURL(callback: (deepLink: string) => void): void; | ||
/** | ||
* When launching an iOS application that has previously been force closed, React Native's Linking API doesn't | ||
* support handling push notifications and deep links in the payload. This is due to a race condition on startup between | ||
* the call to `addListener` and React's loading of its JavaScript. This function provides a workaround: | ||
* If an application is launched from a push notification click, we return the full push payload. | ||
* @param {function(string)} callback - A callback that returns the formatted Braze push notification as a PushNotificationEvent. | ||
* If there is no push payload, returns null. | ||
*/ | ||
export function getInitialPushPayload(callback: (pushPayload: PushNotificationEvent) => void): void; | ||
/** | ||
* @deprecated This method is deprecated in favor of `getDeviceId`. | ||
@@ -20,0 +27,0 @@ */ |
@@ -7,2 +7,3 @@ import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport'; | ||
getInitialURL(callback: (deepLink: string) => void): void; | ||
getInitialPushPayload(callback: (pushPayload: Object) => void): void; | ||
getDeviceId(callback: (error?: Object, result?: string) => void): void; | ||
@@ -9,0 +10,0 @@ changeUser(userId: string, signature?: string | null): void; |
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
302163
3580