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,8 @@
1
+ export default class MoEAccountMeta {
2
+ appId:String;
3
+
4
+ constructor(appId: String){
5
+ this.appId = appId;
6
+
7
+ }
8
+ }
@@ -0,0 +1,4 @@
1
+
2
+ export default class MoEAction {
3
+
4
+ }
@@ -0,0 +1,4 @@
1
+ export enum MoEActionType {
2
+ NAVIGATION = "navigation",
3
+ CUSTOM = "customAction"
4
+ }
@@ -0,0 +1,10 @@
1
+ export default class MoECampaignContext {
2
+ formattedCampaignId:string;
3
+ attributes: Map<String, Object>;
4
+
5
+ constructor(formattedCampaignId: string, attributes: Map<String, Object>) {
6
+ this.formattedCampaignId = formattedCampaignId;
7
+ this.attributes = attributes;
8
+ }
9
+
10
+ }
@@ -0,0 +1,14 @@
1
+ import MoECampaignContext from "./MoECampaignContext";
2
+
3
+ export default class MoECampaignData {
4
+ campaignId: string;
5
+ campaignName: string;
6
+ context: MoECampaignContext;
7
+
8
+ constructor(campaignId: string, campaignName: string, context: MoECampaignContext) {
9
+ this.campaignId = campaignId;
10
+ this.campaignName = campaignName;
11
+ this.context = context;
12
+ }
13
+
14
+ }
@@ -0,0 +1,18 @@
1
+ import MoEAccountMeta from "./MoEAccountMeta";
2
+ import MoECampaignData from "./MoECampaignData";
3
+ import MoEAction from "./MoEAction";
4
+ import { MoEPlatform } from "./MoEPlatform";
5
+
6
+ export default class MoEClickData {
7
+ accountMeta: MoEAccountMeta;
8
+ platform: MoEPlatform;
9
+ campaignData: MoECampaignData;
10
+ action: MoEAction;
11
+ constructor(accountMeta: MoEAccountMeta, platform: MoEPlatform, campaignData: MoECampaignData, action: MoEAction) {
12
+ this.accountMeta = accountMeta;
13
+ this.platform = platform;
14
+ this.campaignData = campaignData;
15
+ this.action = action;
16
+ }
17
+
18
+ }
@@ -3,16 +3,8 @@ export default class MoEGeoLocation {
3
3
  longitude: Number;
4
4
 
5
5
  constructor(latitude: Number, longitude: Number) {
6
- if (typeof latitude == "number" && typeof longitude == "number") {
7
- this.latitude = latitude;
8
- this.longitude = longitude;
9
- }
6
+ this.latitude = latitude;
7
+ this.longitude = longitude;
10
8
  }
11
9
 
12
- toJSON(): Object {
13
- return {
14
- latitude: this.latitude,
15
- longitude: this.longitude,
16
- };
17
- }
18
10
  }
@@ -1,19 +1,14 @@
1
- import { isValidObject } from "../utils/MoEHelper";
1
+ import MoEAction from "./MoEAction";
2
+ import { MoEActionType } from "./MoEActionType";
2
3
 
3
- export default class MoEInAppCustomAction {
4
+ export default class MoEInAppCustomAction extends MoEAction{
4
5
  keyValuePair: Map<String, Object>;
6
+ actionType: MoEActionType;
5
7
 
6
- constructor(customAction: Object) {
7
- if (isValidObject(customAction)) {
8
- if (isValidObject(customAction["kvPair"])) {
9
- this.keyValuePair = customAction["kvPair"];
10
- }
11
- }
8
+ constructor(keyValuePair: Map<String, Object>, actionType: MoEActionType) {
9
+ super();
10
+ this.keyValuePair = keyValuePair;
11
+ this.actionType = actionType
12
12
  }
13
13
 
14
- toJSON(): Object {
15
- return {
16
- kvPair: this.keyValuePair,
17
- };
18
- }
19
14
  }
@@ -0,0 +1,16 @@
1
+ import MoEAccountMeta from "./MoEAccountMeta";
2
+ import MoECampaignData from "./MoECampaignData";
3
+ import { MoEPlatform } from "./MoEPlatform";
4
+
5
+ export default class MoEInAppData {
6
+ accountMeta: MoEAccountMeta;
7
+ platform: MoEPlatform;
8
+ campaignData: MoECampaignData;
9
+
10
+ constructor(accountMeta: MoEAccountMeta, platform: MoEPlatform, campaignData: MoECampaignData) {
11
+ this.accountMeta = accountMeta;
12
+ this.platform = platform;
13
+ this.campaignData = campaignData;
14
+ }
15
+
16
+ }
@@ -1,29 +1,19 @@
1
- import { isValidObject, isValidString } from "../utils/MoEHelper";
1
+ import MoEAction from "./MoEAction";
2
+ import { MoEActionType } from "./MoEActionType";
3
+ import { MoENavigationType } from "./MoENavigationType";
2
4
 
3
- export default class MoEInAppNavigation {
4
- navigationType: String;
5
- url: String;
6
- keyValuePair: Map<String, Object>;
5
+ export default class MoEInAppNavigation extends MoEAction {
6
+ navigationType: MoENavigationType;
7
+ navigationUrl: String;
8
+ keyValuePair?: Map<String, Object>;
9
+ actionType :MoEActionType;
7
10
 
8
- constructor(navigation: Object) {
9
- if (isValidObject(navigation)) {
10
- if (isValidString(navigation["navigationType"])) {
11
- this.navigationType = navigation["navigationType"];
12
- }
13
- if (isValidString(navigation["value"])) {
14
- this.url = navigation["value"];
15
- }
16
- if (isValidObject(navigation["kvPair"])) {
17
- this.keyValuePair = navigation["kvPair"];
18
- }
19
- }
11
+ constructor(navigationType: MoENavigationType, navigationUrl: String, keyValuePair: Map<String, Object>,actionType:MoEActionType) {
12
+ super();
13
+ this.navigationType = navigationType;
14
+ this.navigationUrl = navigationUrl;
15
+ this.keyValuePair = keyValuePair;
16
+ this.actionType = actionType;
20
17
  }
21
18
 
22
- toJSON(): Object {
23
- return {
24
- navigationType: this.navigationType,
25
- value: this.url,
26
- kvPair: this.keyValuePair,
27
- };
28
- }
29
19
  }
@@ -0,0 +1,4 @@
1
+ export enum MoENavigationType {
2
+ SCREEN = "screen",
3
+ DEEP_LINK = "deep_linking"
4
+ }
@@ -0,0 +1,4 @@
1
+ export enum MoEPlatform {
2
+ Android = "android",
3
+ IOS = "iOS"
4
+ }
@@ -1,10 +1,11 @@
1
1
  /// Helper class to track event attributes.
2
+ import { MoEGeoLocationToJson } from "../utils/MoEObjectToJson";
2
3
  import MoEGeoLocation from "./MoEGeoLocation";
3
4
 
4
5
  export default class MoEProperties {
5
- private generalAttributes: Object;
6
- private locationAttributes: Object;
7
- private dateTimeAttributes: Object;
6
+ private generalAttributes: { [k: string]: any }
7
+ private locationAttributes: { [k: string]: any};
8
+ private dateTimeAttributes: { [k: string]: any };
8
9
  private isNonInteractive: Boolean;
9
10
 
10
11
  constructor() {
@@ -14,15 +15,18 @@ export default class MoEProperties {
14
15
  this.isNonInteractive = false;
15
16
  }
16
17
 
17
- toJSON(): Object {
18
- return {
19
- eventAttributes: {
20
- generalAttributes: this.generalAttributes,
21
- locationAttributes: this.locationAttributes,
22
- dateTimeAttributes: this.dateTimeAttributes,
23
- },
24
- isNonInteractive: this.isNonInteractive,
25
- };
18
+ getGeneralAttributes() {
19
+ return this.generalAttributes;
20
+ }
21
+
22
+ getLocationAttributess() {
23
+ return this.locationAttributes;
24
+ }
25
+ getDateTimeAttributes() {
26
+ return this.dateTimeAttributes;
27
+ }
28
+ getIsNonInteractive() {
29
+ return this.isNonInteractive;
26
30
  }
27
31
 
28
32
  /**
@@ -36,12 +40,12 @@ export default class MoEProperties {
36
40
  return;
37
41
  }
38
42
  if (Array.isArray(value)) {
39
- value = (value as Array<any>).filter( e => (this.validateType(["string", "number"], e)));
43
+ value = (value as Array<any>).filter(e => (this.validateType(["string", "number"], e)));
40
44
  } else if (!this.validateType(["string", "number", "boolean"], value)) {
41
45
  console.warn("MoEProperties->addAttribute: invalid attribute");
42
46
  return
43
47
  }
44
-
48
+
45
49
  this.generalAttributes[key.toString()] = value;
46
50
  }
47
51
 
@@ -75,7 +79,7 @@ export default class MoEProperties {
75
79
  return;
76
80
  }
77
81
  if (this.validateLatLong(location)) {
78
- this.locationAttributes[key.toString()] = location.toJSON();
82
+ this.locationAttributes[key.toString()] = MoEGeoLocationToJson(location)
79
83
  } else {
80
84
  console.warn("MoEGeoLocation->addLocationAttribute: invalid coordinates");
81
85
  }
@@ -1,27 +1,11 @@
1
- import { isValidObject, isValidString } from "../utils/MoEHelper";
2
-
3
1
  export default class MoEPushCampaign {
4
- platform: String;
5
2
  payload: Map<String, Object>;
6
- isDefaultAction: Boolean
7
- clickAction: Map<String, Object>
3
+ isDefaultAction: Boolean;
4
+ clickAction: Map<String, Object>;
8
5
 
9
- constructor(pushPayload: Object) {
10
- if (isValidObject(pushPayload)) {
11
- if (isValidString(pushPayload["platform"])) {
12
- this.platform = pushPayload["platform"];
13
- }
14
- if (isValidObject(pushPayload["payload"])) {
15
- this.payload = pushPayload["payload"];
16
- }
17
- if("isDefaultAction" in pushPayload){
18
- this.isDefaultAction = pushPayload["isDefaultAction"]
19
- }else{
20
- this.isDefaultAction = false
21
- }
22
- if("clickedAction" in pushPayload){
23
- this.clickAction = pushPayload["clickedAction"]
24
- }
25
- }
6
+ constructor(payload: Map<String, Object>, isDefaultAction: Boolean, clickAction: Map<String, Object>) {
7
+ this.payload = payload;
8
+ this.isDefaultAction = isDefaultAction;
9
+ this.clickAction = clickAction;
26
10
  }
27
11
  }
@@ -0,0 +1,14 @@
1
+ import MoEAccountMeta from "./MoEAccountMeta";
2
+ import { MoEPlatform } from "./MoEPlatform";
3
+ import MoEPushCampaign from "./MoEPushCampaign";
4
+
5
+ export default class MoEPushPayload {
6
+ accountMeta: MoEAccountMeta;
7
+ data: MoEPushCampaign;
8
+ platform: MoEPlatform;
9
+ constructor(accountMeta: MoEAccountMeta, data: MoEPushCampaign, platform: MoEPlatform) {
10
+ this.accountMeta = accountMeta;
11
+ this.data = data;
12
+ this.platform = platform;
13
+ }
14
+ }
@@ -1,6 +1,6 @@
1
1
  export enum MoEPushService {
2
- APNS,
3
- FCM,
4
- MI_PUSH,
5
- PUSH_KIT,
2
+ APNS = "APNS",
3
+ FCM = "FCM",
4
+ MI_PUSH = "MI_PUSH",
5
+ PUSH_KIT = "PUSH_KIT",
6
6
  }
@@ -1,23 +1,14 @@
1
- import { isValidObject, isValidString } from "../utils/MoEHelper";
1
+ import { MoEPlatform } from "./MoEPlatform";
2
2
  import { MoEPushService } from "./MoEPushService";
3
3
 
4
4
  export default class MoEPushToken {
5
- platform: String;
5
+ platform: MoEPlatform;
6
6
  pushService: MoEPushService;
7
7
  token: String;
8
8
 
9
- constructor(tokenPayload: Object) {
10
- if (isValidObject(tokenPayload)) {
11
- if (isValidString(tokenPayload["platform"])) {
12
- this.platform = tokenPayload["platform"];
13
- }
14
- if (isValidString(tokenPayload["token"])) {
15
- this.token = tokenPayload["token"];
16
- }
17
- if (isValidString(tokenPayload["pushService"])) {
18
- this.pushService = tokenPayload["pushService"] as MoEPushService;
19
- }
20
- }
9
+ constructor(platform: MoEPlatform, pushService: MoEPushService, token: String) {
10
+ this.platform = platform;
11
+ this.pushService = pushService;
12
+ this.token = token;
21
13
  }
22
14
  }
23
-
@@ -0,0 +1,10 @@
1
+ export default class MoESelfHandledCampaign {
2
+ payload: string;
3
+ dismissInterval: Number;
4
+
5
+ constructor(payload: string, dismissInterval: Number) {
6
+ this.payload = payload;
7
+ this.dismissInterval = dismissInterval;
8
+ }
9
+
10
+ }
@@ -0,0 +1,18 @@
1
+ import MoEAccountMeta from "./MoEAccountMeta";
2
+ import MoECampaignData from "./MoECampaignData";
3
+ import { MoEPlatform } from "./MoEPlatform";
4
+ import MoESelfHandledCampaign from "./MoESelfHandledCampaign";
5
+
6
+ export default class MoESelfHandledCampaignData {
7
+ campaignData:MoECampaignData;
8
+ accountMeta: MoEAccountMeta;
9
+ platform: MoEPlatform;
10
+ campaign: MoESelfHandledCampaign
11
+ constructor(accountMeta: MoEAccountMeta, platform: MoEPlatform, campaign: MoESelfHandledCampaign,campaignData:MoECampaignData) {
12
+ this.accountMeta = accountMeta;
13
+ this.platform = platform;
14
+ this.campaign = campaign;
15
+ this.campaignData = campaignData;
16
+ }
17
+
18
+ }
@@ -0,0 +1,192 @@
1
+ import MoEAccountMeta from "../models/MoEAccountMeta";
2
+ import MoECampaignContext from "../models/MoECampaignContext";
3
+ import MoECampaignData from "../models/MoECampaignData";
4
+ import MoEClickData from "../models/MoEClickData";
5
+ import MoEInAppCustomAction from "../models/MoEInAppCustomAction";
6
+ import MoEInAppData from "../models/MoEInAppData";
7
+ import MoEInAppNavigation from "../models/MoEInAppNavigation";
8
+ import MoESelfHandledCampaign from "../models/MoESelfHandledCampaign";
9
+ import MoESelfHandledCampaignData from "../models/MoESelfHandledCampaignData";
10
+ import { ACTION_TYPE, APP_ID, ATTRIBUTES, FORMATTED_CAMPAIGN_ID, MOE_CAMPAIGN_CONTEXT, MOE_CAMPAIGN_ID, MOE_CAMPAIGN_NAME, MOE_CUSTOM_ACTION, MOE_CUSTOM_ACTION_OBJ_ERROR, MOE_DISMISSINTERVAL, MOE_IN_APP_OBJECT_ERROR, MOE_IS_CANCELLABLE, MOE_KEY_VALUE_PAIR, MOE_NAVIGATION, MOE_NAVIGATION_OBJ_ERROR, MOE_NAVIGATION_TYPE, MOE_PAYLOAD, MOE_PLATFORM, MOE_SELF_HANDLED, MOE_SELF_HANDLED_OBJ_ERROR, MOE_NAVIGATION_VALUE, MOE_WIDGET_ID } from "../utils/MoEConstants";
11
+ import { isValidObject } from "../utils/MoEHelper";
12
+
13
+ /**
14
+ *
15
+ * @param obj is a json that has InApp details
16
+ * @returns true if obj is a valid InApp Object else false
17
+ */
18
+ export function isMoEInAppCampaignValid(obj: { [k: string]: any }) {
19
+ try {
20
+ if (obj != undefined && obj[MOE_CAMPAIGN_ID] != undefined && obj[MOE_CAMPAIGN_NAME] != undefined && obj[MOE_CAMPAIGN_CONTEXT]
21
+ && obj[MOE_PLATFORM]) {
22
+ return true;
23
+ }
24
+ else {
25
+ throw new Error(MOE_IN_APP_OBJECT_ERROR);
26
+ }
27
+ }
28
+ catch (error: any) {
29
+ console.log(error?.message);
30
+ return false;
31
+ }
32
+ }
33
+
34
+
35
+ function getMoEAccountMeta(accountMeta: { [k: string]: any }) {
36
+ return new MoEAccountMeta(accountMeta[APP_ID]);
37
+ }
38
+
39
+ function getMoECampaignData(json: { [k: string]: any }) {
40
+ console.log("getMoECampaignData(): Payload: ", json)
41
+ var campaignId = json[MOE_CAMPAIGN_ID];
42
+ var campaignName = json[MOE_CAMPAIGN_NAME];
43
+ var campaignContext = json[MOE_CAMPAIGN_CONTEXT];
44
+ var formattedCampaignId = campaignContext[FORMATTED_CAMPAIGN_ID];
45
+ var campaignContextObj = new MoECampaignContext(formattedCampaignId, campaignContext);
46
+ return new MoECampaignData(campaignId, campaignName, campaignContextObj);
47
+ }
48
+
49
+ function getMoESelfHandledCampaign(json: { [k: string]: any }) {
50
+ var selfHandled = json[MOE_SELF_HANDLED];
51
+ var payload = selfHandled[MOE_PAYLOAD];
52
+ var dismissInterval = selfHandled[MOE_DISMISSINTERVAL];
53
+ return new MoESelfHandledCampaign(payload, dismissInterval);
54
+ }
55
+
56
+ function getMoEInAppCustomAction(json: { [k: string]: any }) {
57
+ var customAction = json[MOE_CUSTOM_ACTION]
58
+ var keyValuePair = customAction[MOE_KEY_VALUE_PAIR]
59
+ var actionType = json[ACTION_TYPE]
60
+ return new MoEInAppCustomAction(keyValuePair, actionType)
61
+ }
62
+
63
+ function getMoEInAppNavigation(json: { [k: string]: any }) {
64
+ var navigation = json[MOE_NAVIGATION]
65
+ var navigationType = navigation[MOE_NAVIGATION_TYPE]
66
+ var url = navigation[MOE_NAVIGATION_VALUE]
67
+ var keyValuePair = navigation[MOE_KEY_VALUE_PAIR]
68
+ var actionType = json[ACTION_TYPE]
69
+ return new MoEInAppNavigation(navigationType, url, keyValuePair, actionType)
70
+
71
+ }
72
+ /**
73
+ * this funtion creates MoEInAppData Object from json
74
+ */
75
+ export function getMoEInAppData(json: { [k: string]: any }, accountMetaPayload: { [k: string]: any }) {
76
+ if (isMoEInAppCampaignValid(json)) {
77
+ var campaignData = getMoECampaignData(json);
78
+ var platform = json[MOE_PLATFORM];
79
+ var accountMeta = getMoEAccountMeta(accountMetaPayload);
80
+ return new MoEInAppData(accountMeta, platform, campaignData);
81
+ }
82
+ else return undefined
83
+ }
84
+
85
+ /**
86
+ * this funtion creates MoESelfHandledCampaignData Object from json
87
+ */
88
+ export function getMoESelfHandledCampaignData(json: { [k: string]: any }, accountMetaPayload: { [k: string]: any }) {
89
+ console.log("getMoESelfHandledCampaignData(): Payload: ", json);
90
+ if (isSelfHandledCampaignValid(json)) {
91
+ var campaignData = getMoECampaignData(json);
92
+ var platform = json[MOE_PLATFORM];
93
+ var accountMeta = getMoEAccountMeta(accountMetaPayload);
94
+ var campaign = getMoESelfHandledCampaign(json);
95
+ return new MoESelfHandledCampaignData(accountMeta, platform, campaign, campaignData);
96
+ }
97
+ else return undefined
98
+ }
99
+
100
+
101
+ /**
102
+ * This function checks weather customAction key exists or not. And also checks value is a type of object
103
+ */
104
+ export function isInAppCustomActionValid(obj: { [k: string]: any }) {
105
+ try {
106
+ if (obj[MOE_CUSTOM_ACTION] != undefined && isValidObject(obj[MOE_CUSTOM_ACTION])) {
107
+ return true;
108
+ }
109
+ else {
110
+ throw new Error(MOE_CUSTOM_ACTION_OBJ_ERROR);
111
+ }
112
+ }
113
+ catch (error: any) {
114
+ console.log(error?.message);
115
+ return false;
116
+ }
117
+ }
118
+
119
+ /**
120
+ * this funtion creates MoEInAppCustomAction Object from json
121
+ */
122
+ export function getCustomActionObj(json: { [k: string]: any }, accountMetaPayload: { [k: string]: any }) {
123
+ if (isInAppCustomActionValid(json)) {
124
+ var campaignData = getMoECampaignData(json);
125
+ var platform = json[MOE_PLATFORM];
126
+ var accountMeta = getMoEAccountMeta(accountMetaPayload);
127
+ var action = getMoEInAppCustomAction(json);
128
+
129
+ return new MoEClickData(accountMeta, platform, campaignData, action);
130
+ }
131
+ else return undefined
132
+
133
+
134
+ }
135
+
136
+
137
+ /**
138
+ * This function checks weather selfHandled key exists or not.
139
+ * checks value is a type of object
140
+ * checks mandatory keys of selfHandled exist or not
141
+ */
142
+ export function isSelfHandledCampaignValid(obj: { [k: string]: any }) {
143
+ try {
144
+ if (obj[MOE_SELF_HANDLED] != undefined && isValidObject(obj[MOE_SELF_HANDLED])) {
145
+ var selfHandled = obj[MOE_SELF_HANDLED];
146
+ if (selfHandled[MOE_PAYLOAD] != undefined && selfHandled[MOE_DISMISSINTERVAL] != undefined)
147
+ return true;
148
+ else throw new Error(MOE_SELF_HANDLED_OBJ_ERROR);
149
+
150
+ }
151
+ else {
152
+ throw new Error(MOE_SELF_HANDLED_OBJ_ERROR);
153
+ }
154
+ }
155
+ catch (error: any) {
156
+ console.log(error?.message);
157
+ return false;
158
+ }
159
+ }
160
+
161
+ /**
162
+ * This function checks weather navigation key exists or not. And also checks value is a type of object
163
+ */
164
+ export function isNavigationValid(obj: { [k: string]: any }) {
165
+ try {
166
+ if (obj[MOE_NAVIGATION] != undefined && isValidObject(obj[MOE_NAVIGATION])) {
167
+ return true;
168
+ }
169
+ else {
170
+ throw new Error(MOE_NAVIGATION_OBJ_ERROR);
171
+ }
172
+ }
173
+ catch (error: any) {
174
+ console.log(error?.message);
175
+ return false;
176
+ }
177
+ }
178
+
179
+ /**
180
+ * this funtion creates MoEInAppNavigation Object from json
181
+ */
182
+ export function getNavigationObj(json: { [k: string]: any }, accountMetaPayload: { [k: string]: any }) {
183
+ if (isNavigationValid(json)) {
184
+ var campaignData = getMoECampaignData(json);
185
+ var platform = json[MOE_PLATFORM];
186
+ var accountMeta = getMoEAccountMeta(accountMetaPayload);
187
+ var action = getMoEInAppNavigation(json);
188
+ return new MoEClickData(accountMeta, platform, campaignData, action);
189
+
190
+ }
191
+ else return undefined
192
+ }
@@ -0,0 +1,78 @@
1
+ import MoEAccountMeta from "../models/MoEAccountMeta";
2
+ import MoEPushCampaign from "../models/MoEPushCampaign";
3
+ import MoEPushPayload from "../models/MoEPushPayload";
4
+ import MoEPushToken from "../models/MoEPushToken";
5
+ import { APP_ID, MOE_CLICKED_ACTION, MOE_IS_DEFAULT_ACTION, MOE_PAYLOAD, MOE_PLATFORM, MOE_PUSH_CAMPAIGN_OBJ_ERROR, MOE_PUSH_SERVICE, MOE_PUSH_TOKEN_OBJ_ERROR, MOE_TOKEN } from "../utils/MoEConstants";
6
+
7
+
8
+ /**
9
+ *
10
+ * @param obj is a json that has MoEPushToken details
11
+ * @returns true if obj is a valid MoEPushToken Object else false
12
+ */
13
+ export function isPushTokenValid(tokenPayload: { [k: string]: any }) {
14
+ try {
15
+ if (tokenPayload != undefined && tokenPayload[MOE_PLATFORM] != undefined && tokenPayload[MOE_PUSH_SERVICE] != undefined && tokenPayload[MOE_TOKEN] != undefined)
16
+ return true;
17
+ else {
18
+ throw new Error(MOE_PUSH_TOKEN_OBJ_ERROR);
19
+ }
20
+ }
21
+ catch (error: any) {
22
+ console.log(error?.message);
23
+ return false;
24
+ }
25
+
26
+ }
27
+
28
+ /**
29
+ * this funtion creates MoEPushToken Object from json
30
+ */
31
+ export function getMoEPushToken(tokenPayload: { [k: string]: any }) {
32
+ if (isPushTokenValid(tokenPayload)) {
33
+ var platform = tokenPayload[MOE_PLATFORM];
34
+ var pushService = tokenPayload[MOE_PUSH_SERVICE];
35
+ var token = tokenPayload[MOE_TOKEN];
36
+ return new MoEPushToken(platform, pushService, token)
37
+ }
38
+ else return undefined
39
+
40
+ }
41
+
42
+
43
+ /**
44
+ *
45
+ * @param obj is a json that has MoEPushCampaign details
46
+ * @returns true if obj is a valid MoEPushCampaign Object else false
47
+ */
48
+ export function isPushCampaignObjectValid(pushPayload: { [k: string]: any }) {
49
+ try {
50
+ if (pushPayload[MOE_PLATFORM] != undefined && pushPayload[MOE_PAYLOAD] != undefined)
51
+ return true;
52
+ else {
53
+ throw new Error(MOE_PUSH_CAMPAIGN_OBJ_ERROR);
54
+ }
55
+ }
56
+ catch (error: any) {
57
+ console.log(error?.message);
58
+ return false;
59
+ }
60
+
61
+ }
62
+
63
+ /**
64
+ * this funtion creates MoEPushCampaign Object from json
65
+ */
66
+ export function getMoEPushPayload(pushPayload: { [k: string]: any },accountMetaPayload:{ [k: string]: any }) {
67
+ if (isPushCampaignObjectValid(pushPayload)) {
68
+ var payload = pushPayload[MOE_PAYLOAD];
69
+ var isDefaultAction = pushPayload[MOE_IS_DEFAULT_ACTION];
70
+ var clickAction = pushPayload[MOE_CLICKED_ACTION];
71
+ var pushCampaignPayload = new MoEPushCampaign(payload, isDefaultAction, clickAction);
72
+ var accountMeta = new MoEAccountMeta(accountMetaPayload[APP_ID])
73
+ var platform = pushPayload[MOE_PLATFORM];
74
+ return new MoEPushPayload(accountMeta, pushCampaignPayload,platform);
75
+ }
76
+ else return undefined
77
+
78
+ }