react-native-moengage 7.4.1 → 8.0.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +53 -1
  2. package/ReactNativeMoEngage.podspec +3 -3
  3. package/android/build.gradle +11 -12
  4. package/android/gradle/wrapper/gradle-wrapper.properties +3 -3
  5. package/android/gradle.properties +0 -1
  6. package/android/src/main/java/com/moengage/react/EventEmitterImpl.kt +46 -21
  7. package/android/src/main/java/com/moengage/react/MoEInitializer.kt +44 -13
  8. package/android/src/main/java/com/moengage/react/MoEReactBridge.kt +82 -85
  9. package/android/src/main/java/com/moengage/react/MoEReactHelper.kt +2 -2
  10. package/android/src/main/java/com/moengage/react/PayloadGenerator.kt +32 -17
  11. package/iOS/MoEReactBridge/MoEReactBridge.h +1 -1
  12. package/iOS/MoEReactBridge/MoEReactBridge.m +34 -60
  13. package/iOS/MoEReactBridge/{MOReactInitializer.h → MoEngageInitializer.h} +11 -11
  14. package/iOS/MoEReactBridge/MoEngageInitializer.m +153 -0
  15. package/iOS/MoEReactBridge/{MoEReactConstants.h → MoEngageReactConstants.h} +12 -3
  16. package/iOS/MoEReactBridge/{MoEReactConstants.m → MoEngageReactConstants.m} +13 -7
  17. package/iOS/MoEReactBridge/MoEngageReactPluginInfo.h +2 -0
  18. package/iOS/MoEReactBridge.xcodeproj/project.pbxproj +6 -6
  19. package/package.json +8 -3
  20. package/src/index.ts +134 -203
  21. package/src/models/MoEAccountMeta.ts +8 -0
  22. package/src/models/MoEAction.ts +4 -0
  23. package/src/models/MoEActionType.ts +4 -0
  24. package/src/models/MoECampaignContext.ts +10 -0
  25. package/src/models/MoECampaignData.ts +14 -0
  26. package/src/models/MoEClickData.ts +18 -0
  27. package/src/models/MoEGeoLocation.ts +2 -10
  28. package/src/models/MoEInAppCustomAction.ts +8 -13
  29. package/src/models/MoEInAppData.ts +16 -0
  30. package/src/models/MoEInAppNavigation.ts +14 -24
  31. package/src/models/MoENavigationType.ts +4 -0
  32. package/src/models/MoEPlatform.ts +4 -0
  33. package/src/models/MoEProperties.ts +19 -15
  34. package/src/models/MoEPushCampaign.ts +6 -22
  35. package/src/models/MoEPushPayload.ts +14 -0
  36. package/src/models/MoEPushService.ts +4 -4
  37. package/src/models/MoEPushToken.ts +6 -15
  38. package/src/models/MoESelfHandledCampaign.ts +10 -0
  39. package/src/models/MoESelfHandledCampaignData.ts +18 -0
  40. package/src/moeParser/MoEInAppParser.ts +192 -0
  41. package/src/moeParser/MoEPushNotificationParser.ts +78 -0
  42. package/src/platform/MoERNAndroid.ts +36 -92
  43. package/src/platform/MoERNiOS.ts +27 -60
  44. package/src/utils/MoEConstants.ts +59 -0
  45. package/src/utils/MoEEventHandlerHelper.ts +38 -25
  46. package/src/utils/MoEJsonBuilder.ts +220 -0
  47. package/src/utils/MoEObjectToJson.ts +44 -0
  48. package/iOS/MoEReactBridge/MOReactInitializer.m +0 -172
  49. package/iOS/MoEReactBridge/MOReactPluginInfo.h +0 -2
  50. package/src/models/MoEInAppCampaign.ts +0 -46
  51. package/src/models/MoEInAppSelfHandledCampaign.ts +0 -34
@@ -0,0 +1,220 @@
1
+ import MoEClickData from "../models/MoEClickData";
2
+ import MoEInAppData from "../models/MoEInAppData";
3
+ import MoEProperties from "../models/MoEProperties";
4
+ import MoESelfHandledCampaignData from "../models/MoESelfHandledCampaignData";
5
+ import { MOE_LOCATION } from "./MoEConstants";
6
+ import { MoEPropertiesToJson} from "./MoEObjectToJson";
7
+
8
+ export function getInAppCampaignJson(moEInAppData: MoEInAppData, type: string, appId: String) {
9
+ var json: { [k: string]: any } = {
10
+ accountMeta: {
11
+ appId: appId
12
+ },
13
+ data: {
14
+ type: type,
15
+ campaignName: moEInAppData.campaignData.campaignName,
16
+ campaignId: moEInAppData.campaignData.campaignId,
17
+ campaignContext: moEInAppData.campaignData.context,
18
+ platform: moEInAppData.platform
19
+ }
20
+ }
21
+ return json;
22
+ }
23
+
24
+ export function getSelfHandledJson(moESelfHandledCampaignData: MoESelfHandledCampaignData, type: string, appId: String) {
25
+ var json: { [k: string]: any } = {
26
+ accountMeta: {
27
+ appId: appId
28
+ },
29
+ data: {
30
+ type: type,
31
+ campaignName: moESelfHandledCampaignData.campaignData.campaignName,
32
+ campaignId: moESelfHandledCampaignData.campaignData.campaignId,
33
+ campaignContext: moESelfHandledCampaignData.campaignData.context.attributes,
34
+ selfHandled: moESelfHandledCampaignData.campaign,
35
+ platform: moESelfHandledCampaignData.platform
36
+ }
37
+ }
38
+ console.log("getSelfHandledJson(): payload json: ", json)
39
+ return json;
40
+ }
41
+
42
+ export function getInAppClickDataJson(moEClickData: MoEClickData, type: string, appId: String) {
43
+ var json: { [k: string]: any } = {
44
+ accountMeta: {
45
+ appId: appId
46
+ },
47
+ data: {
48
+ type: type,
49
+ campaignName: moEClickData.campaignData.campaignName,
50
+ campaignId: moEClickData.campaignData.campaignId,
51
+ campaignContext: moEClickData.campaignData.context,
52
+ platform: moEClickData.platform
53
+ }
54
+ }
55
+ return json;
56
+ }
57
+
58
+ export function getMoEPropertiesJson(moEProperties: MoEProperties, eventName: String, appId: String) {
59
+ var json: { [k: string]: any } = {
60
+ accountMeta: {
61
+ appId: appId
62
+ },
63
+ data: {
64
+ ...MoEPropertiesToJson(moEProperties),
65
+ eventName,
66
+ }
67
+ }
68
+ return json;
69
+ }
70
+
71
+ export function getMoEPushCampaignJson(pushPayload: object, service: string, appId: String) {
72
+ var json: { [k: string]: any } = {
73
+ accountMeta: {
74
+ appId: appId
75
+ },
76
+ data: {
77
+ payload: pushPayload,
78
+ service:service
79
+ }
80
+ }
81
+ return json;
82
+ }
83
+
84
+ export function getMoEPushTokenJson(pushToken: string, pushService: string, platform: string, appId: String) {
85
+ var json: { [k: string]: any} = {
86
+ accountMeta: {
87
+ appId: appId
88
+ },
89
+ data: {
90
+ token: pushToken,
91
+ service: pushService,
92
+ platform: platform
93
+
94
+ }
95
+ }
96
+ return json;
97
+ }
98
+
99
+ export function getAliasJson(alias: String, appId: String) {
100
+ var json: { [k: string]: any } = {
101
+ accountMeta: {
102
+ appId: appId
103
+ },
104
+ data:
105
+ { alias: alias }
106
+ }
107
+ return json;
108
+ }
109
+ export function getAppStatusJson(appStatus: String, appId: String) {
110
+ var json: { [k: string]: any } = {
111
+ accountMeta: {
112
+ appId: appId
113
+ },
114
+ data: {
115
+ appStatus: appStatus
116
+ }
117
+ }
118
+ return json;
119
+ }
120
+
121
+ export function getUserAttributeJson(name: String, value: String | object, type: String, appId: String) {
122
+ var json: { [k: string]: any } = {
123
+ accountMeta: {
124
+ appId: appId
125
+ },
126
+ data: {
127
+ attributeName: name,
128
+ attributeValue: value,
129
+ type: type,
130
+ }
131
+ }
132
+ return json;
133
+ }
134
+ export function getUserLocAttributeJson(name: String, latitude: Number, longitude: Number, appId: String) {
135
+ var json: { [k: string]: any } = {
136
+ accountMeta: {
137
+ appId: appId
138
+ },
139
+ data: {
140
+ attributeName: name,
141
+ type: MOE_LOCATION,
142
+ locationAttribute: {
143
+ latitude: latitude,
144
+ longitude: longitude,
145
+ }
146
+ }
147
+ }
148
+ return json;
149
+ }
150
+
151
+ export function getInAppContextJson(contexts: Array<String>, appId: String) {
152
+ var json: { [k: string]: any } = {
153
+ accountMeta: {
154
+ appId: appId
155
+ },
156
+ data: {
157
+ contexts: contexts
158
+ }
159
+ }
160
+ return json;
161
+ }
162
+
163
+ export function getSdkStateJson(isSdkEnabled: Boolean, appId: String) {
164
+ var json: { [k: string]: any } = {
165
+ accountMeta: {
166
+ appId: appId
167
+ },
168
+ data: {
169
+ isSdkEnabled: isSdkEnabled,
170
+
171
+ }
172
+ }
173
+ return json;
174
+ }
175
+
176
+ export function getAdIdTrackingJson(isAdIdTrackingEnabled: Boolean, appId: String) {
177
+ var json: { [k: string]: any } = {
178
+ accountMeta: {
179
+ appId: appId
180
+ },
181
+ data: {
182
+ isAdIdTrackingEnabled: isAdIdTrackingEnabled,
183
+ }
184
+ }
185
+ return json;
186
+ }
187
+
188
+ export function getAndroidIdTrackingJson(isAndroidIdTrackingEnabled: Boolean, appId: String) {
189
+ var json: { [k: string]: any } = {
190
+ accountMeta: {
191
+ appId: appId
192
+ },
193
+ data: {
194
+ isAndroidIdTrackingEnabled: isAndroidIdTrackingEnabled
195
+ }
196
+ }
197
+ return json;
198
+ }
199
+
200
+ export function getAppIdJson(appId: String) {
201
+ var json: { [k: string]: any } = {
202
+ accountMeta: {
203
+ appId: appId
204
+ }
205
+ }
206
+ return json;
207
+ }
208
+
209
+ export function getOptOutTrackingJson(type: string, state: boolean, appId: string) {
210
+ var json: { [k: string]: any } = {
211
+ accountMeta: {
212
+ appId: appId
213
+ },
214
+ data: {
215
+ type: type,
216
+ state: state
217
+ }
218
+ }
219
+ return json;
220
+ }
@@ -0,0 +1,44 @@
1
+ import MoEGeoLocation from "../models/MoEGeoLocation";
2
+ import MoEInAppCustomAction from "../models/MoEInAppCustomAction";
3
+ import MoEProperties from "../models/MoEProperties";
4
+ import MoEPushCampaign from "../models/MoEPushCampaign";
5
+ import MoEPushToken from "../models/MoEPushToken";
6
+
7
+ export function MoEGeoLocationToJson(location: MoEGeoLocation) {
8
+ return {
9
+ latitude: location.latitude,
10
+ longitude: location.longitude,
11
+ };
12
+ }
13
+ export function MoEInAppCustomActionToJson(moEInAppCustomAction: MoEInAppCustomAction | undefined) {
14
+ return {
15
+ kvPair: moEInAppCustomAction?.keyValuePair,
16
+ };
17
+ }
18
+
19
+ export function MoEPropertiesToJson(moEProperties: MoEProperties) {
20
+ return {
21
+ eventAttributes: {
22
+ generalAttributes: moEProperties.getGeneralAttributes(),
23
+ locationAttributes: moEProperties.getLocationAttributess(),
24
+ dateTimeAttributes: moEProperties.getDateTimeAttributes(),
25
+ },
26
+ isNonInteractive: moEProperties.getIsNonInteractive(),
27
+ };
28
+ }
29
+
30
+ export function MoEPushCampaignToJson(moEPushCampaign: MoEPushCampaign) {
31
+ return {
32
+ payload: moEPushCampaign.payload,
33
+ isDefaultAction: moEPushCampaign.isDefaultAction,
34
+ clickAction: moEPushCampaign.clickAction,
35
+
36
+ };
37
+ }
38
+ export function MoEPushTokenToJson(MoEPushToken: MoEPushToken) {
39
+ return {
40
+ platform: MoEPushToken.platform,
41
+ service: MoEPushToken.pushService,
42
+ token: MoEPushToken.token,
43
+ };
44
+ }
@@ -1,172 +0,0 @@
1
- //
2
- // MOReactInitializer.m
3
- // ReactNativeMoEngage
4
- //
5
- // Created by Chengappa C D on 14/02/20.
6
- //
7
-
8
- #import "MOReactInitializer.h"
9
- #import "MOReactPluginInfo.h"
10
- #import <MoEngage/MoEngage.h>
11
- #import <MoEPluginBase/MoEPluginBase.h>
12
- #import "MoEReactConstants.h"
13
- #import "MoEReactBridge.h"
14
-
15
- @interface MOReactInitializer() <MoEPluginBridgeDelegate>
16
-
17
- @end
18
-
19
- @implementation MOReactInitializer
20
-
21
- #pragma mark- Initialization
22
-
23
- +(instancetype)sharedInstance{
24
- static dispatch_once_t onceToken;
25
- static MOReactInitializer *instance;
26
- dispatch_once(&onceToken, ^{
27
- instance = [[MOReactInitializer alloc] init];
28
- });
29
- return instance;
30
- }
31
-
32
- // Client Exposed Method
33
- - (void)intializeSDKWithLaunchOptions:(NSDictionary*)launchOptions{
34
- [self intializeSDKWithState:true andLaunchOptions:launchOptions];
35
- }
36
-
37
- - (void)intializeSDKWithState:(BOOL)isSdkEnabled andLaunchOptions:(NSDictionary*)launchOptions{
38
- MOSDKConfig *sdkConfig = [self fetchSDKConfig];
39
- [self intializeSDKWithConfig:sdkConfig withSDKState:isSdkEnabled andLaunchOptions:launchOptions];
40
- }
41
-
42
- - (void)intializeSDKWithConfig:(MOSDKConfig*)sdkConfig andLaunchOptions:(NSDictionary*)launchOptions{
43
- [self intializeSDKWithConfig:sdkConfig withSDKState:true andLaunchOptions:launchOptions];
44
- }
45
-
46
- - (void)intializeSDKWithConfig:(MOSDKConfig*)sdkConfig withSDKState:(BOOL)isSdkEnabled andLaunchOptions:(NSDictionary*)launchOptions{
47
- [MoEPluginBridge sharedInstance].bridgeDelegate = self;
48
-
49
- if (sdkConfig.moeAppID == nil || sdkConfig == nil) {
50
- return;
51
- }
52
-
53
- sdkConfig.pluginIntegrationType = REACT_NATIVE;
54
- sdkConfig.pluginIntegrationVersion = MO_REACT_PLUGIN_VERSION;
55
-
56
- [[MoEPluginInitializer sharedInstance] initializeSDKWithConfig:sdkConfig withSDKState:isSdkEnabled andLaunchOptions:launchOptions];
57
- }
58
-
59
- -(MOSDKConfig*)fetchSDKConfig {
60
- NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
61
- MOSDKConfig *sdkConfig = [[MoEngage sharedInstance] getDefaultSDKConfiguration];
62
-
63
- if ( [infoDict objectForKey: kMoEngage] != nil && [infoDict objectForKey: kMoEngage] != [NSNull null]) {
64
- NSDictionary* moeDict = [infoDict objectForKey: kMoEngage];
65
- if ([moeDict objectForKey: kAppId] != nil && [moeDict objectForKey:kAppId] != [NSNull null]) {
66
-
67
- NSString *appId = [moeDict objectForKey: kAppId];
68
-
69
- if (appId.length > 0) {
70
- if (sdkConfig == nil) {
71
- sdkConfig = [[MOSDKConfig alloc] initWithAppID:appId];
72
- }
73
- else{
74
- sdkConfig.moeAppID = appId;
75
- }
76
- }
77
- else{
78
- NSLog(@"%@", kInvalidAppIdAlert);
79
- return nil;
80
- }
81
- }
82
-
83
- if ([moeDict objectForKey: kDataCenter] != nil && [moeDict objectForKey:kDataCenter] != [NSNull null]) {
84
- sdkConfig.moeDataCenter = [self getDataCenterFromString: [moeDict objectForKey: kDataCenter]];
85
- }
86
-
87
- if ([moeDict objectForKey:kAppGroupId] != nil && [moeDict objectForKey:kAppGroupId] != [NSNull null]) {
88
- sdkConfig.appGroupID = [moeDict objectForKey:kAppGroupId];
89
- }
90
-
91
- if ([moeDict objectForKey:kDisablePeriodicFlush] != nil && [moeDict objectForKey:kDisablePeriodicFlush] != [NSNull null]) {
92
- sdkConfig.analyticsDisablePeriodicFlush = [moeDict getBooleanForKey:kDisablePeriodicFlush];
93
- }
94
-
95
- if ([moeDict objectForKey:kPeriodicFlushDuration] != nil && [moeDict objectForKey:kPeriodicFlushDuration] != [NSNull null]) {
96
- sdkConfig.analyticsPeriodicFlushDuration = [moeDict getIntegerForKey:kPeriodicFlushDuration];
97
- }
98
-
99
- if ([moeDict objectForKey:kEncryptNetworkRequests] != nil && [moeDict objectForKey:kEncryptNetworkRequests] != [NSNull null]) {
100
- sdkConfig.encryptNetworkRequests = [moeDict getBooleanForKey:kEncryptNetworkRequests];
101
- }
102
-
103
- if ([moeDict objectForKey:kOptOutDataTracking] != nil && [moeDict objectForKey:kOptOutDataTracking] != [NSNull null]) {
104
- sdkConfig.optOutDataTracking = [moeDict getBooleanForKey:kOptOutDataTracking];
105
- }
106
-
107
- if ([moeDict objectForKey:kOptOutPushNotifications] != nil && [moeDict objectForKey:kOptOutPushNotifications] != [NSNull null]) {
108
- sdkConfig.optOutPushNotification = [moeDict getBooleanForKey:kOptOutPushNotifications];
109
- }
110
-
111
- if ([moeDict objectForKey:kOptOutInApp] != nil && [moeDict objectForKey:kOptOutInApp] != [NSNull null]) {
112
- sdkConfig.optOutInAppCampaign = [moeDict getBooleanForKey:kOptOutInApp];
113
- }
114
-
115
- if ([moeDict objectForKey:kOptOutIDFATracking] != nil && [moeDict objectForKey:kOptOutIDFATracking] != [NSNull null]) {
116
- sdkConfig.optOutIDFATracking = [moeDict getBooleanForKey:kOptOutIDFATracking];
117
- }
118
-
119
- if ([moeDict objectForKey:kOptOutIDFVTracking] != nil && [moeDict objectForKey:kOptOutIDFVTracking] != [NSNull null]) {
120
- sdkConfig.optOutIDFVTracking = [moeDict getBooleanForKey:kOptOutIDFVTracking];
121
- }
122
- }
123
-
124
- return sdkConfig;
125
- }
126
-
127
- - (MODataCenter)getDataCenterFromString:(NSString*)stringVal {
128
- MODataCenter dataCenter = DATA_CENTER_01;
129
-
130
- if ([stringVal isEqual:kDataCenter1])
131
- {
132
- dataCenter = DATA_CENTER_01;
133
- }
134
- else if ([stringVal isEqual:kDataCenter2])
135
- {
136
- dataCenter = DATA_CENTER_02;
137
- }
138
- else if ([stringVal isEqual:kDataCenter3])
139
- {
140
- dataCenter = DATA_CENTER_03;
141
- }
142
- else
143
- {
144
- NSLog(@"%@", kInvalidDataCenterAlert);
145
- }
146
-
147
- return dataCenter;
148
- }
149
-
150
- - (void)sendMessageWithName:(NSString *)name andPayload:(NSDictionary *)payloadDict {
151
- NSMutableDictionary* updatedDict = [NSMutableDictionary dictionary];
152
-
153
- if (payloadDict) {
154
- NSDictionary *payload = payloadDict[kPayload];
155
-
156
- NSError *err;
157
- NSData * jsonData = [NSJSONSerialization dataWithJSONObject:payload options:0 error:&err];
158
- if (jsonData) {
159
- NSString *strPayload = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
160
- updatedDict[kPayload] = strPayload;
161
- } else {
162
- NSLog(@"Error converting to dictionary to string %@", err.localizedDescription);
163
- }
164
- }
165
-
166
- NSDictionary* userInfo = @{kEventName:name,kPayloadDict:updatedDict};
167
- MoEReactBridge *reactBridge = [MoEReactBridge allocWithZone: nil];
168
- [reactBridge sendEventWithName:userInfo];
169
-
170
- }
171
-
172
- @end
@@ -1,2 +0,0 @@
1
- // Generated file, do not edit
2
- #define MO_REACT_PLUGIN_VERSION @"7.3.0"
@@ -1,46 +0,0 @@
1
- import MoEInAppCustomAction from "./MoEInAppCustomAction";
2
- import MoEInAppSelfHandledCampaign from "./MoEInAppSelfHandledCampaign";
3
- import MoEInAppNavigation from "./MoEInAppNavigation";
4
- import { isValidObject } from "../utils/MoEHelper";
5
-
6
- export default class MoEInAppCampaign {
7
- campaignId: String;
8
- campaignName: String;
9
- campaignContext: Map<String, Object>;
10
- customAction: MoEInAppCustomAction;
11
- selfHandled: MoEInAppSelfHandledCampaign;
12
- navigation: MoEInAppNavigation;
13
- platform: String;
14
-
15
- constructor(campaign: Object) {
16
- if (isValidObject(campaign)) {
17
- this.campaignId = campaign["campaignId"];
18
- this.campaignName = campaign["campaignName"];
19
- this.campaignContext = campaign["campaignContext"];
20
- this.platform = campaign["platform"];
21
- this.customAction = new MoEInAppCustomAction(campaign["customAction"]);
22
- this.selfHandled = new MoEInAppSelfHandledCampaign(
23
- campaign["selfHandled"]
24
- );
25
- this.navigation = new MoEInAppNavigation(campaign["navigation"]);
26
- }
27
- }
28
-
29
- toJSON(): Object {
30
- var json = {
31
- campaignId: this.campaignId,
32
- campaignName: this.campaignName,
33
- campaignContext: this.campaignContext,
34
- };
35
- if (isValidObject(this.customAction)) {
36
- json["customAction"] = this.customAction.toJSON();
37
- }
38
- if (isValidObject(this.selfHandled)) {
39
- json["selfHandled"] = this.selfHandled.toJSON();
40
- }
41
- if (isValidObject(this.navigation)) {
42
- json["navigation"] = this.navigation.toJSON();
43
- }
44
- return json;
45
- }
46
- }
@@ -1,34 +0,0 @@
1
- import {
2
- isValidObject,
3
- isValidString,
4
- isValidNumber,
5
- isValidBoolean,
6
- } from "../utils/MoEHelper";
7
-
8
- export default class MoEInAppSelfHandledCampaign {
9
- campaignContent: String;
10
- dismissInterval: Number;
11
- cancellable: Boolean;
12
-
13
- constructor(campaign: Object) {
14
- if (isValidObject(campaign)) {
15
- if (isValidString(campaign["payload"])) {
16
- this.campaignContent = campaign["payload"];
17
- }
18
- if (isValidNumber(campaign["dismissInterval"])) {
19
- this.dismissInterval = campaign["dismissInterval"];
20
- }
21
- if (isValidBoolean(campaign["isCancellable"])) {
22
- this.cancellable = campaign["isCancellable"];
23
- }
24
- }
25
- }
26
-
27
- toJSON() {
28
- return {
29
- payload: this.campaignContent,
30
- dismissInterval: this.dismissInterval,
31
- isCancellable: this.cancellable,
32
- };
33
- }
34
- }