react-native-moengage 7.4.1 → 8.1.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 (55) hide show
  1. package/CHANGELOG.md +72 -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 +57 -22
  7. package/android/src/main/java/com/moengage/react/MoEInitializer.kt +44 -13
  8. package/android/src/main/java/com/moengage/react/MoEReactBridge.kt +116 -82
  9. package/android/src/main/java/com/moengage/react/MoEReactHelper.kt +2 -2
  10. package/android/src/main/java/com/moengage/react/PayloadGenerator.kt +41 -17
  11. package/iOS/MoEReactBridge/MoEReactBridge.h +1 -1
  12. package/iOS/MoEReactBridge/MoEReactBridge.m +34 -60
  13. package/iOS/MoEReactBridge/MoEngageInitializer.h +61 -0
  14. package/iOS/MoEReactBridge/MoEngageInitializer.m +164 -0
  15. package/iOS/MoEReactBridge/{MoEReactConstants.h → MoEngageReactConstants.h} +13 -3
  16. package/iOS/MoEReactBridge/{MoEReactConstants.m → MoEngageReactConstants.m} +14 -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 +196 -208
  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/models/MoEngagePermissionType.ts +3 -0
  41. package/src/models/MoEngagePersimissionResultData.ts +14 -0
  42. package/src/moeParser/MoEInAppParser.ts +192 -0
  43. package/src/moeParser/MoEPushNotificationParser.ts +78 -0
  44. package/src/moeParser/MoEngagePayloadParser.ts +11 -0
  45. package/src/platform/MoERNAndroid.ts +62 -92
  46. package/src/platform/MoERNiOS.ts +27 -60
  47. package/src/utils/MoEConstants.ts +61 -0
  48. package/src/utils/MoEEventHandlerHelper.ts +47 -28
  49. package/src/utils/MoEJsonBuilder.ts +229 -0
  50. package/src/utils/MoEObjectToJson.ts +44 -0
  51. package/iOS/MoEReactBridge/MOReactInitializer.h +0 -46
  52. package/iOS/MoEReactBridge/MOReactInitializer.m +0 -172
  53. package/iOS/MoEReactBridge/MOReactPluginInfo.h +0 -2
  54. package/src/models/MoEInAppCampaign.ts +0 -46
  55. package/src/models/MoEInAppSelfHandledCampaign.ts +0 -34
@@ -0,0 +1,11 @@
1
+ import {MoEngagePermissionType} from "../models/MoEngagePermissionType";
2
+ import MoEngagePersimissionResultData from "../models/MoEngagePersimissionResultData";
3
+ import {MOE_PERMISSION_STATE, MOE_PERMISSION_TYPE, MOE_PLATFORM} from "../utils/MoEConstants";
4
+
5
+ export function getPermissionResult(payload: { [k: string]: any }) {
6
+ return new MoEngagePersimissionResultData(
7
+ payload[MOE_PLATFORM],
8
+ payload[MOE_PERMISSION_STATE],
9
+ payload[MOE_PERMISSION_TYPE]
10
+ )
11
+ }
@@ -1,144 +1,110 @@
1
+ import { MoEngagePermissionType } from "../models/MoEngagePermissionType";
2
+ import {
3
+ getAdIdTrackingJson,
4
+ getAndroidIdTrackingJson,
5
+ getAppIdJson,
6
+ getMoEPushCampaignJson,
7
+ getMoEPushTokenJson,
8
+ getOptOutTrackingJson,
9
+ getPermissionResponseJson,
10
+ getSdkStateJson
11
+ } from "../utils/MoEJsonBuilder";
12
+
1
13
  const MoEReactBridge = require("react-native").NativeModules.MoEReactBridge;
14
+ const PLATFORM_ANDROID = "android";
2
15
 
3
16
  export class MoERNAndroid {
4
- static initialize() {
5
- MoEReactBridge.initialize();
17
+ static initialize(payload: { [k: string]: any }) {
18
+ MoEReactBridge.initialize(JSON.stringify(payload));
6
19
  }
7
20
 
8
- static trackEvent(payload: Object){
21
+ static trackEvent(payload: { [k: string]: any }) {
9
22
  MoEReactBridge.trackEvent(JSON.stringify(payload))
10
23
  }
11
24
 
12
- static setAppStatus(payload: object) {
25
+ static setAppStatus(payload: { [k: string]: any }) {
13
26
  MoEReactBridge.setAppStatus(JSON.stringify(payload));
14
27
  }
15
28
 
16
- static setUserAttribute(payload: object) {
29
+ static setUserAttribute(payload: { [k: string]: any }) {
17
30
  MoEReactBridge.setUserAttribute(JSON.stringify(payload));
18
31
  }
19
32
 
20
- static setAlias(payload: object){
33
+ static setAlias(payload: { [k: string]: any }) {
21
34
  MoEReactBridge.setAlias(JSON.stringify(payload));
22
35
  }
23
36
 
24
- static logout() {
25
- MoEReactBridge.logout();
37
+ static logout(payload: { [k: string]: any }) {
38
+ MoEReactBridge.logout(JSON.stringify(payload));
26
39
  }
27
40
 
28
- static showInApp() {
29
- MoEReactBridge.showInApp();
41
+ static showInApp(payload: { [k: string]: any }) {
42
+ MoEReactBridge.showInApp(JSON.stringify(payload));
30
43
  }
31
44
 
32
- static getSelfHandledInApp() {
33
- MoEReactBridge.getSelfHandledInApp();
45
+ static getSelfHandledInApp(payload: { [k: string]: any }) {
46
+ MoEReactBridge.getSelfHandledInApp(JSON.stringify(payload));
34
47
  }
35
48
 
36
- static selfHandledShown(payload: object) {
37
- payload["type"] = "impression";
49
+ static selfHandledShown(payload: { [k: string]: any }) {
38
50
  MoERNAndroid.selfHandledCallback(payload);
39
51
  }
40
52
 
41
- static selfHandledClicked(payload: object) {
42
- payload["type"] = "click";
53
+ static selfHandledClicked(payload: { [k: string]: any }) {
43
54
  MoERNAndroid.selfHandledCallback(payload);
44
55
  }
45
56
 
46
- static selfHandledDismissed(payload: object) {
47
- payload["type"] = "dismissed";
57
+ static selfHandledDismissed(payload: { [k: string]: any }) {
48
58
  MoERNAndroid.selfHandledCallback(payload);
49
59
  }
50
60
 
51
- static selfHandledPrimaryClicked(payload: object){
52
- payload["type"] = "primary_clicked";
53
- MoERNAndroid.selfHandledCallback(payload);
54
- }
55
-
56
- private static selfHandledCallback(payload: object){
61
+ private static selfHandledCallback(payload: { [k: string]: any }) {
57
62
  MoEReactBridge.selfHandledCallback(JSON.stringify(payload));
58
63
  }
59
64
 
60
- static setAppContext(payload: object) {
65
+ static setAppContext(payload: { [k: string]: any }) {
61
66
  MoEReactBridge.setAppContext(JSON.stringify(payload));
62
67
  }
63
68
 
64
- static resetAppContext() {
65
- MoEReactBridge.resetAppContext();
69
+ static resetAppContext(payload: { [k: string]: any }) {
70
+ MoEReactBridge.resetAppContext(JSON.stringify(payload));
66
71
  }
67
72
 
68
- static passFcmPushToken(pushToken: string) {
69
- let payload = {
70
- token: pushToken,
71
- service: PUSH_SERVICE_FCM
72
- };
73
+ static passFcmPushToken(payload: { [k: string]: any }) {
73
74
  MoERNAndroid.passPushToken(payload)
74
75
  }
75
76
 
76
- static passFcmPushPayload(pushPayload: object) {
77
- let payload = {
78
- payload: pushPayload,
79
- service: PUSH_SERVICE_FCM
80
- };
81
- MoERNAndroid.passPushPayload(payload)
77
+ static passFcmPushPayload(pushPayload: { [k: string]: any }) {
78
+ MoERNAndroid.passPushPayload(pushPayload)
82
79
  }
83
80
 
84
- private static passPushToken(payload: object){
81
+ private static passPushToken(payload: { [k: string]: any }) {
85
82
  MoEReactBridge.passPushToken(JSON.stringify(payload));
86
83
  }
87
84
 
88
- private static passPushPayload(payload: object){
85
+ private static passPushPayload(payload: { [k: string]: any }) {
89
86
  MoEReactBridge.passPushPayload(JSON.stringify(payload));
90
87
  }
91
88
 
92
- static enableSDKLogs() {
93
- MoEReactBridge.enableLogs();
94
- }
95
-
96
- static optOutDataTracking(shouldOptOutDataTracking: boolean){
97
- let payload = {
98
- type: "data",
99
- state: shouldOptOutDataTracking
100
- };
101
- MoERNAndroid.optOutTracking(payload)
102
- }
103
-
104
- static optOutPushNotification(shouldOptOutPushNotification: boolean){
105
- let payload = {
106
- type: "push",
107
- state: shouldOptOutPushNotification
108
- };
109
- MoERNAndroid.optOutTracking(payload)
110
- }
111
-
112
- static optOutInAppNotification(shouldOptOutInApp: boolean){
113
- let payload = {
114
- type: "inapp",
115
- state: shouldOptOutInApp
116
- };
89
+ static optOutDataTracking(payload: { [k: string]: any }) {
117
90
  MoERNAndroid.optOutTracking(payload)
118
91
  }
119
92
 
120
- private static optOutTracking(payload: object){
93
+ private static optOutTracking(payload: { [k: string]: any }) {
121
94
  MoEReactBridge.optOutTracking(JSON.stringify(payload));
122
95
  }
123
96
 
124
- static validateSDKVersion(){
97
+ static validateSDKVersion() {
125
98
  MoEReactBridge.validateSdkVersion().catch((error: Error) => {
126
99
  console.error(error.message);
127
100
  });
128
101
  }
129
102
 
130
- static passPushKitPushToken(pushToken: string) {
131
- let payload = {
132
- token: pushToken,
133
- service: PUSH_SERVICE_PUSH_KIT
134
- };
103
+ static passPushKitPushToken(payload: { [k: string]: any }) {
135
104
  MoERNAndroid.passPushToken(payload)
136
105
  }
137
106
 
138
- static updateSdkState(state: boolean) {
139
- let payload = {
140
- isSdkEnabled: state
141
- };
107
+ static updateSdkState(payload: { [k: string]: any }) {
142
108
  MoEReactBridge.updateSdkState(JSON.stringify(payload));
143
109
  }
144
110
 
@@ -146,33 +112,37 @@ export class MoERNAndroid {
146
112
  MoEReactBridge.onOrientationChanged()
147
113
  }
148
114
 
149
- static enableAdIdTracking() {
150
- let payload = {
151
- "isAdIdTrackingEnabled": true
152
- }
115
+ static enableAdIdTracking(payload: { [k: string]: any }) {
153
116
  MoEReactBridge.deviceIdentifierTrackingStatusUpdate(JSON.stringify(payload))
154
117
  }
155
118
 
156
- static disableAdIdTracking() {
157
- let payload = {
158
- "isAdIdTrackingEnabled": false
159
- }
119
+ static disableAdIdTracking(payload: { [k: string]: any }) {
160
120
  MoEReactBridge.deviceIdentifierTrackingStatusUpdate(JSON.stringify(payload))
161
121
  }
162
122
 
163
- static enableAndroidIdTracking() {
164
- let payload = {
165
- "isAndroidIdTrackingEnabled": true
166
- }
123
+ static enableAndroidIdTracking(payload: { [k: string]: any }) {
167
124
  MoEReactBridge.deviceIdentifierTrackingStatusUpdate(JSON.stringify(payload))
168
125
  }
169
126
 
170
- static disableAndroidIdTracking() {
171
- let payload = {
172
- "isAndroidIdTrackingEnabled": false
173
- }
127
+ static disableAndroidIdTracking(payload: { [k: string]: any }) {
174
128
  MoEReactBridge.deviceIdentifierTrackingStatusUpdate(JSON.stringify(payload))
175
129
  }
130
+
131
+ static permissionResponse(isGranted: boolean, permissionType: MoEngagePermissionType) {
132
+ MoEReactBridge.permissionResponse(JSON.stringify(getPermissionResponseJson(isGranted, permissionType)));
133
+ }
134
+
135
+ static setupNotificationChannels() {
136
+ MoEReactBridge.setupNotificationChannels();
137
+ }
138
+
139
+ static navigateToSettings() {
140
+ MoEReactBridge.navigateToSettings()
141
+ }
142
+
143
+ static requestPushPermission() {
144
+ MoEReactBridge.requestPushPermission();
145
+ }
176
146
  }
177
147
 
178
148
  const PUSH_SERVICE_FCM = "FCM"
@@ -1,76 +1,66 @@
1
+ import { getAppIdJson, getOptOutTrackingJson } from "../utils/MoEJsonBuilder";
2
+
1
3
  const MoEReactBridge = require("react-native").NativeModules.MoEReactBridge;
2
4
 
3
5
  export class MoERNiOS {
4
- static initialize() {
5
- MoEReactBridge.initialize();
6
+ static initialize(payload: { [k: string]: any }) {
7
+ MoEReactBridge.initialize(payload);
6
8
  }
7
9
 
8
- static setAppStatus(payload: Object) {
10
+ static setAppStatus(payload: { [k: string]: any }) {
9
11
  MoEReactBridge.setAppStatus(payload);
10
12
  }
11
13
 
12
- static trackEvent(payload: Object) {
14
+ static trackEvent(payload: { [k: string]: any }) {
13
15
  MoEReactBridge.trackEventWithProperties(payload);
14
16
  }
15
17
 
16
- static setUserAttribute(payload: Object) {
18
+ static setUserAttribute(payload: { [k: string]: any }) {
17
19
  MoEReactBridge.setUserAttribute(payload);
18
20
  }
19
21
 
20
- static setAlias(payload: Object) {
22
+ static setAlias(payload: { [k: string]: any }) {
21
23
  MoEReactBridge.setAlias(payload);
22
24
  }
23
25
 
24
- static logout() {
25
- MoEReactBridge.logout();
26
- }
27
-
28
- static showInApp() {
29
- MoEReactBridge.showInApp();
26
+ static logout(payload: { [k: string]: any }) {
27
+ MoEReactBridge.logout(payload);
30
28
  }
31
29
 
32
- static getSelfHandledInApp() {
33
- MoEReactBridge.getSelfHandledInApp();
30
+ static showInApp(payload: { [k: string]: any }) {
31
+ MoEReactBridge.showInApp(payload);
34
32
  }
35
33
 
36
- static selfHandledShown(payload: Object) {
37
- payload["type"] = "impression";
38
- MoEReactBridge.updateSelfHandledInAppStatusWithPayload(payload);
34
+ static getSelfHandledInApp(payload: { [k: string]: any }) {
35
+ MoEReactBridge.getSelfHandledInApp(payload);
39
36
  }
40
37
 
41
- static selfHandledPrimaryClicked(payload: Object) {
42
- payload["type"] = "primary_clicked";
38
+ static selfHandledShown(payload: { [k: string]: any }) {
43
39
  MoEReactBridge.updateSelfHandledInAppStatusWithPayload(payload);
44
40
  }
45
41
 
46
- static selfHandledClicked(payload: Object) {
47
- payload["type"] = "click";
42
+ static selfHandledClicked(payload: { [k: string]: any }) {
48
43
  MoEReactBridge.updateSelfHandledInAppStatusWithPayload(payload);
49
44
  }
50
45
 
51
- static selfHandledDismissed(payload: Object) {
52
- payload["type"] = "dismissed";
46
+ static selfHandledDismissed(payload: { [k: string]: any }) {
53
47
  MoEReactBridge.updateSelfHandledInAppStatusWithPayload(payload);
54
48
  }
55
49
 
56
- static setAppContext(payload: Object) {
50
+ static setAppContext(payload: { [k: string]: any }) {
57
51
  MoEReactBridge.setAppContext(payload);
58
52
  }
59
53
 
60
- static resetAppContext() {
61
- MoEReactBridge.resetAppContext();
54
+ static resetAppContext(payload: { [k: string]: any }) {
55
+ MoEReactBridge.resetAppContext(payload);
62
56
  }
63
57
 
64
58
  static registerForPush() {
65
59
  MoEReactBridge.registerForPushNotification();
66
60
  }
67
61
 
68
- static disableInbox() {
69
- MoEReactBridge.disableInbox();
70
- }
71
-
72
- static enableSDKLogs() {
73
- MoEReactBridge.enableSDKLogs();
62
+ static disableInbox(payload: { [k: string]: any }) {
63
+ MoEReactBridge.disableInbox(payload);
74
64
  }
75
65
 
76
66
  static validateSDKVersion() {
@@ -79,42 +69,19 @@ export class MoERNiOS {
79
69
  });
80
70
  }
81
71
 
82
- static startGeofenceMonitoring() {
83
- MoEReactBridge.startGeofenceMonitoring();
84
- }
85
-
86
- static optOutDataTracking(shouldOptOutDataTracking: boolean){
87
- let payload = {
88
- type: "data",
89
- state: shouldOptOutDataTracking
90
- };
91
- MoERNiOS.optOutTracking(payload)
92
- }
93
-
94
- static optOutPushNotification(shouldOptOutPushNotification: boolean){
95
- let payload = {
96
- type: "push",
97
- state: shouldOptOutPushNotification
98
- };
99
- MoERNiOS.optOutTracking(payload)
72
+ static startGeofenceMonitoring(payload: { [k: string]: any }) {
73
+ MoEReactBridge.startGeofenceMonitoring(payload);
100
74
  }
101
75
 
102
- static optOutInAppNotification(shouldOptOutInApp: boolean){
103
- let payload = {
104
- type: "inapp",
105
- state: shouldOptOutInApp
106
- };
76
+ static optOutDataTracking(payload: { [k: string]: any }){
107
77
  MoERNiOS.optOutTracking(payload)
108
78
  }
109
79
 
110
- private static optOutTracking(payload: object){
80
+ private static optOutTracking(payload: { [k: string]: any }){
111
81
  MoEReactBridge.optOutTracking(payload);
112
82
  }
113
83
 
114
- static updateSdkState(state: boolean) {
115
- let payload = {
116
- isSdkEnabled: state
117
- };
84
+ static updateSdkState(payload: { [k: string]: any }) {
118
85
  MoEReactBridge.updateSDKState(payload);
119
86
  }
120
87
  }
@@ -0,0 +1,61 @@
1
+ export const MOE_PLATFORM = 'platform'
2
+ export const MOE_PAYLOAD = 'payload'
3
+ export const MOE_DATA = 'data'
4
+ export const ACCOUNT_META = 'accountMeta'
5
+ export const APP_ID = 'appId'
6
+
7
+ //LOCATION ATTRIBUTE
8
+ export const MOE_LOCATION = 'location'
9
+
10
+ //INAPP CAMPAIGN
11
+ export const MOE_CAMPAIGN_ID = 'campaignId'
12
+ export const MOE_CAMPAIGN_NAME = 'campaignName'
13
+ export const MOE_CAMPAIGN_CONTEXT = 'campaignContext'
14
+ export const MOE_CUSTOM_ACTION = 'customAction'
15
+ export const MOE_SELF_HANDLED = 'selfHandled'
16
+ export const MOE_NAVIGATION = 'navigation'
17
+ export const MOE_WIDGET_ID = 'widgetId'
18
+ export const FORMATTED_CAMPAIGN_ID = 'cid'
19
+ export const ATTRIBUTES = 'attributes'
20
+
21
+ //IN APP CUSTOM ACTION
22
+ export const MOE_KEY_VALUE_PAIR = 'kvPair'
23
+
24
+ //IN APP SELF HANDLED
25
+ export const MOE_DISMISSINTERVAL = 'dismissInterval'
26
+ export const MOE_IS_CANCELLABLE = 'isCancellable'
27
+
28
+ //IN APP NAVIGATION
29
+ export const MOE_NAVIGATION_TYPE = 'navigationType'
30
+ export const ACTION_TYPE = 'actionType'
31
+ export const MOE_NAVIGATION_VALUE = 'value'
32
+
33
+ //PUSH TOKEN
34
+ export const MOE_PUSH_SERVICE = 'pushService'
35
+ export const MOE_TOKEN = 'token'
36
+
37
+ //PUSH CAMPAIGN
38
+ export const MOE_CLICKED_ACTION = 'clickedAction'
39
+ export const MOE_IS_DEFAULT_ACTION = 'isDefaultAction'
40
+
41
+ //INVALID OBJECT ERROR MESSAGES
42
+ export const MOE_IN_APP_OBJECT_ERROR = 'MoEInAppCampaign is an invalid object'
43
+ export const MOE_CUSTOM_ACTION_OBJ_ERROR = 'MoEInAppCustomAction is an invalid object'
44
+ export const MOE_SELF_HANDLED_OBJ_ERROR = 'MoEInAppSelfHandledCampaign is an invalid object'
45
+ export const MOE_NAVIGATION_OBJ_ERROR = 'MoEInAppNavigation is an invalid object'
46
+ export const MOE_PUSH_CAMPAIGN_OBJ_ERROR = 'MoEPushCampaign is an invalid object'
47
+ export const MOE_PUSH_TOKEN_OBJ_ERROR = 'MoEPushToken is an invalid object'
48
+ //USER ATTRIBUTES
49
+ export const USER_ATTRIBUTE_UNIQUE_ID = 'USER_ATTRIBUTE_UNIQUE_ID';
50
+ export const USER_ATTRIBUTE_USER_NAME = 'USER_ATTRIBUTE_USER_NAME';
51
+ export const USER_ATTRIBUTE_USER_FIRST_NAME = 'USER_ATTRIBUTE_USER_FIRST_NAME';
52
+ export const USER_ATTRIBUTE_USER_LAST_NAME = 'USER_ATTRIBUTE_USER_LAST_NAME';
53
+ export const USER_ATTRIBUTE_USER_EMAIL = 'USER_ATTRIBUTE_USER_EMAIL';
54
+ export const USER_ATTRIBUTE_USER_MOBILE = 'USER_ATTRIBUTE_USER_MOBILE';
55
+ export const USER_ATTRIBUTE_USER_BDAY = 'USER_ATTRIBUTE_USER_BDAY';
56
+ export const USER_ATTRIBUTE_USER_GENDER = 'USER_ATTRIBUTE_USER_GENDER';
57
+ export const USER_ATTRIBUTE_USER_LOCATION = 'USER_ATTRIBUTE_USER_LOCATION';
58
+
59
+ export const MOE_PERMISSION_TYPE = "type";
60
+ export const MOE_PERMISSION_STATE = "isGranted";
61
+
@@ -1,34 +1,53 @@
1
- import MoEInAppCampaign from "../models/MoEInAppCampaign";
2
- import MoEPushCampaign from "../models/MoEPushCampaign";
3
- import MoEPushToken from "../models/MoEPushToken";
4
- import { isValidObject, isValidString } from "../utils/MoEHelper";
5
-
6
- const inAppEventNames: Array<String> = [
7
- "inAppCampaignShown",
8
- "inAppCampaignClicked",
9
- "inAppCampaignDismissed",
10
- "inAppCampaignCustomAction",
11
- "inAppCampaignSelfHandled",
12
- ];
1
+ import {isValidObject} from "../utils/MoEHelper";
2
+ import {
3
+ getCustomActionObj,
4
+ getMoEInAppData,
5
+ getNavigationObj,
6
+ getMoESelfHandledCampaignData
7
+ } from "../moeParser/MoEInAppParser";
8
+ import {getMoEPushPayload, getMoEPushToken} from "../moeParser/MoEPushNotificationParser";
9
+ import {MOE_DATA, ACCOUNT_META, MOE_PAYLOAD} from "./MoEConstants";
10
+ import {PERMISSION_RESULT} from "..";
11
+ import {getPermissionResult} from "../moeParser/MoEngagePayloadParser";
13
12
 
14
13
  export function executeHandler(
15
- handler: Function,
16
- notification: Object,
17
- type: String
14
+ handler: Function,
15
+ notification: any,
16
+ type: String
18
17
  ) {
19
- if (handler && isValidObject(notification) && type) {
20
- const payload = notification["payload"];
21
- if (isValidString(payload)) {
22
- const json = JSON.parse(payload);
23
- if (isValidObject(json)) {
24
- if (inAppEventNames.includes(type)) {
25
- handler(new MoEInAppCampaign(json));
26
- } else if (type == "pushClicked") {
27
- handler(new MoEPushCampaign(json));
28
- } else if (type == "pushTokenGenerated") {
29
- handler(new MoEPushToken(json));
18
+ if (handler && type) {
19
+ const payload = notification[MOE_PAYLOAD];
20
+ const notificationPayload = JSON.parse(payload);
21
+ if (isValidObject(notificationPayload)) {
22
+ if (type == "pushTokenGenerated") {
23
+ var pushTokenObject = getMoEPushToken(notificationPayload);
24
+ pushTokenObject != undefined ? handler(pushTokenObject) : null;
25
+ } else if (type == PERMISSION_RESULT) {
26
+ let payload = getPermissionResult(notificationPayload)
27
+ handler(payload)
28
+ } else {
29
+ const accountMeta = notificationPayload[ACCOUNT_META];
30
+ if (accountMeta != undefined && isValidObject(accountMeta)) {
31
+ const payload = notificationPayload[MOE_DATA];
32
+ if (type == "inAppCampaignShown" || type == "inAppCampaignDismissed") {
33
+ var inAppObject = getMoEInAppData(payload, accountMeta);
34
+ inAppObject != undefined ? handler(inAppObject) : null;
35
+ } else if (type == "inAppCampaignSelfHandled") {
36
+ var selfHandled = getMoESelfHandledCampaignData(payload, accountMeta);
37
+ selfHandled != undefined ? handler(selfHandled) : null;
38
+ } else if (type == "inAppCampaignCustomAction") {
39
+ var cutomAction = getCustomActionObj(payload, accountMeta);
40
+ cutomAction != undefined ? handler(cutomAction) : null;
41
+ } else if (type == "inAppCampaignClicked") {
42
+ var navigationAction = getNavigationObj(payload, accountMeta);
43
+ navigationAction != undefined ? handler(navigationAction) : null;
44
+ } else if (type == "pushClicked") {
45
+ var pushCampaignObject = getMoEPushPayload(payload, accountMeta);
46
+ pushCampaignObject != undefined ? handler(pushCampaignObject) : null;
47
+ }
48
+ }
49
+
50
+ }
30
51
  }
31
- }
32
52
  }
33
- }
34
53
  }