react-native-moengage 7.4.0 → 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.
- package/CHANGELOG.md +57 -3
- package/README.md +29 -6
- package/ReactNativeMoEngage.podspec +3 -3
- package/android/build.gradle +11 -12
- package/android/gradle/wrapper/gradle-wrapper.properties +3 -3
- package/android/gradle.properties +0 -1
- package/android/src/main/java/com/moengage/react/EventEmitterImpl.kt +46 -21
- package/android/src/main/java/com/moengage/react/MoEInitializer.kt +44 -13
- package/android/src/main/java/com/moengage/react/MoEReactBridge.kt +87 -80
- package/android/src/main/java/com/moengage/react/MoEReactHelper.kt +2 -2
- package/android/src/main/java/com/moengage/react/MoEReactPackage.kt +0 -1
- package/android/src/main/java/com/moengage/react/PayloadGenerator.kt +32 -17
- package/iOS/MoEReactBridge/MoEReactBridge.h +1 -1
- package/iOS/MoEReactBridge/MoEReactBridge.m +34 -60
- package/iOS/MoEReactBridge/{MOReactInitializer.h → MoEngageInitializer.h} +11 -11
- package/iOS/MoEReactBridge/MoEngageInitializer.m +153 -0
- package/iOS/MoEReactBridge/{MoEReactConstants.h → MoEngageReactConstants.h} +12 -3
- package/iOS/MoEReactBridge/{MoEReactConstants.m → MoEngageReactConstants.m} +13 -7
- package/iOS/MoEReactBridge/MoEngageReactPluginInfo.h +2 -0
- package/iOS/MoEReactBridge.xcodeproj/project.pbxproj +6 -6
- package/package.json +8 -3
- package/src/index.ts +169 -190
- package/src/models/MoEAccountMeta.ts +8 -0
- package/src/models/MoEAction.ts +4 -0
- package/src/models/MoEActionType.ts +4 -0
- package/src/models/MoECampaignContext.ts +10 -0
- package/src/models/MoECampaignData.ts +14 -0
- package/src/models/MoEClickData.ts +18 -0
- package/src/models/MoEGeoLocation.ts +2 -10
- package/src/models/MoEInAppCustomAction.ts +8 -13
- package/src/models/MoEInAppData.ts +16 -0
- package/src/models/MoEInAppNavigation.ts +14 -24
- package/src/models/MoENavigationType.ts +4 -0
- package/src/models/MoEPlatform.ts +4 -0
- package/src/models/MoEProperties.ts +19 -15
- package/src/models/MoEPushCampaign.ts +6 -22
- package/src/models/MoEPushPayload.ts +14 -0
- package/src/models/MoEPushService.ts +4 -4
- package/src/models/MoEPushToken.ts +6 -15
- package/src/models/MoESelfHandledCampaign.ts +10 -0
- package/src/models/MoESelfHandledCampaignData.ts +18 -0
- package/src/moeParser/MoEInAppParser.ts +192 -0
- package/src/moeParser/MoEPushNotificationParser.ts +78 -0
- package/src/platform/MoERNAndroid.ts +48 -76
- package/src/platform/MoERNiOS.ts +27 -60
- package/src/utils/MoEConstants.ts +59 -0
- package/src/utils/MoEEventHandlerHelper.ts +38 -25
- package/src/utils/MoEJsonBuilder.ts +220 -0
- package/src/utils/MoEObjectToJson.ts +44 -0
- package/iOS/MoEReactBridge/MOReactInitializer.m +0 -172
- package/iOS/MoEReactBridge/MOReactPluginInfo.h +0 -2
- package/src/models/MoEInAppCampaign.ts +0 -46
- package/src/models/MoEInAppSelfHandledCampaign.ts +0 -34
|
@@ -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
|
-
|
|
7
|
-
|
|
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
|
|
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(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
1
|
+
import MoEAction from "./MoEAction";
|
|
2
|
+
import { MoEActionType } from "./MoEActionType";
|
|
3
|
+
import { MoENavigationType } from "./MoENavigationType";
|
|
2
4
|
|
|
3
|
-
export default class MoEInAppNavigation {
|
|
4
|
-
navigationType:
|
|
5
|
-
|
|
6
|
-
keyValuePair
|
|
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(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
}
|
|
@@ -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:
|
|
6
|
-
private locationAttributes:
|
|
7
|
-
private dateTimeAttributes:
|
|
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
|
-
|
|
18
|
-
return
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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(
|
|
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
|
|
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(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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,23 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MoEPlatform } from "./MoEPlatform";
|
|
2
2
|
import { MoEPushService } from "./MoEPushService";
|
|
3
3
|
|
|
4
4
|
export default class MoEPushToken {
|
|
5
|
-
platform:
|
|
5
|
+
platform: MoEPlatform;
|
|
6
6
|
pushService: MoEPushService;
|
|
7
7
|
token: String;
|
|
8
8
|
|
|
9
|
-
constructor(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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,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
|
+
}
|