reactnative-plugin-appice 1.7.14 → 1.7.16

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 (105) hide show
  1. package/README.md +37 -37
  2. package/android/README.md +14 -14
  3. package/android/build.gradle +153 -151
  4. package/android/gitignore +47 -47
  5. package/android/gradle/wrapper/gradle-wrapper.properties +5 -5
  6. package/android/gradlew +234 -234
  7. package/android/local.properties +8 -8
  8. package/android/src/main/AndroidManifest.xml +153 -153
  9. package/android/src/main/java/com/reactlibrary/AppICEUtils.java +241 -241
  10. package/android/src/main/java/com/reactlibrary/AppIceReactPluginModule.java +748 -748
  11. package/android/src/main/java/com/reactlibrary/AppIceReactPluginPackage.java +28 -28
  12. package/android/src/main/java/com/reactlibrary/CampaignCampsReceiver.java +56 -56
  13. package/android/src/main/java/com/reactlibrary/EnumConstants.java +256 -256
  14. package/android/src/main/java/com/reactlibrary/NotificationEventService.java +59 -59
  15. package/android/src/main/java/com/reactlibrary/StringConstants.java +9 -9
  16. package/example/App.js +292 -292
  17. package/example/Gemfile +6 -6
  18. package/example/__tests__/App-test.js +14 -14
  19. package/example/ancilliary.js +484 -474
  20. package/example/android/app/_BUCK +55 -55
  21. package/example/android/app/build.gradle +320 -320
  22. package/example/android/app/build_defs.bzl +19 -19
  23. package/example/android/app/proguard-rules.pro +10 -10
  24. package/example/android/app/src/debug/AndroidManifest.xml +13 -13
  25. package/example/android/app/src/debug/java/com/example/ReactNativeFlipper.java +73 -73
  26. package/example/android/app/src/main/AndroidManifest.xml +72 -72
  27. package/example/android/app/src/main/java/com/example/MainActivity.java +48 -48
  28. package/example/android/app/src/main/java/com/example/MainApplication.java +91 -91
  29. package/example/android/app/src/main/java/com/example/newarchitecture/MainApplicationReactNativeHost.java +116 -116
  30. package/example/android/app/src/main/java/com/example/newarchitecture/components/MainComponentsRegistry.java +36 -36
  31. package/example/android/app/src/main/java/com/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java +48 -48
  32. package/example/android/app/src/main/jni/Android.mk +48 -48
  33. package/example/android/app/src/main/jni/MainApplicationModuleProvider.cpp +24 -24
  34. package/example/android/app/src/main/jni/MainApplicationModuleProvider.h +16 -16
  35. package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp +45 -45
  36. package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h +38 -38
  37. package/example/android/app/src/main/jni/MainComponentsRegistry.cpp +61 -61
  38. package/example/android/app/src/main/jni/MainComponentsRegistry.h +32 -32
  39. package/example/android/app/src/main/jni/OnLoad.cpp +11 -11
  40. package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -36
  41. package/example/android/app/src/main/res/values/strings.xml +3 -3
  42. package/example/android/app/src/main/res/values/styles.xml +9 -9
  43. package/example/android/build.gradle +73 -73
  44. package/example/android/gradle/wrapper/gradle-wrapper.properties +5 -5
  45. package/example/android/gradle.properties +40 -40
  46. package/example/android/gradlew +234 -234
  47. package/example/android/local.properties +8 -0
  48. package/example/android/settings.gradle +11 -11
  49. package/example/app.json +3 -3
  50. package/example/babel.config.js +3 -3
  51. package/example/index.js +9 -9
  52. package/example/ios/Podfile +44 -44
  53. package/example/ios/Podfile.lock +561 -561
  54. package/example/ios/_xcode.env +11 -11
  55. package/example/ios/example/AppDelegate.h +8 -8
  56. package/example/ios/example/AppDelegate.mm +174 -174
  57. package/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json +53 -53
  58. package/example/ios/example/Images.xcassets/Contents.json +6 -6
  59. package/example/ios/example/Info.plist +62 -62
  60. package/example/ios/example/LaunchScreen.storyboard +47 -47
  61. package/example/ios/example/example.entitlements +8 -8
  62. package/example/ios/example/main.m +10 -10
  63. package/example/ios/example.xcodeproj/project.pbxproj +712 -712
  64. package/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme +88 -88
  65. package/example/ios/example.xcworkspace/contents.xcworkspacedata +10 -10
  66. package/example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  67. package/example/ios/exampleTests/Info.plist +24 -24
  68. package/example/ios/exampleTests/exampleTests.m +66 -66
  69. package/example/metro.config.js +17 -17
  70. package/example/package.json +36 -36
  71. package/example/yarn.lock +7713 -7176
  72. package/index.js +520 -485
  73. package/ios/AppICEReactEvent.h +23 -23
  74. package/ios/AppICEReactEvent.m +86 -86
  75. package/ios/AppIceReactPlugin.h +59 -59
  76. package/ios/AppIceReactPlugin.m +641 -641
  77. package/ios/AppIceReactPlugin.xcodeproj/project.pbxproj +364 -364
  78. package/ios/AppIceReactPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -4
  79. package/ios/AppIceReactPlugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  80. package/ios/AppIceReactPlugin.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  81. package/ios/AppIceReactPlugin.xcodeproj/xcuserdata/artherajesh.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  82. package/ios/AppIceReactPlugin.xcworkspace/contents.xcworkspacedata +10 -10
  83. package/ios/AppIceReactPlugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  84. package/ios/Podfile +10 -10
  85. package/ios/Podfile.lock +3 -3
  86. package/ios/Pods/Manifest.lock +3 -3
  87. package/ios/Pods/Pods.xcodeproj/project.pbxproj +395 -395
  88. package/ios/Pods/Pods.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/Pods-AppIceReactPlugin.xcscheme +58 -58
  89. package/ios/Pods/Pods.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/xcschememanagement.plist +18 -18
  90. package/ios/Pods/Pods.xcodeproj/xcuserdata/artherajesh.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  91. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-Info.plist +26 -26
  92. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-acknowledgements.markdown +3 -3
  93. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-acknowledgements.plist +29 -29
  94. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-dummy.m +5 -5
  95. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-umbrella.h +16 -16
  96. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.debug.xcconfig +6 -6
  97. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.modulemap +6 -6
  98. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.release.xcconfig +6 -6
  99. package/package.json +41 -41
  100. package/reactnative-plugin-appice.podspec +30 -30
  101. package/example/android/.gradle/7.3.3/checksums/checksums.lock +0 -0
  102. package/example/android/.gradle/7.3.3/fileChanges/last-build.bin +0 -0
  103. package/example/android/.gradle/7.3.3/fileHashes/fileHashes.lock +0 -0
  104. package/example/android/.gradle/vcs-1/gc.properties +0 -0
  105. /package/{example/android/.gradle/7.3.3/gc.properties → android/src/main/test} +0 -0
package/index.js CHANGED
@@ -1,485 +1,520 @@
1
- import { DeviceEventEmitter, NativeEventEmitter, NativeModules } from 'react-native';
2
- import { Platform, Component } from 'react-native';
3
- import { MMKV } from 'react-native-mmkv'
4
-
5
-
6
-
7
- const AppIceReactPlugin = NativeModules.AppIceReactPlugin;
8
- var eventEmitter;
9
- if (Platform.OS === 'ios') {
10
- eventEmitter = NativeModules.AppICEReactEvent ? new NativeEventEmitter(NativeModules.AppICEReactEvent) : DeviceEventEmitter;
11
- }
12
- else {
13
- eventEmitter = new NativeEventEmitter(NativeModules.AppIceReactPlugin);
14
- }
15
-
16
- export const appStorage = new MMKV({
17
- id: 'AppICE-storage',
18
- })
19
-
20
- const EVENT_KEY = "lastEvent"
21
- const LAST_EVENT_KEY = "event_"
22
-
23
-
24
- var AppICEReact = {
25
-
26
- validateIntegration: AppIceReactPlugin.validateIntegration,
27
-
28
- //========================
29
- // PUSH
30
- //========================
31
- AppICEPushNotificationClicked: AppIceReactPlugin.AppICEPushNotificationClicked,
32
-
33
- //==========================
34
- // IN-APP
35
- //==========================
36
- AppICEInAppClicked: AppIceReactPlugin.AppICEInAppClicked,
37
-
38
- //========================
39
- // APP-INBOX
40
- //========================
41
- INBOX_MESSAGE: AppIceReactPlugin.INBOX_MESSAGE,
42
- INBOX_TITLE: AppIceReactPlugin.INBOX_TITLE,
43
- INBOX_MESSAGE_STATUS: AppIceReactPlugin.INBOX_MESSAGE_STATUS,
44
- INBOX_CAMPAIGN_TYPE: AppIceReactPlugin.INBOX_CAMPAIGN_TYPE,
45
- INBOX_MESSAGE_LANGUAGE: AppIceReactPlugin.INBOX_MESSAGE_LANGUAGE,
46
- INBOX_MESSAGE_ID: AppIceReactPlugin.INBOX_MESSAGE_ID,
47
- INBOX_CAMPAIGN_ID: AppIceReactPlugin.INBOX_CAMPAIGN_ID,
48
- INBOX_MESSAGE_ICON: AppIceReactPlugin.INBOX_MESSAGE_ICON,
49
- INBOX_CUSTOM_DATA: AppIceReactPlugin.INBOX_CUSTOM_DATA,
50
- INBOX_MESSAGE_EXPANDED_IMAGE: AppIceReactPlugin.INBOX_MESSAGE_EXPANDED_IMAGE,
51
-
52
-
53
- //=======================
54
- // USER-PROFILE SETTING
55
- //=======================
56
- name: AppIceReactPlugin.APPICE_USER_NAME,
57
- email: AppIceReactPlugin.APPICE_USER_EMAIL,
58
- phone: AppIceReactPlugin.APPICE_USER_PHONE,
59
- age: AppIceReactPlugin.APPICE_USER_AGE,
60
- gender: AppIceReactPlugin.APPICE_USER_GENDER,
61
- educationType: AppIceReactPlugin.APPICE_USER_EDUCATION_TYPE,
62
- employmentType: AppIceReactPlugin.APPICE_USER_EMPLOYMENT_TYPE,
63
- married: AppIceReactPlugin.APPICE_USER_MARRIED,
64
- isEmployed: AppIceReactPlugin.APPICE_USER_IS_EMPLOYED,
65
- dob: AppIceReactPlugin.APPICE_DATE_OF_BIRTH,
66
-
67
-
68
- TOP_N_PRODUCTS_VIEWED: AppIceReactPlugin.TOP_N_PRODUCTS_VIEWED,
69
- N_COMPLAINTS_RAISED: AppIceReactPlugin.N_COMPLAINTS_RAISED,
70
- PREF_LOGIN_DEVICE: AppIceReactPlugin.PREF_LOGIN_DEVICE,
71
- REFERRAL_CAMPAIGN: AppIceReactPlugin.REFERRAL_CAMPAIGN,
72
- FIRST_SEEN: AppIceReactPlugin.FIRST_SEEN,
73
- LAST_SEEN: AppIceReactPlugin.LAST_SEEN,
74
- DEMOGRAPHIC_INFO: AppIceReactPlugin.DEMOGRAPHIC_INFO,
75
-
76
- //================
77
- // ECOMMERCE
78
- //================
79
- TOTAL_ORDER_VALUE: AppIceReactPlugin.TOTAL_ORDER_VALUE,
80
- ADD_TO_CART_N_DAYS: AppIceReactPlugin.ADD_TO_CART_N_DAYS,
81
-
82
- //====================
83
- // FinancialServices
84
- //====================
85
- FINANCIAL_SERVICES: AppIceReactPlugin.FINANCIAL_SERVICES,
86
- CREDIT_SCORE: AppIceReactPlugin.CREDIT_SCORE,
87
- DEBT_TO_INCOME_RATIO: AppIceReactPlugin.DEBT_TO_INCOME_RATIO,
88
- SAVINGS_BALANCE: AppIceReactPlugin.SAVINGS_BALANCE,
89
- CHECKING_BALANCE: AppIceReactPlugin.CHECKING_BALANCE,
90
- AVERAGE_TRANSACTION_AMOUNT: AppIceReactPlugin.AVERAGE_TRANSACTION_AMOUNT,
91
- FREQUENCY_OF_TRANSACTION: AppIceReactPlugin.FREQUENCY_OF_TRANSACTION,
92
- TYPE_OF_TRANSACTION: AppIceReactPlugin.TYPE_OF_TRANSACTION,
93
-
94
- //======================
95
- // LISTENER
96
- //======================
97
- /**
98
- * add all of the registered listeners for given eventName.
99
- *
100
- * @param {string} eventName - name of the event whose registered listeners to remove
101
- * @param {callback} handler - handler for events
102
- */
103
- addListener: function (eventName, handler) {
104
- if (eventEmitter) {
105
- eventEmitter.addListener(eventName, handler);
106
- }
107
- },
108
-
109
- /**
110
- * Removes all of the registered listeners for given eventName.
111
- *
112
- * @param {string} eventName - name of the event whose registered listeners to remove
113
- */
114
- removeListener: function (eventName) {
115
- if (eventEmitter) {
116
- eventEmitter.removeAllListeners(eventName);
117
- }
118
- },
119
-
120
-
121
- //=========================
122
- // SDK CONFIG
123
- //========================
124
-
125
- /**
126
- * call this function before clearing old data from db/keychain
127
- */
128
- preInitialise: function () {
129
- this.getDeviceId((res) => {
130
- if (res) {
131
- this.setInternalId(res);
132
- }
133
- });
134
- },
135
-
136
- /**
137
- * Meta data of the apps that is needed for sdk setting
138
- * @param {string} appID - meta key
139
- * @param {string} appKey - meta key
140
- * @param {string} apiKey - meta key
141
- * @param {string} deviceID - unique value to idetify the data from panel
142
- * @param {string} region - e.i. US/GCC/IND
143
- * @param {string} baseUrl -
144
- * @param {object} certs - arrays of certificate paths
145
- * startContext executes after getDeviceId callback
146
- * if res exist assign the value of res else assign deviceID
147
- */
148
- startContext: function (appID, appKey, apiKey, deviceID, region, baseUrl, certs) {
149
- this.getDeviceId((res) => {
150
- if (res) {
151
- AppIceReactPlugin.startContext(appID, appKey, apiKey, res, region, baseUrl, certs)
152
- } else {
153
- AppIceReactPlugin.startContext(appID, appKey, apiKey, deviceID, region, baseUrl, certs)
154
- }
155
- });
156
- },
157
-
158
- /**
159
- * call this function to register the lifeCycle state of the app
160
- */
161
- registerLifeCycle: function () {
162
- AppIceReactPlugin.registerLifeCycle();
163
- },
164
-
165
- //===========================
166
- // EVENTS AND VARIABLES
167
- //===========================
168
- /**
169
- * Record an event with optional event properties
170
- * @param {string} eventName - the name of the event
171
- * @param {object} props - the key-value properties of the event.
172
- * @param {boolean} flush - to use caching feature.
173
- * keys are strings and values can be string, number or boolean.
174
- */
175
- tagEvent: async function (eventName, props, flush) {
176
- console.log("tagEvent : eventName " + eventName + ", prop " + props + ", flush " + flush);
177
-
178
- if (flush == undefined) {
179
- await AppIceReactPlugin.tagEvent(eventName, props);
180
- } else {
181
- lastEventData = appStorage.getString(LAST_EVENT_KEY)
182
- if (lastEventData != undefined && lastEventData !== eventName) {
183
- try {
184
- const storedEvents = appStorage.getString(EVENT_KEY + lastEventData);
185
- console.log("tagEvent : storedEvents " + storedEvents);
186
-
187
- if (storedEvents != null && storedEvents.length > 0) {
188
- let events = storedEvents ? JSON.parse(storedEvents) : [];
189
-
190
- const lastPropsData = events.reduce((acc, event) => {
191
- return { ...acc, ...event.props };
192
- }, {});
193
-
194
- await AppIceReactPlugin.tagEvent(lastEventData, lastPropsData);
195
- appStorage.delete(EVENT_KEY + lastEventData);
196
- appStorage.delete(LAST_EVENT_KEY);
197
- }
198
- } catch (error) {
199
- console.error('Failed to flush events:', error);
200
- }
201
-
202
- await handleStoredEvents(eventName, props);
203
- } else {
204
- if (flush) {
205
- await handleFlushEvent(eventName, props);
206
- } else {
207
- await handleStoredEvents(eventName, props);
208
- }
209
- }
210
- }
211
- },
212
-
213
-
214
- /**
215
- * to store custom varibles like fcm token..
216
- * @param {string} eventName - the name of the event
217
- * @param {string} props - the name of the event
218
- */
219
- setCustomVariable: function (eventName, props) {
220
- AppIceReactPlugin.setCustomVariable(eventName, props);
221
- },
222
-
223
-
224
- //===========================
225
- // CAMPAIGN SETTING
226
- //===========================
227
- /**
228
- * Record an click event
229
- * @param {string} eventName - the name of the event
230
- */
231
- pushNotificationClicked: function (payload) {
232
- AppIceReactPlugin.pushNotificationClicked(payload);
233
- },
234
-
235
- getCustomDataFromPayload: function (object) {
236
- let userObj = JSON.parse(object, (key, value) => {
237
- return value;
238
- });
239
-
240
- let map = new Map(Object.entries(userObj.cdata));
241
-
242
- return map;
243
- },
244
-
245
- //=======================
246
- // USER-PROFILE SETTING
247
- //=======================
248
- /**
249
- * Set key-value properties on a user profile
250
- * @param {object} profile - key-value profile properties. keys are strings and values can be string, number or boolean.
251
- */
252
- setUser: function (profile) {
253
- AppIceReactPlugin.setUser(profile);
254
- },
255
-
256
- /**
257
- * get the properties of a user profile
258
- * return JSONObject
259
- */
260
- getUser: function (callback) {
261
- callWithCallback('getUser', null, callback);
262
- },
263
-
264
- //===============================================
265
- // User id setting
266
- //===============================================
267
-
268
- /**
269
- * Set unique user id
270
- * @param {object} values - array of userids
271
- */
272
- setUserId: function (values) {
273
- AppIceReactPlugin.setUserId(values);
274
- },
275
-
276
- /**
277
- * Getuser id
278
- * @param {object} values - array of userids
279
- */
280
- getUserId: function (callback) {
281
- callWithCallback('getUserId', null, callback);
282
- },
283
-
284
- //===============================================
285
- // Device id setting
286
- //===============================================
287
-
288
- getDeviceId: function (callback) {
289
- callWithCallback('getDeviceId', null, callback)
290
- },
291
-
292
- setInternalId: function (deviceId) {
293
- AppIceReactPlugin.setInternalId(deviceId);
294
- },
295
-
296
- //===============================================
297
- // AppInbox
298
- //===============================================
299
-
300
- /**
301
- * Get inbox messages list.
302
- *
303
- * @param type the message type
304
- * 1 = ALL
305
- * 2 = UNREAD
306
- * 3 = READ
307
- * 4 = VIEWED
308
- * 5 = DELETED
309
- * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
310
- * @callback will have the string json array
311
- */
312
- getInboxMessages: function (type, userIds, callback) {
313
- callWithCallback('getInboxMessages', [type, userIds], callback);
314
- },
315
-
316
-
317
- /**
318
- * Get inbox messages count.
319
- *
320
- * @param type the message type is integer
321
- * 1 = ALL
322
- * 2 = UNREAD
323
- * 3 = READ
324
- * 4 = VIEWED
325
- * 5 = DELETED
326
- * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
327
- * @callback will have the integer
328
- */
329
- getMessageCount: function (type, userIds, callback) {
330
- callWithCallback('getMessageCount', [type, userIds], callback);
331
- },
332
-
333
- /**
334
- * Get messages payload based on message id.
335
- *
336
- * @param messageId - message id of the notification
337
- * @param userId - single userid in string ie. "useridA"
338
- * @callback will have the json object
339
- */
340
- getInboxMessageForId: function (messageId, userId, callback) {
341
- callWithCallback('getInboxMessageForId', [messageId, userId], callback);
342
- },
343
-
344
- /**
345
- * update message status ex. UNREAD to READ.
346
- *
347
- * @param messageId - message id of the notification
348
- * @param type - integer value for status
349
- * @param userId - single userid in string
350
- * @callback will have the boolean
351
- */
352
- updateInboxMessage: function (messageId, type, userId, callback) {
353
- callWithCallback('updateInboxMessage', [messageId, type, userId], callback);
354
- },
355
-
356
- synchronizeInbox: function (timeout, callback) {
357
- callWithCallback('synchronizeInbox', [timeout], callback)
358
- },
359
-
360
- //===============================================
361
- // Rich Push AppInbox
362
- //===============================================
363
-
364
- /**
365
- * getMediaData
366
- * @param instanceInboxMessage - instance Dictionary
367
- * @param values - NSString
368
- * @callback will have the Dictionary
369
- */
370
-
371
- getMediaData: function (instanceInboxMessage, mediaKey, callback) {
372
- callWithCallback('getMediaData', [instanceInboxMessage, mediaKey], callback);
373
- },
374
-
375
- /**
376
- * getMediaUrl
377
- * @param instanceInboxMessage - instance Dictionary
378
- * @param values - Dictionary
379
- * @callback will have the string
380
- */
381
- getMediaUrl: function (instanceInboxMessage, values, callback) {
382
- callWithCallback('getMediaUrl', [instanceInboxMessage, values], callback);
383
- },
384
-
385
- /**
386
- * getMediaType
387
- * @param instanceInboxMessage - instance Dictionary
388
- * @param values - Dictionary
389
- * @callback will have the string
390
- */
391
- getMediaType: function (instanceInboxMessage, values, callback) {
392
- callWithCallback('getMediaType', [instanceInboxMessage, values], callback);
393
- },
394
-
395
- /**
396
- * getMediaThumbnail
397
- * @param instanceInboxMessage - instance Dictionary
398
- * @param values - Dictionary
399
- * @callback will have the string
400
- */
401
-
402
- getMediaThumbnail: function (instanceInboxMessage, values, callback) {
403
- callWithCallback('getMediaThumbnail', [instanceInboxMessage, values], callback);
404
- },
405
-
406
- /*==================
407
- isDeviceReady
408
- =====================*/
409
- isDeviceReady: function (isActive) {
410
- AppIceReactPlugin.isDeviceReady(isActive);
411
- },
412
-
413
- /*===============
414
- synchronizeData
415
- ================*/
416
- synchronizeData: function (timeout, callback) {
417
- callWithCallback('synchronizeData', [timeout], callback)
418
- },
419
-
420
- /*===================
421
- getUserForIds with userIds
422
- =====================*/
423
-
424
- getUserForIds: function (userIds, callback) {
425
- callWithCallback('getUserForIds', [userIds], callback);
426
- },
427
- };
428
-
429
-
430
- //================================
431
- // INTERNAL COMMON APIS
432
- //=================================
433
-
434
- // internal function for callback
435
- function callWithCallback(method, args, callback) {
436
- if (typeof callback === 'undefined' || callback == null || typeof callback !== 'function') {
437
- callback = (err, res) => {
438
- defaultCallback(method, err, res);
439
- };
440
- }
441
-
442
- if (args == null) {
443
- args = [];
444
- }
445
-
446
- args.push(callback);
447
-
448
- AppIceReactPlugin[method].apply(this, args);
449
- }
450
-
451
- const handleStoredEvents = async (eventName, props) => {
452
- try {
453
- const storedEvents = appStorage.getString(EVENT_KEY + eventName);
454
- let events = storedEvents ? JSON.parse(storedEvents) : [];
455
-
456
- // Add the current event
457
- events.push({ eventName, props });
458
-
459
- // Save the updated events list
460
- appStorage.set(EVENT_KEY + eventName, JSON.stringify(events));
461
- appStorage.set(LAST_EVENT_KEY, eventName);
462
- } catch (error) {
463
- console.error('Failed to store event:', error);
464
- }
465
- };
466
-
467
- const handleFlushEvent = async (eventName, props) => {
468
- try {
469
- const storedEvents = appStorage.getString(EVENT_KEY + eventName);
470
- let events = storedEvents ? JSON.parse(storedEvents) : [];
471
-
472
- events.forEach(event => {
473
- Object.assign(props, event.props);
474
- });
475
-
476
- await AppIceReactPlugin.tagEvent(eventName, props);
477
-
478
- appStorage.delete(EVENT_KEY + eventName);
479
- appStorage.delete(LAST_EVENT_KEY);
480
- } catch (error) {
481
- console.error('Failed to flush events:', error);
482
- }
483
- };
484
-
485
- module.exports = AppICEReact;
1
+ import { DeviceEventEmitter, NativeEventEmitter, NativeModules } from 'react-native';
2
+ import { Platform, Component } from 'react-native';
3
+ // import { MMKV } from 'react-native-mmkv'
4
+ import AsyncStorage from '@react-native-async-storage/async-storage';
5
+
6
+ const AppIceReactPlugin = NativeModules.AppIceReactPlugin;
7
+ var eventEmitter;
8
+ if (Platform.OS === 'ios') {
9
+ eventEmitter = NativeModules.AppICEReactEvent ? new NativeEventEmitter(NativeModules.AppICEReactEvent) : DeviceEventEmitter;
10
+ }
11
+ else {
12
+ eventEmitter = new NativeEventEmitter(NativeModules.AppIceReactPlugin);
13
+ }
14
+
15
+ // export const appStorage = new MMKV({
16
+ // id: 'AppICE-storage',
17
+ // })
18
+
19
+ const EVENT_KEY = "lastEvent"
20
+ const LAST_EVENT_KEY = "event_"
21
+
22
+
23
+ var AppICEReact = {
24
+
25
+ validateIntegration: AppIceReactPlugin.validateIntegration,
26
+
27
+ //========================
28
+ // PUSH
29
+ //========================
30
+ AppICEPushNotificationClicked: AppIceReactPlugin.AppICEPushNotificationClicked,
31
+
32
+ //==========================
33
+ // IN-APP
34
+ //==========================
35
+ AppICEInAppClicked: AppIceReactPlugin.AppICEInAppClicked,
36
+
37
+ //========================
38
+ // APP-INBOX
39
+ //========================
40
+ INBOX_MESSAGE: AppIceReactPlugin.INBOX_MESSAGE,
41
+ INBOX_TITLE: AppIceReactPlugin.INBOX_TITLE,
42
+ INBOX_MESSAGE_STATUS: AppIceReactPlugin.INBOX_MESSAGE_STATUS,
43
+ INBOX_CAMPAIGN_TYPE: AppIceReactPlugin.INBOX_CAMPAIGN_TYPE,
44
+ INBOX_MESSAGE_LANGUAGE: AppIceReactPlugin.INBOX_MESSAGE_LANGUAGE,
45
+ INBOX_MESSAGE_ID: AppIceReactPlugin.INBOX_MESSAGE_ID,
46
+ INBOX_CAMPAIGN_ID: AppIceReactPlugin.INBOX_CAMPAIGN_ID,
47
+ INBOX_MESSAGE_ICON: AppIceReactPlugin.INBOX_MESSAGE_ICON,
48
+ INBOX_CUSTOM_DATA: AppIceReactPlugin.INBOX_CUSTOM_DATA,
49
+ INBOX_MESSAGE_EXPANDED_IMAGE: AppIceReactPlugin.INBOX_MESSAGE_EXPANDED_IMAGE,
50
+
51
+
52
+ //=======================
53
+ // USER-PROFILE SETTING
54
+ //=======================
55
+ name: AppIceReactPlugin.APPICE_USER_NAME,
56
+ email: AppIceReactPlugin.APPICE_USER_EMAIL,
57
+ phone: AppIceReactPlugin.APPICE_USER_PHONE,
58
+ age: AppIceReactPlugin.APPICE_USER_AGE,
59
+ gender: AppIceReactPlugin.APPICE_USER_GENDER,
60
+ educationType: AppIceReactPlugin.APPICE_USER_EDUCATION_TYPE,
61
+ employmentType: AppIceReactPlugin.APPICE_USER_EMPLOYMENT_TYPE,
62
+ married: AppIceReactPlugin.APPICE_USER_MARRIED,
63
+ isEmployed: AppIceReactPlugin.APPICE_USER_IS_EMPLOYED,
64
+ dob: AppIceReactPlugin.APPICE_DATE_OF_BIRTH,
65
+
66
+
67
+ TOP_N_PRODUCTS_VIEWED: AppIceReactPlugin.TOP_N_PRODUCTS_VIEWED,
68
+ N_COMPLAINTS_RAISED: AppIceReactPlugin.N_COMPLAINTS_RAISED,
69
+ PREF_LOGIN_DEVICE: AppIceReactPlugin.PREF_LOGIN_DEVICE,
70
+ REFERRAL_CAMPAIGN: AppIceReactPlugin.REFERRAL_CAMPAIGN,
71
+ FIRST_SEEN: AppIceReactPlugin.FIRST_SEEN,
72
+ LAST_SEEN: AppIceReactPlugin.LAST_SEEN,
73
+ DEMOGRAPHIC_INFO: AppIceReactPlugin.DEMOGRAPHIC_INFO,
74
+
75
+ //================
76
+ // ECOMMERCE
77
+ //================
78
+ TOTAL_ORDER_VALUE: AppIceReactPlugin.TOTAL_ORDER_VALUE,
79
+ ADD_TO_CART_N_DAYS: AppIceReactPlugin.ADD_TO_CART_N_DAYS,
80
+
81
+ //====================
82
+ // FinancialServices
83
+ //====================
84
+ FINANCIAL_SERVICES: AppIceReactPlugin.FINANCIAL_SERVICES,
85
+ CREDIT_SCORE: AppIceReactPlugin.CREDIT_SCORE,
86
+ DEBT_TO_INCOME_RATIO: AppIceReactPlugin.DEBT_TO_INCOME_RATIO,
87
+ SAVINGS_BALANCE: AppIceReactPlugin.SAVINGS_BALANCE,
88
+ CHECKING_BALANCE: AppIceReactPlugin.CHECKING_BALANCE,
89
+ AVERAGE_TRANSACTION_AMOUNT: AppIceReactPlugin.AVERAGE_TRANSACTION_AMOUNT,
90
+ FREQUENCY_OF_TRANSACTION: AppIceReactPlugin.FREQUENCY_OF_TRANSACTION,
91
+ TYPE_OF_TRANSACTION: AppIceReactPlugin.TYPE_OF_TRANSACTION,
92
+
93
+ //======================
94
+ // LISTENER
95
+ //======================
96
+ /**
97
+ * add all of the registered listeners for given eventName.
98
+ *
99
+ * @param {string} eventName - name of the event whose registered listeners to remove
100
+ * @param {callback} handler - handler for events
101
+ */
102
+ addListener: function (eventName, handler) {
103
+ if (eventEmitter) {
104
+ eventEmitter.addListener(eventName, handler);
105
+ }
106
+ },
107
+
108
+ /**
109
+ * Removes all of the registered listeners for given eventName.
110
+ *
111
+ * @param {string} eventName - name of the event whose registered listeners to remove
112
+ */
113
+ removeListener: function (eventName) {
114
+ if (eventEmitter) {
115
+ eventEmitter.removeAllListeners(eventName);
116
+ }
117
+ },
118
+
119
+
120
+ //=========================
121
+ // SDK CONFIG
122
+ //========================
123
+
124
+ /**
125
+ * call this function before clearing old data from db/keychain
126
+ */
127
+ preInitialise: function () {
128
+ this.getDeviceId((res) => {
129
+ if (res) {
130
+ this.setInternalId(res);
131
+ }
132
+ });
133
+ },
134
+
135
+ /**
136
+ * Meta data of the apps that is needed for sdk setting
137
+ * @param {string} appID - meta key
138
+ * @param {string} appKey - meta key
139
+ * @param {string} apiKey - meta key
140
+ * @param {string} deviceID - unique value to idetify the data from panel
141
+ * @param {string} region - e.i. US/GCC/IND
142
+ * @param {string} baseUrl -
143
+ * @param {object} certs - arrays of certificate paths
144
+ * startContext executes after getDeviceId callback
145
+ * if res exist assign the value of res else assign deviceID
146
+ */
147
+ startContext: function (appID, appKey, apiKey, deviceID, region, baseUrl, certs) {
148
+ this.getDeviceId((res) => {
149
+ if (res) {
150
+ AppIceReactPlugin.startContext(appID, appKey, apiKey, res, region, baseUrl, certs)
151
+ } else {
152
+ AppIceReactPlugin.startContext(appID, appKey, apiKey, deviceID, region, baseUrl, certs)
153
+ }
154
+ });
155
+ },
156
+
157
+ /**
158
+ * call this function to register the lifeCycle state of the app
159
+ */
160
+ registerLifeCycle: function () {
161
+ AppIceReactPlugin.registerLifeCycle();
162
+ },
163
+
164
+ //===========================
165
+ // EVENTS AND VARIABLES
166
+ //===========================
167
+ /**
168
+ * Record an event with optional event properties
169
+ * @param {string} eventName - the name of the event
170
+ * @param {object} props - the key-value properties of the event.
171
+ * @param {boolean} flush - to use caching feature.
172
+ * keys are strings and values can be string, number or boolean.
173
+ */
174
+ tagEvent: async function (eventName, props, flush) {
175
+ console.log("tagEvent : eventName " + eventName + ", prop " + props + ", flush " + flush);
176
+
177
+ if (flush == undefined || flush == null) {
178
+ await AppIceReactPlugin.tagEvent(eventName, props);
179
+ } else {
180
+ const lastEventData = await getEventData(LAST_EVENT_KEY)
181
+
182
+
183
+ if (lastEventData != undefined && lastEventData !== eventName) {
184
+ try {
185
+ const storedEvents = await getEventData(EVENT_KEY + lastEventData)
186
+
187
+ console.log("tagEvent : storedEvents " + storedEvents);
188
+
189
+ if (storedEvents != null && storedEvents.length > 0) {
190
+ let events = storedEvents ? JSON.parse(storedEvents) : [];
191
+
192
+ const lastPropsData = events.reduce((acc, event) => {
193
+ return { ...acc, ...event.props };
194
+ }, {});
195
+
196
+ await AppIceReactPlugin.tagEvent(lastEventData, lastPropsData);
197
+
198
+ await deleteData(EVENT_KEY + lastEventData)
199
+ await deleteData(LAST_EVENT_KEY)
200
+
201
+ }
202
+ } catch (error) {
203
+ console.error('Failed to flush events:', error);
204
+ }
205
+
206
+ await handleStoredEvents(eventName, props);
207
+ } else {
208
+ if (flush) {
209
+ await handleFlushEvent(eventName, props);
210
+ } else {
211
+ await handleStoredEvents(eventName, props);
212
+ }
213
+ }
214
+ }
215
+ },
216
+
217
+
218
+ /**
219
+ * to store custom varibles like fcm token..
220
+ * @param {string} eventName - the name of the event
221
+ * @param {string} props - the name of the event
222
+ */
223
+ setCustomVariable: function (eventName, props) {
224
+ AppIceReactPlugin.setCustomVariable(eventName, props);
225
+ },
226
+
227
+
228
+ //===========================
229
+ // CAMPAIGN SETTING
230
+ //===========================
231
+ /**
232
+ * Record an click event
233
+ * @param {string} eventName - the name of the event
234
+ */
235
+ pushNotificationClicked: function (payload) {
236
+ AppIceReactPlugin.pushNotificationClicked(payload);
237
+ },
238
+
239
+ getCustomDataFromPayload: function (object) {
240
+ let userObj = JSON.parse(object, (key, value) => {
241
+ return value;
242
+ });
243
+
244
+ let map = new Map(Object.entries(userObj.cdata));
245
+
246
+ return map;
247
+ },
248
+
249
+ //=======================
250
+ // USER-PROFILE SETTING
251
+ //=======================
252
+ /**
253
+ * Set key-value properties on a user profile
254
+ * @param {object} profile - key-value profile properties. keys are strings and values can be string, number or boolean.
255
+ */
256
+ setUser: function (profile) {
257
+ AppIceReactPlugin.setUser(profile);
258
+ },
259
+
260
+ /**
261
+ * get the properties of a user profile
262
+ * return JSONObject
263
+ */
264
+ getUser: function (callback) {
265
+ callWithCallback('getUser', null, callback);
266
+ },
267
+
268
+ //===============================================
269
+ // User id setting
270
+ //===============================================
271
+
272
+ /**
273
+ * Set unique user id
274
+ * @param {object} values - array of userids
275
+ */
276
+ setUserId: function (values) {
277
+ AppIceReactPlugin.setUserId(values);
278
+ },
279
+
280
+ /**
281
+ * Getuser id
282
+ * @param {object} values - array of userids
283
+ */
284
+ getUserId: function (callback) {
285
+ callWithCallback('getUserId', null, callback);
286
+ },
287
+
288
+ //===============================================
289
+ // Device id setting
290
+ //===============================================
291
+
292
+ getDeviceId: function (callback) {
293
+ callWithCallback('getDeviceId', null, callback)
294
+ },
295
+
296
+ setInternalId: function (deviceId) {
297
+ AppIceReactPlugin.setInternalId(deviceId);
298
+ },
299
+
300
+ //===============================================
301
+ // AppInbox
302
+ //===============================================
303
+
304
+ /**
305
+ * Get inbox messages list.
306
+ *
307
+ * @param type the message type
308
+ * 1 = ALL
309
+ * 2 = UNREAD
310
+ * 3 = READ
311
+ * 4 = VIEWED
312
+ * 5 = DELETED
313
+ * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
314
+ * @callback will have the string json array
315
+ */
316
+ getInboxMessages: function (type, userIds, callback) {
317
+ callWithCallback('getInboxMessages', [type, userIds], callback);
318
+ },
319
+
320
+
321
+ /**
322
+ * Get inbox messages count.
323
+ *
324
+ * @param type the message type is integer
325
+ * 1 = ALL
326
+ * 2 = UNREAD
327
+ * 3 = READ
328
+ * 4 = VIEWED
329
+ * 5 = DELETED
330
+ * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
331
+ * @callback will have the integer
332
+ */
333
+ getMessageCount: function (type, userIds, callback) {
334
+ callWithCallback('getMessageCount', [type, userIds], callback);
335
+ },
336
+
337
+ /**
338
+ * Get messages payload based on message id.
339
+ *
340
+ * @param messageId - message id of the notification
341
+ * @param userId - single userid in string ie. "useridA"
342
+ * @callback will have the json object
343
+ */
344
+ getInboxMessageForId: function (messageId, userId, callback) {
345
+ callWithCallback('getInboxMessageForId', [messageId, userId], callback);
346
+ },
347
+
348
+ /**
349
+ * update message status ex. UNREAD to READ.
350
+ *
351
+ * @param messageId - message id of the notification
352
+ * @param type - integer value for status
353
+ * @param userId - single userid in string
354
+ * @callback will have the boolean
355
+ */
356
+ updateInboxMessage: function (messageId, type, userId, callback) {
357
+ callWithCallback('updateInboxMessage', [messageId, type, userId], callback);
358
+ },
359
+
360
+ synchronizeInbox: function (timeout, callback) {
361
+ callWithCallback('synchronizeInbox', [timeout], callback)
362
+ },
363
+
364
+ //===============================================
365
+ // Rich Push AppInbox
366
+ //===============================================
367
+
368
+ /**
369
+ * getMediaData
370
+ * @param instanceInboxMessage - instance Dictionary
371
+ * @param values - NSString
372
+ * @callback will have the Dictionary
373
+ */
374
+
375
+ getMediaData: function (instanceInboxMessage, mediaKey, callback) {
376
+ callWithCallback('getMediaData', [instanceInboxMessage, mediaKey], callback);
377
+ },
378
+
379
+ /**
380
+ * getMediaUrl
381
+ * @param instanceInboxMessage - instance Dictionary
382
+ * @param values - Dictionary
383
+ * @callback will have the string
384
+ */
385
+ getMediaUrl: function (instanceInboxMessage, values, callback) {
386
+ callWithCallback('getMediaUrl', [instanceInboxMessage, values], callback);
387
+ },
388
+
389
+ /**
390
+ * getMediaType
391
+ * @param instanceInboxMessage - instance Dictionary
392
+ * @param values - Dictionary
393
+ * @callback will have the string
394
+ */
395
+ getMediaType: function (instanceInboxMessage, values, callback) {
396
+ callWithCallback('getMediaType', [instanceInboxMessage, values], callback);
397
+ },
398
+
399
+ /**
400
+ * getMediaThumbnail
401
+ * @param instanceInboxMessage - instance Dictionary
402
+ * @param values - Dictionary
403
+ * @callback will have the string
404
+ */
405
+
406
+ getMediaThumbnail: function (instanceInboxMessage, values, callback) {
407
+ callWithCallback('getMediaThumbnail', [instanceInboxMessage, values], callback);
408
+ },
409
+
410
+ /*==================
411
+ isDeviceReady
412
+ =====================*/
413
+ isDeviceReady: function (isActive) {
414
+ AppIceReactPlugin.isDeviceReady(isActive);
415
+ },
416
+
417
+ /*===============
418
+ synchronizeData
419
+ ================*/
420
+ synchronizeData: function (timeout, callback) {
421
+ callWithCallback('synchronizeData', [timeout], callback)
422
+ },
423
+
424
+ /*===================
425
+ getUserForIds with userIds
426
+ =====================*/
427
+
428
+ getUserForIds: function (userIds, callback) {
429
+ callWithCallback('getUserForIds', [userIds], callback);
430
+ },
431
+ };
432
+
433
+
434
+ //================================
435
+ // INTERNAL COMMON APIS
436
+ //=================================
437
+
438
+ // internal function for callback
439
+ function callWithCallback(method, args, callback) {
440
+ if (typeof callback === 'undefined' || callback == null || typeof callback !== 'function') {
441
+ callback = (err, res) => {
442
+ defaultCallback(method, err, res);
443
+ };
444
+ }
445
+
446
+ if (args == null) {
447
+ args = [];
448
+ }
449
+
450
+ args.push(callback);
451
+
452
+ AppIceReactPlugin[method].apply(this, args);
453
+ }
454
+
455
+ const handleStoredEvents = async (eventName, props) => {
456
+ try {
457
+ const storedEvents = await getEventData(EVENT_KEY + eventName);
458
+ let events = storedEvents ? JSON.parse(storedEvents) : [];
459
+
460
+ // Add the current event
461
+ events.push({ eventName, props });
462
+
463
+ // Save the updated events list
464
+ // appStorage.set(EVENT_KEY + eventName, JSON.stringify(events));
465
+ // appStorage.set(LAST_EVENT_KEY, eventName);
466
+
467
+ // async Storage
468
+ await AsyncStorage.setItem(EVENT_KEY + eventName, JSON.stringify(events))
469
+ await AsyncStorage.setItem(LAST_EVENT_KEY, eventName)
470
+
471
+
472
+ } catch (error) {
473
+ console.error('Failed to store event:', error);
474
+ }
475
+ };
476
+
477
+ const handleFlushEvent = async (eventName, props) => {
478
+ try {
479
+ const storedEvents = await getEventData(EVENT_KEY + eventName);
480
+ let events = storedEvents ? JSON.parse(storedEvents) : [];
481
+
482
+ events.forEach(event => {
483
+ Object.assign(props, event.props);
484
+ });
485
+
486
+ await AppIceReactPlugin.tagEvent(eventName, props);
487
+
488
+ await deleteData(EVENT_KEY + eventName)
489
+ await deleteData(LAST_EVENT_KEY)
490
+
491
+
492
+ } catch (error) {
493
+ console.error('Failed to flush events:', error);
494
+ }
495
+ };
496
+
497
+ const deleteData = async (eventName) => {
498
+ try {
499
+ //appStorage.delete(EVENT_KEY + eventName);
500
+ //appStorage.delete(LAST_EVENT_KEY);
501
+
502
+ await AsyncStorage.removeItem(eventName)
503
+ } catch (error) {
504
+ console.error('Failed to delete events:', error);
505
+ }
506
+ };
507
+
508
+ const getEventData = async (eventName) => {
509
+ try {
510
+
511
+ // const storedEvents1 = appStorage.getString(EVENT_KEY + lastEventData);
512
+
513
+ return await AsyncStorage.getItem(eventName)
514
+ } catch (error) {
515
+ console.error('Failed to fetch events:', error);
516
+ }
517
+ };
518
+
519
+
520
+ module.exports = AppICEReact;