react-native-moengage-cards 2.0.1 → 3.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.
@@ -16,53 +16,63 @@ import {
16
16
  } from "../Constants";
17
17
  import { cardToJson } from "./ModelToJsonMapper";
18
18
 
19
- export function getAccountMetaPayload(appId: string): { [k: string]: any } {
20
- return {
19
+ export function getAccountMetaPayload(appId: string): string {
20
+ let payload = {
21
21
  [keyAccountMeta]: getAppIdPayload(appId)
22
22
  };
23
+
24
+ return JSON.stringify(payload);
23
25
  }
24
26
 
25
- export function getCardClickedPayload(card: Card, widgetId: number, appId: string): { [k: string]: any } {
26
- return {
27
+ export function getCardClickedPayload(card: Card, widgetId: number, appId: string): string {
28
+ let payload = {
27
29
  [keyAccountMeta]: getAppIdPayload(appId),
28
30
  [keyData]: {
29
31
  [keyCard]: cardToJson(card),
30
32
  [keyWidgetIdentifier]: widgetId
31
33
  }
32
- };
34
+ }
35
+
36
+ return JSON.stringify(payload);
33
37
  }
34
38
 
35
- export function getCardShownPayload(card: Card, appId: string): { [k: string]: any } {
36
- return {
39
+ export function getCardShownPayload(card: Card, appId: string): string {
40
+ let payload = {
37
41
  [keyAccountMeta]: getAppIdPayload(appId),
38
42
  [keyData]: {
39
43
  [keyCard]: cardToJson(card)
40
44
  }
41
- };
45
+ }
46
+
47
+ return JSON.stringify(payload);
42
48
  }
43
49
 
44
- export function getCardsForCategoriesPayload(category: string, appId: string): { [k: string]: any } {
45
- return {
50
+ export function getCardsForCategoriesPayload(category: string, appId: string): string {
51
+ let payload = {
46
52
  [keyAccountMeta]: getAppIdPayload(appId),
47
53
  [keyData]: {
48
54
  [keyCategory]: category
49
55
  }
50
- };
56
+ }
57
+
58
+ return JSON.stringify(payload);
51
59
  }
52
60
 
53
- export function getDeleteCardsPayload(cards: Array<Card>, appId: string): { [k: string]: any } {
54
- return {
61
+ export function getDeleteCardsPayload(cards: Array<Card>, appId: string): string {
62
+ let payload = {
55
63
  [keyAccountMeta]: getAppIdPayload(appId),
56
64
  [keyData]: {
57
65
  [keyCards]: cards.map((card) => {
58
66
  return cardToJson(card);
59
67
  })
60
68
  }
61
- };
69
+ }
70
+
71
+ return JSON.stringify(payload);
62
72
  }
63
73
 
64
74
  function getAppIdPayload(appId: string): { [k: string]: any } {
65
75
  return {
66
76
  [keyAppId]: appId
67
- };
77
+ }
68
78
  }
@@ -1,149 +0,0 @@
1
- // MoEngageCardsBridge.m
2
-
3
- #import "MoEngageCardsBridge.h"
4
- #import "MoEngageCardsReactConstants.h"
5
- #import "MoEngageCardsReactUtil.h"
6
-
7
- @interface MoEngageCardsBridge() <MoEngageCardSyncDelegate>
8
- @end
9
-
10
- @implementation MoEngageCardsBridge
11
- {
12
- bool hasListeners;
13
- }
14
- // Will be called when this module's first listener is added.
15
- -(void)startObserving {
16
- hasListeners = YES;
17
- // Set up any upstream listeners or background tasks as necessary
18
-
19
- }
20
-
21
- // Will be called when this module's last listener is removed, or on dealloc.
22
- -(void)stopObserving {
23
- hasListeners = NO;
24
- // Remove upstream listeners, stop unnecessary background tasks
25
- }
26
-
27
- - (NSArray<NSString *> *)supportedEvents
28
- {
29
- return @[kAppOpenCardsSyncListener, kPullToRefreshCardsSyncListener, kInboxOpenCardsSyncListener];
30
- }
31
-
32
-
33
- RCT_EXPORT_MODULE();
34
-
35
- RCT_EXPORT_METHOD(initialize:(NSDictionary *) payload)
36
- {
37
- [[MoEngagePluginCardsBridge sharedInstance] initialize:payload];
38
- [[MoEngagePluginCardsBridge sharedInstance] setAppOpenSyncListener:payload];
39
- [[MoEngagePluginCardsBridge sharedInstance] setSyncEventListnerDelegate:self];
40
- }
41
-
42
- RCT_EXPORT_METHOD(isAllCategoryEnabled:(NSDictionary *) payload resolver:(RCTPromiseResolveBlock) resolver rejecter:(RCTPromiseRejectBlock)rejecter)
43
- {
44
- [[MoEngagePluginCardsBridge sharedInstance] isAllCategoryEnabled:payload completionHandler:^(NSDictionary<NSString *,id> * _Nonnull cardPayload) {
45
- [MoEngageCardsReactUtil handleDataToReact:cardPayload rejecter:rejecter resolver:resolver];
46
- }];
47
- }
48
-
49
-
50
- RCT_EXPORT_METHOD(getCardsCategories:(NSDictionary *) payload resolver:(RCTPromiseResolveBlock) resolver rejecter:(RCTPromiseRejectBlock)rejecter)
51
- {
52
- [[MoEngagePluginCardsBridge sharedInstance] getCardsCategories:payload completionHandler:^(NSDictionary<NSString *,id> * _Nonnull cardPayload) {
53
- [MoEngageCardsReactUtil handleDataToReact:cardPayload rejecter:rejecter resolver:resolver];
54
- }];
55
- }
56
-
57
-
58
- RCT_EXPORT_METHOD(getCardsInfo:(NSDictionary *) payload resolver:(RCTPromiseResolveBlock) resolver rejecter:(RCTPromiseRejectBlock)rejecter)
59
- {
60
- [[MoEngagePluginCardsBridge sharedInstance] getCardsInfo:payload completionHandler:^(NSDictionary<NSString *,id> * _Nonnull cardPayload) {
61
- [MoEngageCardsReactUtil handleDataToReact:cardPayload rejecter:rejecter resolver:resolver];
62
- }];
63
- }
64
-
65
- RCT_EXPORT_METHOD(getCardsForCategory:(NSDictionary *) payload resolver:(RCTPromiseResolveBlock) resolver rejecter:(RCTPromiseRejectBlock)rejecter)
66
- {
67
- [[MoEngagePluginCardsBridge sharedInstance] getCardsForCategory:payload completionHandler:^(NSDictionary<NSString *,id> * _Nonnull cardPayload) {
68
- [MoEngageCardsReactUtil handleDataToReact:cardPayload rejecter:rejecter resolver:resolver];
69
- }];
70
- }
71
-
72
- RCT_EXPORT_METHOD(fetchCards:(NSDictionary *) payload resolver:(RCTPromiseResolveBlock) resolver rejecter:(RCTPromiseRejectBlock)rejecter)
73
- {
74
- [[MoEngagePluginCardsBridge sharedInstance] fetchCards:payload completionHandler:^(NSDictionary<NSString *,id> * _Nonnull cardPayload) {
75
- [MoEngageCardsReactUtil handleDataToReact:cardPayload rejecter:rejecter resolver:resolver];
76
- }];
77
- }
78
-
79
-
80
- RCT_EXPORT_METHOD(getNewCardsCount:(NSDictionary *) payload resolver:(RCTPromiseResolveBlock) resolver rejecter:(RCTPromiseRejectBlock)rejecter)
81
- {
82
- [[MoEngagePluginCardsBridge sharedInstance] getNewCardsCount:payload completionHandler:^(NSDictionary<NSString *,id> * _Nonnull cardPayload) {
83
- [MoEngageCardsReactUtil handleDataToReact:cardPayload rejecter:rejecter resolver:resolver];
84
- }];
85
- }
86
-
87
-
88
- RCT_EXPORT_METHOD(getUnClickedCardsCount:(NSDictionary *) payload resolver:(RCTPromiseResolveBlock) resolver rejecter:(RCTPromiseRejectBlock)rejecter)
89
- {
90
- [[MoEngagePluginCardsBridge sharedInstance] getUnClickedCardsCount:payload completionHandler:^(NSDictionary<NSString *,id> * _Nonnull cardPayload) {
91
- [MoEngageCardsReactUtil handleDataToReact:cardPayload rejecter:rejecter resolver:resolver];
92
- }];
93
- }
94
-
95
- RCT_EXPORT_METHOD(refreshCards:(NSDictionary *) payload)
96
- {
97
- [[MoEngagePluginCardsBridge sharedInstance] refreshCards:payload];
98
- }
99
-
100
-
101
- RCT_EXPORT_METHOD(onCardSectionLoaded:(NSDictionary *) payload)
102
- {
103
- [[MoEngagePluginCardsBridge sharedInstance] onCardsSectionLoaded:payload];
104
- }
105
-
106
- RCT_EXPORT_METHOD(onCardSectionUnLoaded:(NSDictionary *) payload)
107
- {
108
- [[MoEngagePluginCardsBridge sharedInstance] onCardsSectionUnLoaded:payload];
109
- }
110
-
111
- RCT_EXPORT_METHOD(cardClicked:(NSDictionary *) payload)
112
- {
113
- [[MoEngagePluginCardsBridge sharedInstance] cardClicked:payload];
114
- }
115
-
116
- RCT_EXPORT_METHOD(cardDelivered:(NSDictionary *) payload)
117
- {
118
- [[MoEngagePluginCardsBridge sharedInstance] cardDelivered:payload];
119
- }
120
-
121
- RCT_EXPORT_METHOD(cardShown:(NSDictionary *) payload)
122
- {
123
- [[MoEngagePluginCardsBridge sharedInstance] cardShown:payload];
124
- }
125
-
126
- RCT_EXPORT_METHOD(deleteCards:(NSDictionary *) payload)
127
- {
128
- [[MoEngagePluginCardsBridge sharedInstance] deleteCards:payload];
129
- }
130
-
131
- - (void)syncCompleteForEventType:(enum MoEngageCardsSyncEventType)eventType withData:(NSDictionary<NSString *,id> *)data {
132
-
133
- NSMutableDictionary* updatedDict = [NSMutableDictionary dictionary];
134
- NSString* eventName = [MoEngageCardsReactUtil fetchSyncType:eventType];
135
-
136
- if (hasListeners && eventName && data) {
137
- NSError *err;
138
- NSData * jsonData = [NSJSONSerialization dataWithJSONObject:data options:0 error:&err];
139
- if (jsonData) {
140
- NSString* strPayload = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
141
- updatedDict[kPayload] = strPayload;
142
- [self sendEventWithName:eventName body:updatedDict];
143
- } else {
144
- NSLog(@"Error converting to dictionary to string %@", err.localizedDescription);
145
- }
146
- }
147
- }
148
-
149
- @end
@@ -1,81 +0,0 @@
1
- import Card from "../../model/Card";
2
- import {
3
- getAccountMetaPayload,
4
- getCardClickedPayload,
5
- getCardShownPayload,
6
- getCardsForCategoriesPayload,
7
- getDeleteCardsPayload
8
- } from "./PayloadBuilder";
9
-
10
- const PLATFORM_ANDROID = "android";
11
- const PLATFORM_iOS = "ios";
12
-
13
- /**
14
- * Class to build the Platform specific payload to communicate with the bridge
15
- *
16
- * @author Abhishek Kumar
17
- * @since 1.0.0
18
- */
19
- class PlatformPayloadBuilder {
20
-
21
- private platform: string;
22
- private appId: string;
23
-
24
- constructor(platform: string, appId: string) {
25
- this.platform = platform;
26
- this.appId = appId;
27
- }
28
-
29
- getAccountMetaPayload(): string | { [k: string]: any } {
30
- if (this.platform === PLATFORM_ANDROID) {
31
- return JSON.stringify(getAccountMetaPayload(this.appId));
32
- } else if (this.platform === PLATFORM_iOS) {
33
- return getAccountMetaPayload(this.appId);
34
- } else {
35
- throw new Error("Platform Not Supported");
36
- }
37
- }
38
-
39
- getCardClickedPayload(card: Card, widgetId: number): string | { [k: string]: any } {
40
- if (this.platform === PLATFORM_ANDROID) {
41
- return JSON.stringify(getCardClickedPayload(card, widgetId, this.appId));
42
- } else if (this.platform === PLATFORM_iOS) {
43
- return getCardClickedPayload(card, widgetId, this.appId);
44
- } else {
45
- throw new Error("Platform Not Supported");
46
- }
47
- }
48
-
49
- getCardShowPayload(card: Card): string | { [k: string]: any } {
50
- if (this.platform === PLATFORM_ANDROID) {
51
- return JSON.stringify(getCardShownPayload(card, this.appId));
52
- } else if (this.platform === PLATFORM_iOS) {
53
- return getCardShownPayload(card, this.appId);
54
- } else {
55
- throw new Error("Platform Not Supported");
56
- }
57
- }
58
-
59
- getCardsForCategoriesPayload(category: string): string | { [k: string]: any } {
60
- if (this.platform === PLATFORM_ANDROID) {
61
- return JSON.stringify(getCardsForCategoriesPayload(category, this.appId));
62
- } else if (this.platform === PLATFORM_iOS) {
63
- return getCardsForCategoriesPayload(category, this.appId);
64
- } else {
65
- throw new Error("Platform Not Supported");
66
- }
67
-
68
- }
69
-
70
- getDeleteCardsPayload(cards: Array<Card>): string | { [k: string]: any } {
71
- if (this.platform === PLATFORM_ANDROID) {
72
- return JSON.stringify(getDeleteCardsPayload(cards, this.appId));
73
- } else if (this.platform === PLATFORM_iOS) {
74
- return getDeleteCardsPayload(cards, this.appId);
75
- } else {
76
- throw new Error("Platform Not Supported");
77
- }
78
- }
79
- }
80
-
81
- export default PlatformPayloadBuilder;