reactnative-plugin-appice 1.7.12 → 1.7.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reactnative-plugin-appice",
3
- "version": "1.7.12",
3
+ "version": "1.7.13",
4
4
  "description": "appICE React Native SDK",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -1,483 +0,0 @@
1
- import React, { useEffect } from 'react';
2
- import { connect } from 'react-redux';
3
- import store from './componenets/store';
4
- import { addEvent, flushEvents } from './componenets/actions';
5
- import { View, Text, TouchableOpacity, StyleSheet, FlatList } from 'react-native';
6
-
7
-
8
- const AppICE = require('reactnative-plugin-appice');
9
-
10
- const HelloWorldApp = () => {
11
-
12
- useEffect(() => {
13
- const certs = [];
14
-
15
- if (AppICE) {
16
- console.log('AppICE is available');
17
- AppICE.startContext(
18
-
19
-
20
- //=============================
21
- // SAMPLE - APP
22
- //=============================
23
-
24
- // "5bebe93c25d705690ffbc758",
25
- // "9e9ec60197c8373a11ac15ce4dae80e973608ab2",
26
- // "d985715d1bb48942d36d5d08de3b6a8c",
27
- // "",
28
- // "US",
29
- // "https://devapi.appice.io",
30
-
31
- //===========================
32
- //BOI- UAT
33
- //============================
34
-
35
- "63ff2f6656903ac80342836f",
36
- "f77142c61559d217188336610f0d4e432063e0c8",
37
- "869a33728bd9b54fb920cee790062f6c",
38
- "",
39
- "BOI-UAT",
40
- "https://uaappiceuatapi.bankofindia.co.in:11443/uat/api",
41
- //===============================
42
- certs
43
- );
44
-
45
- AppICE.registerLifeCycle();
46
- }
47
- addAppICEAPIListeners();
48
- }, []);
49
-
50
- const buttonsData = [
51
- { key: 'Send Event', onPress: sendEvent },
52
- { key: 'Set User Profile', onPress: setUserProfile },
53
- { key: 'Set Sample User ID', onPress: setSampleUserID },
54
- { key: 'Set Language', onPress: setLanguage },
55
- { key: 'Send View', onPress: sendView },
56
- { key: 'Get User ID', onPress: getUserId },
57
- { key: 'Get Inbox Message', onPress: getInboxMessage },
58
- { key: 'Get Message Count', onPress: getMessageCount },
59
- { key: 'Get Inbox Message For ID', onPress: getInboxMessageForId },
60
- { key: 'Update Inbox Message', onPress: updateInboxMessage },
61
- { key: 'Synchronize Inbox', onPress: synchronizeInbox },
62
- { key: 'Get User', onPress: getUser },
63
- ];
64
-
65
- return (
66
- <View style={styles.container}>
67
- <Text style={styles.title}>AppICE React Demo</Text>
68
-
69
- <FlatList
70
- data={buttonsData}
71
- numColumns={2}
72
- renderItem={({ item }) => (
73
- <CustomButton onPress={item.onPress} title={item.key} />
74
- )}
75
- keyExtractor={(item) => item.key}
76
- />
77
- </View>
78
- );
79
- };
80
-
81
-
82
- const styles = StyleSheet.create({
83
- container: {
84
- flex: 1,
85
- padding: 16,
86
- backgroundColor: '#F5FCFF',
87
- },
88
- title: {
89
- fontSize: 20,
90
- fontWeight: 'bold',
91
- marginBottom: 20,
92
- },
93
- buttonContainer: {
94
- flex: 1,
95
- justifyContent: 'center',
96
- alignItems: 'center',
97
- margin: 8,
98
- backgroundColor: '#841584',
99
- paddingVertical: 15,
100
- paddingHorizontal: 30,
101
- borderRadius: 5,
102
- },
103
- buttonText: {
104
- color: '#FFFFFF',
105
- fontSize: 16,
106
- fontWeight: 'bold',
107
- },
108
- });
109
-
110
- // CustomButton component for rendering buttons
111
- const CustomButton = ({ onPress, title }) => (
112
- <TouchableOpacity onPress={onPress} style={styles.buttonContainer}>
113
- <Text style={styles.buttonText}>{title}</Text>
114
- </TouchableOpacity>
115
- );
116
-
117
- function addAppICEAPIListeners() {
118
-
119
- console.log('handleAppICETapEvent');
120
-
121
- AppICE.addListener(AppICE.AppICEPushNotificationClicked, (event) => {
122
- if (typeof event !== 'undefined') {
123
- console.log('handleAppICETapEvent', AppICE.AppICEPushNotificationClicked, event.AppICEPushNotificationClicked);
124
- AppICE.pushNotificationClicked(event.AppICEPushNotificationClicked);
125
- //fetching custom data from push payload
126
- var data = AppICE.getCustomDataFromPayload(event.AppICEPushNotificationClicked);
127
- console.log(data);
128
- }
129
- });
130
-
131
- AppICE.addListener(AppICE.AppICEInAppClicked, (event) => {
132
- if (typeof event !== 'undefined') {
133
- console.log('handleAppICETapEvent', AppICE.AppICEInAppClicked, event.AppICEInAppClicked);
134
- // AppICE.pushNotificationClicked(event.AppICEInAppClicked);
135
- }
136
- });
137
- }
138
-
139
-
140
- const flushEventCache = () => {
141
- const events = flushEvents();
142
- console.log('Flushed events:', events);
143
- };
144
-
145
-
146
- const sendEvent = () => {
147
- console.log("inside sendEvent");
148
- var dataObj = {
149
- "ClickedMenuBtn": "false",
150
- "CLickedSubmitBtn": "false",
151
- "AppName": "ReactSampleApp"
152
- };
153
- //AppICE.tagEvent("ReactSampleApp", dataObj);
154
-
155
- addEvent("ReactSampleApp", dataObj);
156
- //Recording an Event
157
- }
158
-
159
-
160
- const setUserProfile = () => {
161
- AppICE.setUser({
162
- [AppICE.name]: 'testUserA1', [AppICE.phone]: '123456', [AppICE.email]: 'test@test.com', [AppICE.age]: 23
163
- });
164
- };
165
-
166
- const setSampleUserID = () => {
167
- AppICE.setUserId(['kuOEN8bCqdrROmJPVCeKSg==']);
168
- };
169
-
170
- const setLanguage = () => {
171
- AppICE.setCustomVariable("_lang", "ar-AE");
172
- };
173
- const sendView = () => {
174
- AppICE.tagEvent("HomeScreen", {});
175
- };
176
-
177
- const getUserId = () => {
178
- AppICE.getUserId((userIds) => {
179
- console.log('User IDs:', userIds);
180
- });
181
- };
182
-
183
- const type = 1;
184
- const userIds = ['1232323', 'kuOEN8bCqdrROmJPVCeKSg=='];
185
-
186
- const getInboxMessage = () => {
187
- const userId = ['kuOEN8bCqdrROmJPVCeKSg=='];
188
- getInboxMessages(1, userId, "Savings", 10, 0, 10, false, (result) => {
189
- console.log("Inbox data set: ", result);
190
- showAlert("Inbox Data", result);
191
-
192
- })
193
- }
194
-
195
- const getMessageCount = () => {
196
- const userId = ['kuOEN8bCqdrROmJPVCeKSg=='];
197
- const count = getMessageCounts(2, userId, 10, (result) => {
198
- showAlert('getMessageCount', "" + result)
199
- })
200
- }
201
-
202
-
203
- const getInboxMessageForId = () => {
204
- const messageId = "4305ea15-f506-4ec8-b46d-05ee7b24d1ba";
205
- const userIds = ['181166344', 'kuOEN8bCqdrROmJPVCeKSg=='];
206
- }
207
-
208
-
209
-
210
- const updateInboxMessage = () => {
211
- const messageId = "13f6a43b-6618-4918-addf-d9d341984e23";
212
- updatedInboxMessage(messageId, 3, 'kuOEN8bCqdrROmJPVCeKSg==', (result) => {
213
- showAlert("updateInboxMessage", "" + result)
214
- });
215
- }
216
-
217
- const synchronizeInbox = () => {
218
- AppICE.synchronizeInbox(10, (res) => {
219
- showAlert("synchronizeInbox", "" + res);
220
- })
221
- }
222
-
223
- const getUser = () => {
224
- const userData = AppICE.getUser((res)=>{
225
- if(res){
226
- console.log("getUser "+res)
227
- var response;
228
- if (Platform.OS == 'android'){
229
- const resData = JSON.stringify(res);
230
- console.log("userprofile res = "+resData)
231
-
232
- const data = JSON.parse(resData);
233
- response = data;
234
- }
235
-
236
- if(!response){
237
- response = res;
238
- }
239
-
240
- const customProperties = response[AppICE.DEMOGRAPHIC_INFO];
241
- const customPropertiesObj = JSON.parse(customProperties);
242
- console.log("customPropertiesObj "+customPropertiesObj)
243
-
244
- console.log("user Profile, top_n_product_viewed = "+customPropertiesObj[AppICE.TOP_N_PRODUCTS_VIEWED]);
245
- showAlert("getUser", "TOP_N_PRODUCTS_VIEWED = "+customPropertiesObj[AppICE.TOP_N_PRODUCTS_VIEWED])
246
- }
247
- });
248
- }
249
-
250
-
251
- //===========================
252
- // AppICE inbox ApiS
253
- //===========================
254
-
255
- /*
256
- * type = { All = 1, UNREAD = 2, READ = 3, VIEWED = 4, DELETED = 5 },
257
- * userids = list of the userid ie. ['userid1', 'userid2'],
258
- * key = is String type ie. key = 'category',
259
- * limit = pagination limit ie. we need 10 set of data then we will pass limit = 10
260
- * offset = offset is index from which position you will need data ie. you need it from index 0.
261
- * timeout = to sync with server we are doing server call internally for that we will timeout time from app
262
- * return JSONObject
263
- *
264
- * below is the structure
265
- * {
266
- "count": [
267
- {
268
- "Chip A": 3
269
- },
270
- {
271
- "chip B": 4
272
- }
273
- ],
274
- "inboxData": [
275
- {
276
- "cData": {
277
- "category": "Chip A",
278
- "targetScreen": "url to redirect"
279
- },
280
- "campId": "12323333",
281
- "campType": "pn",
282
- "icon": "",
283
- "id": "cdf6ea28r",
284
- "message": "Hi",
285
- "messageExpiryTime": 1663500485,
286
- "messageLanguage": "en-us",
287
- "messageStatus": "unread",
288
- "title": "Hi"
289
- }
290
- ]
291
- }
292
- * NOTE : when user will open appInbox then we are calling getInboxMessage(1, ['userid'], 'category', 'chip A', 10, 0, 10)
293
- */
294
- function getInboxMessages(type, userids, category, limit, offset, timeout, withServerHit, callback) {
295
-
296
- if (withServerHit) {
297
- AppICE.synchronizeInbox(timeout, (res) => {
298
- if (res) {
299
- AppICE.getInboxMessages(type, userids, (res) => {
300
- if (res) {
301
- const newData = JSON.stringify(res);
302
- const result = getFilteredData(newData, category, limit, offset);
303
- const val = JSON.stringify(result);
304
- if (val) {
305
- console.log("internalGetInboxMessage " + val)
306
- callback(val);
307
- }
308
- }
309
- })
310
- } else {
311
- AppICE.getInboxMessages(type, userids, (res) => {
312
- if (res) {
313
- const newData = JSON.stringify(res);
314
- const result = getFilteredData(newData, category, limit, offset);
315
- const val = JSON.stringify(result);
316
- if (val) {
317
- console.log("internalGetInboxMessage " + val)
318
- callback(val);
319
- }
320
- }
321
- })
322
- }
323
- });
324
- } else {
325
- AppICE.getInboxMessages(type, userids, (res) => {
326
- if (res) {
327
- const newData = JSON.stringify(res);
328
- const result = getFilteredData(newData, category, limit, offset);
329
- const val = JSON.stringify(result);
330
- if (val) {
331
- console.log("internalGetInboxMessage " + val)
332
- callback(val);
333
- }
334
- }
335
- })
336
- }
337
- }
338
-
339
-
340
- /*
341
- * type = { All = 1, UNREAD = 2, READ = 3, VIEWED = 4, DELETED = 5 },
342
- * userids = list of the userid ie. ['userid1', 'userid2'],
343
- * timeout = to sync with server we are doing server call internally for that we will timeout time from app
344
- * return integer ie. 10 or 20
345
- *
346
- * NOTE : We will use it on bell icon
347
- */
348
- function getMessageCounts(type, userids, timeout, callback) {
349
- AppICE.synchronizeInbox(timeout, (res) => {
350
- if (res) {
351
- console.log("getMessageCounts inside the sync type = "+type+", userid = "+userids)
352
- AppICE.getMessageCount(2, userids, (res) => {
353
- if (res) {
354
- console.log("getMessageCounts inside the sync res = "+res)
355
- callback(res);
356
- }
357
- });
358
- } else {
359
- console.log("getMessageCounts outside the sync type = "+type+", userid = "+userids)
360
- console.log("inbox is not synced with server, showing old stored data")
361
- AppICE.getMessageCount(2, userids, (res) => {
362
- if (res) {
363
- callback(res);
364
- }
365
- });
366
- }
367
- })
368
- }
369
-
370
-
371
- /*
372
- * messageId = it will be string which you will extract from @getInboxMessageApi ie. 'messageid'
373
- * userids = this will be string as we are updating from one device so there will be single user who is updating, ie. 'userid'
374
- * return boolean ie. true or false
375
- *
376
- * NOTE : every time we have to call it when user will click on particular inbox item
377
- */
378
- function updatedInboxMessage(messageId, type, userid, callback) {
379
- AppICE.updateInboxMessage(messageId, type, userid, (res) => {
380
- callback(res);
381
- console.log("updateInboxMessage res : " + res)
382
- });
383
- }
384
-
385
-
386
-
387
- //==============================
388
- // internal logic
389
- //==============================
390
-
391
- function getFilteredData(newData, category, limit, offset) {
392
- const jsonArray = JSON.parse(newData);
393
- if (!jsonArray || !Array.isArray(jsonArray)) {
394
- console.error('Invalid jsonArray:', jsonArray);
395
- return null;
396
- }
397
-
398
- // Convert the provided category to lowercase for case-insensitive comparison
399
- const lowerCaseCategory = category.toLowerCase();
400
-
401
- // Count occurrences of each category with original case for the entire array
402
- const categoryCount = jsonArray.reduce((acc, item) => {
403
- const categoryName = item?.cdata?.category; // Added null checks
404
- if (categoryName) {
405
- acc[categoryName] = (acc[categoryName] || 0) + 1;
406
- }
407
- return acc;
408
- }, {});
409
-
410
- // Ensure that "chip A" and "chip B" are in the count array, even if they are not present in the filtered array
411
- ["Offers & Promotions", "Bank Communications"].forEach(chip => {
412
- if (!categoryCount[chip]) {
413
- categoryCount[chip] = 0;
414
- }
415
- });
416
-
417
- // Filter the array based on the provided category (case-insensitive)
418
- const filteredArray = jsonArray.filter(item => item?.cdata?.category?.toLowerCase() === lowerCaseCategory);
419
-
420
- // Apply limit and offset to the filtered array
421
- const slicedArray = filteredArray.slice(offset, offset + limit);
422
-
423
- // Prepare the result object without assigning new values
424
- const result = {
425
- count: Object.entries(categoryCount).map(([key, value]) => ({ [key]: value })),
426
- inboxData: slicedArray.map(item => ({
427
- cdata: item?.cdata,
428
- campId: item?.campId,
429
- campType: item?.campType,
430
- icon: item?.icon,
431
- id: item?.id,
432
- message: item?.message,
433
- messageExpiryTime: item?.messageExpiryTime,
434
- messageLanguage: item?.messageLanguage,
435
- messageStatus: item?.messageStatus,
436
- title: item?.title
437
- }))
438
- };
439
- console.log("filtered data " + JSON.stringify(result));
440
- return result;
441
- }
442
-
443
-
444
- // internal logic avoid multiple code
445
- function internalGetInboxMessage(type, userids, category, limit, offset, callback) {
446
- AppICE.getInboxMessages(type, userids, (res) => {
447
- if (res) {
448
- const newData = JSON.stringify(res);
449
- const result = getFilteredData(newData, category, limit, offset);
450
- const val = JSON.stringify(result);
451
- if (val) {
452
- console.log("internalGetInboxMessage " + val)
453
- callback(val);
454
- }
455
- }
456
- })
457
- }
458
-
459
- // show Alert
460
- function showAlert(title, message) {
461
- Alert.alert(
462
- title,
463
- message,
464
- [
465
- { text: 'Ask me later', onPress: () => console.log('Ask me later pressed') },
466
- {
467
- text: 'Cancel',
468
- onPress: () => console.log('Cancel Pressed'),
469
- style: 'cancel',
470
- },
471
- { text: 'OK', onPress: () => console.log('OK Pressed') },
472
- ],
473
- { cancelable: false }
474
- )
475
- }
476
-
477
- const mapStateToProps = (state) => ({
478
- // Map relevant state properties here if needed
479
- });
480
-
481
- export default connect(mapStateToProps, { addEvent, flushEvents })(HelloWorldApp);
482
-
483
- // export default HelloWorldApp;