react-native-hubspot-wrapper 0.5.0 → 0.5.1

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.
@@ -81,10 +81,8 @@ public class HubspotWrapperImpl: NSObject {
81
81
  }
82
82
  }
83
83
 
84
- /// Clear the SDK's in-memory identity/property state and synchronously wait for ALL
85
- /// HubSpot website data (cookies, localStorage, sessionStorage, IndexedDB, service
86
- /// workers, etc.) to be removed from the shared `WKWebsiteDataStore` before invoking
87
- /// `completion`.
84
+ /// Clear the SDK's in-memory identity/property state and synchronously wait for HubSpot's
85
+ /// visitor-identity cookies to be removed before invoking `completion`.
88
86
  ///
89
87
  /// Why we do our own clearing instead of relying on the SDK:
90
88
  ///
@@ -95,29 +93,29 @@ public class HubspotWrapperImpl: NSObject {
95
93
  /// races the still-in-flight cookie deletion, so the next chat session re-uses
96
94
  /// the previous visitor identity.
97
95
  ///
98
- /// 2. Even when the SDK's cookie deletion *does* finish, it only removes the two
99
- /// visitor-identity cookies (`hubspotutk`, `messagesUtk`). The chat widget also
100
- /// persists the unsent draft message and other state in `localStorage` /
101
- /// `sessionStorage` / `IndexedDB`. Cookie-only clearing leaves the draft visible
102
- /// on the next open, which is exactly the bug we kept seeing.
103
- ///
104
- /// We therefore remove all shared WebKit website data during logout. This is intentionally
105
- /// broader than HubSpot-only cleanup: fetching individual `WKWebsiteDataRecord`s crashed
106
- /// in production inside WebKit's `_fetchDataRecords...allDataStores` path.
96
+ /// Broader WebKit website-data cleanup is intentionally avoided here. Both
97
+ /// `dataRecords(ofTypes:)` and `removeData(ofTypes:modifiedSince:)` have crashed in
98
+ /// production inside WebKit's `allDataStores()` path on iOS 18 simulators.
107
99
  public func clearUserData(_ completion: @escaping () -> Void) {
108
100
  Task { @MainActor in
109
101
  HubspotManager.shared.clearUserData()
110
- await Self.deleteAllChatWebsiteData()
102
+ await Self.deleteHubspotIdentityCookies()
111
103
  completion()
112
104
  }
113
105
  }
114
106
 
115
- private static func deleteAllChatWebsiteData() async {
116
- let store = WKWebsiteDataStore.default()
117
- let allTypes = WKWebsiteDataStore.allWebsiteDataTypes()
118
- await store.removeData(ofTypes: allTypes, modifiedSince: .distantPast)
107
+ private static func deleteHubspotIdentityCookies() async {
108
+ let cookieStore = WKWebsiteDataStore.default().httpCookieStore
109
+ let matchingCookies = await cookieStore.allCookies().filter {
110
+ hubspotIdentityCookieNames.contains($0.name)
111
+ }
112
+ for cookie in matchingCookies {
113
+ await cookieStore.deleteCookie(cookie)
114
+ }
119
115
  }
120
116
 
117
+ private static let hubspotIdentityCookieNames = Set(["hubspotutk", "messagesUtk"])
118
+
121
119
  private static func topViewController(
122
120
  base: UIViewController? = UIApplication.shared.connectedScenes
123
121
  .compactMap { $0 as? UIWindowScene }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-hubspot-wrapper",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "TurboModule wrapper for HubSpot mobile chat SDK",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",