react-native-nitro-cookies 1.0.4 → 1.2.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.
- package/android/src/main/cpp/cpp-adapter.cpp +4 -1
- package/android/src/main/java/com/margelo/nitro/nitrocookies/NitroCookies.kt +69 -0
- package/ios/NitroCookies.swift +101 -0
- package/lib/module/index.js +96 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NitroCookies.nitro.d.ts +48 -0
- package/lib/typescript/src/NitroCookies.nitro.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +88 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JCookie.hpp +1 -1
- package/nitrogen/generated/android/c++/JHybridNitroCookiesSpec.cpp +107 -53
- package/nitrogen/generated/android/c++/JHybridNitroCookiesSpec.hpp +23 -22
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocookies/Cookie.kt +27 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocookies/HybridNitroCookiesSpec.kt +31 -18
- package/nitrogen/generated/android/nitrocookiesOnLoad.cpp +26 -16
- package/nitrogen/generated/android/nitrocookiesOnLoad.hpp +13 -4
- package/nitrogen/generated/ios/NitroCookies+autolinking.rb +2 -0
- package/nitrogen/generated/ios/NitroCookies-Swift-Cxx-Bridge.cpp +8 -0
- package/nitrogen/generated/ios/NitroCookies-Swift-Cxx-Bridge.hpp +52 -0
- package/nitrogen/generated/ios/c++/HybridNitroCookiesSpecSwift.hpp +32 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridNitroCookiesSpec.swift +4 -0
- package/nitrogen/generated/ios/swift/HybridNitroCookiesSpec_cxx.swift +76 -0
- package/nitrogen/generated/shared/c++/HybridNitroCookiesSpec.cpp +4 -0
- package/nitrogen/generated/shared/c++/HybridNitroCookiesSpec.hpp +4 -0
- package/package.json +9 -8
- package/src/NitroCookies.nitro.ts +56 -0
- package/src/index.tsx +104 -0
|
@@ -133,6 +133,40 @@ namespace margelo::nitro::nitrocookies::bridge::swift {
|
|
|
133
133
|
return Func_void_std__exception_ptr_Wrapper(std::move(value));
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
// pragma MARK: std::shared_ptr<Promise<std::string>>
|
|
137
|
+
/**
|
|
138
|
+
* Specialized version of `std::shared_ptr<Promise<std::string>>`.
|
|
139
|
+
*/
|
|
140
|
+
using std__shared_ptr_Promise_std__string__ = std::shared_ptr<Promise<std::string>>;
|
|
141
|
+
inline std::shared_ptr<Promise<std::string>> create_std__shared_ptr_Promise_std__string__() noexcept {
|
|
142
|
+
return Promise<std::string>::create();
|
|
143
|
+
}
|
|
144
|
+
inline PromiseHolder<std::string> wrap_std__shared_ptr_Promise_std__string__(std::shared_ptr<Promise<std::string>> promise) noexcept {
|
|
145
|
+
return PromiseHolder<std::string>(std::move(promise));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// pragma MARK: std::function<void(const std::string& /* result */)>
|
|
149
|
+
/**
|
|
150
|
+
* Specialized version of `std::function<void(const std::string&)>`.
|
|
151
|
+
*/
|
|
152
|
+
using Func_void_std__string = std::function<void(const std::string& /* result */)>;
|
|
153
|
+
/**
|
|
154
|
+
* Wrapper class for a `std::function<void(const std::string& / * result * /)>`, this can be used from Swift.
|
|
155
|
+
*/
|
|
156
|
+
class Func_void_std__string_Wrapper final {
|
|
157
|
+
public:
|
|
158
|
+
explicit Func_void_std__string_Wrapper(std::function<void(const std::string& /* result */)>&& func): _function(std::make_unique<std::function<void(const std::string& /* result */)>>(std::move(func))) {}
|
|
159
|
+
inline void call(std::string result) const noexcept {
|
|
160
|
+
_function->operator()(result);
|
|
161
|
+
}
|
|
162
|
+
private:
|
|
163
|
+
std::unique_ptr<std::function<void(const std::string& /* result */)>> _function;
|
|
164
|
+
} SWIFT_NONCOPYABLE;
|
|
165
|
+
Func_void_std__string create_Func_void_std__string(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
166
|
+
inline Func_void_std__string_Wrapper wrap_Func_void_std__string(Func_void_std__string value) noexcept {
|
|
167
|
+
return Func_void_std__string_Wrapper(std::move(value));
|
|
168
|
+
}
|
|
169
|
+
|
|
136
170
|
// pragma MARK: std::shared_ptr<Promise<std::vector<Cookie>>>
|
|
137
171
|
/**
|
|
138
172
|
* Specialized version of `std::shared_ptr<Promise<std::vector<Cookie>>>`.
|
|
@@ -231,6 +265,15 @@ namespace margelo::nitro::nitrocookies::bridge::swift {
|
|
|
231
265
|
return Result<bool>::withError(error);
|
|
232
266
|
}
|
|
233
267
|
|
|
268
|
+
// pragma MARK: Result<std::string>
|
|
269
|
+
using Result_std__string_ = Result<std::string>;
|
|
270
|
+
inline Result_std__string_ create_Result_std__string_(const std::string& value) noexcept {
|
|
271
|
+
return Result<std::string>::withValue(value);
|
|
272
|
+
}
|
|
273
|
+
inline Result_std__string_ create_Result_std__string_(const std::exception_ptr& error) noexcept {
|
|
274
|
+
return Result<std::string>::withError(error);
|
|
275
|
+
}
|
|
276
|
+
|
|
234
277
|
// pragma MARK: Result<std::shared_ptr<Promise<bool>>>
|
|
235
278
|
using Result_std__shared_ptr_Promise_bool___ = Result<std::shared_ptr<Promise<bool>>>;
|
|
236
279
|
inline Result_std__shared_ptr_Promise_bool___ create_Result_std__shared_ptr_Promise_bool___(const std::shared_ptr<Promise<bool>>& value) noexcept {
|
|
@@ -240,6 +283,15 @@ namespace margelo::nitro::nitrocookies::bridge::swift {
|
|
|
240
283
|
return Result<std::shared_ptr<Promise<bool>>>::withError(error);
|
|
241
284
|
}
|
|
242
285
|
|
|
286
|
+
// pragma MARK: Result<std::shared_ptr<Promise<std::string>>>
|
|
287
|
+
using Result_std__shared_ptr_Promise_std__string___ = Result<std::shared_ptr<Promise<std::string>>>;
|
|
288
|
+
inline Result_std__shared_ptr_Promise_std__string___ create_Result_std__shared_ptr_Promise_std__string___(const std::shared_ptr<Promise<std::string>>& value) noexcept {
|
|
289
|
+
return Result<std::shared_ptr<Promise<std::string>>>::withValue(value);
|
|
290
|
+
}
|
|
291
|
+
inline Result_std__shared_ptr_Promise_std__string___ create_Result_std__shared_ptr_Promise_std__string___(const std::exception_ptr& error) noexcept {
|
|
292
|
+
return Result<std::shared_ptr<Promise<std::string>>>::withError(error);
|
|
293
|
+
}
|
|
294
|
+
|
|
243
295
|
// pragma MARK: Result<std::shared_ptr<Promise<std::vector<Cookie>>>>
|
|
244
296
|
using Result_std__shared_ptr_Promise_std__vector_Cookie____ = Result<std::shared_ptr<Promise<std::vector<Cookie>>>>;
|
|
245
297
|
inline Result_std__shared_ptr_Promise_std__vector_Cookie____ create_Result_std__shared_ptr_Promise_std__vector_Cookie____(const std::shared_ptr<Promise<std::vector<Cookie>>>& value) noexcept {
|
|
@@ -103,6 +103,22 @@ namespace margelo::nitro::nitrocookies {
|
|
|
103
103
|
auto __value = std::move(__result.value());
|
|
104
104
|
return __value;
|
|
105
105
|
}
|
|
106
|
+
inline std::string getCookieHeaderSync(const std::string& url) override {
|
|
107
|
+
auto __result = _swiftPart.getCookieHeaderSync(url);
|
|
108
|
+
if (__result.hasError()) [[unlikely]] {
|
|
109
|
+
std::rethrow_exception(__result.error());
|
|
110
|
+
}
|
|
111
|
+
auto __value = std::move(__result.value());
|
|
112
|
+
return __value;
|
|
113
|
+
}
|
|
114
|
+
inline bool setManySync(const std::string& url, const std::vector<Cookie>& cookies) override {
|
|
115
|
+
auto __result = _swiftPart.setManySync(url, cookies);
|
|
116
|
+
if (__result.hasError()) [[unlikely]] {
|
|
117
|
+
std::rethrow_exception(__result.error());
|
|
118
|
+
}
|
|
119
|
+
auto __value = std::move(__result.value());
|
|
120
|
+
return __value;
|
|
121
|
+
}
|
|
106
122
|
inline std::shared_ptr<Promise<bool>> set(const std::string& url, const Cookie& cookie, std::optional<bool> useWebKit) override {
|
|
107
123
|
auto __result = _swiftPart.set(url, std::forward<decltype(cookie)>(cookie), useWebKit);
|
|
108
124
|
if (__result.hasError()) [[unlikely]] {
|
|
@@ -111,6 +127,22 @@ namespace margelo::nitro::nitrocookies {
|
|
|
111
127
|
auto __value = std::move(__result.value());
|
|
112
128
|
return __value;
|
|
113
129
|
}
|
|
130
|
+
inline std::shared_ptr<Promise<bool>> setMany(const std::string& url, const std::vector<Cookie>& cookies, std::optional<bool> useWebKit) override {
|
|
131
|
+
auto __result = _swiftPart.setMany(url, cookies, useWebKit);
|
|
132
|
+
if (__result.hasError()) [[unlikely]] {
|
|
133
|
+
std::rethrow_exception(__result.error());
|
|
134
|
+
}
|
|
135
|
+
auto __value = std::move(__result.value());
|
|
136
|
+
return __value;
|
|
137
|
+
}
|
|
138
|
+
inline std::shared_ptr<Promise<std::string>> getCookieHeader(const std::string& url, std::optional<bool> useWebKit) override {
|
|
139
|
+
auto __result = _swiftPart.getCookieHeader(url, useWebKit);
|
|
140
|
+
if (__result.hasError()) [[unlikely]] {
|
|
141
|
+
std::rethrow_exception(__result.error());
|
|
142
|
+
}
|
|
143
|
+
auto __value = std::move(__result.value());
|
|
144
|
+
return __value;
|
|
145
|
+
}
|
|
114
146
|
inline std::shared_ptr<Promise<std::vector<Cookie>>> get(const std::string& url, std::optional<bool> useWebKit) override {
|
|
115
147
|
auto __result = _swiftPart.get(url, useWebKit);
|
|
116
148
|
if (__result.hasError()) [[unlikely]] {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__string.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a Swift `(_ value: String) -> Void` as a class.
|
|
12
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
|
+
*/
|
|
14
|
+
public final class Func_void_std__string {
|
|
15
|
+
public typealias bridge = margelo.nitro.nitrocookies.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: (_ value: String) -> Void
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping (_ value: String) -> Void) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call(value: std.string) -> Void {
|
|
25
|
+
self.closure(String(value))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
30
|
+
* This acquires one additional strong reference on the object!
|
|
31
|
+
*/
|
|
32
|
+
@inline(__always)
|
|
33
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
34
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Casts an unsafe pointer to a `Func_void_std__string`.
|
|
39
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__string>`.
|
|
40
|
+
* This removes one strong reference from the object!
|
|
41
|
+
*/
|
|
42
|
+
@inline(__always)
|
|
43
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__string {
|
|
44
|
+
return Unmanaged<Func_void_std__string>.fromOpaque(pointer).takeRetainedValue()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -17,7 +17,11 @@ public protocol HybridNitroCookiesSpec_protocol: HybridObject {
|
|
|
17
17
|
func setSync(url: String, cookie: Cookie) throws -> Bool
|
|
18
18
|
func setFromResponseSync(url: String, value: String) throws -> Bool
|
|
19
19
|
func clearByNameSync(url: String, name: String) throws -> Bool
|
|
20
|
+
func getCookieHeaderSync(url: String) throws -> String
|
|
21
|
+
func setManySync(url: String, cookies: [Cookie]) throws -> Bool
|
|
20
22
|
func set(url: String, cookie: Cookie, useWebKit: Bool?) throws -> Promise<Bool>
|
|
23
|
+
func setMany(url: String, cookies: [Cookie], useWebKit: Bool?) throws -> Promise<Bool>
|
|
24
|
+
func getCookieHeader(url: String, useWebKit: Bool?) throws -> Promise<String>
|
|
21
25
|
func get(url: String, useWebKit: Bool?) throws -> Promise<[Cookie]>
|
|
22
26
|
func clearAll(useWebKit: Bool?) throws -> Promise<Bool>
|
|
23
27
|
func setFromResponse(url: String, value: String) throws -> Promise<Bool>
|
|
@@ -178,6 +178,30 @@ open class HybridNitroCookiesSpec_cxx {
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
@inline(__always)
|
|
182
|
+
public final func getCookieHeaderSync(url: std.string) -> bridge.Result_std__string_ {
|
|
183
|
+
do {
|
|
184
|
+
let __result = try self.__implementation.getCookieHeaderSync(url: String(url))
|
|
185
|
+
let __resultCpp = std.string(__result)
|
|
186
|
+
return bridge.create_Result_std__string_(__resultCpp)
|
|
187
|
+
} catch (let __error) {
|
|
188
|
+
let __exceptionPtr = __error.toCpp()
|
|
189
|
+
return bridge.create_Result_std__string_(__exceptionPtr)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@inline(__always)
|
|
194
|
+
public final func setManySync(url: std.string, cookies: bridge.std__vector_Cookie_) -> bridge.Result_bool_ {
|
|
195
|
+
do {
|
|
196
|
+
let __result = try self.__implementation.setManySync(url: String(url), cookies: cookies.map({ __item in __item }))
|
|
197
|
+
let __resultCpp = __result
|
|
198
|
+
return bridge.create_Result_bool_(__resultCpp)
|
|
199
|
+
} catch (let __error) {
|
|
200
|
+
let __exceptionPtr = __error.toCpp()
|
|
201
|
+
return bridge.create_Result_bool_(__exceptionPtr)
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
181
205
|
@inline(__always)
|
|
182
206
|
public final func set(url: std.string, cookie: Cookie, useWebKit: bridge.std__optional_bool_) -> bridge.Result_std__shared_ptr_Promise_bool___ {
|
|
183
207
|
do {
|
|
@@ -204,6 +228,58 @@ open class HybridNitroCookiesSpec_cxx {
|
|
|
204
228
|
}
|
|
205
229
|
}
|
|
206
230
|
|
|
231
|
+
@inline(__always)
|
|
232
|
+
public final func setMany(url: std.string, cookies: bridge.std__vector_Cookie_, useWebKit: bridge.std__optional_bool_) -> bridge.Result_std__shared_ptr_Promise_bool___ {
|
|
233
|
+
do {
|
|
234
|
+
let __result = try self.__implementation.setMany(url: String(url), cookies: cookies.map({ __item in __item }), useWebKit: { () -> Bool? in
|
|
235
|
+
if bridge.has_value_std__optional_bool_(useWebKit) {
|
|
236
|
+
let __unwrapped = bridge.get_std__optional_bool_(useWebKit)
|
|
237
|
+
return __unwrapped
|
|
238
|
+
} else {
|
|
239
|
+
return nil
|
|
240
|
+
}
|
|
241
|
+
}())
|
|
242
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_bool__ in
|
|
243
|
+
let __promise = bridge.create_std__shared_ptr_Promise_bool__()
|
|
244
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_bool__(__promise)
|
|
245
|
+
__result
|
|
246
|
+
.then({ __result in __promiseHolder.resolve(__result) })
|
|
247
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
248
|
+
return __promise
|
|
249
|
+
}()
|
|
250
|
+
return bridge.create_Result_std__shared_ptr_Promise_bool___(__resultCpp)
|
|
251
|
+
} catch (let __error) {
|
|
252
|
+
let __exceptionPtr = __error.toCpp()
|
|
253
|
+
return bridge.create_Result_std__shared_ptr_Promise_bool___(__exceptionPtr)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
@inline(__always)
|
|
258
|
+
public final func getCookieHeader(url: std.string, useWebKit: bridge.std__optional_bool_) -> bridge.Result_std__shared_ptr_Promise_std__string___ {
|
|
259
|
+
do {
|
|
260
|
+
let __result = try self.__implementation.getCookieHeader(url: String(url), useWebKit: { () -> Bool? in
|
|
261
|
+
if bridge.has_value_std__optional_bool_(useWebKit) {
|
|
262
|
+
let __unwrapped = bridge.get_std__optional_bool_(useWebKit)
|
|
263
|
+
return __unwrapped
|
|
264
|
+
} else {
|
|
265
|
+
return nil
|
|
266
|
+
}
|
|
267
|
+
}())
|
|
268
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__string__ in
|
|
269
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__string__()
|
|
270
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__string__(__promise)
|
|
271
|
+
__result
|
|
272
|
+
.then({ __result in __promiseHolder.resolve(std.string(__result)) })
|
|
273
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
274
|
+
return __promise
|
|
275
|
+
}()
|
|
276
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__resultCpp)
|
|
277
|
+
} catch (let __error) {
|
|
278
|
+
let __exceptionPtr = __error.toCpp()
|
|
279
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__string___(__exceptionPtr)
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
207
283
|
@inline(__always)
|
|
208
284
|
public final func get(url: std.string, useWebKit: bridge.std__optional_bool_) -> bridge.Result_std__shared_ptr_Promise_std__vector_Cookie____ {
|
|
209
285
|
do {
|
|
@@ -18,7 +18,11 @@ namespace margelo::nitro::nitrocookies {
|
|
|
18
18
|
prototype.registerHybridMethod("setSync", &HybridNitroCookiesSpec::setSync);
|
|
19
19
|
prototype.registerHybridMethod("setFromResponseSync", &HybridNitroCookiesSpec::setFromResponseSync);
|
|
20
20
|
prototype.registerHybridMethod("clearByNameSync", &HybridNitroCookiesSpec::clearByNameSync);
|
|
21
|
+
prototype.registerHybridMethod("getCookieHeaderSync", &HybridNitroCookiesSpec::getCookieHeaderSync);
|
|
22
|
+
prototype.registerHybridMethod("setManySync", &HybridNitroCookiesSpec::setManySync);
|
|
21
23
|
prototype.registerHybridMethod("set", &HybridNitroCookiesSpec::set);
|
|
24
|
+
prototype.registerHybridMethod("setMany", &HybridNitroCookiesSpec::setMany);
|
|
25
|
+
prototype.registerHybridMethod("getCookieHeader", &HybridNitroCookiesSpec::getCookieHeader);
|
|
22
26
|
prototype.registerHybridMethod("get", &HybridNitroCookiesSpec::get);
|
|
23
27
|
prototype.registerHybridMethod("clearAll", &HybridNitroCookiesSpec::clearAll);
|
|
24
28
|
prototype.registerHybridMethod("setFromResponse", &HybridNitroCookiesSpec::setFromResponse);
|
|
@@ -57,7 +57,11 @@ namespace margelo::nitro::nitrocookies {
|
|
|
57
57
|
virtual bool setSync(const std::string& url, const Cookie& cookie) = 0;
|
|
58
58
|
virtual bool setFromResponseSync(const std::string& url, const std::string& value) = 0;
|
|
59
59
|
virtual bool clearByNameSync(const std::string& url, const std::string& name) = 0;
|
|
60
|
+
virtual std::string getCookieHeaderSync(const std::string& url) = 0;
|
|
61
|
+
virtual bool setManySync(const std::string& url, const std::vector<Cookie>& cookies) = 0;
|
|
60
62
|
virtual std::shared_ptr<Promise<bool>> set(const std::string& url, const Cookie& cookie, std::optional<bool> useWebKit) = 0;
|
|
63
|
+
virtual std::shared_ptr<Promise<bool>> setMany(const std::string& url, const std::vector<Cookie>& cookies, std::optional<bool> useWebKit) = 0;
|
|
64
|
+
virtual std::shared_ptr<Promise<std::string>> getCookieHeader(const std::string& url, std::optional<bool> useWebKit) = 0;
|
|
61
65
|
virtual std::shared_ptr<Promise<std::vector<Cookie>>> get(const std::string& url, std::optional<bool> useWebKit) = 0;
|
|
62
66
|
virtual std::shared_ptr<Promise<bool>> clearAll(std::optional<bool> useWebKit) = 0;
|
|
63
67
|
virtual std::shared_ptr<Promise<bool>> setFromResponse(const std::string& url, const std::string& value) = 0;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-cookies",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
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",
|
|
@@ -72,22 +72,23 @@
|
|
|
72
72
|
"registry": "https://registry.npmjs.org/"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@react-native/babel-preset": "0.
|
|
75
|
+
"@react-native/babel-preset": "0.85.3",
|
|
76
|
+
"@react-native/jest-preset": "0.85.3",
|
|
76
77
|
"@types/jest": "30.0.0",
|
|
77
|
-
"@types/react": "19.2.
|
|
78
|
+
"@types/react": "19.2.17",
|
|
78
79
|
"del-cli": "6.0.0",
|
|
79
80
|
"jest": "30.2.0",
|
|
80
|
-
"nitrogen": "0.
|
|
81
|
-
"react": "19.2.
|
|
82
|
-
"react-native": "0.
|
|
81
|
+
"nitrogen": "0.35.9",
|
|
82
|
+
"react": "19.2.7",
|
|
83
|
+
"react-native": "0.85.3",
|
|
83
84
|
"react-native-builder-bob": "0.40.18",
|
|
84
|
-
"react-native-nitro-modules": "0.
|
|
85
|
+
"react-native-nitro-modules": "0.35.9",
|
|
85
86
|
"typescript": "5.9.3"
|
|
86
87
|
},
|
|
87
88
|
"peerDependencies": {
|
|
88
89
|
"react": "*",
|
|
89
90
|
"react-native": "*",
|
|
90
|
-
"react-native-nitro-modules": "
|
|
91
|
+
"react-native-nitro-modules": ">=0.35.0 <1.0.0"
|
|
91
92
|
},
|
|
92
93
|
"prettier": {
|
|
93
94
|
"quoteProps": "consistent",
|
|
@@ -75,6 +75,33 @@ export interface NitroCookies extends HybridObject<{
|
|
|
75
75
|
*/
|
|
76
76
|
clearByNameSync(url: string, name: string): boolean;
|
|
77
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Get the `Cookie` request-header string for a URL synchronously
|
|
80
|
+
*
|
|
81
|
+
* Returns the value you would put in an HTTP `Cookie` request header
|
|
82
|
+
* (e.g. "name1=value1; name2=value2"), built from every cookie that
|
|
83
|
+
* matches the URL. Use this to attach cookies to a manual `fetch`/
|
|
84
|
+
* `XMLHttpRequest`. Uses NSHTTPCookieStorage (iOS) or CookieManager (Android).
|
|
85
|
+
*
|
|
86
|
+
* @param url - The URL to match cookies against (must include protocol)
|
|
87
|
+
* @returns The Cookie header string, or "" when no cookies match
|
|
88
|
+
* @throws Error if URL is invalid
|
|
89
|
+
*/
|
|
90
|
+
getCookieHeaderSync(url: string): string;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Set multiple cookies for a URL synchronously
|
|
94
|
+
*
|
|
95
|
+
* Applies the same domain validation as `setSync` to every cookie.
|
|
96
|
+
* Uses NSHTTPCookieStorage (iOS) or CookieManager (Android).
|
|
97
|
+
*
|
|
98
|
+
* @param url - The URL for which to set the cookies (must include protocol)
|
|
99
|
+
* @param cookies - The cookie objects to store
|
|
100
|
+
* @returns true on success
|
|
101
|
+
* @throws Error if URL is invalid or any cookie's domain mismatches
|
|
102
|
+
*/
|
|
103
|
+
setManySync(url: string, cookies: Cookie[]): boolean;
|
|
104
|
+
|
|
78
105
|
// ========================================
|
|
79
106
|
// ASYNCHRONOUS METHODS
|
|
80
107
|
// ========================================
|
|
@@ -89,6 +116,35 @@ export interface NitroCookies extends HybridObject<{
|
|
|
89
116
|
*/
|
|
90
117
|
set(url: string, cookie: Cookie, useWebKit?: boolean): Promise<boolean>;
|
|
91
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Set multiple cookies for a URL
|
|
121
|
+
*
|
|
122
|
+
* Applies the same domain validation as `set` to every cookie.
|
|
123
|
+
*
|
|
124
|
+
* @param url - The URL for which to set the cookies (must include protocol)
|
|
125
|
+
* @param cookies - The cookie objects to store
|
|
126
|
+
* @param useWebKit - (iOS only) If true, use WKHTTPCookieStore instead of NSHTTPCookieStorage (requires iOS 11+)
|
|
127
|
+
* @returns Promise that resolves to true on success
|
|
128
|
+
*/
|
|
129
|
+
setMany(
|
|
130
|
+
url: string,
|
|
131
|
+
cookies: Cookie[],
|
|
132
|
+
useWebKit?: boolean
|
|
133
|
+
): Promise<boolean>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Get the `Cookie` request-header string for a URL
|
|
137
|
+
*
|
|
138
|
+
* Returns the value you would put in an HTTP `Cookie` request header
|
|
139
|
+
* (e.g. "name1=value1; name2=value2"), built from every cookie that
|
|
140
|
+
* matches the URL.
|
|
141
|
+
*
|
|
142
|
+
* @param url - The URL to match cookies against (must include protocol)
|
|
143
|
+
* @param useWebKit - (iOS only) If true, read from WKHTTPCookieStore instead of NSHTTPCookieStorage
|
|
144
|
+
* @returns Promise that resolves to the Cookie header string, or "" when no cookies match
|
|
145
|
+
*/
|
|
146
|
+
getCookieHeader(url: string, useWebKit?: boolean): Promise<string>;
|
|
147
|
+
|
|
92
148
|
/**
|
|
93
149
|
* Get all cookies matching a specific URL's domain
|
|
94
150
|
*
|
package/src/index.tsx
CHANGED
|
@@ -123,6 +123,53 @@ export const NitroCookies = {
|
|
|
123
123
|
return NitroCookiesHybridObject.clearByNameSync(url, name);
|
|
124
124
|
},
|
|
125
125
|
|
|
126
|
+
/**
|
|
127
|
+
* Get the `Cookie` request-header string for a URL synchronously.
|
|
128
|
+
*
|
|
129
|
+
* Returns the value you would put in an HTTP `Cookie` request header
|
|
130
|
+
* (e.g. `"name1=value1; name2=value2"`), built from every cookie that
|
|
131
|
+
* matches the URL. Handy for attaching cookies to a manual `fetch` or
|
|
132
|
+
* `XMLHttpRequest`. Returns an empty string when no cookies match.
|
|
133
|
+
*
|
|
134
|
+
* @param url - The URL to match cookies against (must include protocol)
|
|
135
|
+
* @returns The Cookie header string, or "" when no cookies match
|
|
136
|
+
* @throws {Error} INVALID_URL - URL is malformed or missing protocol
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const header = NitroCookies.getCookieHeaderSync('https://example.com');
|
|
141
|
+
* await fetch('https://example.com/api', { headers: { Cookie: header } });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
getCookieHeaderSync(url: string): string {
|
|
145
|
+
return NitroCookiesHybridObject.getCookieHeaderSync(url);
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Set multiple cookies for a URL synchronously.
|
|
150
|
+
*
|
|
151
|
+
* Applies the same domain validation as `setSync` to every cookie. If any
|
|
152
|
+
* cookie's domain doesn't match the URL host, the whole call throws and no
|
|
153
|
+
* cookies are written.
|
|
154
|
+
*
|
|
155
|
+
* @param url - The URL for which to set the cookies (must include protocol)
|
|
156
|
+
* @param cookies - The cookie objects to store
|
|
157
|
+
* @returns true on success
|
|
158
|
+
* @throws {Error} INVALID_URL - URL is malformed or missing protocol
|
|
159
|
+
* @throws {Error} DOMAIN_MISMATCH - A cookie's domain doesn't match URL host
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* NitroCookies.setManySync('https://example.com', [
|
|
164
|
+
* { name: 'session', value: 'abc123' },
|
|
165
|
+
* { name: 'theme', value: 'dark' },
|
|
166
|
+
* ]);
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
setManySync(url: string, cookies: Cookie[]): boolean {
|
|
170
|
+
return NitroCookiesHybridObject.setManySync(url, cookies);
|
|
171
|
+
},
|
|
172
|
+
|
|
126
173
|
// ========================================
|
|
127
174
|
// ASYNCHRONOUS METHODS
|
|
128
175
|
// ========================================
|
|
@@ -168,6 +215,63 @@ export const NitroCookies = {
|
|
|
168
215
|
return NitroCookiesHybridObject.set(url, cookie, useWebKit ?? false);
|
|
169
216
|
},
|
|
170
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Set multiple cookies for a URL.
|
|
220
|
+
*
|
|
221
|
+
* Applies the same domain validation as `set` to every cookie. If any
|
|
222
|
+
* cookie's domain doesn't match the URL host, the whole call rejects and no
|
|
223
|
+
* cookies are written.
|
|
224
|
+
*
|
|
225
|
+
* @param url - The URL for which to set the cookies. Must include protocol.
|
|
226
|
+
* @param cookies - The cookie objects to store
|
|
227
|
+
* @param useWebKit - (iOS only) If true, use WKHTTPCookieStore instead of NSHTTPCookieStorage. Requires iOS 11+.
|
|
228
|
+
*
|
|
229
|
+
* @returns Promise that resolves to true on success
|
|
230
|
+
*
|
|
231
|
+
* @throws {Error} INVALID_URL - URL is malformed or missing protocol
|
|
232
|
+
* @throws {Error} DOMAIN_MISMATCH - A cookie's domain doesn't match URL host
|
|
233
|
+
* @throws {Error} WEBKIT_UNAVAILABLE - useWebKit=true on iOS < 11
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* await NitroCookies.setMany('https://example.com', [
|
|
238
|
+
* { name: 'session', value: 'abc123', secure: true },
|
|
239
|
+
* { name: 'theme', value: 'dark' },
|
|
240
|
+
* ]);
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
async setMany(
|
|
244
|
+
url: string,
|
|
245
|
+
cookies: Cookie[],
|
|
246
|
+
useWebKit?: boolean
|
|
247
|
+
): Promise<boolean> {
|
|
248
|
+
return NitroCookiesHybridObject.setMany(url, cookies, useWebKit ?? false);
|
|
249
|
+
},
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Get the `Cookie` request-header string for a URL.
|
|
253
|
+
*
|
|
254
|
+
* Returns the value you would put in an HTTP `Cookie` request header
|
|
255
|
+
* (e.g. `"name1=value1; name2=value2"`), built from every cookie that
|
|
256
|
+
* matches the URL. Returns an empty string when no cookies match.
|
|
257
|
+
*
|
|
258
|
+
* @param url - The URL to match cookies against. Must include protocol.
|
|
259
|
+
* @param useWebKit - (iOS only) If true, read from WKHTTPCookieStore instead of NSHTTPCookieStorage
|
|
260
|
+
*
|
|
261
|
+
* @returns Promise that resolves to the Cookie header string, or "" when no cookies match
|
|
262
|
+
*
|
|
263
|
+
* @throws {Error} INVALID_URL - URL is malformed or missing protocol
|
|
264
|
+
*
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* const header = await NitroCookies.getCookieHeader('https://example.com');
|
|
268
|
+
* await fetch('https://example.com/api', { headers: { Cookie: header } });
|
|
269
|
+
* ```
|
|
270
|
+
*/
|
|
271
|
+
async getCookieHeader(url: string, useWebKit?: boolean): Promise<string> {
|
|
272
|
+
return NitroCookiesHybridObject.getCookieHeader(url, useWebKit ?? false);
|
|
273
|
+
},
|
|
274
|
+
|
|
171
275
|
/**
|
|
172
276
|
* Get all cookies matching a specific URL's domain.
|
|
173
277
|
*
|