reactnative-plugin-appice 1.7.12 → 1.7.14

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