@capillarytech/react-native-hydra-lib 1.7.0-beta.1 → 1.7.0-beta.10

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 (153) hide show
  1. package/android/build.gradle +12 -13
  2. package/android/src/main/java/com/hydralib/delegates/NonHydraNotificationActivity.kt +22 -10
  3. package/android/src/main/java/com/hydralib/eventemitter/HydraEventEmitter.kt +34 -4
  4. package/android/src/main/java/com/hydralib/eventemitter/HydraEventType.kt +5 -1
  5. package/android/src/main/java/com/hydralib/gamification/GamificationBannerViewManager.kt +34 -3
  6. package/android/src/main/java/com/hydralib/gamification/GamificationEmbedViewManager.kt +25 -4
  7. package/android/src/main/java/com/hydralib/gamification/GamificationLoyaltyViewManager.kt +41 -6
  8. package/android/src/main/java/com/hydralib/hydrasdk/HydraCore.kt +109 -6
  9. package/android/src/main/java/com/hydralib/hydrasdk/HydraInAppMessages.kt +68 -41
  10. package/android/src/main/java/com/hydralib/hydrasdk/HydraInbox.kt +2 -2
  11. package/android/src/main/java/com/hydralib/hydrasdk/HydraPushNotification.kt +29 -1
  12. package/android/src/newarch/HydraLibModule.kt +16 -0
  13. package/android/src/oldarch/HydraLibModule.kt +20 -0
  14. package/ios/Delegates/HydraApplicationDelegate.swift +8 -0
  15. package/ios/EventEmitter/HydraEventType.swift +2 -0
  16. package/ios/GamificationViews/GamificationBannerViewComponentView.mm +43 -6
  17. package/ios/GamificationViews/GamificationEmbedViewComponentView.mm +37 -6
  18. package/ios/GamificationViews/GamificationLoyaltyViewComponentView.mm +45 -5
  19. package/ios/HydraLib.h +3 -4
  20. package/ios/HydraLib.mm +16 -0
  21. package/ios/HydraSDK/HydraInAppMessages.swift +35 -8
  22. package/ios/HydraSDK/HydraInbox.swift +36 -9
  23. package/ios/HydraSDK/HydraInboxUI.swift +5 -1
  24. package/ios/HydraSDK/HydraPushNotification.swift +2 -2
  25. package/ios/HydraSDK/HydraSDKCore.swift +185 -82
  26. package/ios/Utils/HydraExtensions.swift +1 -1
  27. package/lib/commonjs/GamificationBannerViewNativeComponent.ts +10 -0
  28. package/lib/commonjs/GamificationEmbedViewNativeComponent.ts +10 -0
  29. package/lib/commonjs/GamificationLoyaltyViewNativeComponent.ts +10 -0
  30. package/lib/commonjs/NativeHydraLib.ts +85 -0
  31. package/lib/commonjs/components/GamificationBannerView.js +1 -1
  32. package/lib/commonjs/components/GamificationEmbedView.js +1 -1
  33. package/lib/commonjs/components/GamificationLoyaltyView.js +1 -1
  34. package/lib/commonjs/hydra-apis/Hydra.js +14 -1
  35. package/lib/commonjs/hydra-apis/Hydra.js.map +1 -1
  36. package/lib/commonjs/hydra-apis/HydraCore.js +1 -1
  37. package/lib/commonjs/hydra-apis/HydraInAppMessaging.js +1 -1
  38. package/lib/commonjs/hydra-apis/HydraInbox.js +1 -1
  39. package/lib/commonjs/hydra-apis/HydraInboxUI.js +1 -1
  40. package/lib/commonjs/hydra-apis/HydraNativeEventEmitter.js +11 -1
  41. package/lib/commonjs/hydra-apis/HydraNativeEventEmitter.js.map +1 -1
  42. package/lib/commonjs/hydra-apis/HydraPushNotification.js +1 -1
  43. package/lib/commonjs/index.js +7 -0
  44. package/lib/commonjs/index.js.map +1 -1
  45. package/lib/commonjs/models/HydraNativeEvent.js +2 -0
  46. package/lib/commonjs/models/HydraNativeEvent.js.map +1 -1
  47. package/lib/commonjs/models/ThemeMode.js +14 -0
  48. package/lib/commonjs/models/ThemeMode.js.map +1 -0
  49. package/lib/module/GamificationBannerViewNativeComponent.ts +10 -0
  50. package/lib/module/GamificationEmbedViewNativeComponent.ts +10 -0
  51. package/lib/module/GamificationLoyaltyViewNativeComponent.ts +10 -0
  52. package/lib/module/NativeHydraLib.ts +85 -0
  53. package/lib/module/components/GamificationBannerView.js +1 -1
  54. package/lib/module/components/GamificationEmbedView.js +1 -1
  55. package/lib/module/components/GamificationLoyaltyView.js +1 -1
  56. package/lib/module/hydra-apis/Hydra.js +14 -1
  57. package/lib/module/hydra-apis/Hydra.js.map +1 -1
  58. package/lib/module/hydra-apis/HydraCore.js +1 -1
  59. package/lib/module/hydra-apis/HydraInAppMessaging.js +1 -1
  60. package/lib/module/hydra-apis/HydraInbox.js +1 -1
  61. package/lib/module/hydra-apis/HydraInboxUI.js +1 -1
  62. package/lib/module/hydra-apis/HydraNativeEventEmitter.js +11 -1
  63. package/lib/module/hydra-apis/HydraNativeEventEmitter.js.map +1 -1
  64. package/lib/module/hydra-apis/HydraPushNotification.js +1 -1
  65. package/lib/module/index.js +2 -1
  66. package/lib/module/index.js.map +1 -1
  67. package/lib/module/models/HydraNativeEvent.js +2 -0
  68. package/lib/module/models/HydraNativeEvent.js.map +1 -1
  69. package/lib/module/models/ThemeMode.js +10 -0
  70. package/lib/module/models/ThemeMode.js.map +1 -0
  71. package/lib/typescript/commonjs/src/NativeHydraLib.d.ts +4 -0
  72. package/lib/typescript/commonjs/src/NativeHydraLib.d.ts.map +1 -1
  73. package/lib/typescript/commonjs/src/hydra-apis/Hydra.d.ts +5 -0
  74. package/lib/typescript/commonjs/src/hydra-apis/Hydra.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/src/hydra-apis/HydraNativeEventEmitter.d.ts +2 -0
  76. package/lib/typescript/commonjs/src/hydra-apis/HydraNativeEventEmitter.d.ts.map +1 -1
  77. package/lib/typescript/commonjs/src/index.d.ts +2 -1
  78. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/src/models/HydraNativeEvent.d.ts +3 -1
  80. package/lib/typescript/commonjs/src/models/HydraNativeEvent.d.ts.map +1 -1
  81. package/lib/typescript/commonjs/src/models/ThemeMode.d.ts +7 -0
  82. package/lib/typescript/commonjs/src/models/ThemeMode.d.ts.map +1 -0
  83. package/lib/typescript/module/src/NativeHydraLib.d.ts +4 -0
  84. package/lib/typescript/module/src/NativeHydraLib.d.ts.map +1 -1
  85. package/lib/typescript/module/src/hydra-apis/Hydra.d.ts +5 -0
  86. package/lib/typescript/module/src/hydra-apis/Hydra.d.ts.map +1 -1
  87. package/lib/typescript/module/src/hydra-apis/HydraNativeEventEmitter.d.ts +2 -0
  88. package/lib/typescript/module/src/hydra-apis/HydraNativeEventEmitter.d.ts.map +1 -1
  89. package/lib/typescript/module/src/index.d.ts +2 -1
  90. package/lib/typescript/module/src/index.d.ts.map +1 -1
  91. package/lib/typescript/module/src/models/HydraNativeEvent.d.ts +3 -1
  92. package/lib/typescript/module/src/models/HydraNativeEvent.d.ts.map +1 -1
  93. package/lib/typescript/module/src/models/ThemeMode.d.ts +7 -0
  94. package/lib/typescript/module/src/models/ThemeMode.d.ts.map +1 -0
  95. package/package.json +13 -4
  96. package/react-native-hydra-lib.podspec +9 -1
  97. package/react-native.config.js +9 -23
  98. package/sbom.spdx.json +4 -4
  99. package/scripts/HydraPods.rb +1 -1
  100. package/scripts/preserve-codegen-specs.js +117 -0
  101. package/src/NativeHydraLib.ts +4 -0
  102. package/src/hydra-apis/Hydra.ts +18 -0
  103. package/src/hydra-apis/HydraNativeEventEmitter.ts +20 -0
  104. package/src/index.tsx +2 -0
  105. package/src/models/HydraNativeEvent.ts +2 -0
  106. package/src/models/ThemeMode.ts +6 -0
  107. package/android/generated/java/com/hydralib/NativeHydraLibSpec.java +0 -185
  108. package/android/generated/jni/CMakeLists.txt +0 -36
  109. package/android/generated/jni/RNHydraLibSpec-generated.cpp +0 -248
  110. package/android/generated/jni/RNHydraLibSpec.h +0 -31
  111. package/android/generated/jni/react/renderer/components/RNHydraLibSpec/ComponentDescriptors.cpp +0 -24
  112. package/android/generated/jni/react/renderer/components/RNHydraLibSpec/ComponentDescriptors.h +0 -26
  113. package/android/generated/jni/react/renderer/components/RNHydraLibSpec/EventEmitters.cpp +0 -18
  114. package/android/generated/jni/react/renderer/components/RNHydraLibSpec/EventEmitters.h +0 -37
  115. package/android/generated/jni/react/renderer/components/RNHydraLibSpec/Props.cpp +0 -39
  116. package/android/generated/jni/react/renderer/components/RNHydraLibSpec/Props.h +0 -47
  117. package/android/generated/jni/react/renderer/components/RNHydraLibSpec/RNHydraLibSpecJSI-generated.cpp +0 -283
  118. package/android/generated/jni/react/renderer/components/RNHydraLibSpec/RNHydraLibSpecJSI.h +0 -395
  119. package/android/generated/jni/react/renderer/components/RNHydraLibSpec/ShadowNodes.cpp +0 -19
  120. package/android/generated/jni/react/renderer/components/RNHydraLibSpec/ShadowNodes.h +0 -54
  121. package/android/generated/jni/react/renderer/components/RNHydraLibSpec/States.cpp +0 -16
  122. package/android/generated/jni/react/renderer/components/RNHydraLibSpec/States.h +0 -53
  123. package/ios/generated/RNHydraLibSpec/ComponentDescriptors.cpp +0 -24
  124. package/ios/generated/RNHydraLibSpec/ComponentDescriptors.h +0 -26
  125. package/ios/generated/RNHydraLibSpec/EventEmitters.cpp +0 -18
  126. package/ios/generated/RNHydraLibSpec/EventEmitters.h +0 -37
  127. package/ios/generated/RNHydraLibSpec/Props.cpp +0 -39
  128. package/ios/generated/RNHydraLibSpec/Props.h +0 -47
  129. package/ios/generated/RNHydraLibSpec/RCTComponentViewHelpers.h +0 -28
  130. package/ios/generated/RNHydraLibSpec/RNHydraLibSpec-generated.mm +0 -291
  131. package/ios/generated/RNHydraLibSpec/RNHydraLibSpec.h +0 -167
  132. package/ios/generated/RNHydraLibSpec/ShadowNodes.cpp +0 -19
  133. package/ios/generated/RNHydraLibSpec/ShadowNodes.h +0 -54
  134. package/ios/generated/RNHydraLibSpec/States.cpp +0 -16
  135. package/ios/generated/RNHydraLibSpec/States.h +0 -53
  136. package/ios/generated/RNHydraLibSpecJSI-generated.cpp +0 -283
  137. package/ios/generated/RNHydraLibSpecJSI.h +0 -395
  138. package/lib/commonjs/GamificationBannerViewNativeComponent.js +0 -10
  139. package/lib/commonjs/GamificationBannerViewNativeComponent.js.map +0 -1
  140. package/lib/commonjs/GamificationEmbedViewNativeComponent.js +0 -10
  141. package/lib/commonjs/GamificationEmbedViewNativeComponent.js.map +0 -1
  142. package/lib/commonjs/GamificationLoyaltyViewNativeComponent.js +0 -10
  143. package/lib/commonjs/GamificationLoyaltyViewNativeComponent.js.map +0 -1
  144. package/lib/commonjs/NativeHydraLib.js +0 -11
  145. package/lib/commonjs/NativeHydraLib.js.map +0 -1
  146. package/lib/module/GamificationBannerViewNativeComponent.js +0 -5
  147. package/lib/module/GamificationBannerViewNativeComponent.js.map +0 -1
  148. package/lib/module/GamificationEmbedViewNativeComponent.js +0 -5
  149. package/lib/module/GamificationEmbedViewNativeComponent.js.map +0 -1
  150. package/lib/module/GamificationLoyaltyViewNativeComponent.js +0 -5
  151. package/lib/module/GamificationLoyaltyViewNativeComponent.js.map +0 -1
  152. package/lib/module/NativeHydraLib.js +0 -7
  153. package/lib/module/NativeHydraLib.js.map +0 -1
@@ -32,13 +32,18 @@ import React
32
32
  }
33
33
 
34
34
  @objc public func getInboxMessages(_ resolve : RCTPromiseResolveBlock?, reject : RCTPromiseRejectBlock? ){
35
- self.inboxCore?.getNotifications(){
35
+ guard let inboxCore = self.inboxCore else {
36
+ Logger.error("HydraInbox: getInboxMessages: inboxCore is nil, InboxCore not initialized")
37
+ reject?("Error", "InboxCore not initialized", nil)
38
+ return
39
+ }
40
+ inboxCore.getNotifications(){
36
41
  (rawNotifications) -> Void in
37
42
  let notifications = rawNotifications.map{$0.toDict()}
38
43
  resolve?(notifications)
39
44
  Logger.debug("HydraInbox: getInboxMessages: notifications = \(String(describing: notifications))")
40
45
  }
41
-
46
+
42
47
  }
43
48
 
44
49
  fileprivate func updateBadgeCount() {
@@ -49,15 +54,25 @@ import React
49
54
  }
50
55
 
51
56
  @objc public func getUnreadInboxMessagesCount(_ resolve : RCTPromiseResolveBlock?, reject : RCTPromiseRejectBlock? ){
52
- inboxCore?.getUnreadNotificationCount(){
57
+ guard let inboxCore = self.inboxCore else {
58
+ Logger.error("HydraInbox: getUnreadInboxMessagesCount: inboxCore is nil, InboxCore not initialized")
59
+ reject?("Error", "InboxCore not initialized", nil)
60
+ return
61
+ }
62
+ inboxCore.getUnreadNotificationCount(){
53
63
  (count) -> Void in
54
64
  resolve?(count)
55
65
  Logger.debug("HydraInbox: getUnreadInboxMessagesCount: count = \(count)")
56
66
  }
57
67
  }
58
-
68
+
59
69
  @objc public func deleteAllInboxMessages(_ resolve : RCTPromiseResolveBlock?, reject : RCTPromiseRejectBlock? ){
60
- inboxCore?.handleDeleteAllNotifications(){
70
+ guard let inboxCore = self.inboxCore else {
71
+ Logger.error("HydraInbox: deleteAllInboxMessages: inboxCore is nil, InboxCore not initialized")
72
+ reject?("Error", "InboxCore not initialized", nil)
73
+ return
74
+ }
75
+ inboxCore.handleDeleteAllNotifications(){
61
76
  (isDeleted) -> Void in
62
77
  if isDeleted {
63
78
  self.updateBadgeCount()
@@ -66,26 +81,38 @@ import React
66
81
  Logger.debug("HydraInbox: deleteAllInboxMessages: deleted = \(isDeleted)")
67
82
  }
68
83
  }
69
-
84
+
70
85
  @objc public func deleteInboxMessage(_ inboxMessage: [String: Any] ,resolve : RCTPromiseResolveBlock?, reject : RCTPromiseRejectBlock? ){
86
+ guard let inboxCore = self.inboxCore else {
87
+ Logger.error("HydraInbox: deleteInboxMessage: inboxCore is nil, InboxCore not initialized")
88
+ reject?("Error", "InboxCore not initialized", nil)
89
+ return
90
+ }
71
91
  let payload = HydraNotificationPayload.generate(from: inboxMessage)
72
- inboxCore?.handleNotification(notification: payload, action: .delete){
92
+ inboxCore.handleNotification(notification: payload, action: .delete){
73
93
  (isDeleted) -> Void in
74
94
  if isDeleted {
75
95
  self.updateBadgeCount()
76
96
  }
77
97
  resolve?(isDeleted)
98
+ Logger.debug("HydraInbox: deleteInboxMessage: deleted = \(isDeleted)")
78
99
  }
79
100
  }
80
-
101
+
81
102
  @objc public func markInboxMessageAsRead(_ inboxMessage: [String: Any] ,resolve : RCTPromiseResolveBlock?, reject : RCTPromiseRejectBlock? ){
103
+ guard let inboxCore = self.inboxCore else {
104
+ Logger.error("HydraInbox: markInboxMessageAsRead: inboxCore is nil, InboxCore not initialized")
105
+ reject?("Error", "InboxCore not initialized", nil)
106
+ return
107
+ }
82
108
  let payload = HydraNotificationPayload.generate(from: inboxMessage)
83
- inboxCore?.handleNotification(notification: payload, action: .read){
109
+ inboxCore.handleNotification(notification: payload, action: .read){
84
110
  (isRead) -> Void in
85
111
  if isRead {
86
112
  self.updateBadgeCount()
87
113
  }
88
114
  resolve?(isRead)
115
+ Logger.debug("HydraInbox: markInboxMessageAsRead: read = \(isRead)")
89
116
  }
90
117
  }
91
118
  }
@@ -72,13 +72,17 @@ import React
72
72
  @objc public func showNotificationCenter(_ resolve : RCTPromiseResolveBlock?, reject : RCTPromiseRejectBlock? ){
73
73
  if self.inboxUICore != nil{
74
74
  DispatchQueue.main.async{
75
- guard let notificationCenter = self.inboxUICore?.getNotificationCenter() else { return}
75
+ guard let notificationCenter = self.inboxUICore?.getNotificationCenter() else {
76
+ Logger.error("HydraInboxUI: showNotificationCenter: getNotificationCenter() returned nil, cannot push notification center")
77
+ return
78
+ }
76
79
  self.navigationController?.pushViewController(notificationCenter, animated: true)
77
80
  self.hydraNotificationController = notificationCenter
78
81
  }
79
82
  resolve?(true)
80
83
  return
81
84
  }
85
+ Logger.error("HydraInboxUI: showNotificationCenter: inboxUICore is nil, InboxUI not initialized")
82
86
  resolve?(false)
83
87
  }
84
88
 
@@ -61,7 +61,7 @@ import HydraInAppMessage
61
61
 
62
62
  @objc public func getFCMToken(_ resolve : RCTPromiseResolveBlock?, reject : RCTPromiseRejectBlock? ){
63
63
  guard fcmToken != nil else{
64
- Logger.debug("HydraPushNotification: getFCMToken: Did not receive the token yet")
64
+ Logger.error("HydraPushNotification: getFCMToken: Did not receive the token yet")
65
65
  reject?( "TOKEN_NOT_AVAILABLE", "Did not receive the token yet", nil)
66
66
  return
67
67
  }
@@ -234,7 +234,7 @@ import HydraInAppMessage
234
234
  }
235
235
 
236
236
  @objc public func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: any Error) {
237
- Logger.debug("HydraPushNotification: application:didFailToRegisterForRemoteNotificationsWithError error = \(error.localizedDescription)")
237
+ Logger.error("HydraPushNotification: application:didFailToRegisterForRemoteNotificationsWithError error = \(error.localizedDescription)")
238
238
  // if HydraSDKCore.shared.hydra == nil{
239
239
  // DispatchQueue.main.asyncAfter(deadline: .now() + 0.3){
240
240
  // self.application(application, didFailToRegisterForRemoteNotificationsWithError: error)
@@ -18,7 +18,7 @@ import FirebaseRemoteConfig
18
18
  }
19
19
 
20
20
  public func gamificationDidFail(_ error: any Error) {
21
- Logger.debug("gamificationDidFail \(error)")
21
+ Logger.error("gamificationDidFail \(error)")
22
22
  }
23
23
 
24
24
  public func gamificationDidLoadEntryPoints(
@@ -40,6 +40,10 @@ import FirebaseRemoteConfig
40
40
  payload: [String : Any]
41
41
  ) {
42
42
  Logger.debug("gamificationDidEmitAnalyticsEvent \(name) \(payload)")
43
+ HydraEventEmitter.shared.sendEvent(
44
+ HydraEventType.ON_GAMIFICATION_ANALYTICS_EVENT.rawValue,
45
+ body: ["name": name, "payload": payload]
46
+ )
43
47
  }
44
48
 
45
49
  public func gamificationWidgetHeightChanged(
@@ -51,21 +55,55 @@ import FirebaseRemoteConfig
51
55
 
52
56
  public func gamificationRequestedDeeplink(_ url: String) {
53
57
  Logger.debug("gamificationRequestedDeeplink \(url)")
58
+ HydraEventEmitter.shared.sendEvent(
59
+ HydraEventType.ON_GAMIFICATION_DEEPLINK.rawValue,
60
+ body: url
61
+ )
54
62
  }
55
63
 
56
64
 
57
65
  @objc public static let shared = HydraSDKCore()
58
66
 
67
+ // Reads HydraConfig.plist ahead of Hydra initialization, for the flags that
68
+ // have to be known before initializeHydra runs. `context` only names the
69
+ // caller in the log lines.
70
+ private static func loadHydraConfigDict(context: String) -> [String : Any]? {
71
+ guard let path = Bundle.main.url(forResource: "HydraConfig", withExtension: "plist") else {
72
+ Logger.error("HydraSDKCore: \(context): HydraConfig.plist not found")
73
+ return nil
74
+ }
75
+ do {
76
+ let data = try Data(contentsOf: path)
77
+ guard let hydraConfigDict = try PropertyListSerialization.propertyList(from: data, options: .mutableContainers, format: nil) as? [String : Any] else {
78
+ Logger.error("HydraSDKCore: \(context): HydraConfig.plist did not parse to a dictionary")
79
+ return nil
80
+ }
81
+ return hydraConfigDict
82
+ } catch {
83
+ Logger.error("HydraSDKCore: \(context): Failed to read/parse HydraConfig.plist: \(error)")
84
+ return nil
85
+ }
86
+ }
87
+
59
88
  @objc public static func isPushNotificationEnabled() -> Bool {
60
- guard let path = Bundle.main.url(forResource: "HydraConfig", withExtension: "plist"),
61
- let data = try? Data(contentsOf: path),
62
- let hydraConfigDict = try? PropertyListSerialization.propertyList(from: data, options: .mutableContainers, format: nil) as? [String : Any]
63
- else {
89
+ guard let hydraConfigDict = loadHydraConfigDict(context: "isPushNotificationEnabled") else {
90
+ Logger.error("HydraSDKCore: isPushNotificationEnabled: defaulting to true")
64
91
  return true
65
92
  }
66
93
  return (hydraConfigDict["enable_push_notification"] as? Bool) ?? true
67
94
  }
68
95
 
96
+ // Must match the `enableInboxUI` flag read in createHydraInstance (same keys,
97
+ // same default) - the navigation controller setup in HydraApplicationDelegate
98
+ // is only needed when InboxUI will actually be initialized.
99
+ @objc public static func isInboxUIEnabled() -> Bool {
100
+ guard let hydraConfigDict = loadHydraConfigDict(context: "isInboxUIEnabled") else {
101
+ Logger.error("HydraSDKCore: isInboxUIEnabled: defaulting to false")
102
+ return false
103
+ }
104
+ return (hydraConfigDict["enable_inbox_ui"] as? Bool) ?? (hydraConfigDict["ENABLE_INBOX_UI"] as? Bool) ?? false
105
+ }
106
+
69
107
  var hydra : HydraCore.Hydra? = nil
70
108
  var lastUsedHydraConfig : HydraNativeRemoteConfig? = nil
71
109
  // Screen name queued before hydra was ready; replayed after init.
@@ -93,102 +131,119 @@ import FirebaseRemoteConfig
93
131
  }
94
132
 
95
133
  fileprivate func createHydraInstance(_ hydraRemoteConfig: HydraNativeRemoteConfig) {
96
- if let path = Bundle.main.url(forResource: "HydraConfig", withExtension: "plist"),
97
- let data = try? Data(contentsOf:path),
98
- let hydraConfigDict =
99
- try? PropertyListSerialization.propertyList(from: data, options: .mutableContainers, format: nil) as? [String : Any]{
100
-
101
- let accountId : String = hydraRemoteConfig.accountId
102
- let baseUrl : String = ensureTrailingSlash(ensureHttps(hydraRemoteConfig.baseUrl))
103
- let sslPublicKey: String = hydraRemoteConfig.sslPublicKey
104
- let remoteLogLevel : Int = hydraRemoteConfig.remoteLogLevel
105
- let orgId : String? = hydraRemoteConfig.orgId
106
-
107
-
108
- let supportsPushNotification : Bool = (hydraConfigDict["SUPPORTS_PUSH_NOTIFICATION"] as? Bool) ?? true
109
- let logLevelsDict : [String : Int] = (hydraConfigDict["LOG_LEVELS"] as? [String: Int]) ?? [:]
110
-
111
- let consoleLogLevel : Int = hydraConfigDict["console_log_level"] as? Int ?? logLevelsDict["CONSOLE"] ?? 1
112
- let enableInAppMessaging : Bool = (hydraConfigDict["enable_in_app_messaging"] as? Bool) ?? (hydraConfigDict["ENABLE_IN_APP_MESSAGING"] as? Bool) ?? false
113
- let enableSelfHandlingInInApp : Bool = (hydraConfigDict["enable_in_app_messaging_in_react_native"] as? Bool) ?? false
114
-
115
- let enableInboxAPI : Bool = (hydraConfigDict["enable_inbox_api"] as? Bool) ?? (hydraConfigDict["ENABLE_INBOX_API"] as? Bool) ?? false
116
- let enableInboxUI : Bool = (hydraConfigDict["enable_inbox_ui"] as? Bool) ?? (hydraConfigDict["ENABLE_INBOX_UI"] as? Bool) ?? false
117
-
118
- let useDefaultInboxUIConfig : Bool = (hydraConfigDict["use_default_inbox_ui_config"] as? Bool) ?? (hydraConfigDict["USE_DEFAULT_INBOX_UI_CONFIG"] as? Bool) ?? true
119
-
120
- let inboxUIConfigDict : [String : Any]? = !useDefaultInboxUIConfig ? hydraConfigDict["INBOX_UI_CONFIG"] as? [String : Any] : nil
121
-
122
- let maxNotificationCount = (hydraConfigDict["max_notification_count"] as? Int)
123
-
124
- Logger.updateLogLevel(level: getSdkLogLevel(debugLevel: consoleLogLevel), for: HydraLoggerType.console)
125
-
126
- do{
127
- Logger.debug("HydraLib: HydraCore.initializeHydra: Creating HydraConfiguration")
128
- let gamificationKey = hydraRemoteConfig.gamificationKey//"d01d1d13e6e5c8a8daaadbb8f96fa054379347e3"
129
- let gamificationRegion = hydraRemoteConfig.gamificationRegion
130
- let gamificationBaseUrl = hydraRemoteConfig.gamificationBaseUrl
131
- let config: HydraConfiguration = try HydraConfiguration(
132
- accountID: accountId,
133
- customerId: HydraCore.Hydra.getSharedUserDefaults()?.customerId() ?? "",
134
- server:
135
- .genericServer(baseUrl, sslPublicKey, [0,5,10,30,120]),
136
- orgID: orgId,
137
- gamificationWriteKey: gamificationKey,
138
- gamificationRegion: gamificationRegion,
139
- gamificationBaseURL: gamificationBaseUrl
140
- )
141
-
142
- Logger.debug("HydraLib: HydraCore.initializeHydra: Generating Hydra Instance")
143
- hydra = try HydraCore.Hydra.generate(
144
- with: config,
145
- supportsPushNotifications: supportsPushNotification,
146
- consoleLogLevel: getSdkLogLevel(debugLevel: consoleLogLevel),
147
- remoteLogLevel: getSdkLogLevel(debugLevel: remoteLogLevel)
148
- )
149
- hydra?.setGamificationDelegate(self)
150
- lastUsedHydraConfig = hydraRemoteConfig
151
- // Replay any gamification screen that was registered before SDK was ready.
152
- if let pending = pendingGamificationScreen {
153
- pendingGamificationScreen = nil
154
- DispatchQueue.main.async { [weak self] in
155
- self?.hydra?.gamificationScreenAppeared(pending)
156
- }
134
+ guard let path = Bundle.main.url(forResource: "HydraConfig", withExtension: "plist") else {
135
+ let errorMesssage = "HydraConfig.plist not found"
136
+ Logger.error("HydraLib: HydraCore.initializeHydra: Error initializing Hydra SDK: \(errorMesssage)")
137
+ sendHydraSdkInitializationResultEvent(false, errorMesssage)
138
+ return
139
+ }
140
+
141
+ let hydraConfigDict: [String: Any]
142
+ do {
143
+ let data = try Data(contentsOf: path)
144
+ guard let parsed = try PropertyListSerialization.propertyList(from: data, options: .mutableContainers, format: nil) as? [String : Any] else {
145
+ let errorMesssage = "HydraConfig.plist did not parse to a dictionary"
146
+ Logger.error("HydraLib: HydraCore.initializeHydra: Error initializing Hydra SDK: \(errorMesssage)")
147
+ sendHydraSdkInitializationResultEvent(false, errorMesssage)
148
+ return
149
+ }
150
+ hydraConfigDict = parsed
151
+ } catch {
152
+ let errorMesssage = "Failed to read HydraConfig.plist: \(error)"
153
+ Logger.error("HydraLib: HydraCore.initializeHydra: Error initializing Hydra SDK: \(errorMesssage)")
154
+ sendHydraSdkInitializationResultEvent(false, errorMesssage)
155
+ return
156
+ }
157
+
158
+ let accountId : String = hydraRemoteConfig.accountId
159
+ let baseUrl : String = ensureTrailingSlash(ensureHttps(hydraRemoteConfig.baseUrl))
160
+ let sslPublicKey: String = hydraRemoteConfig.sslPublicKey
161
+ let remoteLogLevel : Int = hydraRemoteConfig.remoteLogLevel
162
+ let orgId : String? = hydraRemoteConfig.orgId
163
+
164
+
165
+ let supportsPushNotification : Bool = (hydraConfigDict["SUPPORTS_PUSH_NOTIFICATION"] as? Bool) ?? true
166
+ let logLevelsDict : [String : Int] = (hydraConfigDict["LOG_LEVELS"] as? [String: Int]) ?? [:]
167
+
168
+ let consoleLogLevel : Int = hydraConfigDict["console_log_level"] as? Int ?? logLevelsDict["CONSOLE"] ?? 1
169
+ let enableInAppMessaging : Bool = (hydraConfigDict["enable_in_app_messaging"] as? Bool) ?? (hydraConfigDict["ENABLE_IN_APP_MESSAGING"] as? Bool) ?? false
170
+ let enableSelfHandlingInInApp : Bool = (hydraConfigDict["enable_in_app_messaging_in_react_native"] as? Bool) ?? false
171
+
172
+ let enableInboxAPI : Bool = (hydraConfigDict["enable_inbox_api"] as? Bool) ?? (hydraConfigDict["ENABLE_INBOX_API"] as? Bool) ?? false
173
+ let enableInboxUI : Bool = (hydraConfigDict["enable_inbox_ui"] as? Bool) ?? (hydraConfigDict["ENABLE_INBOX_UI"] as? Bool) ?? false
174
+
175
+ let useDefaultInboxUIConfig : Bool = (hydraConfigDict["use_default_inbox_ui_config"] as? Bool) ?? (hydraConfigDict["USE_DEFAULT_INBOX_UI_CONFIG"] as? Bool) ?? true
176
+
177
+ let inboxUIConfigDict : [String : Any]? = !useDefaultInboxUIConfig ? hydraConfigDict["INBOX_UI_CONFIG"] as? [String : Any] : nil
178
+
179
+ let maxNotificationCount = (hydraConfigDict["max_notification_count"] as? Int)
180
+
181
+ Logger.updateLogLevel(level: getSdkLogLevel(debugLevel: consoleLogLevel), for: HydraLoggerType.console)
182
+
183
+ do{
184
+ Logger.debug("HydraLib: HydraCore.initializeHydra: Creating HydraConfiguration")
185
+ let gamificationKey = hydraRemoteConfig.gamificationKey//"d01d1d13e6e5c8a8daaadbb8f96fa054379347e3"
186
+ let gamificationRegion = hydraRemoteConfig.gamificationRegion
187
+ let gamificationBaseUrl = hydraRemoteConfig.gamificationBaseUrl
188
+ let config: HydraConfiguration = try HydraConfiguration(
189
+ accountID: accountId,
190
+ customerId: HydraCore.Hydra.getSharedUserDefaults()?.customerId() ?? "",
191
+ server:
192
+ .genericServer(baseUrl, sslPublicKey, [0,5,10,30,120]),
193
+ orgID: orgId,
194
+ gamificationWriteKey: gamificationKey,
195
+ gamificationRegion: gamificationRegion,
196
+ gamificationBaseURL: gamificationBaseUrl
197
+ )
198
+
199
+ Logger.debug("HydraLib: HydraCore.initializeHydra: Generating Hydra Instance")
200
+ hydra = try HydraCore.Hydra.generate(
201
+ with: config,
202
+ supportsPushNotifications: supportsPushNotification,
203
+ consoleLogLevel: getSdkLogLevel(debugLevel: consoleLogLevel),
204
+ remoteLogLevel: getSdkLogLevel(debugLevel: remoteLogLevel)
205
+ )
206
+ hydra?.setGamificationDelegate(self)
207
+ lastUsedHydraConfig = hydraRemoteConfig
208
+ // Replay any gamification screen that was registered before SDK was ready.
209
+ if let pending = pendingGamificationScreen {
210
+ pendingGamificationScreen = nil
211
+ DispatchQueue.main.async { [weak self] in
212
+ self?.hydra?.gamificationScreenAppeared(pending)
157
213
  }
158
-
159
- NotificationCore.shared.update(sdk: hydra!)
160
-
161
- HydraPushNotification.shared.forceUpdateFcmToken()
162
- Task{
214
+ }
215
+
216
+ NotificationCore.shared.update(sdk: hydra!)
217
+
218
+ HydraPushNotification.shared.forceUpdateFcmToken()
219
+ Task{
220
+ do {
163
221
  try await Task.sleep(seconds: 1)
164
222
  try await MainActor.run {
165
223
  if enableInAppMessaging{
166
224
  Logger.debug("HydraLib: HydraCore.initializeHydra: Initializing InAppMessaging")
167
225
  try HydraInAppMessages.shared.initializeInAppMessagingCore(hydraConfig: config, selfHandlingEnabled: enableSelfHandlingInInApp)
168
226
  }
169
-
227
+
170
228
  if enableInboxAPI || enableInboxUI{
171
229
  Logger.debug("HydraLib: HydraCore.initializeHydra: Initializing InboxCore")
172
230
  try HydraInbox.shared.initializeInboxCore(hydraConfig: config, maxNotificationCount: maxNotificationCount)
173
231
  }
174
-
232
+
175
233
  if enableInboxUI{
176
234
  Logger.debug("HydraLib: HydraCore.initializeHydra: Initializing InboxUI")
177
235
  HydraInboxUI.shared.initializeInboxUICore(inboxUIConfigDict: inboxUIConfigDict)
178
236
  }
179
237
  }
238
+ } catch {
239
+ Logger.error("HydraLib: HydraCore.initializeHydra: Failed to initialize InApp/Inbox/InboxUI: \(error)")
180
240
  }
181
-
182
- }
183
- catch{
184
- let errorMesssage = "Error initializing Hydra SDK"
185
- Logger.error("HydraLib: HydraCore.initializeHydra: \(errorMesssage)")
186
- sendHydraSdkInitializationResultEvent(false, errorMesssage)
187
241
  }
242
+
188
243
  }
189
- else{
190
- let errorMesssage = "HydraConfig.plist not found"
191
- Logger.error("HydraLib: HydraCore.initializeHydra: Error initializing Hydra SDK: \(errorMesssage)")
244
+ catch{
245
+ let errorMesssage = "Error initializing Hydra SDK: \(error)"
246
+ Logger.error("HydraLib: HydraCore.initializeHydra: \(errorMesssage)")
192
247
  sendHydraSdkInitializationResultEvent(false, errorMesssage)
193
248
  }
194
249
  }
@@ -693,6 +748,54 @@ import FirebaseRemoteConfig
693
748
  resolve?(nil)
694
749
  }
695
750
 
751
+ @objc public func setGamificationSuppressed(_ suppressed: Bool, resolve: RCTPromiseResolveBlock?, reject: RCTPromiseRejectBlock?) {
752
+ guard let hydra = hydra else {
753
+ Logger.error("HydraCore: setGamificationSuppressed: hydra instance not initialized")
754
+ reject?("Error setting gamification suppressed", "Hydra instance not initialized", getHydraNotFoundError())
755
+ return
756
+ }
757
+
758
+ hydra.setGamificationSuppressed(suppressed)
759
+ resolve?(nil)
760
+ }
761
+
762
+ @objc public func isGamificationSuppressed(_ resolve: RCTPromiseResolveBlock?, reject: RCTPromiseRejectBlock?) {
763
+ guard let hydra = hydra else {
764
+ Logger.error("HydraCore: isGamificationSuppressed: hydra instance not initialized")
765
+ reject?("Error reading gamification suppressed", "Hydra instance not initialized", getHydraNotFoundError())
766
+ return
767
+ }
768
+
769
+ resolve?(hydra.isGamificationSuppressed())
770
+ }
771
+
772
+ @objc public func setThemeMode(_ mode: String, resolve: RCTPromiseResolveBlock?, reject: RCTPromiseRejectBlock?) {
773
+ guard let hydra = hydra else {
774
+ Logger.error("HydraCore: setThemeMode: hydra instance not initialized")
775
+ reject?("Error setting theme mode", "Hydra instance not initialized", getHydraNotFoundError())
776
+ return
777
+ }
778
+
779
+ guard let themeMode = ThemeMode(rawValue: mode.lowercased()) else {
780
+ Logger.error("HydraCore: setThemeMode: invalid theme mode \(mode)")
781
+ reject?("Error setting theme mode", "Invalid theme mode: \(mode)", nil)
782
+ return
783
+ }
784
+
785
+ hydra.setThemeMode(themeMode)
786
+ resolve?(nil)
787
+ }
788
+
789
+ @objc public func getThemeMode(_ resolve: RCTPromiseResolveBlock?, reject: RCTPromiseRejectBlock?) {
790
+ guard let hydra = hydra else {
791
+ Logger.error("HydraCore: getThemeMode: hydra instance not initialized")
792
+ reject?("Error reading theme mode", "Hydra instance not initialized", getHydraNotFoundError())
793
+ return
794
+ }
795
+
796
+ resolve?(hydra.getThemeMode().rawValue.uppercased())
797
+ }
798
+
696
799
  @objc public func logError(errorMsg : String){
697
800
  Logger.error(errorMsg)
698
801
  }
@@ -215,7 +215,7 @@ extension Dictionary<String, Any>{
215
215
  let data = try JSONSerialization.data(withJSONObject: self, options: [.prettyPrinted])
216
216
  return String(data: data, encoding: .utf8)
217
217
  } catch {
218
- print("Error serializing JSON:", error)
218
+ Logger.error("HydraExtensions: toJsonString: Error serializing JSON: \(error)")
219
219
  return nil
220
220
  }
221
221
  }
@@ -0,0 +1,10 @@
1
+ import type { HostComponent, ViewProps } from 'react-native';
2
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
3
+
4
+ export interface NativeProps extends ViewProps {
5
+ bannerId: string;
6
+ }
7
+
8
+ export default codegenNativeComponent<NativeProps>(
9
+ 'GamificationBannerView'
10
+ ) as HostComponent<NativeProps>;
@@ -0,0 +1,10 @@
1
+ import type { HostComponent, ViewProps } from 'react-native';
2
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
3
+
4
+ export interface NativeProps extends ViewProps {
5
+ embedId: string;
6
+ }
7
+
8
+ export default codegenNativeComponent<NativeProps>(
9
+ 'GamificationEmbedView'
10
+ ) as HostComponent<NativeProps>;
@@ -0,0 +1,10 @@
1
+ import type { HostComponent, ViewProps } from 'react-native';
2
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
3
+
4
+ export interface NativeProps extends ViewProps {
5
+ loyaltyId: string;
6
+ }
7
+
8
+ export default codegenNativeComponent<NativeProps>(
9
+ 'GamificationLoyaltyView'
10
+ ) as HostComponent<NativeProps>;
@@ -0,0 +1,85 @@
1
+ import type { TurboModule } from 'react-native';
2
+ import { NativeModules, TurboModuleRegistry } from 'react-native';
3
+
4
+ export interface Spec extends TurboModule {
5
+ //HydraCore Methods
6
+ setHydraAccountConfig(hydraAccountConfig: Object): Promise<boolean>;
7
+ setFirebaseRemoteConfigKeys(remoteConfigKeys: Object): Promise<boolean>;
8
+ updateGeoConfig(geoConfig: Object): Promise<boolean>;
9
+ signUp(userDetails: Object, customData: Object | null): Promise<boolean>;
10
+ signIn(userDetails: Object, customData: Object | null): Promise<boolean>;
11
+ updateUser(
12
+ userDetails: Object,
13
+ customData: Object | null,
14
+ subscriptions: Object[] | null
15
+ ): Promise<boolean>;
16
+ signOut(customerId: string): Promise<boolean>;
17
+ updatePushPreferences(
18
+ customerId: string,
19
+ preferences: Object
20
+ ): Promise<boolean>;
21
+ reportUserEvent(
22
+ eventName: string,
23
+ attributes: Object | null
24
+ ): Promise<boolean>;
25
+ isSdkInitialized(): Promise<boolean>;
26
+ getCurrentUserState(): Promise<string | null>;
27
+ getVisitorDetails(): Promise<Object | null>;
28
+ isVisitorFlowEnabled(): Promise<boolean>;
29
+
30
+ //Gamification Methods
31
+ gamificationScreenAppeared(screenName: string): Promise<void>;
32
+ gamificationScreenDisappeared(screenName: string): Promise<void>;
33
+ setCapToken(token: string): Promise<void>;
34
+ setGamificationSuppressed(suppressed: boolean): Promise<void>;
35
+ isGamificationSuppressed(): Promise<boolean>;
36
+ setThemeMode(mode: string): Promise<void>;
37
+ getThemeMode(): Promise<string>;
38
+ //Hydra Methods
39
+ identify(userDetails: Object, customData: Object | null): Promise<boolean>;
40
+ track(eventName: string, attributes: Object | null): Promise<boolean>;
41
+ reset(customerId: string): Promise<boolean>;
42
+
43
+ //HydraPushNotification Methods
44
+ openExternalUrl(url: string): Promise<void>;
45
+ getFCMToken(): Promise<string>;
46
+ requestPermission(): Promise<boolean>;
47
+
48
+ //HydraInboxUI Methods
49
+ showNotificationCenter(): Promise<void>;
50
+ hideNotificationCenterIfShowing(): Promise<void>;
51
+
52
+ //HydraInbox Methods
53
+ getInboxMessages(): Promise<Object[]>;
54
+ getUnreadInboxMessagesCount(): Promise<number>;
55
+ markInboxMessageAsRead(inboxMessage: Object): Promise<boolean>;
56
+ deleteInboxMessage(inboxMessage: Object): Promise<boolean>;
57
+ deleteAllInboxMessages(): Promise<boolean>;
58
+
59
+ //HydraInAppMessage Methods
60
+ selfHandledInAppResponse(message: Object, handled: boolean): Promise<void>;
61
+ reportMessageClicked(message: Object): Promise<void>;
62
+ reportMessageRating(message: Object, rating: number): Promise<void>;
63
+ reportMessageFeedback(
64
+ message: Object,
65
+ feedback: string,
66
+ feedbackOptions: number[]
67
+ ): Promise<void>;
68
+ reportMessageDismissed(message: Object): Promise<void>;
69
+ //HydraNativeEventEmitter Methods
70
+ addListener(eventName: string): void;
71
+ removeListener(eventName: string): void;
72
+ removeListeners(count: number): void;
73
+ }
74
+
75
+ declare global {
76
+ var __turboModuleProxy: any;
77
+ }
78
+
79
+ const isTurboModuleEnabled = global.__turboModuleProxy != null;
80
+
81
+ const NativeHydraLib: Spec = isTurboModuleEnabled
82
+ ? TurboModuleRegistry.getEnforcing<Spec>('HydraLib')
83
+ : NativeModules.HydraLib;
84
+
85
+ export default NativeHydraLib;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.GamificationBannerView = GamificationBannerView;
7
- var _GamificationBannerViewNativeComponent = _interopRequireDefault(require("../GamificationBannerViewNativeComponent.js"));
7
+ var _GamificationBannerViewNativeComponent = _interopRequireDefault(require("../GamificationBannerViewNativeComponent.ts"));
8
8
  var _jsxRuntime = require("react/jsx-runtime");
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
10
  function GamificationBannerView(props) {
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.GamificationEmbedView = GamificationEmbedView;
7
- var _GamificationEmbedViewNativeComponent = _interopRequireDefault(require("../GamificationEmbedViewNativeComponent.js"));
7
+ var _GamificationEmbedViewNativeComponent = _interopRequireDefault(require("../GamificationEmbedViewNativeComponent.ts"));
8
8
  var _jsxRuntime = require("react/jsx-runtime");
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
10
  function GamificationEmbedView(props) {
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.GamificationLoyaltyView = GamificationLoyaltyView;
7
- var _GamificationLoyaltyViewNativeComponent = _interopRequireDefault(require("../GamificationLoyaltyViewNativeComponent.js"));
7
+ var _GamificationLoyaltyViewNativeComponent = _interopRequireDefault(require("../GamificationLoyaltyViewNativeComponent.ts"));
8
8
  var _jsxRuntime = require("react/jsx-runtime");
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
10
  function GamificationLoyaltyView(props) {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.Hydra = void 0;
7
7
  var _HydraVisitorInfo = require("../models/HydraVisitorInfo.js");
8
8
  var _UserState = require("../models/UserState.js");
9
- var _NativeHydraLib = _interopRequireDefault(require("../NativeHydraLib.js"));
9
+ var _NativeHydraLib = _interopRequireDefault(require("../NativeHydraLib.ts"));
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  class Hydra {
12
12
  static identify(userDetails, customAttributes = null) {
@@ -38,6 +38,19 @@ class Hydra {
38
38
  static setCapToken(token) {
39
39
  return _NativeHydraLib.default.setCapToken(token);
40
40
  }
41
+ static setGamificationSuppressed(suppressed) {
42
+ return _NativeHydraLib.default.setGamificationSuppressed(suppressed);
43
+ }
44
+ static isGamificationSuppressed() {
45
+ return _NativeHydraLib.default.isGamificationSuppressed();
46
+ }
47
+ static setThemeMode(mode) {
48
+ return _NativeHydraLib.default.setThemeMode(mode);
49
+ }
50
+ static async getThemeMode() {
51
+ const mode = await _NativeHydraLib.default.getThemeMode();
52
+ return mode;
53
+ }
41
54
  }
42
55
  exports.Hydra = Hydra;
43
56
  //# sourceMappingURL=Hydra.js.map