react-native-nitro-cookies 1.0.2 → 1.0.4

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.
@@ -20,6 +20,14 @@ Pod::Spec.new do |s|
20
20
  "cpp/**/*.{hpp,cpp}",
21
21
  ]
22
22
 
23
+ s.pod_target_xcconfig = {
24
+ "HEADER_SEARCH_PATHS" => [
25
+ "${PODS_ROOT}/RCT-Folly",
26
+ ],
27
+ "GCC_PREPROCESSOR_DEFINITIONS" => "$(inherited) FOLLY_NO_CONFIG FOLLY_CFG_NO_COROUTINES",
28
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
29
+ }
30
+
23
31
  s.dependency 'React-jsi'
24
32
  s.dependency 'React-callinvoker'
25
33
 
@@ -187,6 +187,45 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
187
187
  return url
188
188
  }
189
189
 
190
+ // MARK: - WebKit Main-Thread Helpers
191
+
192
+ /**
193
+ * Run a WKHTTPCookieStore operation on the main thread and return a result.
194
+ *
195
+ * All WKHTTPCookieStore interactions must happen on the main thread to avoid
196
+ * EXC_BREAKPOINT crashes in WebKit's non-thread-safe internal data structures.
197
+ */
198
+ @available(iOS 11.0, *)
199
+ private func withWebKitStore<T>(
200
+ _ operation: @escaping (WKHTTPCookieStore, @escaping (T) -> Void) -> Void
201
+ ) async -> T {
202
+ await withCheckedContinuation { continuation in
203
+ DispatchQueue.main.async {
204
+ let store = WKWebsiteDataStore.default().httpCookieStore
205
+ operation(store) { result in
206
+ continuation.resume(returning: result)
207
+ }
208
+ }
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Run a void WKHTTPCookieStore operation on the main thread.
214
+ */
215
+ @available(iOS 11.0, *)
216
+ private func withWebKitStoreVoid(
217
+ _ operation: @escaping (WKHTTPCookieStore, @escaping () -> Void) -> Void
218
+ ) async {
219
+ await withCheckedContinuation { (continuation: CheckedContinuation<Void, Never>) in
220
+ DispatchQueue.main.async {
221
+ let store = WKWebsiteDataStore.default().httpCookieStore
222
+ operation(store) {
223
+ continuation.resume(returning: ())
224
+ }
225
+ }
226
+ }
227
+ }
228
+
190
229
  // MARK: - Synchronous Cookie Operations
191
230
 
192
231
  /**
@@ -211,16 +250,7 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
211
250
  let url = try validateURL(urlString)
212
251
  try validateDomain(cookie: cookie, url: url)
213
252
 
214
- // Apply defaults
215
- var cookieWithDefaults = cookie
216
- if cookieWithDefaults.path == nil {
217
- cookieWithDefaults.path = "/"
218
- }
219
- if cookieWithDefaults.domain == nil {
220
- cookieWithDefaults.domain = url.host
221
- }
222
-
223
- let httpCookie = try makeHTTPCookie(from: cookieWithDefaults, url: url)
253
+ let httpCookie = try makeHTTPCookie(from: cookie, url: url)
224
254
  HTTPCookieStorage.shared.setCookie(httpCookie)
225
255
  return true
226
256
  }
@@ -271,32 +301,13 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
271
301
  let url = try self.validateURL(urlString)
272
302
  try self.validateDomain(cookie: cookie, url: url)
273
303
 
274
- // Apply defaults
275
- var cookieWithDefaults = cookie
276
- if cookieWithDefaults.path == nil {
277
- cookieWithDefaults.path = "/"
278
- }
279
- if cookieWithDefaults.domain == nil {
280
- cookieWithDefaults.domain = url.host
281
- }
282
-
283
- let httpCookie = try self.makeHTTPCookie(from: cookieWithDefaults, url: url)
304
+ let httpCookie = try self.makeHTTPCookie(from: cookie, url: url)
284
305
 
285
306
  if useWebKit == true {
286
307
  // Use WKHTTPCookieStore
287
308
  if #available(iOS 11.0, *) {
288
- // Accessing WKWebsiteDataStore.default() inside MainActor.run is necessary for iOS 11-12 compatibility,
289
- // since it is not marked @MainActor in those versions.
290
- // For iOS 13+, WKWebsiteDataStore.default() is already @MainActor, so wrapping in MainActor.run is redundant.
291
- // This workaround is safe for iOS 13+ and does not introduce any performance penalty or behavioral change,
292
- // as MainActor.run is a no-op when already on the main actor. This ensures compatibility across all supported iOS versions.
293
- let store = await MainActor.run {
294
- WKWebsiteDataStore.default().httpCookieStore
295
- }
296
- await withCheckedContinuation { continuation in
297
- store.setCookie(httpCookie) {
298
- continuation.resume(returning: ())
299
- }
309
+ await self.withWebKitStoreVoid { store, done in
310
+ store.setCookie(httpCookie) { done() }
300
311
  }
301
312
  return true
302
313
  } else {
@@ -321,13 +332,8 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
321
332
 
322
333
  if useWebKit == true {
323
334
  if #available(iOS 11.0, *) {
324
- let store = await MainActor.run {
325
- WKWebsiteDataStore.default().httpCookieStore
326
- }
327
- let httpCookies = await withCheckedContinuation { continuation in
328
- store.getAllCookies { cookies in
329
- continuation.resume(returning: cookies)
330
- }
335
+ let httpCookies: [HTTPCookie] = await self.withWebKitStore { store, done in
336
+ store.getAllCookies { cookies in done(cookies) }
331
337
  }
332
338
  let filteredCookies = httpCookies.filter { cookie in
333
339
  self.isMatchingDomain(cookieDomain: cookie.domain,
@@ -357,20 +363,16 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
357
363
  return Promise.async {
358
364
  if useWebKit == true {
359
365
  if #available(iOS 11.0, *) {
360
- let store = await MainActor.run {
361
- WKWebsiteDataStore.default().httpCookieStore
362
- }
363
- let cookies = await withCheckedContinuation { continuation in
364
- store.getAllCookies { cookies in
365
- continuation.resume(returning: cookies)
366
- }
366
+ let cookies: [HTTPCookie] = await self.withWebKitStore { store, done in
367
+ store.getAllCookies { cookies in done(cookies) }
367
368
  }
368
- for cookie in cookies {
369
- await withCheckedContinuation { continuation in
370
- store.delete(cookie) {
371
- continuation.resume(returning: ())
372
- }
369
+ await self.withWebKitStoreVoid { store, done in
370
+ let group = DispatchGroup()
371
+ for cookie in cookies {
372
+ group.enter()
373
+ store.delete(cookie) { group.leave() }
373
374
  }
375
+ group.notify(queue: .main) { done() }
374
376
  }
375
377
  return true
376
378
  } else {
@@ -434,13 +436,8 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
434
436
  return Promise.async {
435
437
  if useWebKit == true {
436
438
  if #available(iOS 11.0, *) {
437
- let store = await MainActor.run {
438
- WKWebsiteDataStore.default().httpCookieStore
439
- }
440
- let cookies = await withCheckedContinuation { continuation in
441
- store.getAllCookies { cookies in
442
- continuation.resume(returning: cookies)
443
- }
439
+ let cookies: [HTTPCookie] = await self.withWebKitStore { store, done in
440
+ store.getAllCookies { cookies in done(cookies) }
444
441
  }
445
442
  return cookies.map { self.createCookieData(from: $0) }
446
443
  } else {
@@ -464,13 +461,8 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
464
461
 
465
462
  if useWebKit == true {
466
463
  if #available(iOS 11.0, *) {
467
- let store = await MainActor.run {
468
- WKWebsiteDataStore.default().httpCookieStore
469
- }
470
- let cookies = await withCheckedContinuation { continuation in
471
- store.getAllCookies { cookies in
472
- continuation.resume(returning: cookies)
473
- }
464
+ let cookies: [HTTPCookie] = await self.withWebKitStore { store, done in
465
+ store.getAllCookies { cookies in done(cookies) }
474
466
  }
475
467
  let matchingCookie = cookies.first { cookie in
476
468
  cookie.name == name &&
@@ -479,10 +471,8 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
479
471
  }
480
472
 
481
473
  if let cookie = matchingCookie {
482
- await withCheckedContinuation { continuation in
483
- store.delete(cookie) {
484
- continuation.resume(returning: ())
485
- }
474
+ await self.withWebKitStoreVoid { store, done in
475
+ store.delete(cookie) { done() }
486
476
  }
487
477
  return true
488
478
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-cookies",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Fetch, Get Cookies 🍪 at the Speed of Nitro",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",