@braze/react-native-sdk
Advanced tools
@@ -16,8 +16,20 @@ const NativeEventEmitter = require('react-native').NativeEventEmitter; | ||
| test('it calls BrazeReactBridge.registerAndroidPushToken', () => { | ||
| test('it calls BrazeReactBridge.registerAndroidPushToken on Android', () => { | ||
| const platform = Platform.OS; | ||
| Platform.OS = 'android'; | ||
| const token = "some_token"; | ||
| Braze.registerAndroidPushToken(token); | ||
| expect(NativeBrazeReactModule.registerPushToken).toBeCalledWith(token); | ||
| Platform.OS = platform; | ||
| }); | ||
| test('it calls BrazeReactBridge.registerAndroidPushToken on iOS', () => { | ||
| const platform = Platform.OS; | ||
| Platform.OS = 'ios'; | ||
| const token = "some_token"; | ||
| Braze.registerAndroidPushToken(token); | ||
| expect(NativeBrazeReactModule.registerPushToken).not.toBeCalledWith(token); | ||
| Platform.OS = platform; | ||
| }); | ||
| test('it calls BrazeReactBridge.registerPushToken', () => { | ||
@@ -243,2 +255,18 @@ const token = "some_token"; | ||
| test('it calls BrazeReactBridge.getUserId', () => { | ||
| const user_id = "some_user_id"; | ||
| Braze.changeUser(user_id); | ||
| NativeBrazeReactModule.getUserId.mockImplementation((callback) => { | ||
| callback(null, "some_user_id"); | ||
| }); | ||
| }); | ||
| test('it calls BrazeReactBridge.getUserId with null', () => { | ||
| const user_id = null; | ||
| Braze.changeUser(user_id); | ||
| NativeBrazeReactModule.getUserId.mockImplementation((callback) => { | ||
| callback(null, null); | ||
| }); | ||
| }); | ||
| test('it calls BrazeReactBridge.setSdkAuthenticationSignature', () => { | ||
@@ -245,0 +273,0 @@ const signature = "signature"; |
@@ -29,2 +29,3 @@ jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter'); | ||
| changeUser: jest.fn(), | ||
| getUserId: jest.fn(), | ||
| setSdkAuthenticationSignature: jest.fn(), | ||
@@ -31,0 +32,0 @@ addAlias: jest.fn(), |
@@ -55,4 +55,4 @@ apply plugin: 'com.android.library' | ||
| dependencies { | ||
| api 'com.braze:android-sdk-ui:27.0.1' | ||
| api 'com.braze:android-sdk-ui:29.0.0' | ||
| api 'com.facebook.react:react-native:+' | ||
| } |
@@ -79,2 +79,12 @@ package com.braze.reactbridge | ||
| fun getUserId(callback: Callback?) { | ||
| runOnUser { | ||
| if (it.userId.isNullOrBlank()) { | ||
| callback.reportResult(null, "User ID not found.") | ||
| } else { | ||
| callback.reportResult(it.userId) | ||
| } | ||
| } | ||
| } | ||
| fun addAlias(aliasName: String?, aliasLabel: String?) { | ||
@@ -791,3 +801,7 @@ if (aliasName.isNullOrBlank()) { | ||
| val ff = braze.getFeatureFlag(id) | ||
| promise.resolve(convertFeatureFlag(ff)) | ||
| if (ff == null) { | ||
| promise.resolve(null) | ||
| } else { | ||
| promise.resolve(convertFeatureFlag(ff)) | ||
| } | ||
| } | ||
@@ -806,3 +820,3 @@ } | ||
| if (id != null && key != null && promise != null) { | ||
| promise.resolve(braze.getFeatureFlag(id).getBooleanProperty(key)) | ||
| promise.resolve(braze.getFeatureFlag(id)?.getBooleanProperty(key)) | ||
| } | ||
@@ -813,3 +827,3 @@ } | ||
| if (id != null && key != null && promise != null) { | ||
| promise.resolve(braze.getFeatureFlag(id).getStringProperty(key)) | ||
| promise.resolve(braze.getFeatureFlag(id)?.getStringProperty(key)) | ||
| } | ||
@@ -820,3 +834,3 @@ } | ||
| if (id != null && key != null && promise != null) { | ||
| promise.resolve(braze.getFeatureFlag(id).getNumberProperty(key)) | ||
| promise.resolve(braze.getFeatureFlag(id)?.getNumberProperty(key)) | ||
| } | ||
@@ -823,0 +837,0 @@ } |
@@ -38,3 +38,3 @@ package com.braze.reactbridge | ||
| when (card.cardType) { | ||
| CardType.BANNER -> mappedCard.merge(bannerImageCardToWritableMap(card as BannerImageCard)) | ||
| CardType.IMAGE -> mappedCard.merge(imageOnlyCardToWritableMap(card as ImageOnlyCard)) | ||
| CardType.CAPTIONED_IMAGE -> mappedCard.merge(captionedImageCardToWritableMap(card as CaptionedImageCard)) | ||
@@ -79,3 +79,3 @@ CardType.SHORT_NEWS -> mappedCard.merge(shortNewsCardToWritableMap(card as ShortNewsCard)) | ||
| fun bannerImageCardToWritableMap(card: BannerImageCard): WritableMap { | ||
| fun imageOnlyCardToWritableMap(card: ImageOnlyCard): WritableMap { | ||
| val mappedCard = Arguments.createMap() | ||
@@ -85,3 +85,3 @@ mappedCard.putString("image", card.imageUrl) | ||
| mappedCard.putString("domain", card.domain) | ||
| mappedCard.putString("type", "Banner") | ||
| mappedCard.putString("type", "ImageOnly") | ||
| return mappedCard | ||
@@ -88,0 +88,0 @@ } |
@@ -24,2 +24,6 @@ package com.braze.reactbridge | ||
| override fun getUserId(callback: Callback?) { | ||
| return brazeImpl.getUserId(callback) | ||
| } | ||
| override fun setSdkAuthenticationSignature(signature: String?) { | ||
@@ -26,0 +30,0 @@ brazeImpl.setSdkAuthenticationSignature(signature) |
@@ -25,2 +25,7 @@ package com.braze.reactbridge | ||
| } | ||
| @ReactMethod | ||
| fun getUserId(callback: Callback?) { | ||
| return brazeImpl.getUserId(callback) | ||
| } | ||
@@ -27,0 +32,0 @@ @ReactMethod |
@@ -164,2 +164,13 @@ #import "BrazeReactBridge.h" | ||
| RCT_EXPORT_METHOD(getUserId:(RCTResponseSenderBlock)callback) { | ||
| RCTLogInfo(@"getUserId called"); | ||
| [braze.user idWithCompletion:^(NSString * _Nullable userId) { | ||
| if (!userId) { | ||
| [self reportResultWithCallback:callback andError:@"User ID not found." andResult:userId]; | ||
| return; | ||
| } | ||
| [self reportResultWithCallback:callback andError:nil andResult:userId]; | ||
| }]; | ||
| } | ||
| RCT_EXPORT_METHOD(addAlias:(NSString *)aliasName aliasLabel:(NSString *)aliasLabel) { | ||
@@ -705,6 +716,6 @@ RCTLogInfo(@"braze.user addAlias with values %@ %@", aliasName, aliasLabel); | ||
| break; | ||
| case BRZContentCardRawTypeBanner: | ||
| case BRZContentCardRawTypeImageOnly: | ||
| formattedContentCardData[@"image"] = RCTNullIfNil(card.image ? card.image.absoluteString : nil); | ||
| formattedContentCardData[@"imageAspectRatio"] = @(card.imageAspectRatio); | ||
| formattedContentCardData[@"type"] = @"Banner"; | ||
| formattedContentCardData[@"type"] = @"ImageOnly"; | ||
| break; | ||
@@ -902,2 +913,6 @@ case BRZContentCardRawTypeClassic: | ||
| BRZFeatureFlag *featureFlag = [braze.featureFlags featureFlagWithId:flagId]; | ||
| if (!featureFlag) { | ||
| resolve([NSNull null]); | ||
| return; | ||
| } | ||
| NSError* error = nil; | ||
@@ -904,0 +919,0 @@ id flagJSON = [NSJSONSerialization JSONObjectWithData:[featureFlag json] |
+1
-1
| { | ||
| "name": "@braze/react-native-sdk", | ||
| "version": "7.0.0", | ||
| "version": "8.0.0", | ||
| "description": "Braze SDK for React Native.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
+18
-2
@@ -134,2 +134,16 @@ import { | ||
| /** | ||
| * Returns a unique ID stored for the user. | ||
| * If the user is anonymous, there is no ID stored for the user and this method will return `null`. | ||
| * | ||
| * @param {function(error, result)} callback - A callback that receives the function call result. | ||
| */ | ||
| static getUserId(callback) { | ||
| callFunctionWithCallback( | ||
| this.bridge.getUserId, | ||
| [], | ||
| callback | ||
| ); | ||
| } | ||
| /** | ||
| * Sets the signature to be used to authenticate the current user. You can also set the signature when calling `changeUser`. | ||
@@ -166,3 +180,5 @@ * This signature will only have an effect if SDK Authentication is enabled. | ||
| static registerAndroidPushToken(token) { | ||
| this.bridge.registerPushToken(token); | ||
| if (Platform.OS === 'android') { | ||
| this.bridge.registerPushToken(token); | ||
| } | ||
| } | ||
@@ -836,3 +852,3 @@ | ||
| * Returns feature flag | ||
| * @returns {Promise<FeatureFlag>} | ||
| * @returns {Promise<FeatureFlag|null>} | ||
| */ | ||
@@ -839,0 +855,0 @@ static getFeatureFlag(id) { |
+23
-9
@@ -70,2 +70,10 @@ // Definitions by: ahanriat <https://github.com/ahanriat> | ||
| /** | ||
| * Returns a unique ID stored for the user. | ||
| * If the user is anonymous, there is no ID stored for the user and this method will return `null`. | ||
| * | ||
| * @param {function(error, result)} callback - A callback that receives the function call result. | ||
| */ | ||
| export function getUserId(callback: Callback<string>): void; | ||
| /** | ||
| * Sets the signature to be used to authenticate the current user. You can also set the signature when calling `changeUser`. | ||
@@ -451,4 +459,4 @@ * This signature will only have an effect if SDK Authentication is enabled. | ||
| export interface BannerContentCard extends ContentCardBase { | ||
| type: 'Banner'; | ||
| export interface ImageOnlyContentCard extends ContentCardBase { | ||
| type: 'ImageOnly'; | ||
| image: string; | ||
@@ -469,3 +477,3 @@ imageAspectRatio: number; | ||
| | ClassicContentCard | ||
| | BannerContentCard | ||
| | ImageOnlyContentCard | ||
| | CaptionedContentCard; | ||
@@ -701,6 +709,9 @@ | ||
| /** | ||
| * Get a feature flag by its ID | ||
| * @returns {Promise<FeatureFlag>} | ||
| * Get a feature flag by its ID. | ||
| * | ||
| * @param id - The ID of the feature flag. | ||
| * @returns A promise containing the feature flag. | ||
| * If there is no feature flag with that ID, this method will return a null. | ||
| */ | ||
| export function getFeatureFlag(id: string): Promise<FeatureFlag>; | ||
| export function getFeatureFlag(id: string): Promise<FeatureFlag | null>; | ||
@@ -714,3 +725,4 @@ /** | ||
| * @returns A promise containing the value of the property if the key is found and is of type boolean. | ||
| * If the key is not found or if there is a type mismatch, this method will return a null. | ||
| * If the key is not found, if there is a type mismatch, or if there is no feature flag for that ID, | ||
| * this method will return a null. | ||
| */ | ||
@@ -726,3 +738,4 @@ export function getFeatureFlagBooleanProperty(id: string, key: string): Promise<boolean | null>; | ||
| * @returns A promise containing the value of the property if the key is found and is of type string. | ||
| * If the key is not found or if there is a type mismatch, this method will return a null. | ||
| * If the key is not found, if there is a type mismatch, or if there is no feature flag for that ID, | ||
| * this method will return a null. | ||
| */ | ||
@@ -738,3 +751,4 @@ export function getFeatureFlagStringProperty(id: string, key: string): Promise<string | null>; | ||
| * @returns A promise containing the value of the property if the key is found and is of type number. | ||
| * If the key is not found or if there is a type mismatch, this method will return a null. | ||
| * If the key is not found, if there is a type mismatch, or if there is no feature flag for that ID, | ||
| * this method will return a null. | ||
| */ | ||
@@ -741,0 +755,0 @@ export function getFeatureFlagNumberProperty(id: string, key: string): Promise<number | null>; |
@@ -28,3 +28,3 @@ // Enums | ||
| CLASSIC: 'Classic', | ||
| BANNER: 'Banner', | ||
| IMAGE_ONLY: 'ImageOnly', | ||
| CAPTIONED: 'Captioned' | ||
@@ -31,0 +31,0 @@ }; |
@@ -9,2 +9,3 @@ import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport'; | ||
| changeUser(userId: string, signature?: string | null): void; | ||
| getUserId(callback: (error?: Object, result?: string) => void): void; | ||
| setSdkAuthenticationSignature(signature: string): void; | ||
@@ -189,3 +190,3 @@ addAlias(aliasName: string, aliasLabel: string): void; | ||
| getAllFeatureFlags(): Promise<FeatureFlag[]>; | ||
| getFeatureFlag(flagId: string): Promise<FeatureFlag>; | ||
| getFeatureFlag(flagId: string): Promise<FeatureFlag | null>; | ||
| getFeatureFlagBooleanProperty(flagId: string, key: string): Promise<boolean | null>; | ||
@@ -192,0 +193,0 @@ getFeatureFlagStringProperty(flagId: string, key: string): Promise<string | null>; |
Sorry, the diff of this file is not supported yet
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
252145
1.24%2875
1.95%