react-native-moengage 11.1.4 → 11.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 24-03-2025
2
+
3
+ ## 11.2.0
4
+ - Added support to identify user on multiple identities
5
+ - Android
6
+ - Added support for AGP `8.7.3` and above
7
+ - `moe-android-sdk` version updated to `13.06.00`
8
+ - `inapp` version updated to `8.8.0`
9
+ - iOS
10
+ - `MoEngage-iOS-SDK` version updated to `9.23.1`
11
+
1
12
  # 11-03-2025
2
13
 
3
14
  ## 11.1.4
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
16
16
  s.source_files = 'iOS/MoEReactBridge/**/*.{h,m,mm}'
17
17
  s.public_header_files = 'iOS/MoEReactBridge/**/*.h'
18
18
  s.dependency 'React'
19
- s.dependency 'MoEngagePluginBase','5.2.0'
19
+ s.dependency 'MoEngagePluginBase','5.3.0'
20
20
  s.ios.dependency 'MoEngage-iOS-SDK/RichNotification'
21
21
  s.module_map = false
22
22
 
@@ -6,7 +6,7 @@ buildscript {
6
6
  }
7
7
 
8
8
  dependencies {
9
- classpath 'com.android.tools.build:gradle:8.4.0'
9
+ classpath 'com.android.tools.build:gradle:8.7.3'
10
10
  classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
11
11
  }
12
12
  }
@@ -20,9 +20,9 @@ rootProject.allprojects {
20
20
 
21
21
  ext {
22
22
  //dependency version
23
- moengageCoreVersion = "13.05.02"
24
- moengageInAppVersion = "8.7.1"
25
- basePluginVersion = "4.2.1"
23
+ moengageCoreVersion = "13.06.00"
24
+ moengageInAppVersion = "8.8.0"
25
+ basePluginVersion = "4.3.0"
26
26
  //build versions
27
27
  minimumVersion = 21
28
28
  compileVersion = 34
@@ -1,6 +1,6 @@
1
1
  #Thu Aug 18 13:23:11 IST 2022
2
2
  distributionBase=GRADLE_USER_HOME
3
- distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
3
+ distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip
4
4
  distributionPath=wrapper/dists
5
5
  zipStorePath=wrapper/dists
6
6
  zipStoreBase=GRADLE_USER_HOME
@@ -24,8 +24,9 @@
24
24
  import com.moengage.plugin.base.internal.selfHandledInAppsToJson
25
25
  import com.moengage.plugin.base.internal.setEventEmitter
26
26
  import com.moengage.plugin.base.internal.userDeletionDataToJson
27
-
28
- /**
27
+ import org.json.JSONObject
28
+
29
+ /**
29
30
  * Class to handle all the request from the [MoEReactBridge] from both old and new arch
30
31
  *
31
32
  * @author Abhishek Kumar
@@ -264,11 +265,7 @@
264
265
  Logger.print(LogLevel.ERROR, t) { "$tag showNudge() :" }
265
266
  }
266
267
  }
267
-
268
- companion object {
269
- const val NAME = "MoEReactBridge"
270
- }
271
-
268
+
272
269
  fun getSelfHandledInApps(payload: String, promise: Promise) {
273
270
  try {
274
271
  Logger.print { "$tag getSelfHandledInApps() : Payload: $payload" }
@@ -280,4 +277,41 @@
280
277
  promise.reject(t)
281
278
  }
282
279
  }
280
+
281
+ /**
282
+ * Identify the user with the given identity payload
283
+ */
284
+ fun identifyUser(payload: String) {
285
+ try {
286
+ Logger.print { "$tag identifyUser() : Payload: $payload" }
287
+ pluginHelper.identifyUser(context, payload)
288
+ } catch (t: Throwable) {
289
+ Logger.print(LogLevel.ERROR, t) { "$tag identifyUser() : " }
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Return Identities of the user that has been set.
295
+ */
296
+ fun getUserIdentities(payload: String, promise: Promise) {
297
+ try {
298
+ Logger.print { "$tag getUserIdentities() : Payload: $payload" }
299
+ pluginHelper.getUserIdentities(context, payload) { identities ->
300
+ promise.resolve(
301
+ if (identities == null) {
302
+ null
303
+ } else {
304
+ JSONObject(identities).toString()
305
+ }
306
+ )
307
+ }
308
+ } catch (t: Throwable) {
309
+ Logger.print(LogLevel.ERROR, t) { "$tag getUserIdentities() : " }
310
+ promise.reject(t)
311
+ }
312
+ }
313
+
314
+ companion object {
315
+ const val NAME = "MoEReactBridge"
316
+ }
283
317
  }
@@ -137,6 +137,14 @@ class MoEReactBridge(reactContext: ReactApplicationContext) : NativeMoEngageSpec
137
137
  bridgeHandler.deleteUser(payload, promise)
138
138
  }
139
139
 
140
+ override fun identifyUser(payload: String) {
141
+ bridgeHandler.identifyUser(payload)
142
+ }
143
+
144
+ override fun getUserIdentities(payload: String, promise: Promise) {
145
+ bridgeHandler.getUserIdentities(payload, promise)
146
+ }
147
+
140
148
  override fun registerForPush() {
141
149
  // iOS only
142
150
  }
@@ -174,4 +174,14 @@ class MoEReactBridge(
174
174
  fun getSelfHandledInApps(payload: String, promise: Promise) {
175
175
  bridgeHandler.getSelfHandledInApps(payload, promise)
176
176
  }
177
+
178
+ @ReactMethod
179
+ fun identifyUser(payload: String) {
180
+ bridgeHandler.identifyUser(payload)
181
+ }
182
+
183
+ @ReactMethod
184
+ fun getUserIdentities(payload: String, promise: Promise) {
185
+ bridgeHandler.getUserIdentities(payload, promise)
186
+ }
177
187
  }
@@ -170,6 +170,14 @@ RCT_EXPORT_METHOD(updateSdkState:(NSString *)payload) {
170
170
  [[MoEReactNativeHandler sharedInstance] updateSdkState:payload];
171
171
  }
172
172
 
173
+ RCT_EXPORT_METHOD(identifyUser:(NSString *)payload) {
174
+ [[MoEReactNativeHandler sharedInstance] identifyUser:payload];
175
+ }
176
+
177
+ RCT_EXPORT_METHOD(getUserIdentities:(NSString *)payload resolve:(RCTPromiseResolveBlock) resolve reject:(RCTPromiseRejectBlock)reject) {
178
+ [[MoEReactNativeHandler sharedInstance] getUserIdentities:payload resolve:resolve reject:reject];
179
+ }
180
+
173
181
  // MARK: Unimplemented method
174
182
 
175
183
  RCT_EXPORT_METHOD(deleteUser:(NSString *)payload) {
@@ -36,4 +36,6 @@
36
36
  -(void)optOutDataTracking:(NSString *)payload;
37
37
  -(void)updateSdkState:(NSString *)payload;
38
38
  -(void)registerForProvisionalPush;
39
+ -(void)identifyUser:(NSString *)payload;
40
+ -(void)getUserIdentities:(NSString *)payload resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject;
39
41
  @end
@@ -138,6 +138,30 @@
138
138
  [[MoEngagePluginBridge sharedInstance] updateSDKState:jsonPayload];
139
139
  }
140
140
 
141
+ #pragma mark- User Identities
142
+ -(void)identifyUser:(NSString *)payload {
143
+ NSDictionary* jsonPayload = [MoEngageReactUtils getJSONRepresentation:payload];
144
+ [[MoEngagePluginBridge sharedInstance] identifyUser:jsonPayload];
145
+ }
146
+
147
+ -(void)getUserIdentities:(NSString *)payload resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
148
+ NSDictionary* jsonPayload = [MoEngageReactUtils getJSONRepresentation:payload];
149
+ [[MoEngagePluginBridge sharedInstance] getUserIdentities:jsonPayload completionHandler:^(NSDictionary<NSString *,NSString *> * _Nonnull identities) {
150
+ NSError *err;
151
+ NSData * jsonData = [NSJSONSerialization dataWithJSONObject:identities options:0 error:&err];
152
+ if (jsonData) {
153
+ NSString *strPayload = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
154
+ dispatch_async(dispatch_get_main_queue(), ^{
155
+ resolve(strPayload);
156
+ });
157
+ } else {
158
+ dispatch_async(dispatch_get_main_queue(), ^{
159
+ reject(@"Error", @"Error in parsing User Identities Payload", err ? : [NSError errorWithDomain:@"" code:400 userInfo:@{@"Error reason": @"Error in parsing User Identities Payload"}]);
160
+ });
161
+ }
162
+ }];
163
+ }
164
+
141
165
  #pragma mark- Delegate Method
142
166
  - (void)sendMessageWithEvent:(NSString *)event message:(NSDictionary<NSString *,id> *)message {
143
167
  NSMutableDictionary* updatedDict = [NSMutableDictionary dictionary];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-moengage",
3
- "version": "11.1.4",
3
+ "version": "11.2.0",
4
4
  "description": "MoEngage is a mobile marketing automation company. This react-native SDK helps you track events, trigger smart notifications and in-apps, provides a drop-in Inbox Controller for notifications.",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -24,7 +24,7 @@
24
24
  "events"
25
25
  ],
26
26
  "scripts": {
27
- "test": "echo \"Test cases not available\" && exit 0"
27
+ "test": "jest"
28
28
  },
29
29
  "author": {
30
30
  "name": "MoEngage",
@@ -35,7 +35,10 @@
35
35
  ],
36
36
  "license": "SEE LICENSE IN LICENSE.txt",
37
37
  "devDependencies": {
38
- "react-native": "0.73.0"
38
+ "react-native": "0.73.0",
39
+ "@types/jest": "^29.5.0",
40
+ "ts-jest": "^29.1.0",
41
+ "typescript": "^4.3.0"
39
42
  },
40
43
  "codegenConfig": {
41
44
  "name": "NativeMoEngageSpec",
@@ -45,4 +48,4 @@
45
48
  "javaPackageName": "com.moengage.react"
46
49
  }
47
50
  }
48
- }
51
+ }
@@ -123,6 +123,18 @@ export interface Spec extends TurboModule {
123
123
  */
124
124
  updateSdkState: (payload: string) => void;
125
125
 
126
+ /**
127
+ * Identify the user with the given identifiers.
128
+ * @param payload Stringified JSON payload
129
+ */
130
+ identifyUser: (payload: string) => void;
131
+
132
+ /**
133
+ * Return Identities of the user that has been set.
134
+ * @param payload Stringified JSON payload
135
+ */
136
+ getUserIdentities: (payload: string) => Promise<string | null>;
137
+
126
138
  /// Anroid specific
127
139
 
128
140
  /**
package/src/index.ts CHANGED
@@ -26,7 +26,8 @@ import {
26
26
  getDeviceIdTrackingJson,
27
27
  getInitConfigJson,
28
28
  getPermissionResponseJson,
29
- getNudgeDisplayJson
29
+ getNudgeDisplayJson,
30
+ getIdentifyUserPayload
30
31
  } from "./utils/MoEJsonBuilder";
31
32
  import {
32
33
  USER_ATTRIBUTE_UNIQUE_ID,
@@ -54,7 +55,7 @@ import MoEReactBridge from "./NativeMoEngage";
54
55
  import MoEPushToken from "../src/models/MoEPushToken";
55
56
  import MoEPushPayload from "../src/models/MoEPushPayload";
56
57
  import MoEInAppData from "../src/models/MoEInAppData";
57
- import { getUserDeletionData } from "../src/moeParser/MoEngagePayloadParser";
58
+ import { getUserDeletionData, getUserIdentitiesData } from "../src/moeParser/MoEngagePayloadParser";
58
59
  import { MoEngageNudgePosition } from "../src/models/MoEngageNudgePosition";
59
60
  import MoEAnalyticsConfig from "../src/models/MoEAnalyticsConfig";
60
61
  import { MoESupportedAttributes } from "./models/MoESupportedAttributes";
@@ -203,8 +204,11 @@ var ReactMoE = {
203
204
  /**
204
205
  * Sets the unique id of the user. Should be set on user login.
205
206
  * @param uniqueId unique id to be set
207
+ *
208
+ * @deprecated This function is deprecated in favour of identifyUser(). This function will be removed in 13.0.0"
206
209
  */
207
210
  setUserUniqueID: function (uniqueId: string) {
211
+ MoEngageLogger.warn("Deprecated function usage `setUserUniqueID`, use `identifyUser`");
208
212
  MoEngageLogger.verbose("Will set unique ID: ", uniqueId);
209
213
  const payload = getUserAttributeJson(USER_ATTRIBUTE_UNIQUE_ID, uniqueId, GENERAL, moeAppId);
210
214
  MoEReactBridge.setUserAttribute(payload);
@@ -213,8 +217,11 @@ var ReactMoE = {
213
217
  /**
214
218
  * Update user's unique id which was previously set by setUserUniqueID()
215
219
  * @param alias updated unique id.
220
+ *
221
+ * @deprecated This function is deprecated in favour of identifyUser(). This function will be removed in 13.0.0"
216
222
  */
217
223
  setAlias: function (alias: string) {
224
+ MoEngageLogger.warn("Deprecated function usage `setAlias`, use `identifyUser`");
218
225
  MoEngageLogger.verbose("Will set alias: ", alias);
219
226
  let payload = getAliasJson(alias, moeAppId);
220
227
  MoEReactBridge.setAlias(payload);
@@ -750,6 +757,29 @@ var ReactMoE = {
750
757
  MoEngageLogger.debug("This api is not supported on Android platform.");
751
758
  }
752
759
  },
760
+
761
+ /**
762
+ * Identify the user with the given identity.
763
+ * @since Todo: Add Version
764
+ */
765
+ identifyUser(identity: string | { [k: string]: string }) {
766
+ MoEReactBridge.identifyUser(getIdentifyUserPayload(identity, moeAppId));
767
+ },
768
+
769
+ /**
770
+ * Return Identities of the user that has been set.
771
+ * @since Todo: Add Version
772
+ */
773
+ getUserIdentities: async function (): Promise<{ [k: string]: string } | null> {
774
+ try {
775
+ return getUserIdentitiesData(
776
+ await MoEReactBridge.getUserIdentities(getAppIdJson(moeAppId))
777
+ );
778
+ } catch (error) {
779
+ MoEngageLogger.error(`getUserIdentities(): ${error}`);
780
+ return null;
781
+ }
782
+ }
753
783
  };
754
784
 
755
785
  export {
@@ -43,4 +43,16 @@ export function getUserDeletionData(payload: string): UserDeletionData {
43
43
  getMoEAccountMeta(payloadJsonObject[ACCOUNT_META]),
44
44
  payloadJsonObject[MOE_DATA][IS_USER_DELETION_SUCCESS]
45
45
  );
46
+ }
47
+
48
+ export function getUserIdentitiesData(payload: string | null): { [k: string]: string } | null {
49
+ if (payload === null) {
50
+ return null;
51
+ }
52
+ const payloadJsonObject: { [k: string]: string } = JSON.parse(payload);
53
+ const mappedIdentities: { [k: string]: string } = {};
54
+ for (let [key, value] of Object.entries(payloadJsonObject)) {
55
+ mappedIdentities[key] = value;
56
+ }
57
+ return mappedIdentities;
46
58
  }
@@ -81,4 +81,8 @@ export const DEFAULT_CONFIG_LOG_LEVEL = MoEngageLogLevel.INFO;
81
81
  export const DEFAULT_CONFIG_RELEASE_BUILD_LOG_ENABLED = false;
82
82
 
83
83
  // Key to get the user deletion state while deleting user from native bridge
84
- export const IS_USER_DELETION_SUCCESS = "isUserDeletionSuccess";
84
+ export const IS_USER_DELETION_SUCCESS = "isUserDeletionSuccess";
85
+
86
+ // Identify User
87
+ export const USER_IDENTITY = 'identity';
88
+ export const USER_UNIQUE_IDENTITY = 'uid';
@@ -11,6 +11,7 @@ import { MoEngageNudgePosition } from "../models/MoEngageNudgePosition";
11
11
  import { MoESupportedAttributes } from "../models/MoESupportedAttributes";
12
12
  import MoESelfHandledCampaign from "../models/MoESelfHandledCampaign";
13
13
  import MoEInAppRules from "../models/MoEInAppRules";
14
+ import { ACCOUNT_META, APP_ID, MOE_DATA, USER_IDENTITY, USER_UNIQUE_IDENTITY } from "./MoEConstants";
14
15
 
15
16
  export function getInAppCampaignJson(moEInAppData: MoEInAppData, type: string, appId: String) {
16
17
  var json: { [k: string]: any } = {
@@ -305,4 +306,22 @@ export function getDisplayRulesJson(displayRules: MoEInAppRules) {
305
306
  }
306
307
  MoEngageLogger.verbose("getDisplayRulesJson(): payload json: ", json);
307
308
  return json;
309
+ }
310
+
311
+ export function getIdentifyUserPayload(identity: string | { [k: string]: string }, appId: string): string {
312
+ var payload: { [k: string]: any } = {
313
+ [ACCOUNT_META]: {
314
+ [APP_ID]: appId
315
+ },
316
+ };
317
+ if (typeof identity === 'string') {
318
+ payload[MOE_DATA] = {
319
+ [USER_IDENTITY]: { [USER_UNIQUE_IDENTITY]: identity }
320
+ };
321
+ } else {
322
+ payload[MOE_DATA] = {
323
+ [USER_IDENTITY]: identity
324
+ };
325
+ }
326
+ return JSON.stringify(payload);
308
327
  }