react-native-mparticle 2.7.13 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/SECURITY.md +9 -0
  2. package/android/build.gradle +65 -10
  3. package/android/src/main/AndroidManifestNew.xml +3 -0
  4. package/android/src/main/java/com/mparticle/react/MParticleModule.kt +976 -0
  5. package/android/src/main/java/com/mparticle/react/MParticlePackage.kt +68 -0
  6. package/android/src/main/java/com/mparticle/react/rokt/MPRoktModuleImpl.kt +251 -0
  7. package/android/src/main/java/com/mparticle/react/rokt/RoktLayoutViewManagerImpl.kt +79 -0
  8. package/android/src/newarch/java/com/mparticle/react/rokt/MPRoktModule.kt +130 -0
  9. package/android/src/newarch/java/com/mparticle/react/rokt/RoktLayoutViewManager.kt +22 -0
  10. package/android/src/oldarch/java/com/mparticle/react/NativeMPRoktSpec.kt +29 -0
  11. package/android/src/oldarch/java/com/mparticle/react/NativeMParticleSpec.kt +153 -0
  12. package/android/src/oldarch/java/com/mparticle/react/rokt/MPRoktModule.kt +79 -0
  13. package/android/src/oldarch/java/com/mparticle/react/rokt/RoktLayoutViewManager.kt +34 -0
  14. package/ios/RNMParticle/RNMPRokt.h +15 -0
  15. package/ios/RNMParticle/RNMPRokt.mm +247 -0
  16. package/ios/RNMParticle/RNMParticle.h +6 -1
  17. package/ios/RNMParticle/RNMParticle.mm +1199 -0
  18. package/ios/RNMParticle/RoktEventManager.h +16 -0
  19. package/ios/RNMParticle/RoktEventManager.m +174 -0
  20. package/ios/RNMParticle/RoktLayoutManager.m +22 -0
  21. package/ios/RNMParticle/RoktNativeLayoutComponentView.h +18 -0
  22. package/ios/RNMParticle/RoktNativeLayoutComponentView.mm +50 -0
  23. package/ios/RNMParticle.xcodeproj/project.pbxproj +29 -6
  24. package/js/codegenSpecs/NativeMParticle.ts +214 -0
  25. package/js/codegenSpecs/rokt/NativeMPRokt.ts +32 -0
  26. package/js/codegenSpecs/rokt/RoktLayoutNativeComponent.ts +29 -0
  27. package/js/index.tsx +940 -0
  28. package/js/rokt/rokt-layout-view.android.tsx +133 -0
  29. package/js/rokt/rokt-layout-view.ios.tsx +121 -0
  30. package/js/rokt/rokt-layout-view.tsx +15 -0
  31. package/js/rokt/rokt.ts +87 -0
  32. package/js/utils/architecture.ts +22 -0
  33. package/lib/codegenSpecs/NativeMParticle.d.ts +148 -0
  34. package/lib/codegenSpecs/NativeMParticle.js +5 -0
  35. package/lib/codegenSpecs/NativeMParticle.js.map +1 -0
  36. package/lib/codegenSpecs/rokt/NativeMPRokt.d.ts +24 -0
  37. package/lib/codegenSpecs/rokt/NativeMPRokt.js +5 -0
  38. package/lib/codegenSpecs/rokt/NativeMPRokt.js.map +1 -0
  39. package/lib/codegenSpecs/rokt/RoktLayoutNativeComponent.d.ts +18 -0
  40. package/lib/codegenSpecs/rokt/RoktLayoutNativeComponent.js +8 -0
  41. package/lib/codegenSpecs/rokt/RoktLayoutNativeComponent.js.map +1 -0
  42. package/lib/index.d.ts +410 -0
  43. package/lib/index.js +645 -0
  44. package/lib/index.js.map +1 -0
  45. package/lib/rokt/rokt-layout-view.android.d.ts +39 -0
  46. package/lib/rokt/rokt-layout-view.android.js +109 -0
  47. package/lib/rokt/rokt-layout-view.android.js.map +1 -0
  48. package/lib/rokt/rokt-layout-view.d.ts +5 -0
  49. package/lib/rokt/rokt-layout-view.ios.d.ts +32 -0
  50. package/lib/rokt/rokt-layout-view.ios.js +84 -0
  51. package/lib/rokt/rokt-layout-view.ios.js.map +1 -0
  52. package/lib/rokt/rokt-layout-view.js +12 -0
  53. package/lib/rokt/rokt-layout-view.js.map +1 -0
  54. package/lib/rokt/rokt.d.ts +40 -0
  55. package/lib/rokt/rokt.js +54 -0
  56. package/lib/rokt/rokt.js.map +1 -0
  57. package/lib/utils/architecture.d.ts +9 -0
  58. package/lib/utils/architecture.js +19 -0
  59. package/lib/utils/architecture.js.map +1 -0
  60. package/package.json +32 -10
  61. package/react-native-mparticle.podspec +7 -6
  62. package/.github/PULL_REQUEST_TEMPLATE.md +0 -8
  63. package/.github/dependabot.yml +0 -12
  64. package/.github/workflows/daily.yml +0 -19
  65. package/.github/workflows/dependabot-automerge.yml +0 -12
  66. package/.github/workflows/pull-request.yml +0 -60
  67. package/.github/workflows/release.yml +0 -60
  68. package/.github/workflows/sonarcloud.yml +0 -16
  69. package/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
  70. package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
  71. package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
  72. package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  73. package/android/.gradle/7.5.1/dependencies-accessors/gc.properties +0 -0
  74. package/android/.gradle/7.5.1/executionHistory/executionHistory.lock +0 -0
  75. package/android/.gradle/7.5.1/fileChanges/last-build.bin +0 -0
  76. package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
  77. package/android/.gradle/7.5.1/gc.properties +0 -0
  78. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  79. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  80. package/android/.gradle/vcs-1/gc.properties +0 -0
  81. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  82. package/android/gradle/wrapper/gradle-wrapper.properties +0 -6
  83. package/android/gradle.properties +0 -53
  84. package/android/gradlew +0 -160
  85. package/android/gradlew.bat +0 -90
  86. package/android/libs/java-json.jar +0 -0
  87. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug-sources.jar +0 -0
  88. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug-sources.jar.md5 +0 -1
  89. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug-sources.jar.sha1 +0 -1
  90. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug-sources.jar.sha256 +0 -1
  91. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug-sources.jar.sha512 +0 -1
  92. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug.aar +0 -0
  93. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug.aar.md5 +0 -1
  94. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug.aar.sha1 +0 -1
  95. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug.aar.sha256 +0 -1
  96. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-debug.aar.sha512 +0 -1
  97. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release-sources.jar +0 -0
  98. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release-sources.jar.md5 +0 -1
  99. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release-sources.jar.sha1 +0 -1
  100. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release-sources.jar.sha256 +0 -1
  101. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release-sources.jar.sha512 +0 -1
  102. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release.aar +0 -0
  103. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release.aar.md5 +0 -1
  104. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release.aar.sha1 +0 -1
  105. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release.aar.sha256 +0 -1
  106. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5-release.aar.sha512 +0 -1
  107. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.module +0 -204
  108. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.module.md5 +0 -1
  109. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.module.sha1 +0 -1
  110. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.module.sha256 +0 -1
  111. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.module.sha512 +0 -1
  112. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.pom +0 -44
  113. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.pom.md5 +0 -1
  114. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.pom.sha1 +0 -1
  115. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.pom.sha256 +0 -1
  116. package/android/libs/react-native-android/com/facebook/react/hermes-engine/0.70.5/hermes-engine-0.70.5.pom.sha512 +0 -1
  117. package/android/libs/react-native-android/com/facebook/react/hermes-engine/maven-metadata.xml +0 -13
  118. package/android/libs/react-native-android/com/facebook/react/hermes-engine/maven-metadata.xml.md5 +0 -1
  119. package/android/libs/react-native-android/com/facebook/react/hermes-engine/maven-metadata.xml.sha1 +0 -1
  120. package/android/libs/react-native-android/com/facebook/react/hermes-engine/maven-metadata.xml.sha256 +0 -1
  121. package/android/libs/react-native-android/com/facebook/react/hermes-engine/maven-metadata.xml.sha512 +0 -1
  122. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug-sources.jar +0 -0
  123. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug-sources.jar.md5 +0 -1
  124. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug-sources.jar.sha1 +0 -1
  125. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug-sources.jar.sha256 +0 -1
  126. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug-sources.jar.sha512 +0 -1
  127. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug.aar +0 -0
  128. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug.aar.md5 +0 -1
  129. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug.aar.sha1 +0 -1
  130. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug.aar.sha256 +0 -1
  131. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-debug.aar.sha512 +0 -1
  132. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release-sources.jar +0 -0
  133. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release-sources.jar.md5 +0 -1
  134. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release-sources.jar.sha1 +0 -1
  135. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release-sources.jar.sha256 +0 -1
  136. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release-sources.jar.sha512 +0 -1
  137. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release.aar +0 -0
  138. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release.aar.md5 +0 -1
  139. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release.aar.sha1 +0 -1
  140. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release.aar.sha256 +0 -1
  141. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5-release.aar.sha512 +0 -1
  142. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.module +0 -628
  143. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.module.md5 +0 -1
  144. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.module.sha1 +0 -1
  145. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.module.sha256 +0 -1
  146. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.module.sha512 +0 -1
  147. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.pom +0 -156
  148. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.pom.md5 +0 -1
  149. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.pom.sha1 +0 -1
  150. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.pom.sha256 +0 -1
  151. package/android/libs/react-native-android/com/facebook/react/react-native/0.70.5/react-native-0.70.5.pom.sha512 +0 -1
  152. package/android/libs/react-native-android/com/facebook/react/react-native/maven-metadata.xml +0 -13
  153. package/android/libs/react-native-android/com/facebook/react/react-native/maven-metadata.xml.md5 +0 -1
  154. package/android/libs/react-native-android/com/facebook/react/react-native/maven-metadata.xml.sha1 +0 -1
  155. package/android/libs/react-native-android/com/facebook/react/react-native/maven-metadata.xml.sha256 +0 -1
  156. package/android/libs/react-native-android/com/facebook/react/react-native/maven-metadata.xml.sha512 +0 -1
  157. package/android/src/main/java/com/mparticle/react/MParticleModule.java +0 -987
  158. package/android/src/main/java/com/mparticle/react/MParticlePackage.java +0 -34
  159. package/android/src/test/java/com/mparticle/react/IdentityApiTest.java +0 -230
  160. package/android/src/test/java/com/mparticle/react/MParticleUserTest.java +0 -233
  161. package/android/src/test/java/com/mparticle/react/testutils/MockMParticleUser.java +0 -103
  162. package/android/src/test/java/com/mparticle/react/testutils/MockMap.java +0 -169
  163. package/android/src/test/java/com/mparticle/react/testutils/MockReadableArray.java +0 -53
  164. package/android/src/test/java/com/mparticle/react/testutils/MockWritableMap.java +0 -4
  165. package/android/src/test/java/com/mparticle/react/testutils/Mutable.java +0 -13
  166. package/ios/RNMParticle/RNMParticle.m +0 -678
  167. package/ios/RNMParticle.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  168. package/ios/RNMParticle.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  169. package/ios/RNMParticle.xcodeproj/project.xcworkspace/xcuserdata/bstalnaker.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  170. package/ios/RNMParticle.xcodeproj/xcuserdata/bstalnaker.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  171. package/js/index.js +0 -697
  172. package/release.sh +0 -6
@@ -1,987 +0,0 @@
1
- package com.mparticle.react;
2
-
3
- import android.location.Location;
4
- import android.util.Log;
5
-
6
- import com.facebook.react.bridge.Arguments;
7
- import com.facebook.react.bridge.ReactApplicationContext;
8
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
9
- import com.facebook.react.bridge.ReactMethod;
10
- import com.facebook.react.bridge.ReadableArray;
11
- import com.facebook.react.bridge.ReadableMap;
12
- import com.facebook.react.bridge.ReadableMapKeySetIterator;
13
- import com.facebook.react.bridge.Callback;
14
- import com.facebook.react.bridge.ReadableType;
15
- import com.facebook.react.bridge.WritableMap;
16
- import com.facebook.react.bridge.WritableNativeMap;
17
- import com.facebook.react.bridge.WritableArray;
18
- import com.facebook.react.bridge.WritableNativeArray;
19
- import com.mparticle.AttributionResult;
20
- import com.mparticle.MParticle;
21
- import com.mparticle.MPEvent;
22
- import com.mparticle.Session;
23
- import com.mparticle.UserAttributeListenerType;
24
- import com.mparticle.commerce.CommerceEvent;
25
- import com.mparticle.commerce.Impression;
26
- import com.mparticle.commerce.Product;
27
- import com.mparticle.commerce.TransactionAttributes;
28
- import com.mparticle.commerce.Promotion;
29
- import com.mparticle.consent.ConsentState;
30
- import com.mparticle.consent.GDPRConsent;
31
- import com.mparticle.consent.CCPAConsent;
32
- import com.mparticle.identity.AliasRequest;
33
- import com.mparticle.identity.IdentityApi;
34
- import com.mparticle.identity.IdentityApiRequest;
35
- import com.mparticle.identity.IdentityApiResult;
36
- import com.mparticle.identity.MParticleUser;
37
- import com.mparticle.identity.IdentityHttpResponse;
38
- import com.mparticle.identity.TaskFailureListener;
39
- import com.mparticle.identity.TaskSuccessListener;
40
- import com.mparticle.internal.Logger;
41
- import com.mparticle.UserAttributeListener;
42
-
43
- import java.util.ArrayList;
44
- import java.util.HashMap;
45
- import java.util.List;
46
- import java.util.Map;
47
-
48
- import javax.annotation.Nullable;
49
-
50
- public class MParticleModule extends ReactContextBaseJavaModule {
51
-
52
-
53
- private final static String LOG_TAG = "MParticleModule";
54
-
55
- ReactApplicationContext reactContext;
56
-
57
- public MParticleModule(ReactApplicationContext reactContext) {
58
- super(reactContext);
59
- this.reactContext = reactContext;
60
- }
61
-
62
- @Override
63
- public String getName() {
64
- return "MParticle";
65
- }
66
-
67
- @ReactMethod
68
- public void upload() {
69
- MParticle.getInstance().upload();
70
- }
71
-
72
- @ReactMethod
73
- public void setUploadInterval(int uploadInterval) {
74
- MParticle.getInstance().setUpdateInterval(uploadInterval);
75
- }
76
-
77
- @ReactMethod
78
- public void setLocation(double latitude, double longitude) {
79
- Location newLocation = new Location("");
80
- newLocation.setLatitude(latitude);
81
- newLocation.setLongitude(longitude);
82
- MParticle.getInstance().setLocation(newLocation);
83
-
84
- }
85
-
86
- @ReactMethod
87
- public void logEvent(final String name, int type, final ReadableMap attributesMap) {
88
- Map<String, String> attributes = ConvertStringMap(attributesMap);
89
- MParticle.EventType eventType = ConvertEventType(type);
90
-
91
- MPEvent event = new MPEvent.Builder(name, eventType)
92
- .customAttributes(attributes)
93
- .build();
94
- MParticle.getInstance().logEvent(event);
95
- }
96
-
97
- @ReactMethod
98
- public void logMPEvent(final ReadableMap attributesMap) {
99
- MPEvent event = ConvertMPEvent(attributesMap);
100
- MParticle.getInstance().logEvent(event);
101
- }
102
-
103
- @ReactMethod
104
- public void logCommerceEvent(final ReadableMap map) {
105
- if (map != null) {
106
- CommerceEvent commerceEvent = ConvertCommerceEvent(map);
107
- MParticle.getInstance().logEvent(commerceEvent);
108
- }
109
- }
110
-
111
- @ReactMethod
112
- public void logScreenEvent(final String event, final ReadableMap attributesMap, final boolean shouldUploadEvent) {
113
- Map<String, String> attributes = ConvertStringMap(attributesMap);
114
- MParticle.getInstance().logScreen(event, attributes, shouldUploadEvent);
115
- }
116
-
117
- @ReactMethod
118
- public void setUserAttribute(final String userId, final String userAttribute, final String value) {
119
- MParticleUser selectedUser = MParticle.getInstance().Identity().getUser(parseMpid(userId));
120
- if (selectedUser != null) {
121
- selectedUser.setUserAttribute(userAttribute, value);
122
- }
123
- }
124
-
125
- @ReactMethod
126
- public void setUserAttributeArray(final String userId, final String key, final ReadableArray values) {
127
- if (values != null) {
128
- List<String> list = new ArrayList<String>();
129
- for (int i = 0; i < values.size(); ++i) {
130
- list.add(values.getString(i));
131
- }
132
-
133
- MParticleUser selectedUser = MParticle.getInstance().Identity().getUser(parseMpid(userId));
134
- if (selectedUser != null) {
135
- selectedUser.setUserAttributeList(key, list);
136
- }
137
- }
138
- }
139
-
140
- @ReactMethod
141
- public void getUserAttributes(final String userId, final Callback completion) {
142
- MParticleUser selectedUser = MParticle.getInstance().Identity().getUser(parseMpid(userId));
143
- if (selectedUser != null) {
144
- selectedUser.getUserAttributes(new UserAttributeListener() {
145
- @Override
146
- public void onUserAttributesReceived(Map<String, String> userAttributes, Map<String, List<String>> userAttributeLists, Long mpid) {
147
- WritableMap resultMap = new WritableNativeMap();
148
- for (Map.Entry<String, String> entry : userAttributes.entrySet()) {
149
- resultMap.putString(entry.getKey(), entry.getValue());
150
- }
151
- for (Map.Entry<String, List<String>> entry : userAttributeLists.entrySet()) {
152
- WritableArray resultArray = new WritableNativeArray();
153
- List<String> valueList = entry.getValue();
154
- for (String arrayVal : valueList) {
155
- resultArray.pushString(arrayVal);
156
- }
157
- resultMap.putArray(entry.getKey(), resultArray);
158
- }
159
- completion.invoke(null, resultMap);
160
- }
161
- });
162
- } else {
163
- completion.invoke();
164
- }
165
- }
166
-
167
- @ReactMethod
168
- public void setUserTag(final String userId, final String tag) {
169
- MParticleUser selectedUser = MParticle.getInstance().Identity().getUser(parseMpid(userId));
170
- if (selectedUser != null) {
171
- selectedUser.setUserTag(tag);
172
- }
173
- }
174
-
175
- @ReactMethod
176
- public void removeUserAttribute(final String userId, final String key) {
177
- MParticleUser selectedUser = MParticle.getInstance().Identity().getUser(parseMpid(userId));
178
- if (selectedUser != null) {
179
- selectedUser.removeUserAttribute(key);
180
- }
181
- }
182
-
183
- @ReactMethod
184
- public void incrementUserAttribute(final String userId, final String key, final Integer value) {
185
- MParticleUser selectedUser = MParticle.getInstance().Identity().getUser(parseMpid(userId));
186
- if (selectedUser != null) {
187
- selectedUser.incrementUserAttribute(key, value);
188
- }
189
- }
190
- @ReactMethod
191
- public void identify(final ReadableMap requestMap, final Callback completion) {
192
- IdentityApiRequest request = ConvertIdentityAPIRequest(requestMap);
193
-
194
- MParticle.getInstance().Identity().identify(request)
195
- .addFailureListener(new TaskFailureListener() {
196
- @Override
197
- public void onFailure(IdentityHttpResponse identityHttpResponse) {
198
- completion.invoke(ConvertIdentityHttpResponse(identityHttpResponse), null);
199
- }
200
- })
201
- .addSuccessListener(new TaskSuccessListener() {
202
- @Override
203
- public void onSuccess(IdentityApiResult identityApiResult) {
204
- //Continue with login, and you can also access the new/updated user:
205
- MParticleUser user = identityApiResult.getUser();
206
- String userID = Long.toString(user.getId());
207
- completion.invoke(null, userID);
208
- }
209
- });
210
- }
211
-
212
-
213
- @ReactMethod
214
- public void login(final ReadableMap requestMap, final Callback completion) {
215
- IdentityApiRequest request = ConvertIdentityAPIRequest(requestMap);
216
-
217
- MParticle.getInstance().Identity().login(request)
218
- .addFailureListener(new TaskFailureListener() {
219
- @Override
220
- public void onFailure(IdentityHttpResponse identityHttpResponse) {
221
- completion.invoke(ConvertIdentityHttpResponse(identityHttpResponse), null);
222
- }
223
- })
224
- .addSuccessListener(new TaskSuccessListener() {
225
- @Override
226
- public void onSuccess(IdentityApiResult identityApiResult) {
227
- //Continue with login, and you can also access the new/updated user:
228
- MParticleUser user = identityApiResult.getUser();
229
- String userId = Long.toString(user.getId());
230
- MParticleUser previousUser = identityApiResult.getPreviousUser();
231
- String previousUserId = null;
232
- if (previousUser != null) {
233
- previousUserId = Long.toString(previousUser.getId());
234
- }
235
- completion.invoke(null, userId, previousUserId);
236
- }
237
- });
238
- }
239
-
240
-
241
- @ReactMethod
242
- public void logout(final ReadableMap requestMap, final Callback completion) {
243
- IdentityApiRequest request = ConvertIdentityAPIRequest(requestMap);
244
-
245
- MParticle.getInstance().Identity().logout(request)
246
- .addFailureListener(new TaskFailureListener() {
247
- @Override
248
- public void onFailure(IdentityHttpResponse identityHttpResponse) {
249
- completion.invoke(ConvertIdentityHttpResponse(identityHttpResponse), null);
250
- }
251
- })
252
- .addSuccessListener(new TaskSuccessListener() {
253
- @Override
254
- public void onSuccess(IdentityApiResult identityApiResult) {
255
- //Continue with login, and you can also access the new/updated user:
256
- MParticleUser user = identityApiResult.getUser();
257
- String userID = Long.toString(user.getId());
258
- completion.invoke(null, userID);
259
- }
260
- });
261
- }
262
-
263
- @ReactMethod
264
- public void modify(final ReadableMap requestMap, final Callback completion) {
265
- IdentityApiRequest request = ConvertIdentityAPIRequest(requestMap);
266
-
267
- MParticle.getInstance().Identity().modify(request)
268
- .addFailureListener(new TaskFailureListener() {
269
- @Override
270
- public void onFailure(IdentityHttpResponse identityHttpResponse) {
271
- completion.invoke(ConvertIdentityHttpResponse(identityHttpResponse), null);
272
- }
273
- })
274
- .addSuccessListener(new TaskSuccessListener() {
275
- @Override
276
- public void onSuccess(IdentityApiResult identityApiResult) {
277
- //Continue with login, and you can also access the new/updated user:
278
- MParticleUser user = identityApiResult.getUser();
279
- String userID = Long.toString(user.getId());
280
- completion.invoke(null, userID);
281
- }
282
- });
283
- }
284
-
285
- @ReactMethod
286
- public void getCurrentUserWithCompletion(Callback completion) {
287
- MParticleUser currentUser = MParticle.getInstance().Identity().getCurrentUser();
288
- if (currentUser != null) {
289
- String userID = Long.toString(currentUser.getId());
290
- completion.invoke(null, userID);
291
- } else {
292
- completion.invoke(null, null);
293
- }
294
-
295
- }
296
-
297
- @ReactMethod
298
- public void aliasUsers(final ReadableMap readableMap, final Callback completion) {
299
- IdentityApi identityApi = MParticle.getInstance().Identity();
300
- ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
301
- Long destinationMpid = null;
302
- Long sourceMpid = null;
303
- Long startTime = null;
304
- Long endTime = null;
305
-
306
- while (iterator.hasNextKey()) {
307
- try {
308
- switch (iterator.nextKey()) {
309
- case "destinationMpid":
310
- destinationMpid = Utils.getLong(readableMap, "destinationMpid", false);
311
- break;
312
- case "sourceMpid":
313
- sourceMpid = Utils.getLong(readableMap, "sourceMpid", false);
314
- break;
315
- case "startTime":
316
- startTime = Utils.getLong(readableMap, "startTime", true);
317
- break;
318
- case "endTime":
319
- endTime = Utils.getLong(readableMap, "endTime", true);
320
- break;
321
- }
322
- } catch (NumberFormatException ex) {
323
- Logger.error(ex.getMessage());
324
- completion.invoke(false, ex.getMessage());
325
- return;
326
- }
327
- }
328
- if (startTime == null && endTime == null) {
329
- MParticleUser sourceUser = null;
330
- MParticleUser destinationUser = null;
331
- if (sourceMpid != null) {
332
- sourceUser = identityApi.getUser(sourceMpid);
333
- }
334
- if (destinationMpid != null) {
335
- destinationUser = identityApi.getUser(destinationMpid);
336
- }
337
- if (sourceUser != null && destinationUser != null) {
338
- AliasRequest request = AliasRequest.builder(sourceUser, destinationUser).build();
339
- boolean success = MParticle.getInstance().Identity().aliasUsers(request);
340
- completion.invoke(success);
341
- } else {
342
- completion.invoke(false, "MParticleUser could not be found for provided sourceMpid and destinationMpid");
343
- }
344
- } else {
345
- AliasRequest request = AliasRequest.builder()
346
- .destinationMpid(destinationMpid)
347
- .sourceMpid(sourceMpid)
348
- .startTime(startTime)
349
- .endTime(endTime)
350
- .build();
351
- boolean success = identityApi.aliasUsers(request);
352
- completion.invoke(success);
353
- }
354
- }
355
-
356
- @ReactMethod
357
- public void getSession(Callback completion) {
358
- Session session = MParticle.getInstance().getCurrentSession();
359
- if (session != null) {
360
- String sessionId = session.getSessionUUID();
361
- completion.invoke(sessionId);
362
- } else {
363
- completion.invoke();
364
- }
365
- }
366
-
367
- @ReactMethod
368
- public void getUserIdentities(final String userId, Callback completion) {
369
- MParticleUser selectedUser = MParticle.getInstance().Identity().getUser(parseMpid(userId));
370
- if (selectedUser != null) {
371
- completion.invoke(null, ConvertToUserIdentities(selectedUser.getUserIdentities()));
372
- } else {
373
- completion.invoke();
374
- }
375
- }
376
-
377
- @ReactMethod
378
- public void getFirstSeen(final String userId, Callback completion) {
379
- MParticleUser selectedUser = MParticle.getInstance().Identity().getUser(Utils.parseMpid(userId));
380
- if (selectedUser != null) {
381
- completion.invoke(String.valueOf(selectedUser.getFirstSeenTime()));
382
- } else {
383
- completion.invoke();
384
- }
385
- }
386
-
387
- @ReactMethod
388
- public void getLastSeen(final String userId, Callback completion) {
389
- MParticleUser selectedUser = MParticle.getInstance().Identity().getUser(Utils.parseMpid(userId));
390
- if (selectedUser != null) {
391
- completion.invoke(String.valueOf(selectedUser.getLastSeenTime()));
392
- } else {
393
- completion.invoke();
394
- }
395
- }
396
-
397
- @ReactMethod
398
- public void getAttributions(Callback completion) {
399
- Map<Integer, AttributionResult> attributionResultMap = MParticle.getInstance().getAttributionResults();
400
- WritableMap map = Arguments.createMap();
401
- if (attributionResultMap != null) {
402
- for (Map.Entry<Integer, AttributionResult> entry : attributionResultMap.entrySet()) {
403
- WritableMap attributeMap = Arguments.createMap();
404
- AttributionResult attribution = entry.getValue();
405
- if (attribution != null) {
406
- attributeMap.putInt("kitId", attribution.getServiceProviderId());
407
- if (attribution.getLink() != null) {
408
- attributeMap.putString("link", attribution.getLink());
409
- }
410
- if (attribution.getParameters() != null) {
411
- attributeMap.putString("linkParameters", attribution.getParameters().toString());
412
- }
413
- }
414
- map.putMap(String.valueOf(entry.getKey()), attributeMap);
415
- }
416
- }
417
- completion.invoke(map);
418
- }
419
-
420
- @ReactMethod
421
- public void setOptOut(Boolean optOut) {
422
- MParticle.getInstance().setOptOut(optOut);
423
- }
424
-
425
- @ReactMethod
426
- public void getOptOut(Callback completion) {
427
- boolean optedOut = MParticle.getInstance().getOptOut();
428
- completion.invoke(optedOut);
429
- }
430
-
431
- @ReactMethod
432
- public void isKitActive(Integer kitId, Callback completion) {
433
- boolean isActive = MParticle.getInstance().isKitActive(kitId);
434
- completion.invoke(isActive);
435
- }
436
-
437
- @ReactMethod
438
- public void logPushRegistration(String instanceId, String senderId) {
439
- if (!isEmpty(instanceId) && !isEmpty(senderId)) {
440
- MParticle.getInstance().logPushRegistration(instanceId, senderId);
441
- }
442
- }
443
-
444
- @ReactMethod
445
- public void addGDPRConsentState(final ReadableMap map, String purpose) {
446
- MParticleUser currentUser = MParticle.getInstance().Identity().getCurrentUser();
447
- if (currentUser != null) {
448
-
449
-
450
- GDPRConsent consent = ConvertToGDPRConsent(map);
451
- if (consent != null) {
452
- ConsentState consentState = ConsentState.withConsentState(currentUser.getConsentState())
453
- .addGDPRConsentState(purpose, consent)
454
- .build();
455
- currentUser.setConsentState(consentState);
456
- Logger.info("GDPRConsentState added, \n\t\"purpose\": " + purpose + "\n" + consentState.toString());
457
- } else {
458
- Logger.warning("GDPRConsentState was not able to be deserialized, will not be added");
459
- }
460
- }
461
- }
462
-
463
- @ReactMethod
464
- public void removeGDPRConsentStateWithPurpose(String purpose) {
465
- MParticleUser currentUser = MParticle.getInstance().Identity().getCurrentUser();
466
- if (currentUser != null) {
467
- ConsentState consentState = ConsentState.withConsentState(currentUser.getConsentState())
468
- .removeGDPRConsentState(purpose)
469
- .build();
470
- currentUser.setConsentState(consentState);
471
- }
472
- }
473
-
474
- @ReactMethod
475
- public void setCCPAConsentState(final ReadableMap map) {
476
- MParticleUser currentUser = MParticle.getInstance().Identity().getCurrentUser();
477
- if (currentUser != null) {
478
-
479
-
480
- CCPAConsent consent = ConvertToCCPAConsent(map);
481
- if (consent != null) {
482
- ConsentState consentState = ConsentState.withConsentState(currentUser.getConsentState())
483
- .setCCPAConsentState(consent)
484
- .build();
485
- currentUser.setConsentState(consentState);
486
- Logger.info("CCPAConsentState added, \n" + consentState.toString());
487
- } else {
488
- Logger.warning("CCPAConsentState was not able to be deserialized, will not be added");
489
- }
490
- }
491
- }
492
-
493
- @ReactMethod
494
- public void removeCCPAConsentState() {
495
- MParticleUser currentUser = MParticle.getInstance().Identity().getCurrentUser();
496
- if (currentUser != null) {
497
- ConsentState consentState = ConsentState.withConsentState(currentUser.getConsentState())
498
- .removeCCPAConsentState()
499
- .build();
500
- currentUser.setConsentState(consentState);
501
- }
502
- }
503
-
504
- protected WritableMap getWritableMap() {
505
- return new WritableNativeMap();
506
- }
507
-
508
- private static IdentityApiRequest ConvertIdentityAPIRequest(ReadableMap map) {
509
- IdentityApiRequest.Builder identityRequest = IdentityApiRequest.withEmptyUser();
510
- Map<MParticle.IdentityType, String> userIdentities = ConvertUserIdentities(map);
511
- identityRequest.userIdentities(userIdentities);
512
-
513
- return identityRequest.build();
514
- }
515
-
516
- private static MPEvent ConvertMPEvent(ReadableMap map) {
517
- if ((map.hasKey("name")) && (map.hasKey("type"))) {
518
- String name = map.getString("name");
519
- Integer type = map.getInt("type");
520
-
521
- MPEvent.Builder builder = new MPEvent.Builder(name, ConvertEventType(type));
522
-
523
- if (map.hasKey("category")) {
524
- builder.category(map.getString("category"));
525
- }
526
-
527
- if (map.hasKey("duration")) {
528
- builder.duration(map.getDouble("duration"));
529
- }
530
-
531
- if (map.hasKey("info")) {
532
- ReadableMap customInfoMap = map.getMap("info");
533
- Map<String, String> customInfo = ConvertStringMap(customInfoMap);
534
- builder.customAttributes(customInfo);
535
- }
536
-
537
- if (map.hasKey("customFlags")) {
538
- ReadableMap customFlagsMap = map.getMap("customFlags");
539
- Map<String, String> customFlags = ConvertStringMap(customFlagsMap);
540
- for (Map.Entry<String, String> entry : customFlags.entrySet())
541
- {
542
- builder.addCustomFlag(entry.getKey(), entry.getValue());
543
- }
544
- }
545
-
546
- if (map.hasKey("shouldUploadEvent")) {
547
- builder.shouldUploadEvent(map.getBoolean("shouldUploadEvent"));
548
- }
549
-
550
- return builder.build();
551
- }
552
-
553
- return null;
554
- }
555
-
556
- private static ReadableMap ConvertIdentityHttpResponse(IdentityHttpResponse response) {
557
- WritableMap map = Arguments.createMap();
558
- map.putInt("httpCode", response.getHttpCode());
559
- if (response.getMpId() != 0) {
560
- map.putString("mpid", String.valueOf(response.getMpId()));
561
- }
562
- StringBuilder stringBuilder = new StringBuilder();
563
- if (response.getErrors() != null) {
564
- for (IdentityHttpResponse.Error error: response.getErrors()) {
565
- if (error != null) {
566
- stringBuilder.append("Code: " + error.code + "\n");
567
- stringBuilder.append("Message: " + error.message + "\n");
568
- }
569
- }
570
- }
571
- map.putString("errors", stringBuilder.toString());
572
- return map;
573
- }
574
-
575
- private static CommerceEvent ConvertCommerceEvent(ReadableMap map) {
576
- Boolean isProductAction = map.hasKey("productActionType");
577
- Boolean isPromotion = map.hasKey("promotionActionType");
578
- Boolean isImpression = map.hasKey("impressions");
579
-
580
- if (!isProductAction && !isPromotion && !isImpression) {
581
- Log.e(LOG_TAG, "Invalid commerce event:" + map.toString());
582
- return null;
583
- }
584
-
585
- CommerceEvent.Builder builder = null;
586
-
587
- if (isProductAction) {
588
- int productActionInt = map.getInt("productActionType");
589
- String productAction = ConvertProductActionType(productActionInt);
590
- ReadableArray productsArray = map.getArray("products");
591
- ReadableMap productMap = productsArray.getMap(0);
592
- Product product = ConvertProduct(productMap);
593
- ReadableMap transactionAttributesMap = map.getMap("transactionAttributes");
594
- TransactionAttributes transactionAttributes = ConvertTransactionAttributes(transactionAttributesMap);
595
- builder = new CommerceEvent.Builder(productAction, product).transactionAttributes(transactionAttributes);
596
-
597
- for (int i = 1; i < productsArray.size(); ++i) {
598
- productMap = productsArray.getMap(i);
599
- product = ConvertProduct(productMap);
600
- builder.addProduct(product);
601
- }
602
- }
603
- else if (isPromotion) {
604
- int promotionActionTypeInt = map.getInt("promotionActionType");
605
- String promotionAction = ConvertPromotionActionType(promotionActionTypeInt);
606
- ReadableArray promotionsReadableArray = map.getArray("promotions");
607
- ReadableMap promotionMap = promotionsReadableArray.getMap(0);
608
- Promotion promotion = ConvertPromotion(promotionMap);
609
- builder = new CommerceEvent.Builder(promotionAction, promotion);
610
-
611
- for (int i = 1; i < promotionsReadableArray.size(); ++i) {
612
- promotionMap = promotionsReadableArray.getMap(i);
613
- promotion = ConvertPromotion(promotionMap);
614
- builder.addPromotion(promotion);
615
- }
616
- }
617
- else {
618
- ReadableArray impressionsArray = map.getArray("impressions");
619
- ReadableMap impressionMap = impressionsArray.getMap(0);
620
- Impression impression = ConvertImpression(impressionMap);
621
- builder = new CommerceEvent.Builder(impression);
622
-
623
- for (int i = 1; i < impressionsArray.size(); ++i) {
624
- impressionMap = impressionsArray.getMap(i);
625
- impression = ConvertImpression(impressionMap);
626
- builder.addImpression(impression);
627
- }
628
- }
629
-
630
- if (map.hasKey("shouldUploadEvent")) {
631
- builder.shouldUploadEvent(map.getBoolean("shouldUploadEvent"));
632
- }
633
- if (map.hasKey("customAttributes")) {
634
- builder.customAttributes(ConvertStringMap(map.getMap("customAttributes")));
635
- }
636
- if (map.hasKey("currency")) {
637
- builder.currency(map.getString("currency"));
638
- }
639
- if (map.hasKey("checkoutStep")) {
640
- builder.checkoutStep(map.getInt("checkoutStep"));
641
- }
642
- if (map.hasKey("checkoutOptions")) {
643
- builder.checkoutOptions(map.getString("checkoutOptions"));
644
- }
645
-
646
-
647
- return builder.build();
648
- }
649
-
650
- private static Product ConvertProduct(ReadableMap map) {
651
- String name = map.getString("name");
652
- String sku = map.getString("sku");
653
- double unitPrice = map.getDouble("price");
654
- Product.Builder builder = new Product.Builder(name, sku, unitPrice);
655
-
656
- if (map.hasKey("brand")) {
657
- String brand = map.getString("brand");
658
- builder.brand(brand);
659
- }
660
-
661
- if (map.hasKey("category")) {
662
- String category = map.getString("category");
663
- builder.category(category);
664
- }
665
-
666
- if (map.hasKey("couponCode")) {
667
- String couponCode = map.getString("couponCode");
668
- builder.couponCode(couponCode);
669
- }
670
-
671
- if (map.hasKey("customAttributes")) {
672
- ReadableMap customAttributesMap = map.getMap("customAttributes");
673
- Map<String, String> customAttributes = ConvertStringMap(customAttributesMap);
674
- builder.customAttributes(customAttributes);
675
- }
676
-
677
- if (map.hasKey("position")) {
678
- int position = map.getInt("position");
679
- builder.position(position);
680
- }
681
-
682
- if (map.hasKey("quantity")) {
683
- double quantity = map.getDouble("quantity");
684
- builder.quantity(quantity);
685
- }
686
-
687
- if (map.hasKey("variant")) {
688
- String variant = map.getString("variant");
689
- builder.variant(variant);
690
- }
691
-
692
- return builder.build();
693
- }
694
-
695
- private static TransactionAttributes ConvertTransactionAttributes(ReadableMap map) {
696
- if (!map.hasKey("transactionId")) {
697
- return null;
698
- }
699
-
700
- TransactionAttributes transactionAttributes = new TransactionAttributes(map.getString("transactionId"));
701
-
702
- if (map.hasKey("affiliation")) {
703
- transactionAttributes.setAffiliation(map.getString("affiliation"));
704
- }
705
-
706
- if (map.hasKey("revenue")) {
707
- transactionAttributes.setRevenue(map.getDouble("revenue"));
708
- }
709
-
710
- if (map.hasKey("shipping")) {
711
- transactionAttributes.setShipping(map.getDouble("shipping"));
712
- }
713
-
714
- if (map.hasKey("tax")) {
715
- transactionAttributes.setTax(map.getDouble("tax"));
716
- }
717
-
718
- if (map.hasKey("couponCode")) {
719
- transactionAttributes.setCouponCode(map.getString("couponCode"));
720
- }
721
-
722
- return transactionAttributes;
723
- }
724
-
725
- private static Promotion ConvertPromotion(ReadableMap map) {
726
- Promotion promotion = new Promotion();
727
-
728
- if (map.hasKey("id")) {
729
- promotion.setId(map.getString("id"));
730
- }
731
-
732
- if (map.hasKey("name")) {
733
- promotion.setName(map.getString("name"));
734
- }
735
-
736
- if (map.hasKey("creative")) {
737
- promotion.setCreative(map.getString("creative"));
738
- }
739
-
740
- if (map.hasKey("position")) {
741
- promotion.setPosition(map.getString("position"));
742
- }
743
-
744
- return promotion;
745
- }
746
-
747
- private static Impression ConvertImpression(ReadableMap map) {
748
-
749
- String listName = map.getString("impressionListName");
750
- ReadableArray productsArray = map.getArray("products");
751
- ReadableMap productMap = productsArray.getMap(0);
752
- Product product = ConvertProduct(productMap);
753
- Impression impression = new Impression(listName, product);
754
-
755
- for (int i = 1; i < productsArray.size(); ++i) {
756
- productMap = productsArray.getMap(i);
757
- product = ConvertProduct(productMap);
758
- impression.addProduct(product);
759
- }
760
-
761
- return impression;
762
- }
763
-
764
- private static Map<String, String> ConvertStringMap(ReadableMap readableMap) {
765
- Map<String, String> map = null;
766
-
767
- if (readableMap != null) {
768
- map = new HashMap<String, String>();
769
- ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
770
- while (iterator.hasNextKey()) {
771
- String key = iterator.nextKey();
772
- switch (readableMap.getType(key)) {
773
- case Null:
774
- map.put(key, null);
775
- break;
776
- case Boolean:
777
- map.put(key, Boolean.valueOf(readableMap.getBoolean(key)).toString());
778
- break;
779
- case Number:
780
- try {
781
- map.put(key, Integer.toString(readableMap.getInt(key)));
782
- } catch (Exception e) {
783
- try {
784
- map.put(key, Double.toString(readableMap.getDouble(key)));
785
- } catch (Exception ex) {
786
- Logger.warning("Unable to parse value for \"" + key + "\"");
787
- }
788
- }
789
- break;
790
- case String:
791
- map.put(key, readableMap.getString(key));
792
- break;
793
- case Map:
794
- Logger.warning("Maps are not supported Attribute value types");
795
- break;
796
- case Array:
797
- Logger.warning("Lists are not supported Attribute value types");
798
- break;
799
- }
800
- }
801
- }
802
-
803
- return map;
804
- }
805
-
806
- private static Map<MParticle.IdentityType, String> ConvertUserIdentities(ReadableMap readableMap) {
807
- Map<MParticle.IdentityType, String> map = new HashMap<>();
808
- if (readableMap != null) {
809
- ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
810
- while (iterator.hasNextKey()) {
811
- MParticle.IdentityType identity;
812
- String key = iterator.nextKey();
813
- if ("email".equals(key)) {
814
- identity = MParticle.IdentityType.Email;
815
- } else if ("customerId".equals(key)) {
816
- identity = MParticle.IdentityType.CustomerId;
817
- } else {
818
- identity = MParticle.IdentityType.parseInt(Integer.parseInt(key));
819
- }
820
- if (identity != null) {
821
- map.put(identity, readableMap.getString(key));
822
- }
823
- }
824
- }
825
- return map;
826
- }
827
-
828
- private WritableMap ConvertToUserIdentities(Map<MParticle.IdentityType, String> userIdentities) {
829
- WritableMap nativeMap = getWritableMap();
830
- for (Map.Entry<MParticle.IdentityType, String> entry: userIdentities.entrySet()) {
831
- nativeMap.putString(String.valueOf(entry.getKey().getValue()), entry.getValue());
832
- }
833
- return nativeMap;
834
- }
835
-
836
-
837
- private static MParticle.EventType ConvertEventType(int eventType) {
838
- switch (eventType) {
839
- case 1:
840
- return MParticle.EventType.Navigation;
841
- case 2:
842
- return MParticle.EventType.Location;
843
- case 3:
844
- return MParticle.EventType.Search;
845
- case 4:
846
- return MParticle.EventType.Transaction;
847
- case 5:
848
- return MParticle.EventType.UserContent;
849
- case 6:
850
- return MParticle.EventType.UserPreference;
851
- case 7:
852
- return MParticle.EventType.Social;
853
- case 8:
854
- return MParticle.EventType.Other;
855
- case 9:
856
- return MParticle.EventType.Media;
857
- default:
858
- return MParticle.EventType.Other;
859
- }
860
- }
861
-
862
- private static String ConvertProductActionType(int productActionType) {
863
- switch (productActionType) {
864
- case 1:
865
- return Product.ADD_TO_CART;
866
- case 2:
867
- return Product.REMOVE_FROM_CART;
868
- case 3:
869
- return Product.CHECKOUT;
870
- case 4:
871
- return Product.CHECKOUT_OPTION;
872
- case 5:
873
- return Product.CLICK;
874
- case 6:
875
- return Product.DETAIL;
876
- case 7:
877
- return Product.PURCHASE;
878
- case 8:
879
- return Product.REFUND;
880
- case 9:
881
- return Product.ADD_TO_WISHLIST;
882
- default:
883
- return Product.REMOVE_FROM_WISHLIST;
884
- }
885
- }
886
-
887
- private static String ConvertPromotionActionType(int promotionActionType) {
888
- switch (promotionActionType) {
889
- case 0:
890
- return Promotion.VIEW;
891
- default:
892
- return Promotion.CLICK;
893
- }
894
- }
895
-
896
- private boolean isEmpty(String str) {
897
- return str == null || str.length() == 0;
898
- }
899
-
900
- private long parseMpid(String longString) {
901
- try {
902
- return Long.parseLong(longString);
903
- } catch (NumberFormatException ex) {
904
- return 0L;
905
- }
906
- }
907
-
908
- @Nullable
909
- private GDPRConsent ConvertToGDPRConsent(ReadableMap map) {
910
- Boolean consented;
911
- try {
912
- if (map.getType("consented").equals(ReadableType.Boolean)) {
913
- consented = map.getBoolean("consented");
914
- } else {
915
- consented = Boolean.valueOf(map.getString("consented"));
916
- }
917
- } catch (Exception ex) {
918
- Logger.error("failed to convert \"consented\" value to a Boolean, unable to process addGDPRConsentState");
919
- return null;
920
- }
921
- GDPRConsent.Builder builder = GDPRConsent.builder(consented);
922
-
923
- if (map.hasKey("document")) {
924
- String document = map.getString("document");
925
- builder.document(document);
926
- }
927
- if (map.hasKey("hardwareId")) {
928
- String hardwareId = map.getString("hardwareId");
929
- builder.hardwareId(hardwareId);
930
- }
931
- if (map.hasKey("location")) {
932
- String location = map.getString("location");
933
- builder.location(location);
934
- }
935
- if (map.hasKey("timestamp")) {
936
- Long timestamp = null;
937
- try {
938
- String timestampString = map.getString("timestamp");
939
- timestamp = Long.valueOf(timestampString);
940
- builder.timestamp(timestamp);
941
- } catch (Exception ex) {
942
- Logger.warning("failed to convert \"timestamp\" value to Long");
943
- }
944
- }
945
- return builder.build();
946
- }
947
-
948
- @Nullable
949
- private CCPAConsent ConvertToCCPAConsent(ReadableMap map ) {
950
- Boolean consented;
951
- try {
952
- if (map.getType("consented").equals(ReadableType.Boolean)) {
953
- consented = map.getBoolean("consented");
954
- } else {
955
- consented = Boolean.valueOf(map.getString("consented"));
956
- }
957
- } catch (Exception ex) {
958
- Logger.error("failed to convert \"consented\" value to a Boolean, unable to process addCCPAConsentState");
959
- return null;
960
- }
961
- CCPAConsent.Builder builder = CCPAConsent.builder(consented);
962
-
963
- if (map.hasKey("document")) {
964
- String document = map.getString("document");
965
- builder.document(document);
966
- }
967
- if (map.hasKey("hardwareId")) {
968
- String hardwareId = map.getString("hardwareId");
969
- builder.hardwareId(hardwareId);
970
- }
971
- if (map.hasKey("location")) {
972
- String location = map.getString("location");
973
- builder.location(location);
974
- }
975
- if (map.hasKey("timestamp")) {
976
- Long timestamp = null;
977
- try {
978
- String timestampString = map.getString("timestamp");
979
- timestamp = Long.valueOf(timestampString);
980
- builder.timestamp(timestamp);
981
- } catch (Exception ex) {
982
- Logger.warning("failed to convert \"timestamp\" value to Long");
983
- }
984
- }
985
- return builder.build();
986
- }
987
- }