react-native-nitro-sse 2.4.1 → 3.0.0-beta.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.
Files changed (59) hide show
  1. package/README.md +209 -95
  2. package/android/src/main/java/com/margelo/nitro/nitrosse/AndroidSseDispatcher.kt +5 -0
  3. package/android/src/main/java/com/margelo/nitro/nitrosse/JsonUtils.kt +11 -18
  4. package/android/src/main/java/com/margelo/nitro/nitrosse/NetworkInspector.kt +79 -38
  5. package/android/src/main/java/com/margelo/nitro/nitrosse/NitroSse.kt +194 -100
  6. package/android/src/main/java/com/margelo/nitro/nitrosse/SseConnectionHandler.kt +40 -15
  7. package/android/src/main/java/com/margelo/nitro/nitrosse/SseDispatcher.kt +1 -0
  8. package/android/src/main/java/com/margelo/nitro/nitrosse/SseEventBuffer.kt +34 -28
  9. package/android/src/main/java/com/margelo/nitro/nitrosse/SseLifecycleManager.kt +8 -1
  10. package/android/src/main/java/com/margelo/nitro/nitrosse/SseNetworkMonitor.kt +7 -4
  11. package/android/src/main/java/com/margelo/nitro/nitrosse/SseReconnectStrategy.kt +6 -4
  12. package/ios/NitroSse.swift +244 -190
  13. package/ios/SseConfig+CopyWith.swift +2 -1
  14. package/ios/SseConnectionHandler.swift +59 -29
  15. package/ios/SseDispatchQueueDispatcher.swift +15 -2
  16. package/ios/SseDispatcher.swift +7 -1
  17. package/ios/SseEventBuffer.swift +23 -7
  18. package/ios/SseLifecycleManager.swift +10 -1
  19. package/ios/SseNetworkMonitor.swift +8 -2
  20. package/ios/SseReconnectStrategy.swift +9 -3
  21. package/lib/module/MockSseEngine.js +203 -0
  22. package/lib/module/NitroSseClient.js +411 -214
  23. package/lib/module/NitroSseError.js +61 -0
  24. package/lib/module/SseDriver.js +156 -0
  25. package/lib/module/index.js +6 -3
  26. package/lib/module/useNitroSse.js +359 -0
  27. package/lib/typescript/src/MockSseEngine.d.ts +31 -0
  28. package/lib/typescript/src/NitroSse.nitro.d.ts +25 -2
  29. package/lib/typescript/src/NitroSseClient.d.ts +25 -7
  30. package/lib/typescript/src/NitroSseError.d.ts +38 -0
  31. package/lib/typescript/src/SseDriver.d.ts +80 -0
  32. package/lib/typescript/src/SseInterface.d.ts +25 -7
  33. package/lib/typescript/src/index.d.ts +4 -2
  34. package/lib/typescript/src/useNitroSse.d.ts +69 -0
  35. package/nitrogen/generated/android/c++/JSseConfig.hpp +7 -1
  36. package/nitrogen/generated/android/c++/JSseMockConfig.hpp +2 -0
  37. package/nitrogen/generated/android/c++/JSseMockEvent.hpp +9 -3
  38. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseConfig.kt +9 -4
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrosse/SseMockEvent.kt +9 -4
  40. package/nitrogen/generated/ios/NitroSse-Swift-Cxx-Bridge.hpp +15 -15
  41. package/nitrogen/generated/ios/c++/HybridNitroSseSpecSwift.hpp +3 -3
  42. package/nitrogen/generated/ios/swift/SseConfig.swift +19 -1
  43. package/nitrogen/generated/ios/swift/SseMockEvent.swift +12 -1
  44. package/nitrogen/generated/shared/c++/SseConfig.hpp +5 -1
  45. package/nitrogen/generated/shared/c++/SseMockEvent.hpp +9 -2
  46. package/package.json +10 -11
  47. package/android/jacoco.gradle +0 -33
  48. package/lib/module/NitroSse.nitro.js.map +0 -1
  49. package/lib/module/NitroSseClient.js.map +0 -1
  50. package/lib/module/SseInterface.js.map +0 -1
  51. package/lib/module/index.js.map +0 -1
  52. package/lib/typescript/src/NitroSse.nitro.d.ts.map +0 -1
  53. package/lib/typescript/src/NitroSseClient.d.ts.map +0 -1
  54. package/lib/typescript/src/SseInterface.d.ts.map +0 -1
  55. package/lib/typescript/src/index.d.ts.map +0 -1
  56. package/src/NitroSse.nitro.ts +0 -58
  57. package/src/NitroSseClient.ts +0 -337
  58. package/src/SseInterface.ts +0 -272
  59. package/src/index.ts +0 -31
@@ -1,20 +1,37 @@
1
+ import type { AnyMap } from 'react-native-nitro-modules';
1
2
  import type { NitroSse } from './NitroSse.nitro';
2
3
  import type { SseClient, SseConfig, SseEvent, SseListener, SseStats, SseState } from './SseInterface';
4
+ /**
5
+ * Sanitizes HTTP headers by stripping carriage returns, newlines, null bytes,
6
+ * converting non-string values to strings, and pruning null/undefined values.
7
+ */
8
+ export declare function sanitizeHeaders(headers?: Record<string, unknown>): Record<string, string>;
9
+ /**
10
+ * Defensively validates and normalizes the SSE configuration object.
11
+ * Throws NitroSseValidationError if essential requirements (e.g. valid URL) are violated.
12
+ * Clamps numeric properties to safe boundaries and warns in __DEV__.
13
+ */
14
+ export declare function validateConfig(config: SseConfig): SseConfig;
15
+ /**
16
+ * Public facade and typed event emitter for NitroSse, delegating streaming execution to an SseDriver strategy.
17
+ */
3
18
  export declare class NitroSseClient implements SseClient {
4
19
  private _native;
20
+ private _driver;
5
21
  private _listeners;
6
22
  private _legacyCallback?;
7
23
  private _config?;
8
- private _mockIntervalId?;
9
- private _mockIndex;
10
- private _mockState?;
24
+ private _isDisposed;
25
+ private _pendingHeaders;
11
26
  constructor(native: NitroSse);
12
- private _setMockState;
27
+ get isDisposed(): boolean;
28
+ private _checkDisposed;
13
29
  setup(config: SseConfig, onEvent?: (events: SseEvent[]) => void): void;
14
- addEventListener(type: string, listener: SseListener): void;
15
- removeEventListener(type: string, listener: SseListener): void;
30
+ addEventListener<TData = AnyMap>(type: string, listener: SseListener<TData>): void;
31
+ removeEventListener<TData = AnyMap>(type: string, listener: SseListener<TData>): void;
32
+ removeAllEventListeners(type?: string): void;
16
33
  private _emit;
17
- private _createSseEvent;
34
+ private _dispatchEvents;
18
35
  start(): void;
19
36
  stop(): void;
20
37
  restart(): void;
@@ -25,5 +42,6 @@ export declare class NitroSseClient implements SseClient {
25
42
  updateHeaders(headers: Record<string, string>): void;
26
43
  setLastProcessedId(id: string): void;
27
44
  injectMockEvent(event: Partial<SseEvent>): void;
45
+ dispose(): void;
28
46
  }
29
47
  //# sourceMappingURL=NitroSseClient.d.ts.map
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Error codes identifying specific categories of NitroSse failures.
3
+ */
4
+ export type NitroSseErrorCode = 'NATIVE_MODULE_NOT_FOUND' | 'INVALID_CONFIG' | 'INVALID_ARGUMENT' | 'INVALID_STATE' | 'CLIENT_DISPOSED';
5
+ /**
6
+ * Base structured error class for all errors thrown by react-native-nitro-sse.
7
+ * Carries a machine-readable `code` and optional `details` payload for defensive debugging.
8
+ */
9
+ export declare class NitroSseError extends Error {
10
+ readonly code: NitroSseErrorCode;
11
+ readonly details?: unknown;
12
+ constructor(message: string, code: NitroSseErrorCode, details?: unknown);
13
+ }
14
+ /**
15
+ * Thrown when the native Nitro hybrid module cannot be resolved or linked.
16
+ */
17
+ export declare class NitroSseModuleNotFoundError extends NitroSseError {
18
+ constructor(message?: string, details?: unknown);
19
+ }
20
+ /**
21
+ * Thrown when configuration parameters, URLs, headers, or arguments fail defensive validation.
22
+ */
23
+ export declare class NitroSseValidationError extends NitroSseError {
24
+ constructor(message: string, code?: 'INVALID_CONFIG' | 'INVALID_ARGUMENT', details?: unknown);
25
+ }
26
+ /**
27
+ * Thrown when an operation is attempted in an invalid state (e.g. calling operations on an unconfigured client).
28
+ */
29
+ export declare class NitroSseStateError extends NitroSseError {
30
+ constructor(message: string, details?: unknown);
31
+ }
32
+ /**
33
+ * Thrown when any method is invoked on a client instance that has already been disposed.
34
+ */
35
+ export declare class NitroSseDisposedError extends NitroSseError {
36
+ constructor(message?: string, details?: unknown);
37
+ }
38
+ //# sourceMappingURL=NitroSseError.d.ts.map
@@ -0,0 +1,80 @@
1
+ import type { NitroSse } from './NitroSse.nitro';
2
+ import type { SseEvent, SseState, SseStats } from './SseInterface';
3
+ import { MockSseEngine } from './MockSseEngine';
4
+ /**
5
+ * Internal execution strategy driving the SSE lifecycle.
6
+ */
7
+ export interface SseDriver {
8
+ start(): void;
9
+ stop(): void;
10
+ restart(): void;
11
+ flush(): void;
12
+ isConnected(): boolean;
13
+ getStats(): SseStats;
14
+ getState(): SseState;
15
+ updateHeaders(headers: Record<string, string>): void;
16
+ setLastProcessedId(id: string): void;
17
+ injectMockEvent(event: Partial<SseEvent>): void;
18
+ dispose(): void;
19
+ }
20
+ /**
21
+ * Driver delegating all operations to the native JSI NitroSse module.
22
+ */
23
+ export declare class NativeDriver implements SseDriver {
24
+ private _native;
25
+ private _dispatchEvents;
26
+ constructor(_native: NitroSse, _dispatchEvents: (events: SseEvent[]) => void);
27
+ start(): void;
28
+ stop(): void;
29
+ restart(): void;
30
+ flush(): void;
31
+ isConnected(): boolean;
32
+ getStats(): SseStats;
33
+ getState(): SseState;
34
+ updateHeaders(headers: Record<string, string>): void;
35
+ setLastProcessedId(id: string): void;
36
+ injectMockEvent(event: Partial<SseEvent>): void;
37
+ dispose(): void;
38
+ }
39
+ /**
40
+ * Driver simulating the entire SSE stream in JavaScript without native networking.
41
+ */
42
+ export declare class MockReplaceDriver implements SseDriver {
43
+ private _mockEngine;
44
+ private _headers;
45
+ private _lastProcessedId?;
46
+ constructor(_mockEngine: MockSseEngine);
47
+ get headers(): Record<string, string>;
48
+ get lastProcessedId(): string | undefined;
49
+ start(): void;
50
+ stop(): void;
51
+ restart(): void;
52
+ flush(): void;
53
+ isConnected(): boolean;
54
+ getStats(): SseStats;
55
+ getState(): SseState;
56
+ updateHeaders(headers: Record<string, string>): void;
57
+ setLastProcessedId(id: string): void;
58
+ injectMockEvent(event: Partial<SseEvent>): void;
59
+ dispose(): void;
60
+ }
61
+ /**
62
+ * Driver running native networking in parallel with mock event injection.
63
+ */
64
+ export declare class MockInjectDriver implements SseDriver {
65
+ private _native;
66
+ private _mockEngine;
67
+ constructor(_native: NitroSse, _mockEngine: MockSseEngine);
68
+ start(): void;
69
+ stop(): void;
70
+ restart(): void;
71
+ flush(): void;
72
+ isConnected(): boolean;
73
+ getStats(): SseStats;
74
+ getState(): SseState;
75
+ updateHeaders(headers: Record<string, string>): void;
76
+ setLastProcessedId(id: string): void;
77
+ injectMockEvent(event: Partial<SseEvent>): void;
78
+ dispose(): void;
79
+ }
80
+ //# sourceMappingURL=SseDriver.d.ts.map
@@ -64,6 +64,7 @@ export interface SseConfig {
64
64
  /**
65
65
  * Initial delay (in ms) for reconnection attempts.
66
66
  * Subsequent attempts use exponential backoff.
67
+ * Note: Native applies a minimum floor of 1000ms.
67
68
  * @default 1000
68
69
  */
69
70
  retryIntervalMs?: number;
@@ -84,9 +85,15 @@ export interface SseConfig {
84
85
  * @default -1
85
86
  */
86
87
  maxReconnectAttempts?: number;
88
+ /**
89
+ * Maximum number of retries when encountering HTTP 401/403 auth errors before stopping.
90
+ * @default 3
91
+ */
92
+ maxAuthRetries?: number;
87
93
  /**
88
94
  * Whether to automatically parse message data as JSON in a background native thread.
89
- * If true, and parsing succeeds, the result will be available in the 'parsedData' field.
95
+ * If true and data is a root JSON Object ('{...}'), the parsed result is available in 'parsedData'.
96
+ * Returns null for JSON arrays or primitives due to Nitro AnyMap object constraints.
90
97
  * @default false
91
98
  */
92
99
  autoParseJSON?: boolean;
@@ -132,6 +139,8 @@ export interface SseMockEvent {
132
139
  retry?: number;
133
140
  /** Custom delay in milliseconds before this event is dispatched. */
134
141
  delayMs?: number;
142
+ /** The connection state if this event represents a state change. */
143
+ state?: SseState;
135
144
  }
136
145
  /**
137
146
  * Configuration for mock streaming data.
@@ -166,13 +175,13 @@ export interface SseMockConfig {
166
175
  /**
167
176
  * Represents a single SSE event.
168
177
  */
169
- export interface SseEvent {
178
+ export interface SseEvent<TData = AnyMap> {
170
179
  /** The type of the event. */
171
180
  type: SseEventType;
172
181
  /** The data payload of the event as a raw string. */
173
182
  data?: string;
174
183
  /** The parsed JSON data, if autoParseJSON is enabled and parsing succeeds. */
175
- parsedData?: AnyMap;
184
+ parsedData?: TData;
176
185
  /** The event ID, if provided. */
177
186
  id?: string;
178
187
  /** The event name, if provided (internal 'event' field in SSE). */
@@ -202,7 +211,7 @@ export interface SseStats {
202
211
  /**
203
212
  * Listener for a specific SSE event.
204
213
  */
205
- export type SseListener = (event: SseEvent) => void;
214
+ export type SseListener<TData = AnyMap> = (event: SseEvent<TData>) => void;
206
215
  /**
207
216
  * Public interface for the NitroSse client, supporting typed event listeners.
208
217
  */
@@ -217,11 +226,15 @@ export interface SseClient {
217
226
  * Register a listener for a specific event type ('message', 'open', etc.)
218
227
  * or a custom SSE event name (from the 'event:' field).
219
228
  */
220
- addEventListener(type: string, listener: SseListener): void;
229
+ addEventListener<TData = AnyMap>(type: string, listener: SseListener<TData>): void;
221
230
  /**
222
231
  * Unregister a listener.
223
232
  */
224
- removeEventListener(type: string, listener: SseListener): void;
233
+ removeEventListener<TData = AnyMap>(type: string, listener: SseListener<TData>): void;
234
+ /**
235
+ * Unregister all listeners, optionally filtered by event type.
236
+ */
237
+ removeAllEventListeners(type?: string): void;
225
238
  /** Start the connection. */
226
239
  start(): void;
227
240
  /** Stop the connection. */
@@ -230,7 +243,10 @@ export interface SseClient {
230
243
  restart(): void;
231
244
  /** Force flush buffered events to JS. */
232
245
  flush(): void;
233
- /** Check if active. */
246
+ /**
247
+ * Check if the client engine is currently running ('connecting', 'open', or 'reconnecting').
248
+ * Use `getState() === 'open'` to check if the stream is actively open and ready.
249
+ */
234
250
  isConnected(): boolean;
235
251
  /** Get stats. */
236
252
  getStats(): SseStats;
@@ -242,5 +258,7 @@ export interface SseClient {
242
258
  injectMockEvent(event: Partial<SseEvent>): void;
243
259
  /** Get current connection state. */
244
260
  getState(): SseState;
261
+ /** Explicitly dispose instance and release native threads/observers. */
262
+ dispose(): void;
245
263
  }
246
264
  //# sourceMappingURL=SseInterface.d.ts.map
@@ -1,11 +1,13 @@
1
1
  import type { SseClient } from './SseInterface';
2
2
  export * from './SseInterface';
3
- export * from './NitroSse.nitro';
3
+ export * from './useNitroSse';
4
+ export * from './NitroSseClient';
5
+ export * from './NitroSseError';
4
6
  /**
5
7
  * Creates a high-performance SSE client that supports typed event listeners (`addEventListener`) and legacy batching.
6
8
  *
7
9
  * @returns An SseClient instance wrapping the native NitroSse implementation.
8
- * @throws If the native NitroSse module cannot be found. Ensure the library is linked and the app is built for iOS/Android.
10
+ * @throws {NitroSseModuleNotFoundError} If the native NitroSse module cannot be found. Ensure the library is linked and the app is built for iOS/Android.
9
11
  */
10
12
  export declare function createNitroSse(): SseClient;
11
13
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,69 @@
1
+ import type { SseClient, SseConfig, SseEvent, SseState, SseStats } from './SseInterface';
2
+ import type { AnyMap } from 'react-native-nitro-modules';
3
+ type SseEventMap = object;
4
+ export interface UseNitroSseOptions<TEvents extends SseEventMap = Record<string, AnyMap>, TMessage = AnyMap> extends SseConfig {
5
+ /**
6
+ * Whether to automatically start streaming on mount or when URL changes.
7
+ * @default true
8
+ */
9
+ autoStart?: boolean;
10
+ /** Map of handlers for specific custom event types */
11
+ events?: {
12
+ [K in keyof TEvents]?: (event: SseEvent<TEvents[K]>) => void;
13
+ };
14
+ /** Handler for incoming message events (both default and custom events) */
15
+ onMessage?: (event: SseEvent<TMessage>) => void;
16
+ /** Handler for transport or connection errors */
17
+ onError?: (event: SseEvent) => void;
18
+ /** Handler for stream open events */
19
+ onOpen?: (event: SseEvent) => void;
20
+ /** Handler for stream close events */
21
+ onClose?: (event: SseEvent) => void;
22
+ /** Handler for keep-alive heartbeat ping events */
23
+ onHeartbeat?: (event: SseEvent) => void;
24
+ /** Handler for connection state transitions */
25
+ onStateChange?: (state: SseState) => void;
26
+ }
27
+ export interface UseNitroSseReturn {
28
+ /** Underlying SseClient instance (null if uninitialized or failed) */
29
+ client: SseClient | null;
30
+ /** Whether the client instance has finished mounting and is ready */
31
+ isReady: boolean;
32
+ /** Current connection state */
33
+ state: SseState;
34
+ /** Whether the client connection is currently running */
35
+ isConnected: boolean;
36
+ /** Start the stream manually */
37
+ start: () => void;
38
+ /** Stop the stream manually */
39
+ stop: () => void;
40
+ /** Restart the stream manually (stop + start) */
41
+ restart: () => void;
42
+ /** Force flush buffered events to JS */
43
+ flush: () => void;
44
+ /** Update request headers */
45
+ updateHeaders: (headers: Record<string, string>) => void;
46
+ /** Set last processed event ID */
47
+ setLastProcessedId: (id: string) => void;
48
+ /** Get connection statistics */
49
+ getStats: () => SseStats | undefined;
50
+ /** Manually inject a mock event into the stream (for testing/debugging) */
51
+ injectMockEvent: (event: Partial<SseEvent>) => void;
52
+ }
53
+ /**
54
+ * Safely serializes an object into a stable JSON string:
55
+ * - Sorts object keys to avoid reconnection on equivalent configs with reordered keys.
56
+ * - Handles circular structures by substituting '[Circular]'.
57
+ * - Handles BigInt by converting to string.
58
+ * - Catches any unexpected serialization error and falls back gracefully.
59
+ */
60
+ export declare function safeSerializeConfig(obj: unknown): string;
61
+ /**
62
+ * Automatically handles client instantiation, listener attachment, state tracking, and lifecycle disposal on unmount.
63
+ *
64
+ * @param options SSE configuration options, callbacks, and custom event handlers.
65
+ * @returns State, client instance, and imperative control methods.
66
+ */
67
+ export declare function useNitroSse<TEvents extends SseEventMap = Record<string, AnyMap>, TMessage = AnyMap>(options: UseNitroSseOptions<TEvents, TMessage>): UseNitroSseReturn;
68
+ export {};
69
+ //# sourceMappingURL=useNitroSse.d.ts.map
@@ -17,10 +17,12 @@
17
17
  #include "JSseMockConfig.hpp"
18
18
  #include "JSseMockEvent.hpp"
19
19
  #include "JSseMockMode.hpp"
20
+ #include "JSseState.hpp"
20
21
  #include "SseEventType.hpp"
21
22
  #include "SseMockConfig.hpp"
22
23
  #include "SseMockEvent.hpp"
23
24
  #include "SseMockMode.hpp"
25
+ #include "SseState.hpp"
24
26
  #include <NitroModules/AnyMap.hpp>
25
27
  #include <NitroModules/JAnyMap.hpp>
26
28
  #include <NitroModules/JNICallable.hpp>
@@ -77,6 +79,8 @@ namespace margelo::nitro::nitrosse {
77
79
  jni::local_ref<jni::JDouble> jitterFactor = this->getFieldValue(fieldJitterFactor);
78
80
  static const auto fieldMaxReconnectAttempts = clazz->getField<jni::JDouble>("maxReconnectAttempts");
79
81
  jni::local_ref<jni::JDouble> maxReconnectAttempts = this->getFieldValue(fieldMaxReconnectAttempts);
82
+ static const auto fieldMaxAuthRetries = clazz->getField<jni::JDouble>("maxAuthRetries");
83
+ jni::local_ref<jni::JDouble> maxAuthRetries = this->getFieldValue(fieldMaxAuthRetries);
80
84
  static const auto fieldAutoParseJSON = clazz->getField<jni::JBoolean>("autoParseJSON");
81
85
  jni::local_ref<jni::JBoolean> autoParseJSON = this->getFieldValue(fieldAutoParseJSON);
82
86
  static const auto fieldMonitorNetwork = clazz->getField<jni::JBoolean>("monitorNetwork");
@@ -106,6 +110,7 @@ namespace margelo::nitro::nitrosse {
106
110
  maxRetryIntervalMs != nullptr ? std::make_optional(maxRetryIntervalMs->value()) : std::nullopt,
107
111
  jitterFactor != nullptr ? std::make_optional(jitterFactor->value()) : std::nullopt,
108
112
  maxReconnectAttempts != nullptr ? std::make_optional(maxReconnectAttempts->value()) : std::nullopt,
113
+ maxAuthRetries != nullptr ? std::make_optional(maxAuthRetries->value()) : std::nullopt,
109
114
  autoParseJSON != nullptr ? std::make_optional(static_cast<bool>(autoParseJSON->value())) : std::nullopt,
110
115
  monitorNetwork != nullptr ? std::make_optional(static_cast<bool>(monitorNetwork->value())) : std::nullopt,
111
116
  onBeforeRequest != nullptr ? std::make_optional([&]() -> std::function<std::shared_ptr<Promise<std::shared_ptr<Promise<std::unordered_map<std::string, std::string>>>>>()> {
@@ -127,7 +132,7 @@ namespace margelo::nitro::nitrosse {
127
132
  */
128
133
  [[maybe_unused]]
129
134
  static jni::local_ref<JSseConfig::javaobject> fromCpp(const SseConfig& value) {
130
- using JSignature = JSseConfig(jni::alias_ref<jni::JString>, jni::alias_ref<JHttpMethod>, jni::alias_ref<jni::JMap<jni::JString, jni::JString>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>, jni::alias_ref<JSseMockConfig>);
135
+ using JSignature = JSseConfig(jni::alias_ref<jni::JString>, jni::alias_ref<JHttpMethod>, jni::alias_ref<jni::JMap<jni::JString, jni::JString>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____::javaobject>, jni::alias_ref<JSseMockConfig>);
131
136
  static const auto clazz = javaClassStatic();
132
137
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
133
138
  return create(
@@ -151,6 +156,7 @@ namespace margelo::nitro::nitrosse {
151
156
  value.maxRetryIntervalMs.has_value() ? jni::JDouble::valueOf(value.maxRetryIntervalMs.value()) : nullptr,
152
157
  value.jitterFactor.has_value() ? jni::JDouble::valueOf(value.jitterFactor.value()) : nullptr,
153
158
  value.maxReconnectAttempts.has_value() ? jni::JDouble::valueOf(value.maxReconnectAttempts.value()) : nullptr,
159
+ value.maxAuthRetries.has_value() ? jni::JDouble::valueOf(value.maxAuthRetries.value()) : nullptr,
154
160
  value.autoParseJSON.has_value() ? jni::JBoolean::valueOf(value.autoParseJSON.value()) : nullptr,
155
161
  value.monitorNetwork.has_value() ? jni::JBoolean::valueOf(value.monitorNetwork.value()) : nullptr,
156
162
  value.onBeforeRequest.has_value() ? JFunc_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______cxx::fromCpp(value.onBeforeRequest.value()) : nullptr,
@@ -13,9 +13,11 @@
13
13
  #include "JSseEventType.hpp"
14
14
  #include "JSseMockEvent.hpp"
15
15
  #include "JSseMockMode.hpp"
16
+ #include "JSseState.hpp"
16
17
  #include "SseEventType.hpp"
17
18
  #include "SseMockEvent.hpp"
18
19
  #include "SseMockMode.hpp"
20
+ #include "SseState.hpp"
19
21
  #include <NitroModules/AnyMap.hpp>
20
22
  #include <NitroModules/JAnyMap.hpp>
21
23
  #include <optional>
@@ -11,7 +11,9 @@
11
11
  #include "SseMockEvent.hpp"
12
12
 
13
13
  #include "JSseEventType.hpp"
14
+ #include "JSseState.hpp"
14
15
  #include "SseEventType.hpp"
16
+ #include "SseState.hpp"
15
17
  #include <NitroModules/AnyMap.hpp>
16
18
  #include <NitroModules/JAnyMap.hpp>
17
19
  #include <optional>
@@ -54,6 +56,8 @@ namespace margelo::nitro::nitrosse {
54
56
  jni::local_ref<jni::JDouble> retry = this->getFieldValue(fieldRetry);
55
57
  static const auto fieldDelayMs = clazz->getField<jni::JDouble>("delayMs");
56
58
  jni::local_ref<jni::JDouble> delayMs = this->getFieldValue(fieldDelayMs);
59
+ static const auto fieldState = clazz->getField<JSseState>("state");
60
+ jni::local_ref<JSseState> state = this->getFieldValue(fieldState);
57
61
  return SseMockEvent(
58
62
  type != nullptr ? std::make_optional(type->toCpp()) : std::nullopt,
59
63
  data != nullptr ? std::make_optional(data->toStdString()) : std::nullopt,
@@ -63,7 +67,8 @@ namespace margelo::nitro::nitrosse {
63
67
  message != nullptr ? std::make_optional(message->toStdString()) : std::nullopt,
64
68
  statusCode != nullptr ? std::make_optional(statusCode->value()) : std::nullopt,
65
69
  retry != nullptr ? std::make_optional(retry->value()) : std::nullopt,
66
- delayMs != nullptr ? std::make_optional(delayMs->value()) : std::nullopt
70
+ delayMs != nullptr ? std::make_optional(delayMs->value()) : std::nullopt,
71
+ state != nullptr ? std::make_optional(state->toCpp()) : std::nullopt
67
72
  );
68
73
  }
69
74
 
@@ -73,7 +78,7 @@ namespace margelo::nitro::nitrosse {
73
78
  */
74
79
  [[maybe_unused]]
75
80
  static jni::local_ref<JSseMockEvent::javaobject> fromCpp(const SseMockEvent& value) {
76
- using JSignature = JSseMockEvent(jni::alias_ref<JSseEventType>, jni::alias_ref<jni::JString>, jni::alias_ref<JAnyMap::javaobject>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>);
81
+ using JSignature = JSseMockEvent(jni::alias_ref<JSseEventType>, jni::alias_ref<jni::JString>, jni::alias_ref<JAnyMap::javaobject>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<JSseState>);
77
82
  static const auto clazz = javaClassStatic();
78
83
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
79
84
  return create(
@@ -86,7 +91,8 @@ namespace margelo::nitro::nitrosse {
86
91
  value.message.has_value() ? jni::make_jstring(value.message.value()) : nullptr,
87
92
  value.statusCode.has_value() ? jni::JDouble::valueOf(value.statusCode.value()) : nullptr,
88
93
  value.retry.has_value() ? jni::JDouble::valueOf(value.retry.value()) : nullptr,
89
- value.delayMs.has_value() ? jni::JDouble::valueOf(value.delayMs.value()) : nullptr
94
+ value.delayMs.has_value() ? jni::JDouble::valueOf(value.delayMs.value()) : nullptr,
95
+ value.state.has_value() ? JSseState::fromCpp(value.state.value()) : nullptr
90
96
  );
91
97
  }
92
98
  };
@@ -59,6 +59,9 @@ data class SseConfig(
59
59
  val maxReconnectAttempts: Double?,
60
60
  @DoNotStrip
61
61
  @Keep
62
+ val maxAuthRetries: Double?,
63
+ @DoNotStrip
64
+ @Keep
62
65
  val autoParseJSON: Boolean?,
63
66
  @DoNotStrip
64
67
  @Keep
@@ -73,8 +76,8 @@ data class SseConfig(
73
76
  /**
74
77
  * Create a new instance of SseConfig from Kotlin
75
78
  */
76
- constructor(url: String, method: HttpMethod?, headers: Map<String, String>?, body: String?, backgroundExecution: Boolean?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, retryIntervalMs: Double?, maxRetryIntervalMs: Double?, jitterFactor: Double?, maxReconnectAttempts: Double?, autoParseJSON: Boolean?, monitorNetwork: Boolean?, onBeforeRequest: (() -> Promise<Promise<Map<String, String>>>)?, mock: SseMockConfig?):
77
- this(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, retryIntervalMs, maxRetryIntervalMs, jitterFactor, maxReconnectAttempts, autoParseJSON, monitorNetwork, onBeforeRequest?.let { Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______java(it) }, mock)
79
+ constructor(url: String, method: HttpMethod?, headers: Map<String, String>?, body: String?, backgroundExecution: Boolean?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, retryIntervalMs: Double?, maxRetryIntervalMs: Double?, jitterFactor: Double?, maxReconnectAttempts: Double?, maxAuthRetries: Double?, autoParseJSON: Boolean?, monitorNetwork: Boolean?, onBeforeRequest: (() -> Promise<Promise<Map<String, String>>>)?, mock: SseMockConfig?):
80
+ this(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, retryIntervalMs, maxRetryIntervalMs, jitterFactor, maxReconnectAttempts, maxAuthRetries, autoParseJSON, monitorNetwork, onBeforeRequest?.let { Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string______java(it) }, mock)
78
81
 
79
82
  override fun equals(other: Any?): Boolean {
80
83
  if (this === other) return true
@@ -92,6 +95,7 @@ data class SseConfig(
92
95
  && Objects.deepEquals(this.maxRetryIntervalMs, other.maxRetryIntervalMs)
93
96
  && Objects.deepEquals(this.jitterFactor, other.jitterFactor)
94
97
  && Objects.deepEquals(this.maxReconnectAttempts, other.maxReconnectAttempts)
98
+ && Objects.deepEquals(this.maxAuthRetries, other.maxAuthRetries)
95
99
  && Objects.deepEquals(this.autoParseJSON, other.autoParseJSON)
96
100
  && Objects.deepEquals(this.monitorNetwork, other.monitorNetwork)
97
101
  && Objects.deepEquals(this.onBeforeRequest, other.onBeforeRequest)
@@ -113,6 +117,7 @@ data class SseConfig(
113
117
  maxRetryIntervalMs,
114
118
  jitterFactor,
115
119
  maxReconnectAttempts,
120
+ maxAuthRetries,
116
121
  autoParseJSON,
117
122
  monitorNetwork,
118
123
  onBeforeRequest,
@@ -128,8 +133,8 @@ data class SseConfig(
128
133
  @Keep
129
134
  @Suppress("unused")
130
135
  @JvmStatic
131
- private fun fromCpp(url: String, method: HttpMethod?, headers: Map<String, String>?, body: String?, backgroundExecution: Boolean?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, retryIntervalMs: Double?, maxRetryIntervalMs: Double?, jitterFactor: Double?, maxReconnectAttempts: Double?, autoParseJSON: Boolean?, monitorNetwork: Boolean?, onBeforeRequest: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____?, mock: SseMockConfig?): SseConfig {
132
- return SseConfig(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, retryIntervalMs, maxRetryIntervalMs, jitterFactor, maxReconnectAttempts, autoParseJSON, monitorNetwork, onBeforeRequest, mock)
136
+ private fun fromCpp(url: String, method: HttpMethod?, headers: Map<String, String>?, body: String?, backgroundExecution: Boolean?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, retryIntervalMs: Double?, maxRetryIntervalMs: Double?, jitterFactor: Double?, maxReconnectAttempts: Double?, maxAuthRetries: Double?, autoParseJSON: Boolean?, monitorNetwork: Boolean?, onBeforeRequest: Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__unordered_map_std__string__std__string_____?, mock: SseMockConfig?): SseConfig {
137
+ return SseConfig(url, method, headers, body, backgroundExecution, batchingIntervalMs, maxBufferSize, connectionTimeoutMs, readTimeoutMs, retryIntervalMs, maxRetryIntervalMs, jitterFactor, maxReconnectAttempts, maxAuthRetries, autoParseJSON, monitorNetwork, onBeforeRequest, mock)
133
138
  }
134
139
  }
135
140
  }
@@ -44,7 +44,10 @@ data class SseMockEvent(
44
44
  val retry: Double?,
45
45
  @DoNotStrip
46
46
  @Keep
47
- val delayMs: Double?
47
+ val delayMs: Double?,
48
+ @DoNotStrip
49
+ @Keep
50
+ val state: SseState?
48
51
  ) {
49
52
  /* primary constructor */
50
53
 
@@ -60,6 +63,7 @@ data class SseMockEvent(
60
63
  && Objects.deepEquals(this.statusCode, other.statusCode)
61
64
  && Objects.deepEquals(this.retry, other.retry)
62
65
  && Objects.deepEquals(this.delayMs, other.delayMs)
66
+ && Objects.deepEquals(this.state, other.state)
63
67
  }
64
68
 
65
69
  override fun hashCode(): Int {
@@ -72,7 +76,8 @@ data class SseMockEvent(
72
76
  message,
73
77
  statusCode,
74
78
  retry,
75
- delayMs
79
+ delayMs,
80
+ state
76
81
  ).contentDeepHashCode()
77
82
  }
78
83
 
@@ -84,8 +89,8 @@ data class SseMockEvent(
84
89
  @Keep
85
90
  @Suppress("unused")
86
91
  @JvmStatic
87
- private fun fromCpp(type: SseEventType?, data: String?, parsedData: AnyMap?, id: String?, event: String?, message: String?, statusCode: Double?, retry: Double?, delayMs: Double?): SseMockEvent {
88
- return SseMockEvent(type, data, parsedData, id, event, message, statusCode, retry, delayMs)
92
+ private fun fromCpp(type: SseEventType?, data: String?, parsedData: AnyMap?, id: String?, event: String?, message: String?, statusCode: Double?, retry: Double?, delayMs: Double?, state: SseState?): SseMockEvent {
93
+ return SseMockEvent(type, data, parsedData, id, event, message, statusCode, retry, delayMs, state)
89
94
  }
90
95
  }
91
96
  }
@@ -317,6 +317,21 @@ namespace margelo::nitro::nitrosse::bridge::swift {
317
317
  return optional.value();
318
318
  }
319
319
 
320
+ // pragma MARK: std::optional<SseState>
321
+ /**
322
+ * Specialized version of `std::optional<SseState>`.
323
+ */
324
+ using std__optional_SseState_ = std::optional<SseState>;
325
+ inline std::optional<SseState> create_std__optional_SseState_(const SseState& value) noexcept {
326
+ return std::optional<SseState>(value);
327
+ }
328
+ inline bool has_value_std__optional_SseState_(const std::optional<SseState>& optional) noexcept {
329
+ return optional.has_value();
330
+ }
331
+ inline SseState get_std__optional_SseState_(const std::optional<SseState>& optional) noexcept {
332
+ return optional.value();
333
+ }
334
+
320
335
  // pragma MARK: std::vector<SseMockEvent>
321
336
  /**
322
337
  * Specialized version of `std::vector<SseMockEvent>`.
@@ -343,21 +358,6 @@ namespace margelo::nitro::nitrosse::bridge::swift {
343
358
  return optional.value();
344
359
  }
345
360
 
346
- // pragma MARK: std::optional<SseState>
347
- /**
348
- * Specialized version of `std::optional<SseState>`.
349
- */
350
- using std__optional_SseState_ = std::optional<SseState>;
351
- inline std::optional<SseState> create_std__optional_SseState_(const SseState& value) noexcept {
352
- return std::optional<SseState>(value);
353
- }
354
- inline bool has_value_std__optional_SseState_(const std::optional<SseState>& optional) noexcept {
355
- return optional.has_value();
356
- }
357
- inline SseState get_std__optional_SseState_(const std::optional<SseState>& optional) noexcept {
358
- return optional.value();
359
- }
360
-
361
361
  // pragma MARK: std::vector<SseEvent>
362
362
  /**
363
363
  * Specialized version of `std::vector<SseEvent>`.
@@ -24,10 +24,10 @@ namespace margelo::nitro::nitrosse { enum class SseMockMode; }
24
24
  namespace margelo::nitro::nitrosse { struct SseMockEvent; }
25
25
  // Forward declaration of `SseEventType` to properly resolve imports.
26
26
  namespace margelo::nitro::nitrosse { enum class SseEventType; }
27
- // Forward declaration of `SseEvent` to properly resolve imports.
28
- namespace margelo::nitro::nitrosse { struct SseEvent; }
29
27
  // Forward declaration of `SseState` to properly resolve imports.
30
28
  namespace margelo::nitro::nitrosse { enum class SseState; }
29
+ // Forward declaration of `SseEvent` to properly resolve imports.
30
+ namespace margelo::nitro::nitrosse { struct SseEvent; }
31
31
  // Forward declaration of `SseStats` to properly resolve imports.
32
32
  namespace margelo::nitro::nitrosse { struct SseStats; }
33
33
 
@@ -44,8 +44,8 @@ namespace margelo::nitro::nitrosse { struct SseStats; }
44
44
  #include <vector>
45
45
  #include "SseEventType.hpp"
46
46
  #include <NitroModules/AnyMap.hpp>
47
- #include "SseEvent.hpp"
48
47
  #include "SseState.hpp"
48
+ #include "SseEvent.hpp"
49
49
  #include "SseStats.hpp"
50
50
 
51
51
  #include "NitroSse-Swift-Cxx-Umbrella.hpp"
@@ -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?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, retryIntervalMs: Double?, maxRetryIntervalMs: Double?, jitterFactor: Double?, maxReconnectAttempts: Double?, autoParseJSON: Bool?, monitorNetwork: Bool?, onBeforeRequest: (() -> Promise<Promise<Dictionary<String, String>>>)?, mock: SseMockConfig?) {
21
+ init(url: String, method: HttpMethod?, headers: Dictionary<String, String>?, body: String?, backgroundExecution: Bool?, batchingIntervalMs: Double?, maxBufferSize: Double?, connectionTimeoutMs: Double?, readTimeoutMs: Double?, retryIntervalMs: Double?, maxRetryIntervalMs: Double?, jitterFactor: Double?, maxReconnectAttempts: Double?, maxAuthRetries: Double?, autoParseJSON: Bool?, monitorNetwork: Bool?, onBeforeRequest: (() -> Promise<Promise<Dictionary<String, String>>>)?, mock: SseMockConfig?) {
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)
@@ -97,6 +97,12 @@ public extension SseConfig {
97
97
  } else {
98
98
  return .init()
99
99
  }
100
+ }(), { () -> bridge.std__optional_double_ in
101
+ if let __unwrappedValue = maxAuthRetries {
102
+ return bridge.create_std__optional_double_(__unwrappedValue)
103
+ } else {
104
+ return .init()
105
+ }
100
106
  }(), { () -> bridge.std__optional_bool_ in
101
107
  if let __unwrappedValue = autoParseJSON {
102
108
  return bridge.create_std__optional_bool_(__unwrappedValue)
@@ -277,6 +283,18 @@ public extension SseConfig {
277
283
  }()
278
284
  }
279
285
 
286
+ @inline(__always)
287
+ var maxAuthRetries: Double? {
288
+ return { () -> Double? in
289
+ if bridge.has_value_std__optional_double_(self.__maxAuthRetries) {
290
+ let __unwrapped = bridge.get_std__optional_double_(self.__maxAuthRetries)
291
+ return __unwrapped
292
+ } else {
293
+ return nil
294
+ }
295
+ }()
296
+ }
297
+
280
298
  @inline(__always)
281
299
  var autoParseJSON: Bool? {
282
300
  return { () -> Bool? in