@logbrew/react-native 0.1.40 → 0.1.42

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/README.md CHANGED
@@ -80,9 +80,9 @@ For mobile apps, prefer an app-scoped public key through `clientKey`. Expo
80
80
  inlines `EXPO_PUBLIC_*` values into the app, so never use a server key there.
81
81
  `apiKey` is still accepted for compatibility with lower-level SDK examples.
82
82
 
83
- Supplying `transport` enables the core SDK's bounded automatic delivery. On
84
- mobile it sends 5 seconds after the first queued event or at 50 queued events,
85
- which saves battery and radio wakeups; set `deliveryIntervalMs` to change it. It
83
+ Supplying `transport` enables the core SDK's bounded automatic delivery. It
84
+ sends 1 second after the first queued event or at 50 queued events, whichever
85
+ comes first; set `deliveryIntervalMs` to change it. It
86
86
  coalesces concurrent work, retries transient failures, retains rejected
87
87
  batches, waits out short rate limits on its own, and pauses repeated automatic
88
88
  sends after authentication, usage-limit, or non-retryable failures. Do not add a second app-owned flush interval.
package/index.cjs CHANGED
@@ -36,8 +36,8 @@ const { getReactNativeContext } = require("./index-values.cjs");
36
36
  */
37
37
 
38
38
  const DEFAULT_SDK_NAME = "logbrew-react-native";
39
- const DEFAULT_SDK_VERSION = "0.1.40";
40
- const DEFAULT_REACT_NATIVE_DELIVERY_INTERVAL_MS = 5000;
39
+ const DEFAULT_SDK_VERSION = "0.1.42";
40
+ const DEFAULT_REACT_NATIVE_DELIVERY_INTERVAL_MS = 1000;
41
41
  const DEFAULT_MAX_RETRIES = 2;
42
42
 
43
43
  /**
@@ -3,7 +3,7 @@ import Foundation
3
3
  @objc(LBRNAppleNativeDiagnostics)
4
4
  public final class LBRNAppleNativeDiagnostics: NSObject, @unchecked Sendable {
5
5
  private static let shared = LBRNAppleNativeDiagnostics()
6
- private static let sdkVersion = "0.1.40"
6
+ private static let sdkVersion = "0.1.42"
7
7
 
8
8
  private let lock = NSLock()
9
9
  private let replayQueue = DispatchQueue(label: "co.logbrew.react-native.apple-diagnostics-replay")
@@ -106,7 +106,7 @@ final class DeliveryEngine: @unchecked Sendable {
106
106
  consecutiveFailures: consecutiveFailures,
107
107
  lastOutcome: lastOutcome,
108
108
  pauseReason: pauseReason,
109
- nextRetryDelay: state == .retrying ? nextWakeNanoseconds.map { deadline in
109
+ nextRetryDelay: state == .retrying || state == .paused ? nextWakeNanoseconds.map { deadline in
110
110
  let now = DispatchTime.now().uptimeNanoseconds
111
111
  return TimeInterval(deadline > now ? deadline - now : 0) / 1_000_000_000
112
112
  } : nil,
@@ -15,7 +15,7 @@ extension DeliveryEngine {
15
15
  return
16
16
  }
17
17
  nextWakeNanoseconds = nil
18
- let active = automaticTransport != nil && (state == .running || state == .retrying)
18
+ let active = automaticTransport != nil && sendsAutomaticallyLocked
19
19
  stateLock.unlock()
20
20
  guard active else {
21
21
  return
@@ -49,16 +49,22 @@ extension DeliveryEngine {
49
49
  private func transportForAutomaticRun(generation currentGeneration: UInt64) -> (any Transport)? {
50
50
  stateLock.lock()
51
51
  defer { stateLock.unlock() }
52
- guard generation == currentGeneration, state == .running || state == .retrying else {
52
+ guard generation == currentGeneration, sendsAutomaticallyLocked else {
53
53
  return nil
54
54
  }
55
55
  return automaticTransport
56
56
  }
57
57
 
58
+ /// Running and retrying deliveries send on their schedule; a paused one sends only its probe.
59
+ private var sendsAutomaticallyLocked: Bool {
60
+ state == .running || state == .retrying || (state == .paused && pauseReason != .storage)
61
+ }
62
+
58
63
  private func finishEmptyAutomaticRun(generation currentGeneration: UInt64) {
59
64
  stateLock.lock()
60
- if generation == currentGeneration, state != .paused {
65
+ if generation == currentGeneration, state != .paused || pauseReason != .storage {
61
66
  state = .running
67
+ pauseReason = .none
62
68
  }
63
69
  stateLock.unlock()
64
70
  }
@@ -129,14 +135,13 @@ extension DeliveryEngine {
129
135
  private func applyAutomaticResultLocked(_ result: AttemptResult, prefix: FrozenPrefix) -> Bool {
130
136
  switch result {
131
137
  case .accepted:
132
- return applyAcceptedResultLocked(prefix)
138
+ applyAcceptedResultLocked(prefix)
133
139
  case .retryable:
134
- return applyRetryableResultLocked()
140
+ applyRetryableResultLocked()
135
141
  case let .terminal(reason, _, _):
136
142
  applyTerminalResultLocked(reason: reason)
137
- return false
138
143
  case let .rateLimited(retryAfter, _, _):
139
- return applyRateLimitedResultLocked(retryAfter: retryAfter)
144
+ applyRateLimitedResultLocked(retryAfter: retryAfter)
140
145
  }
141
146
  }
142
147
 
@@ -172,6 +177,7 @@ extension DeliveryEngine {
172
177
  return false
173
178
  }
174
179
  state = .running
180
+ pauseReason = .none
175
181
  return scheduleLiveQueueLocked()
176
182
  }
177
183
 
@@ -184,20 +190,45 @@ extension DeliveryEngine {
184
190
  guard retryAttempt < maxRetries else {
185
191
  state = .paused
186
192
  pauseReason = .retryExhausted
187
- return false
193
+ return schedulePauseProbeLocked()
188
194
  }
189
195
  retryAttempt += 1
190
196
  state = .retrying
191
197
  return scheduleRetryLocked()
192
198
  }
193
199
 
194
- private func applyTerminalResultLocked(reason: DeliveryPauseReason) {
200
+ private func applyTerminalResultLocked(reason: DeliveryPauseReason) -> Bool {
195
201
  consecutiveFailures += 1
196
202
  lastOutcome = .terminalFailure
197
- if state != .shuttingDown {
198
- state = .paused
199
- pauseReason = reason
203
+ guard state != .shuttingDown else {
204
+ return false
200
205
  }
206
+ state = .paused
207
+ pauseReason = reason
208
+ return schedulePauseProbeLocked()
209
+ }
210
+
211
+ /// Schedules one resend of a paused delivery, so it resumes on its own once ingest accepts it again.
212
+ /// A storage pause waits for explicit recovery, because sending could lose or repeat durable data.
213
+ private func schedulePauseProbeLocked() -> Bool {
214
+ guard let options = automaticOptions, state == .paused, pauseReason != .storage else {
215
+ return false
216
+ }
217
+ nextWakeNanoseconds = nil
218
+ let delay = Self.pauseProbeDelay(maxRetryDelay: options.maxRetryDelay, failures: consecutiveFailures)
219
+ return setWakeLocked(delay: delay, replaceLaterWake: true)
220
+ }
221
+
222
+ /// Doubles from `maxRetryDelay` with each consecutive failure up to 5 minutes, or up to
223
+ /// `maxRetryDelay` when it is longer, then keeps half to all of that ceiling as jitter.
224
+ static func pauseProbeDelay(
225
+ maxRetryDelay: TimeInterval,
226
+ failures: Int,
227
+ jitter: Double = .random(in: 0 ... 1),
228
+ ) -> TimeInterval {
229
+ let maximum = max(maxRetryDelay, 5 * 60)
230
+ let ceiling = min(maxRetryDelay * pow(2, Double(max(0, failures - 1))), maximum)
231
+ return ceiling / 2 + ceiling / 2 * jitter
201
232
  }
202
233
 
203
234
  func scheduleCaptureLocked() -> Bool {
@@ -279,6 +310,8 @@ extension DeliveryEngine {
279
310
  let shouldSchedule: Bool
280
311
  if state == .retrying, nextWakeNanoseconds != nil {
281
312
  shouldSchedule = true
313
+ } else if state == .paused, pauseReason != .storage {
314
+ shouldSchedule = schedulePauseProbeLocked()
282
315
  } else if automaticTransport != nil, state != .paused, state != .shuttingDown, state != .closed {
283
316
  state = .running
284
317
  retryAttempt = 0
@@ -44,7 +44,7 @@ public struct AutomaticDeliveryOptions: Equatable, Sendable {
44
44
  public let maxRetryDelay: TimeInterval
45
45
 
46
46
  public init(
47
- interval: TimeInterval = 5,
47
+ interval: TimeInterval = 1,
48
48
  threshold: Int = 100,
49
49
  retryBaseDelay: TimeInterval = 0.25,
50
50
  maxRetryDelay: TimeInterval = 30,
@@ -67,6 +67,6 @@ public struct DeliveryHealth: Codable, Equatable, Sendable {
67
67
  public let consecutiveFailures: Int
68
68
  public let lastOutcome: DeliveryOutcome
69
69
  public let pauseReason: DeliveryPauseReason
70
- /// Seconds until the scheduled automatic retry, or `nil` when no retry is scheduled.
70
+ /// Seconds until the scheduled automatic retry or paused-delivery probe, or `nil` when none is scheduled.
71
71
  public let nextRetryDelay: TimeInterval?
72
72
  }
@@ -2,11 +2,11 @@
2
2
  "schemaVersion": 1,
3
3
  "sources": {
4
4
  "swift/logbrew-swift/Sources/LogBrew/AutomaticTelemetryContext.swift": "76ab7f8a7c79db1d54ba13da8d61d96af62c509116b7df0f9d220d5c88364c00",
5
- "swift/logbrew-swift/Sources/LogBrew/DeliveryEngine.swift": "6cbc2c52f5b39b9627fa707b023b84fb306a736bec9f82163d7ca4aa21b01b1c",
6
- "swift/logbrew-swift/Sources/LogBrew/DeliveryEngineAutomatic.swift": "cd05cd45aeea52cde3d228938acf9ff2e784c1e2350cf2473c3b72030a3abf64",
5
+ "swift/logbrew-swift/Sources/LogBrew/DeliveryEngine.swift": "274ca2ed671add1f7c51494e2a4e254b0fecd6fd7d80321ee0836e3521c2b02b",
6
+ "swift/logbrew-swift/Sources/LogBrew/DeliveryEngineAutomatic.swift": "d261e2364edffe82ccb7e962f12e6864a0077d41204e0b021c8160635cc843b2",
7
7
  "swift/logbrew-swift/Sources/LogBrew/DeliveryEngineDurable.swift": "b0d2ca07cce7fe01fc110238c7d10aa9c8ada0d28509e4c022e7fa950a4c79b9",
8
8
  "swift/logbrew-swift/Sources/LogBrew/DeliveryEngineQueue.swift": "e187a737e18dd88a4be8719f1a3a07776c6d6eb0edb5b1904a82c5059a0aef57",
9
- "swift/logbrew-swift/Sources/LogBrew/DeliveryLifecycle.swift": "af7b36649f9d07ac4567652f578c008e4ec8086f14c157b2d5144df93d211aaf",
9
+ "swift/logbrew-swift/Sources/LogBrew/DeliveryLifecycle.swift": "48cc8d89bbdcdff2f73a188d4824b03c3614cade8e3e3a85a710eaf827f6c413",
10
10
  "swift/logbrew-swift/Sources/LogBrew/DurableDeliveryStore.swift": "7c292dda68efc3de790daf44733b25e4392226793343c21ba5df4f51fc1b402b",
11
11
  "swift/logbrew-swift/Sources/LogBrew/DurableDeliveryStoreRecovery.swift": "79fee27975b6571954bf0b3692a50e60bbbcf53b5ab47f653a474db5c56d68ba",
12
12
  "swift/logbrew-swift/Sources/LogBrew/EventEncoding.swift": "b88b6b2d17f7d0cee9ac1a1f34ef35b192cd33d213ef3c9e1c2d21cbcc304a97",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logbrew/react-native",
3
- "version": "0.1.40",
3
+ "version": "0.1.42",
4
4
  "description": "React Native offline delivery, native diagnostics, screen, error, trace, action, and network timeline helpers for LogBrew.",
5
5
  "type": "module",
6
6
  "main": "./index.cjs",
package/types/config.d.ts CHANGED
@@ -26,7 +26,7 @@ type CreateLogBrewReactNativeClientConfig = {
26
26
  apiKey?: string;
27
27
  clientKey?: string;
28
28
  context?: TelemetryContext;
29
- /** Automatic delivery interval in milliseconds. Defaults to 5000 on mobile to save battery. */
29
+ /** Automatic delivery interval in milliseconds. Defaults to 1000. */
30
30
  deliveryIntervalMs?: number;
31
31
  deliveryQueueThreshold?: number;
32
32
  /** Advanced synchronous persistence seam. React Native apps normally use the native entry's persistentQueue mode. */