@logbrew/react-native 0.1.38 → 0.1.39
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/LogBrewReactNative.podspec +1 -1
- package/README.md +17 -15
- package/index.cjs +28 -5
- package/ios/AppleDiagnostics/LBRNAppleNativeDiagnostics.swift +1 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngine.swift +7 -1
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineAutomatic.swift +36 -4
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryEngineQueue.swift +17 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/DeliveryLifecycle.swift +2 -0
- package/ios/GeneratedAppleDiagnostics/LogBrew/Transport.swift +41 -6
- package/ios/GeneratedAppleDiagnostics/SOURCE-MANIFEST.json +5 -5
- package/package.json +2 -2
|
@@ -8,7 +8,7 @@ Pod::Spec.new do |spec|
|
|
|
8
8
|
spec.summary = package["description"]
|
|
9
9
|
spec.homepage = "https://github.com/LogBrewCo/sdk"
|
|
10
10
|
spec.license = package["license"]
|
|
11
|
-
spec.authors = { "LogBrew" => "
|
|
11
|
+
spec.authors = { "LogBrew" => "support@logbrew.co" }
|
|
12
12
|
spec.platforms = { :ios => "13.0" }
|
|
13
13
|
spec.source = {
|
|
14
14
|
:git => "https://github.com/LogBrewCo/sdk.git",
|
package/README.md
CHANGED
|
@@ -84,8 +84,8 @@ Supplying `transport` enables the core SDK's bounded automatic delivery. On
|
|
|
84
84
|
mobile it sends 5 seconds after the first queued event or at 50 queued events,
|
|
85
85
|
which saves battery and radio wakeups; set `deliveryIntervalMs` to change it. It
|
|
86
86
|
coalesces concurrent work, retries transient failures, retains rejected
|
|
87
|
-
batches,
|
|
88
|
-
or non-retryable failures. Do not add a second app-owned flush interval.
|
|
87
|
+
batches, waits out short rate limits on its own, and pauses repeated automatic
|
|
88
|
+
sends after authentication, usage-limit, or non-retryable failures. Do not add a second app-owned flush interval.
|
|
89
89
|
`flushOnBackground: true` requests one final flush when AppState becomes
|
|
90
90
|
`inactive` or `background`; a failure never escapes the AppState callback.
|
|
91
91
|
Helpers generate a fresh opaque event ID by default. Explicit `id` and
|
|
@@ -96,7 +96,7 @@ Helpers generate a fresh opaque event ID by default. Explicit `id` and
|
|
|
96
96
|
Call `verifyLogBrewSetup()` once from a development-only button or setup
|
|
97
97
|
screen. A returned `hosted_accepted` receipt means the configured HTTPS intake
|
|
98
98
|
accepted every batch in that flush. Then use an authenticated CLI session to
|
|
99
|
-
confirm that
|
|
99
|
+
confirm that LogBrew stored the event for the intended project:
|
|
100
100
|
|
|
101
101
|
```bash
|
|
102
102
|
logbrew read logs --project <project_id> \
|
|
@@ -118,9 +118,12 @@ Use `client.deliveryHealth()` for content-free queue and delivery state. In
|
|
|
118
118
|
particular, inspect `deliveryState`, `lastOutcome`, `lastStatusClass`,
|
|
119
119
|
`pausedReason`, `queueEvents`, and `acceptedEvents`. A `401` pauses automatic
|
|
120
120
|
delivery with `pausedReason: "authentication"`; rotate or correct the public
|
|
121
|
-
client key before creating a new client. A `429` preserves the queue
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
client key before creating a new client. A `429` always preserves the queue.
|
|
122
|
+
When it carries `Retry-After` or `code: "rate_limited"`, delivery waits that
|
|
123
|
+
long (1 second to 1 hour, plus a little jitter) and then resends on its own,
|
|
124
|
+
with `deliveryState: "retrying"`. A `429` with `code: "usage_limit_exceeded"`,
|
|
125
|
+
or with neither signal, reports `pausedReason: "rate_limit"` until a
|
|
126
|
+
successful `flush()`.
|
|
124
127
|
|
|
125
128
|
## Read Events Back
|
|
126
129
|
|
|
@@ -377,8 +380,8 @@ Otherwise the crash is recorded as usual.
|
|
|
377
380
|
handlers, stops the watchdog, and leaves queued events available. After closing
|
|
378
381
|
the client, purge only for an explicit discard. Upload exact-release Android
|
|
379
382
|
symbols with `logbrew debug-artifacts upload`, require build-ID/architecture
|
|
380
|
-
lookup
|
|
381
|
-
replay, hang capture, and symbolicated
|
|
383
|
+
lookup. Keep your existing crash reporter until you have confirmed crash
|
|
384
|
+
replay, hang capture, and symbolicated issues in LogBrew.
|
|
382
385
|
|
|
383
386
|
For Expo prebuild or development builds, add the config plugin:
|
|
384
387
|
|
|
@@ -442,8 +445,8 @@ void replayLogBrewAppleNativeDiagnostics().catch((error) => {
|
|
|
442
445
|
```
|
|
443
446
|
|
|
444
447
|
`fatalHandlerOwnership: "logbrew"` is an explicit process-lifetime ownership
|
|
445
|
-
claim. Do not install these diagnostics while
|
|
446
|
-
owns the native fatal signal or Mach exception handlers. Linking both SDKs is
|
|
448
|
+
claim. Do not install these diagnostics while another crash reporter or
|
|
449
|
+
integration owns the native fatal signal or Mach exception handlers. Linking both SDKs is
|
|
447
450
|
allowed, but only one integration may install native fatal capture in a given
|
|
448
451
|
process. LogBrew cannot transfer or remove that ownership before process
|
|
449
452
|
restart.
|
|
@@ -542,8 +545,8 @@ reading the rejection value or emitting the runtime rejection identifier.
|
|
|
542
545
|
`rejectionHealth()` returns bounded duplicate, eviction, and later-handled
|
|
543
546
|
counters.
|
|
544
547
|
|
|
545
|
-
Do not install this helper while
|
|
546
|
-
tracker slot. Use the app-owned callback composition below when another
|
|
548
|
+
Do not install this helper while another crash reporter or integration owns
|
|
549
|
+
the same tracker slot. Use the app-owned callback composition below when another
|
|
547
550
|
integration must remain the owner. Hermes does not expose a previous-owner
|
|
548
551
|
restoration API. `deactivate()` therefore stops LogBrew capture through its
|
|
549
552
|
installed callbacks but cannot reinstate an earlier tracker. Install
|
|
@@ -650,8 +653,7 @@ when available. It strips query strings, hashes, hosts, and local absolute
|
|
|
650
653
|
paths from React Native frame data. Grouping keeps an informative sanitized
|
|
651
654
|
path, or falls back to a safe function name and then generated position for a
|
|
652
655
|
root-only runtime URL; raw stack text is still opt-in with `includeStack: true`.
|
|
653
|
-
|
|
654
|
-
uploaded release artifact.
|
|
656
|
+
LogBrew resolves source maps from the matching uploaded release artifact.
|
|
655
657
|
|
|
656
658
|
## Provider And Hooks
|
|
657
659
|
|
|
@@ -697,7 +699,7 @@ export function App({ client }) {
|
|
|
697
699
|
}
|
|
698
700
|
```
|
|
699
701
|
|
|
700
|
-
Screen views carry the versioned `screen_view` analytics classification, and explicit product actions carry `interaction`. The SDK uses the app-owned screen name as a bounded surface and does not inspect view hierarchies, selectors, or input values. Caller metadata cannot replace the reserved classification. See the repository [product analytics capture contract](../../
|
|
702
|
+
Screen views carry the versioned `screen_view` analytics classification, and explicit product actions carry `interaction`. The SDK uses the app-owned screen name as a bounded surface and does not inspect view hierarchies, selectors, or input values. Caller metadata cannot replace the reserved classification. See the repository [product analytics capture contract](../../README.md#product-analytics-capture).
|
|
701
703
|
|
|
702
704
|
The package ships a `react-native` entry that binds platform state and linked native services for Metro, while the default server entry accepts runtime dependencies explicitly. That keeps mobile setup explicit without treating a server process as a native runtime.
|
|
703
705
|
|
package/index.cjs
CHANGED
|
@@ -16,8 +16,9 @@ const {
|
|
|
16
16
|
} = require("./metadata.cjs");
|
|
17
17
|
|
|
18
18
|
const DEFAULT_SDK_NAME = "logbrew-react-native";
|
|
19
|
-
const DEFAULT_SDK_VERSION = "0.1.
|
|
19
|
+
const DEFAULT_SDK_VERSION = "0.1.39";
|
|
20
20
|
const DEFAULT_ENDPOINT = "https://api.logbrew.co/v1/events";
|
|
21
|
+
const RATE_LIMIT_BODY_LIMIT_BYTES = 4096;
|
|
21
22
|
const NATIVE_RANDOM_HEX = Symbol.for("co.logbrew.react-native.secure-random-hex");
|
|
22
23
|
const MAX_ACTION_NAME_LENGTH = 64;
|
|
23
24
|
const MAX_PRODUCT_ANALYTICS_SURFACE_LENGTH = 256;
|
|
@@ -97,9 +98,13 @@ function createReactNativeFetchTransport({
|
|
|
97
98
|
method: "POST"
|
|
98
99
|
});
|
|
99
100
|
const retryAfterMs = retryAfterMsFromHeaders(response?.headers);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
const errorCode = response?.status === 429 ? await rateLimitCode(response) : undefined;
|
|
102
|
+
return {
|
|
103
|
+
statusCode: response?.status,
|
|
104
|
+
attempts: 1,
|
|
105
|
+
...(retryAfterMs === undefined ? {} : { retryAfterMs }),
|
|
106
|
+
...(errorCode === undefined ? {} : { errorCode })
|
|
107
|
+
};
|
|
103
108
|
} catch {
|
|
104
109
|
throw TransportError.network("LogBrew React Native delivery failed");
|
|
105
110
|
}
|
|
@@ -865,6 +870,21 @@ function retryAfterMsFromHeaders(headers) {
|
|
|
865
870
|
return retryAfterMsFromHeader(headers.get("retry-after"));
|
|
866
871
|
}
|
|
867
872
|
|
|
873
|
+
// Reads a 429 body only when it declares at most 4 KiB, and only to find a known `code`.
|
|
874
|
+
async function rateLimitCode(response) {
|
|
875
|
+
try {
|
|
876
|
+
const length = Number(response.headers?.get?.("content-length"));
|
|
877
|
+
if (!Number.isSafeInteger(length) || length > RATE_LIMIT_BODY_LIMIT_BYTES || typeof response.text !== "function") {
|
|
878
|
+
return undefined;
|
|
879
|
+
}
|
|
880
|
+
const text = await response.text();
|
|
881
|
+
const code = text.length <= RATE_LIMIT_BODY_LIMIT_BYTES ? JSON.parse(text)?.code : undefined;
|
|
882
|
+
return code === "rate_limited" || code === "usage_limit_exceeded" ? code : undefined;
|
|
883
|
+
} catch {
|
|
884
|
+
return undefined;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
868
888
|
function retryAfterMsFromHeader(value, now = Date.now()) {
|
|
869
889
|
if (typeof value !== "string" || value.trim() === "") {
|
|
870
890
|
return undefined;
|
|
@@ -874,7 +894,10 @@ function retryAfterMsFromHeader(value, now = Date.now()) {
|
|
|
874
894
|
const milliseconds = Number(trimmed) * 1000;
|
|
875
895
|
return Number.isSafeInteger(milliseconds) ? milliseconds : undefined;
|
|
876
896
|
}
|
|
877
|
-
|
|
897
|
+
// Only an HTTP date counts; a repeated header arrives comma-joined and is ignored.
|
|
898
|
+
const timestamp = /^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/u.test(trimmed)
|
|
899
|
+
? Date.parse(trimmed)
|
|
900
|
+
: Number.NaN;
|
|
878
901
|
return Number.isFinite(timestamp) ? Math.max(0, timestamp - now) : undefined;
|
|
879
902
|
}
|
|
880
903
|
|
|
@@ -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.
|
|
6
|
+
private static let sdkVersion = "0.1.39"
|
|
7
7
|
|
|
8
8
|
private let lock = NSLock()
|
|
9
9
|
private let replayQueue = DispatchQueue(label: "co.logbrew.react-native.apple-diagnostics-replay")
|
|
@@ -27,10 +27,12 @@ final class DeliveryEngine: @unchecked Sendable {
|
|
|
27
27
|
case accepted(statusCode: Int, attempts: Int)
|
|
28
28
|
case retryable(attempts: Int, error: SdkError)
|
|
29
29
|
case terminal(reason: DeliveryPauseReason, attempts: Int, error: SdkError)
|
|
30
|
+
case rateLimited(retryAfter: TimeInterval?, attempts: Int, error: SdkError)
|
|
30
31
|
|
|
31
32
|
var attempts: Int {
|
|
32
33
|
switch self {
|
|
33
|
-
case let .accepted(_, attempts), let .retryable(attempts, _), let .terminal(_, attempts, _)
|
|
34
|
+
case let .accepted(_, attempts), let .retryable(attempts, _), let .terminal(_, attempts, _),
|
|
35
|
+
let .rateLimited(_, attempts, _):
|
|
34
36
|
attempts
|
|
35
37
|
}
|
|
36
38
|
}
|
|
@@ -104,6 +106,10 @@ final class DeliveryEngine: @unchecked Sendable {
|
|
|
104
106
|
consecutiveFailures: consecutiveFailures,
|
|
105
107
|
lastOutcome: lastOutcome,
|
|
106
108
|
pauseReason: pauseReason,
|
|
109
|
+
nextRetryDelay: state == .retrying ? nextWakeNanoseconds.map { deadline in
|
|
110
|
+
let now = DispatchTime.now().uptimeNanoseconds
|
|
111
|
+
return TimeInterval(deadline > now ? deadline - now : 0) / 1_000_000_000
|
|
112
|
+
} : nil,
|
|
107
113
|
)
|
|
108
114
|
}
|
|
109
115
|
}
|
|
@@ -135,9 +135,33 @@ extension DeliveryEngine {
|
|
|
135
135
|
case let .terminal(reason, _, _):
|
|
136
136
|
applyTerminalResultLocked(reason: reason)
|
|
137
137
|
return false
|
|
138
|
+
case let .rateLimited(retryAfter, _, _):
|
|
139
|
+
return applyRateLimitedResultLocked(retryAfter: retryAfter)
|
|
138
140
|
}
|
|
139
141
|
}
|
|
140
142
|
|
|
143
|
+
/// Schedules a timed retry of the same prefix after a rate-limited response instead of pausing.
|
|
144
|
+
func applyRateLimitedResultLocked(retryAfter: TimeInterval?) -> Bool {
|
|
145
|
+
consecutiveFailures += 1
|
|
146
|
+
lastOutcome = .retryableFailure
|
|
147
|
+
guard let options = automaticOptions, automaticTransport != nil, state != .shuttingDown, state != .closed
|
|
148
|
+
else {
|
|
149
|
+
return false
|
|
150
|
+
}
|
|
151
|
+
state = .retrying
|
|
152
|
+
pauseReason = .none
|
|
153
|
+
nextWakeNanoseconds = nil
|
|
154
|
+
let wait = retryAfter ?? retryBackoffDelay(options, attempt: consecutiveFailures)
|
|
155
|
+
return setWakeLocked(delay: Self.rateLimitDelay(wait), replaceLaterWake: true)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/// Clamps a rate-limit wait to 1 second through 1 hour, then adds up to 10 percent jitter within 1 hour.
|
|
159
|
+
static func rateLimitDelay(_ delay: TimeInterval, jitter: Double = .random(in: 0 ... 1)) -> TimeInterval {
|
|
160
|
+
let maximum: TimeInterval = 60 * 60
|
|
161
|
+
let bounded = delay.isNaN ? 1 : min(max(delay, 1), maximum)
|
|
162
|
+
return min(bounded + bounded * 0.1 * jitter, maximum)
|
|
163
|
+
}
|
|
164
|
+
|
|
141
165
|
private func applyAcceptedResultLocked(_ prefix: FrozenPrefix) -> Bool {
|
|
142
166
|
acknowledgeLocked(prefix)
|
|
143
167
|
acceptedEvents += prefix.count
|
|
@@ -199,10 +223,13 @@ extension DeliveryEngine {
|
|
|
199
223
|
guard let options = automaticOptions else {
|
|
200
224
|
return false
|
|
201
225
|
}
|
|
202
|
-
|
|
226
|
+
return setWakeLocked(delay: retryBackoffDelay(options, attempt: retryAttempt), replaceLaterWake: true)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
private func retryBackoffDelay(_ options: AutomaticDeliveryOptions, attempt: Int) -> TimeInterval {
|
|
230
|
+
let multiplier = pow(2, Double(max(0, attempt - 1)))
|
|
203
231
|
let ceiling = min(options.retryBaseDelay * multiplier, options.maxRetryDelay)
|
|
204
|
-
|
|
205
|
-
return setWakeLocked(delay: delay, replaceLaterWake: true)
|
|
232
|
+
return Double.random(in: (ceiling / 2) ... ceiling)
|
|
206
233
|
}
|
|
207
234
|
|
|
208
235
|
private func setWakeLocked(delay: TimeInterval, replaceLaterWake: Bool) -> Bool {
|
|
@@ -240,6 +267,9 @@ extension DeliveryEngine {
|
|
|
240
267
|
stateLock.unlock()
|
|
241
268
|
throw SdkError(code: "storage_corrupt", message: "durable delivery data requires explicit recovery")
|
|
242
269
|
}
|
|
270
|
+
if state == .retrying {
|
|
271
|
+
state = .running
|
|
272
|
+
}
|
|
243
273
|
nextWakeNanoseconds = nil
|
|
244
274
|
stateLock.unlock()
|
|
245
275
|
}
|
|
@@ -247,7 +277,9 @@ extension DeliveryEngine {
|
|
|
247
277
|
func rescheduleAfterManualOperation() {
|
|
248
278
|
stateLock.lock()
|
|
249
279
|
let shouldSchedule: Bool
|
|
250
|
-
if
|
|
280
|
+
if state == .retrying, nextWakeNanoseconds != nil {
|
|
281
|
+
shouldSchedule = true
|
|
282
|
+
} else if automaticTransport != nil, state != .paused, state != .shuttingDown, state != .closed {
|
|
251
283
|
state = .running
|
|
252
284
|
retryAttempt = 0
|
|
253
285
|
shouldSchedule = scheduleLiveQueueLocked()
|
|
@@ -109,6 +109,9 @@ extension DeliveryEngine {
|
|
|
109
109
|
case let .terminal(reason, _, error):
|
|
110
110
|
recordManualFailure(outcome: .terminalFailure, pauseReason: reason)
|
|
111
111
|
throw error
|
|
112
|
+
case let .rateLimited(retryAfter, _, error):
|
|
113
|
+
recordManualRateLimit(retryAfter: retryAfter)
|
|
114
|
+
throw error
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
117
|
throw SdkError(code: "transport_error", message: "exhausted retries")
|
|
@@ -254,6 +257,10 @@ extension DeliveryEngine {
|
|
|
254
257
|
return .accepted(statusCode: response.statusCode, attempts: attempts)
|
|
255
258
|
}
|
|
256
259
|
let error = transportError(statusCode: response.statusCode)
|
|
260
|
+
let rateLimitSignal = response.retryAfter != nil || response.errorCode == "rate_limited"
|
|
261
|
+
if response.statusCode == 429, rateLimitSignal, response.errorCode != "usage_limit_exceeded" {
|
|
262
|
+
return .rateLimited(retryAfter: response.retryAfter, attempts: attempts, error: error)
|
|
263
|
+
}
|
|
257
264
|
if response.statusCode == 408 || response.statusCode >= 500 {
|
|
258
265
|
return .retryable(attempts: attempts, error: error)
|
|
259
266
|
}
|
|
@@ -293,6 +300,16 @@ extension DeliveryEngine {
|
|
|
293
300
|
stateLock.unlock()
|
|
294
301
|
}
|
|
295
302
|
|
|
303
|
+
private func recordManualRateLimit(retryAfter: TimeInterval?) {
|
|
304
|
+
stateLock.lock()
|
|
305
|
+
inFlight = false
|
|
306
|
+
let shouldSchedule = applyRateLimitedResultLocked(retryAfter: retryAfter)
|
|
307
|
+
stateLock.unlock()
|
|
308
|
+
if shouldSchedule {
|
|
309
|
+
scheduleTimerUpdate()
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
296
313
|
private func recordManualAttempts(_ attempts: Int) {
|
|
297
314
|
stateLock.lock()
|
|
298
315
|
deliveryAttempts += attempts
|
|
@@ -67,4 +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.
|
|
71
|
+
public let nextRetryDelay: TimeInterval?
|
|
70
72
|
}
|
|
@@ -42,10 +42,16 @@ public struct TransportError: Error, Equatable, Sendable, CustomStringConvertibl
|
|
|
42
42
|
public struct TransportResponse: Codable, Equatable, Sendable {
|
|
43
43
|
public let statusCode: Int
|
|
44
44
|
public let attempts: Int
|
|
45
|
+
/// Readable `Retry-After` delay in seconds from a `429` response.
|
|
46
|
+
public let retryAfter: TimeInterval?
|
|
47
|
+
/// String `code` field from a `429` JSON response body.
|
|
48
|
+
public let errorCode: String?
|
|
45
49
|
|
|
46
|
-
public init(statusCode: Int, attempts: Int) {
|
|
50
|
+
public init(statusCode: Int, attempts: Int, retryAfter: TimeInterval? = nil, errorCode: String? = nil) {
|
|
47
51
|
self.statusCode = statusCode
|
|
48
52
|
self.attempts = attempts
|
|
53
|
+
self.retryAfter = retryAfter
|
|
54
|
+
self.errorCode = errorCode
|
|
49
55
|
}
|
|
50
56
|
}
|
|
51
57
|
|
|
@@ -95,13 +101,38 @@ public final class HTTPTransport: Transport {
|
|
|
95
101
|
return try TransportResponse(statusCode: requester(request), attempts: 1)
|
|
96
102
|
}
|
|
97
103
|
|
|
98
|
-
return try
|
|
104
|
+
return try sendWithURLSession(request)
|
|
99
105
|
}
|
|
100
106
|
|
|
101
|
-
|
|
107
|
+
/// Reads only `Retry-After` and at most 4 KiB of body for its `code` field, and only for a `429`.
|
|
108
|
+
static func transportResponse(_ response: HTTPURLResponse, body: Data?, now: Date = Date()) -> TransportResponse {
|
|
109
|
+
guard response.statusCode == 429 else {
|
|
110
|
+
return TransportResponse(statusCode: response.statusCode, attempts: 1)
|
|
111
|
+
}
|
|
112
|
+
let code = body.flatMap { body in
|
|
113
|
+
body.count <= 4096 ? try? JSONDecoder().decode(RateLimitBody.self, from: body).code : nil
|
|
114
|
+
}
|
|
115
|
+
let retryAfter = response.value(forHTTPHeaderField: "Retry-After").flatMap { retryAfterSeconds($0, now: now) }
|
|
116
|
+
return TransportResponse(statusCode: 429, attempts: 1, retryAfter: retryAfter, errorCode: code)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/// Parses delta-seconds or an IMF-fixdate; a past date waits 0 seconds and anything else is unreadable.
|
|
120
|
+
static func retryAfterSeconds(_ value: String, now: Date) -> TimeInterval? {
|
|
121
|
+
let value = value.trimmingCharacters(in: .whitespaces)
|
|
122
|
+
if !value.isEmpty, value.allSatisfy({ $0.isASCII && $0.isNumber }) {
|
|
123
|
+
return TimeInterval(value)
|
|
124
|
+
}
|
|
125
|
+
let formatter = DateFormatter()
|
|
126
|
+
formatter.locale = Locale(identifier: "en_US_POSIX")
|
|
127
|
+
formatter.timeZone = TimeZone(identifier: "GMT")
|
|
128
|
+
formatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ss 'GMT'"
|
|
129
|
+
return formatter.date(from: value).map { max(0, $0.timeIntervalSince(now)) }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private func sendWithURLSession(_ request: URLRequest) throws -> TransportResponse {
|
|
102
133
|
let semaphore = DispatchSemaphore(value: 0)
|
|
103
134
|
let result = HTTPTransportResultBox()
|
|
104
|
-
let task = session.dataTask(with: request) {
|
|
135
|
+
let task = session.dataTask(with: request) { data, response, error in
|
|
105
136
|
defer {
|
|
106
137
|
semaphore.signal()
|
|
107
138
|
}
|
|
@@ -113,7 +144,7 @@ public final class HTTPTransport: Transport {
|
|
|
113
144
|
result.value = .failure(TransportError.network("http transport did not return an HTTP response"))
|
|
114
145
|
return
|
|
115
146
|
}
|
|
116
|
-
result.value = .success(httpResponse
|
|
147
|
+
result.value = .success(Self.transportResponse(httpResponse, body: data))
|
|
117
148
|
}
|
|
118
149
|
task.resume()
|
|
119
150
|
|
|
@@ -157,7 +188,11 @@ public final class HTTPTransport: Transport {
|
|
|
157
188
|
}
|
|
158
189
|
|
|
159
190
|
private final class HTTPTransportResultBox: @unchecked Sendable {
|
|
160
|
-
var value: Result<
|
|
191
|
+
var value: Result<TransportResponse, Error>?
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private struct RateLimitBody: Decodable {
|
|
195
|
+
let code: String?
|
|
161
196
|
}
|
|
162
197
|
|
|
163
198
|
public enum ScriptedTransportResponse: Equatable, Sendable {
|
|
@@ -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": "
|
|
6
|
-
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngineAutomatic.swift": "
|
|
5
|
+
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngine.swift": "6cbc2c52f5b39b9627fa707b023b84fb306a736bec9f82163d7ca4aa21b01b1c",
|
|
6
|
+
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngineAutomatic.swift": "cd05cd45aeea52cde3d228938acf9ff2e784c1e2350cf2473c3b72030a3abf64",
|
|
7
7
|
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngineDurable.swift": "b0d2ca07cce7fe01fc110238c7d10aa9c8ada0d28509e4c022e7fa950a4c79b9",
|
|
8
|
-
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngineQueue.swift": "
|
|
9
|
-
"swift/logbrew-swift/Sources/LogBrew/DeliveryLifecycle.swift": "
|
|
8
|
+
"swift/logbrew-swift/Sources/LogBrew/DeliveryEngineQueue.swift": "e187a737e18dd88a4be8719f1a3a07776c6d6eb0edb5b1904a82c5059a0aef57",
|
|
9
|
+
"swift/logbrew-swift/Sources/LogBrew/DeliveryLifecycle.swift": "af7b36649f9d07ac4567652f578c008e4ec8086f14c157b2d5144df93d211aaf",
|
|
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",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"swift/logbrew-swift/Sources/LogBrew/TelemetryContext.swift": "ce3ac93a62a345f8c9a8f4c69ce84efc991bf02a688f49bad5e68edcff2f6e08",
|
|
26
26
|
"swift/logbrew-swift/Sources/LogBrew/TelemetryContextValidation.swift": "ab5811b48df308bf8f6435efee30a24f91a62bfe8b6dea612a2077c8ae0eb302",
|
|
27
27
|
"swift/logbrew-swift/Sources/LogBrew/TraceEvidence.swift": "40aaa42976164c53d9f4d9e9e30d236534238da43bbe90832a673c8809ad54b6",
|
|
28
|
-
"swift/logbrew-swift/Sources/LogBrew/Transport.swift": "
|
|
28
|
+
"swift/logbrew-swift/Sources/LogBrew/Transport.swift": "692c50da219f4b9a3f718bc9c9407a920f726b66a7b0381b85e4094e0596d6ae",
|
|
29
29
|
"swift/logbrew-swift/Sources/LogBrew/URLSessionTrace.swift": "d0076c72671716c41bd7498d0509e453b8182c418156e169196fee9f26fc66b1",
|
|
30
30
|
"swift/logbrew-swift/Sources/LogBrew/URLSessionTracer.swift": "8f45867e5ec48fc7be8f4c7a015e887ed7f49f3a0ffb11bd850e1bb7e937f9a0",
|
|
31
31
|
"swift/logbrew-swift/Sources/LogBrew/Validation.swift": "4ce069077dcca7899b15733e9aee921392da1e2136996ae3d4eb37bd73a5af07",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logbrew/react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.39",
|
|
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",
|
|
@@ -252,7 +252,7 @@
|
|
|
252
252
|
"url": "git+https://github.com/LogBrewCo/sdk.git"
|
|
253
253
|
},
|
|
254
254
|
"peerDependencies": {
|
|
255
|
-
"@logbrew/sdk": "^0.1.
|
|
255
|
+
"@logbrew/sdk": "^0.1.36",
|
|
256
256
|
"expo": ">=49",
|
|
257
257
|
"react": ">=18",
|
|
258
258
|
"react-native": ">=0.72"
|