react-native-nitro-sse 1.4.1 → 1.5.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 (32) hide show
  1. package/README.md +3 -0
  2. package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +148 -20
  3. package/android/src/test/java/com/margelo/nitro/nitrosse/NitroSseLogicTest.kt +2 -2
  4. package/ios/NitroSse.swift +178 -46
  5. package/lib/module/index.js +3 -2
  6. package/lib/module/index.js.map +1 -1
  7. package/lib/typescript/src/SseInterface.d.ts +17 -0
  8. package/lib/typescript/src/SseInterface.d.ts.map +1 -1
  9. package/lib/typescript/src/index.d.ts.map +1 -1
  10. package/nitrogen/generated/android/c++/JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.hpp +138 -0
  11. package/nitrogen/generated/android/c++/JHybridNitroSseSpec.cpp +5 -2
  12. package/nitrogen/generated/android/c++/JSseConfig.hpp +28 -3
  13. package/nitrogen/generated/android/c++/JSseEvent.hpp +11 -3
  14. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.kt +80 -0
  15. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +18 -5
  16. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseEvent.kt +9 -3
  17. package/nitrogen/generated/android/nitrosseOnLoad.cpp +2 -0
  18. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.cpp +33 -0
  19. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +130 -0
  20. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Umbrella.hpp +1 -0
  21. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +2 -1
  22. package/nitrogen/generated/ios/swift/Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____.swift +67 -0
  23. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  24. package/nitrogen/generated/ios/swift/Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___.swift +66 -0
  25. package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__std__string_.swift +54 -0
  26. package/nitrogen/generated/ios/swift/SseConfig.swift +84 -1
  27. package/nitrogen/generated/ios/swift/SseEvent.swift +37 -1
  28. package/nitrogen/generated/shared/c++/SseConfig.hpp +17 -3
  29. package/nitrogen/generated/shared/c++/SseEvent.hpp +10 -2
  30. package/package.json +1 -1
  31. package/src/SseInterface.ts +17 -0
  32. package/src/{index.tsx → index.ts} +4 -3
@@ -0,0 +1,66 @@
1
+ ///
2
+ /// Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__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: Promise<Dictionary<String, 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__shared_ptr_Promise_std__unordered_map_std__string__std__string___ {
15
+ public typealias bridge = margelo.nitro.nitrosse.bridge.swift
16
+
17
+ private let closure: (_ value: Promise<Dictionary<String, String>>) -> Void
18
+
19
+ public init(_ closure: @escaping (_ value: Promise<Dictionary<String, String>>) -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call(value: bridge.std__shared_ptr_Promise_std__unordered_map_std__string__std__string___) -> Void {
25
+ self.closure({ () -> Promise<Dictionary<String, String>> in
26
+ let __promise = Promise<Dictionary<String, String>>()
27
+ let __resolver = { (__result: Dictionary<String, String>) in
28
+ __promise.resolve(withResult: __result)
29
+ }
30
+ let __rejecter = { (__error: Error) in
31
+ __promise.reject(withError: __error)
32
+ }
33
+ let __resolverCpp = { () -> bridge.Func_void_std__unordered_map_std__string__std__string_ in
34
+ let __closureWrapper = Func_void_std__unordered_map_std__string__std__string_(__resolver)
35
+ return bridge.create_Func_void_std__unordered_map_std__string__std__string_(__closureWrapper.toUnsafe())
36
+ }()
37
+ let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in
38
+ let __closureWrapper = Func_void_std__exception_ptr(__rejecter)
39
+ return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe())
40
+ }()
41
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___(value)
42
+ __promiseHolder.addOnResolvedListener(__resolverCpp)
43
+ __promiseHolder.addOnRejectedListener(__rejecterCpp)
44
+ return __promise
45
+ }())
46
+ }
47
+
48
+ /**
49
+ * Casts this instance to a retained unsafe raw pointer.
50
+ * This acquires one additional strong reference on the object!
51
+ */
52
+ @inline(__always)
53
+ public func toUnsafe() -> UnsafeMutableRawPointer {
54
+ return Unmanaged.passRetained(self).toOpaque()
55
+ }
56
+
57
+ /**
58
+ * Casts an unsafe pointer to a `Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___`.
59
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___>`.
60
+ * This removes one strong reference from the object!
61
+ */
62
+ @inline(__always)
63
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___ {
64
+ return Unmanaged<Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___>.fromOpaque(pointer).takeRetainedValue()
65
+ }
66
+ }
@@ -0,0 +1,54 @@
1
+ ///
2
+ /// Func_void_std__unordered_map_std__string__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: Dictionary<String, 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__unordered_map_std__string__std__string_ {
15
+ public typealias bridge = margelo.nitro.nitrosse.bridge.swift
16
+
17
+ private let closure: (_ value: Dictionary<String, String>) -> Void
18
+
19
+ public init(_ closure: @escaping (_ value: Dictionary<String, String>) -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call(value: bridge.std__unordered_map_std__string__std__string_) -> Void {
25
+ self.closure({ () -> Dictionary<String, String> in
26
+ var __dictionary = Dictionary<String, String>(minimumCapacity: value.size())
27
+ let __keys = bridge.get_std__unordered_map_std__string__std__string__keys(value)
28
+ for __key in __keys {
29
+ let __value = bridge.get_std__unordered_map_std__string__std__string__value(value, __key)
30
+ __dictionary[String(__key)] = String(__value)
31
+ }
32
+ return __dictionary
33
+ }())
34
+ }
35
+
36
+ /**
37
+ * Casts this instance to a retained unsafe raw pointer.
38
+ * This acquires one additional strong reference on the object!
39
+ */
40
+ @inline(__always)
41
+ public func toUnsafe() -> UnsafeMutableRawPointer {
42
+ return Unmanaged.passRetained(self).toOpaque()
43
+ }
44
+
45
+ /**
46
+ * Casts an unsafe pointer to a `Func_void_std__unordered_map_std__string__std__string_`.
47
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__unordered_map_std__string__std__string_>`.
48
+ * This removes one strong reference from the object!
49
+ */
50
+ @inline(__always)
51
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__unordered_map_std__string__std__string_ {
52
+ return Unmanaged<Func_void_std__unordered_map_std__string__std__string_>.fromOpaque(pointer).takeRetainedValue()
53
+ }
54
+ }
@@ -18,7 +18,7 @@ public extension SseConfig {
18
18
  /**
19
19
  * Create a new instance of `SseConfig`.
20
20
  */
21
- init(url: String, method: HttpMethod?, headers: Dictionary<String, String>?, body: String?, backgroundExecution: Bool?, batchingIntervalMs: Double?, maxBufferSize: Double?) {
21
+ init(url: String, method: HttpMethod?, headers: Dictionary<String, String>?, body: String?, backgroundExecution: Bool?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, onBeforeRequest: (() -> Promise<Promise<Dictionary<String, String>>>)?) {
22
22
  self.init(std.string(url), { () -> bridge.std__optional_HttpMethod_ in
23
23
  if let __unwrappedValue = method {
24
24
  return bridge.create_std__optional_HttpMethod_(__unwrappedValue)
@@ -61,6 +61,27 @@ public extension SseConfig {
61
61
  } else {
62
62
  return .init()
63
63
  }
64
+ }(), { () -> bridge.std__optional_double_ in
65
+ if let __unwrappedValue = connectionTimeoutMs {
66
+ return bridge.create_std__optional_double_(__unwrappedValue)
67
+ } else {
68
+ return .init()
69
+ }
70
+ }(), { () -> bridge.std__optional_double_ in
71
+ if let __unwrappedValue = readTimeoutMs {
72
+ return bridge.create_std__optional_double_(__unwrappedValue)
73
+ } else {
74
+ return .init()
75
+ }
76
+ }(), { () -> bridge.std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________ in
77
+ if let __unwrappedValue = onBeforeRequest {
78
+ return bridge.create_std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________({ () -> bridge.Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____ in
79
+ let __closureWrapper = Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____(__unwrappedValue)
80
+ return bridge.create_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____(__closureWrapper.toUnsafe())
81
+ }())
82
+ } else {
83
+ return .init()
84
+ }
64
85
  }())
65
86
  }
66
87
 
@@ -141,4 +162,66 @@ public extension SseConfig {
141
162
  }
142
163
  }()
143
164
  }
165
+
166
+ @inline(__always)
167
+ var connectionTimeoutMs: Double? {
168
+ return { () -> Double? in
169
+ if bridge.has_value_std__optional_double_(self.__connectionTimeoutMs) {
170
+ let __unwrapped = bridge.get_std__optional_double_(self.__connectionTimeoutMs)
171
+ return __unwrapped
172
+ } else {
173
+ return nil
174
+ }
175
+ }()
176
+ }
177
+
178
+ @inline(__always)
179
+ var readTimeoutMs: Double? {
180
+ return { () -> Double? in
181
+ if bridge.has_value_std__optional_double_(self.__readTimeoutMs) {
182
+ let __unwrapped = bridge.get_std__optional_double_(self.__readTimeoutMs)
183
+ return __unwrapped
184
+ } else {
185
+ return nil
186
+ }
187
+ }()
188
+ }
189
+
190
+ @inline(__always)
191
+ var onBeforeRequest: (() -> Promise<Promise<Dictionary<String, String>>>)? {
192
+ return { () -> (() -> Promise<Promise<Dictionary<String, String>>>)? in
193
+ if bridge.has_value_std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________(self.__onBeforeRequest) {
194
+ let __unwrapped = bridge.get_std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_________(self.__onBeforeRequest)
195
+ return { () -> () -> Promise<Promise<Dictionary<String, String>>> in
196
+ let __wrappedFunction = bridge.wrap_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____(__unwrapped)
197
+ return { () -> Promise<Promise<Dictionary<String, String>>> in
198
+ let __result = __wrappedFunction.call()
199
+ return { () -> Promise<Promise<Dictionary<String, String>>> in
200
+ let __promise = Promise<Promise<Dictionary<String, String>>>()
201
+ let __resolver = { (__result: Promise<Dictionary<String, String>>) in
202
+ __promise.resolve(withResult: __result)
203
+ }
204
+ let __rejecter = { (__error: Error) in
205
+ __promise.reject(withError: __error)
206
+ }
207
+ let __resolverCpp = { () -> bridge.Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___ in
208
+ let __closureWrapper = Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___(__resolver)
209
+ return bridge.create_Func_void_std__shared_ptr_Promise_std__unordered_map_std__string__std__string___(__closureWrapper.toUnsafe())
210
+ }()
211
+ let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in
212
+ let __closureWrapper = Func_void_std__exception_ptr(__rejecter)
213
+ return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe())
214
+ }()
215
+ let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____(__result)
216
+ __promiseHolder.addOnResolvedListener(__resolverCpp)
217
+ __promiseHolder.addOnRejectedListener(__rejecterCpp)
218
+ return __promise
219
+ }()
220
+ }
221
+ }()
222
+ } else {
223
+ return nil
224
+ }
225
+ }()
226
+ }
144
227
  }
@@ -18,7 +18,7 @@ public extension SseEvent {
18
18
  /**
19
19
  * Create a new instance of `SseEvent`.
20
20
  */
21
- init(type: SseEventType, data: String?, id: String?, event: String?, message: String?) {
21
+ init(type: SseEventType, data: String?, id: String?, event: String?, message: String?, statusCode: Double?, retry: Double?) {
22
22
  self.init(type, { () -> bridge.std__optional_std__string_ in
23
23
  if let __unwrappedValue = data {
24
24
  return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
@@ -43,6 +43,18 @@ public extension SseEvent {
43
43
  } else {
44
44
  return .init()
45
45
  }
46
+ }(), { () -> bridge.std__optional_double_ in
47
+ if let __unwrappedValue = statusCode {
48
+ return bridge.create_std__optional_double_(__unwrappedValue)
49
+ } else {
50
+ return .init()
51
+ }
52
+ }(), { () -> bridge.std__optional_double_ in
53
+ if let __unwrappedValue = retry {
54
+ return bridge.create_std__optional_double_(__unwrappedValue)
55
+ } else {
56
+ return .init()
57
+ }
46
58
  }())
47
59
  }
48
60
 
@@ -98,4 +110,28 @@ public extension SseEvent {
98
110
  }
99
111
  }()
100
112
  }
113
+
114
+ @inline(__always)
115
+ var statusCode: Double? {
116
+ return { () -> Double? in
117
+ if bridge.has_value_std__optional_double_(self.__statusCode) {
118
+ let __unwrapped = bridge.get_std__optional_double_(self.__statusCode)
119
+ return __unwrapped
120
+ } else {
121
+ return nil
122
+ }
123
+ }()
124
+ }
125
+
126
+ @inline(__always)
127
+ var retry: Double? {
128
+ return { () -> Double? in
129
+ if bridge.has_value_std__optional_double_(self.__retry) {
130
+ let __unwrapped = bridge.get_std__optional_double_(self.__retry)
131
+ return __unwrapped
132
+ } else {
133
+ return nil
134
+ }
135
+ }()
136
+ }
101
137
  }
@@ -35,6 +35,8 @@ namespace margelo::nitro::nitrosse { enum class HttpMethod; }
35
35
  #include "HttpMethod.hpp"
36
36
  #include <optional>
37
37
  #include <unordered_map>
38
+ #include <NitroModules/Promise.hpp>
39
+ #include <functional>
38
40
 
39
41
  namespace margelo::nitro::nitrosse {
40
42
 
@@ -50,13 +52,16 @@ namespace margelo::nitro::nitrosse {
50
52
  std::optional<bool> backgroundExecution SWIFT_PRIVATE;
51
53
  std::optional<double> batchingIntervalMs SWIFT_PRIVATE;
52
54
  std::optional<double> maxBufferSize SWIFT_PRIVATE;
55
+ std::optional<double> connectionTimeoutMs SWIFT_PRIVATE;
56
+ std::optional<double> readTimeoutMs SWIFT_PRIVATE;
57
+ std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>> onBeforeRequest SWIFT_PRIVATE;
53
58
 
54
59
  public:
55
60
  SseConfig() = default;
56
- explicit SseConfig(std::string url, std::optional<HttpMethod> method, std::optional<std::unordered_map<std::string, std::string>> headers, std::optional<std::string> body, std::optional<bool> backgroundExecution, std::optional<double> batchingIntervalMs, std::optional<double> maxBufferSize): url(url), method(method), headers(headers), body(body), backgroundExecution(backgroundExecution), batchingIntervalMs(batchingIntervalMs), maxBufferSize(maxBufferSize) {}
61
+ explicit SseConfig(std::string url, std::optional<HttpMethod> method, std::optional<std::unordered_map<std::string, std::string>> headers, std::optional<std::string> body, std::optional<bool> backgroundExecution, std::optional<double> batchingIntervalMs, std::optional<double> maxBufferSize, std::optional<double> connectionTimeoutMs, std::optional<double> readTimeoutMs, std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>> onBeforeRequest): url(url), method(method), headers(headers), body(body), backgroundExecution(backgroundExecution), batchingIntervalMs(batchingIntervalMs), maxBufferSize(maxBufferSize), connectionTimeoutMs(connectionTimeoutMs), readTimeoutMs(readTimeoutMs), onBeforeRequest(onBeforeRequest) {}
57
62
 
58
63
  public:
59
- friend bool operator==(const SseConfig& lhs, const SseConfig& rhs) = default;
64
+ // SseConfig is not equatable because these properties are not equatable: onBeforeRequest
60
65
  };
61
66
 
62
67
  } // namespace margelo::nitro::nitrosse
@@ -75,7 +80,10 @@ namespace margelo::nitro {
75
80
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "body"))),
76
81
  JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "backgroundExecution"))),
77
82
  JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "batchingIntervalMs"))),
78
- JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxBufferSize")))
83
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxBufferSize"))),
84
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "connectionTimeoutMs"))),
85
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "readTimeoutMs"))),
86
+ JSIConverter<std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onBeforeRequest")))
79
87
  );
80
88
  }
81
89
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrosse::SseConfig& arg) {
@@ -87,6 +95,9 @@ namespace margelo::nitro {
87
95
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "backgroundExecution"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.backgroundExecution));
88
96
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "batchingIntervalMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.batchingIntervalMs));
89
97
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxBufferSize"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxBufferSize));
98
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "connectionTimeoutMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.connectionTimeoutMs));
99
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "readTimeoutMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.readTimeoutMs));
100
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "onBeforeRequest"), JSIConverter<std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>>::toJSI(runtime, arg.onBeforeRequest));
90
101
  return obj;
91
102
  }
92
103
  static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -104,6 +115,9 @@ namespace margelo::nitro {
104
115
  if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "backgroundExecution")))) return false;
105
116
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "batchingIntervalMs")))) return false;
106
117
  if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxBufferSize")))) return false;
118
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "connectionTimeoutMs")))) return false;
119
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "readTimeoutMs")))) return false;
120
+ if (!JSIConverter<std::optional<std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()>>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "onBeforeRequest")))) return false;
107
121
  return true;
108
122
  }
109
123
  };
@@ -47,10 +47,12 @@ namespace margelo::nitro::nitrosse {
47
47
  std::optional<std::string> id SWIFT_PRIVATE;
48
48
  std::optional<std::string> event SWIFT_PRIVATE;
49
49
  std::optional<std::string> message SWIFT_PRIVATE;
50
+ std::optional<double> statusCode SWIFT_PRIVATE;
51
+ std::optional<double> retry SWIFT_PRIVATE;
50
52
 
51
53
  public:
52
54
  SseEvent() = default;
53
- explicit SseEvent(SseEventType type, std::optional<std::string> data, std::optional<std::string> id, std::optional<std::string> event, std::optional<std::string> message): type(type), data(data), id(id), event(event), message(message) {}
55
+ explicit SseEvent(SseEventType type, std::optional<std::string> data, std::optional<std::string> id, std::optional<std::string> event, std::optional<std::string> message, std::optional<double> statusCode, std::optional<double> retry): type(type), data(data), id(id), event(event), message(message), statusCode(statusCode), retry(retry) {}
54
56
 
55
57
  public:
56
58
  friend bool operator==(const SseEvent& lhs, const SseEvent& rhs) = default;
@@ -70,7 +72,9 @@ namespace margelo::nitro {
70
72
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "data"))),
71
73
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id"))),
72
74
  JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "event"))),
73
- JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message")))
75
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message"))),
76
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "statusCode"))),
77
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retry")))
74
78
  );
75
79
  }
76
80
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrosse::SseEvent& arg) {
@@ -80,6 +84,8 @@ namespace margelo::nitro {
80
84
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "id"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.id));
81
85
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "event"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.event));
82
86
  obj.setProperty(runtime, PropNameIDCache::get(runtime, "message"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.message));
87
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "statusCode"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.statusCode));
88
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "retry"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.retry));
83
89
  return obj;
84
90
  }
85
91
  static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -95,6 +101,8 @@ namespace margelo::nitro {
95
101
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "id")))) return false;
96
102
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "event")))) return false;
97
103
  if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "message")))) return false;
104
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "statusCode")))) return false;
105
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "retry")))) return false;
98
106
  return true;
99
107
  }
100
108
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-sse",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "High-performance Server-Sent Events (SSE) for React Native, powered by Nitro Modules.",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -40,6 +40,19 @@ export interface SseConfig {
40
40
  * Maximum number of events to hold in the buffer before forced flushing.
41
41
  */
42
42
  maxBufferSize?: number;
43
+ /**
44
+ * Connection timeout in milliseconds.
45
+ */
46
+ connectionTimeoutMs?: number;
47
+ /**
48
+ * Read timeout in milliseconds.
49
+ */
50
+ readTimeoutMs?: number;
51
+ /**
52
+ * Optional interceptor called before every request.
53
+ * Useful for refreshing tokens or adding dynamic parameters.
54
+ */
55
+ onBeforeRequest?: () => Promise<Record<string, string>>;
43
56
  }
44
57
 
45
58
  /**
@@ -56,6 +69,10 @@ export interface SseEvent {
56
69
  event?: string;
57
70
  /** System message or error description. */
58
71
  message?: string;
72
+ /** HTTP status code if applicable. */
73
+ statusCode?: number;
74
+ /** Server-requested retry delay in milliseconds. */
75
+ retry?: number;
59
76
  }
60
77
 
61
78
  /**
@@ -8,12 +8,13 @@ export function createNitroSse(): NitroSse {
8
8
  let nativeSse: NitroSse | undefined;
9
9
  try {
10
10
  nativeSse = NitroModules.createHybridObject<NitroSse>('NitroSse');
11
- } catch {}
12
-
13
- if (!nativeSse) {
11
+ } catch {
14
12
  console.debug(
15
13
  'Native NitroSse not found. This might be a test environment or web.'
16
14
  );
15
+ }
16
+
17
+ if (!nativeSse) {
17
18
  throw new Error(
18
19
  'NitroSse: Native module not found. Ensure you have linked the library and built the app for iOS/Android.'
19
20
  );