@app-swiss-knife/react-native-sdk 0.3.0 → 0.3.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.
@@ -42,7 +42,7 @@ internal object DeviceContextProvider {
42
42
  * eventually inject this via `BuildConfig`, but for now keep it in
43
43
  * source so we don't have to thread build settings through every test.
44
44
  */
45
- const val SDK_VERSION: String = "0.3.0"
45
+ const val SDK_VERSION: String = "0.3.1"
46
46
 
47
47
  private val cacheLock = Any()
48
48
 
@@ -208,7 +208,7 @@ internal object IngestPlaceholderDevice {
208
208
  appBuild = "unknown",
209
209
  locale = Locale.getDefault().toString(),
210
210
  timezone = TimeZone.getDefault().id,
211
- sdkVersion = "0.3.0",
211
+ sdkVersion = "0.3.1",
212
212
  bundleIdentifier = null,
213
213
  )
214
214
  }
@@ -99,7 +99,7 @@ internal enum DeviceContextProvider {
99
99
  /// Round A baseline. The build pipeline (`swiss-build`) will eventually
100
100
  /// inject this via `-D` flag, but for now keep it in source so we don't
101
101
  /// have to thread build settings through the SPM Package.swift.
102
- static let sdkVersionConstant: String = "0.3.0"
102
+ static let sdkVersionConstant: String = "0.3.1"
103
103
 
104
104
  private static let cacheLock = DispatchQueue(label: "com.swissknife.context.device")
105
105
  private static var cached: DeviceContext?
@@ -1033,6 +1033,13 @@ public final class SKCrashReporting {
1033
1033
  return frames
1034
1034
  }
1035
1035
 
1036
+ /// Path of the running app bundle, resolved once. Everything dyld loaded
1037
+ /// from under it is the app; everything else is the system or the OS's
1038
+ /// shared cache. Resolved lazily rather than at init because this is only
1039
+ /// ever needed while BUILDING a report — never inside a signal handler,
1040
+ /// where a Foundation call would be unsafe.
1041
+ private static let appBundlePath: String = Bundle.main.bundlePath
1042
+
1036
1043
  /// Resolve a single instruction address into a structured frame via
1037
1044
  /// `dladdr()` — symbol name, image name, in-app heuristic. The raw
1038
1045
  /// address is always carried in `instructionAddress` for server-side
@@ -1048,13 +1055,32 @@ public final class SKCrashReporting {
1048
1055
 
1049
1056
  if resolved {
1050
1057
  symbolName = info.dli_sname.map { String(cString: $0) }
1058
+ var imagePath: String?
1051
1059
  if let fname = info.dli_fname {
1052
1060
  let fullPath = String(cString: fname)
1061
+ imagePath = fullPath
1053
1062
  imageName = (fullPath as NSString).lastPathComponent
1054
1063
  } else {
1055
1064
  imageName = nil
1056
1065
  }
1057
- if let appExec = appExecutable {
1066
+ // Anything loaded from INSIDE the app bundle is the app: the main
1067
+ // executable and every embedded framework under `.../Frameworks/`.
1068
+ // System images live in /usr/lib, /System/Library, or the dyld
1069
+ // shared cache, none of which are under the bundle.
1070
+ //
1071
+ // Comparing against the main executable alone — which is what this
1072
+ // did — marks the entire native stack of a React Native app as
1073
+ // NOT-in-app, because such an app's native code is essentially all
1074
+ // frameworks: React, Hermes, whatever the host embeds. Server-side
1075
+ // grouping drops non-in-app frames before fingerprinting, so a
1076
+ // stack of 35 real frames contributed NOTHING and every SIGSEGV in
1077
+ // the app fell back to the constant "Signal|Signal 11" and landed
1078
+ // in one undifferentiated issue.
1079
+ if let path = imagePath,
1080
+ !SKCrashReporting.appBundlePath.isEmpty,
1081
+ path.hasPrefix(SKCrashReporting.appBundlePath) {
1082
+ isInApp = true
1083
+ } else if let appExec = appExecutable {
1058
1084
  isInApp = imageName == appExec
1059
1085
  } else {
1060
1086
  let img = imageName ?? ""
@@ -75,9 +75,32 @@ public extension SwissKnife {
75
75
  public let customerInfo: CustomerInfo
76
76
  public let created: Bool
77
77
 
78
- public init(customerInfo: CustomerInfo, created: Bool) {
78
+ /// A NEWER identity change overtook this call before it could
79
+ /// commit, so this login did not take effect — `customerInfo`
80
+ /// describes the identity that WON, not the one asked for here.
81
+ ///
82
+ /// Being superseded is not a failure, and it is not rare. The
83
+ /// launch sequence this SDK's own setup playbook prescribes —
84
+ /// identify with a bootstrap id, then switch to the real account
85
+ /// (or log out) once the auth listener resolves — produces exactly
86
+ /// this, on every single launch. The earlier call is obsolete
87
+ /// because the host itself said so a moment later; reporting that
88
+ /// as an error trained whole teams to ignore identity errors.
89
+ ///
90
+ /// Hosts that only care about the end state can ignore this flag:
91
+ /// the winning identity is already applied SDK-wide by the time it
92
+ /// is set. Hosts that dispatch on their own call's outcome should
93
+ /// check it before treating the result as "user X is now current".
94
+ public let superseded: Bool
95
+
96
+ public init(
97
+ customerInfo: CustomerInfo,
98
+ created: Bool,
99
+ superseded: Bool = false
100
+ ) {
79
101
  self.customerInfo = customerInfo
80
102
  self.created = created
103
+ self.superseded = superseded
81
104
  }
82
105
  }
83
106
 
@@ -205,11 +228,12 @@ public extension SwissKnife {
205
228
  )
206
229
  } catch {
207
230
  // If a newer mutation (logOut/reset/wipe/another logIn)
208
- // has raced past while we were in flight, swallow the
209
- // error — the caller has already moved on. Otherwise
210
- // surface it. Mirrors Android's Round E behaviour.
231
+ // has raced past while we were in flight, the caller has
232
+ // already moved on — report the supersede rather than this
233
+ // call's own network error, which describes an operation
234
+ // whose outcome no longer matters.
211
235
  let racedPast: Bool = queue.sync { identityGeneration != myGeneration }
212
- if racedPast { throw CancellationError() }
236
+ if racedPast { return try await supersededResult(created: false) }
213
237
  throw error
214
238
  }
215
239
 
@@ -219,7 +243,7 @@ public extension SwissKnife {
219
243
  // mutation's intent wins. Mirrors Android's Round E fix.
220
244
  let generationAfterNetwork: Int = queue.sync { identityGeneration }
221
245
  if generationAfterNetwork != myGeneration {
222
- throw CancellationError()
246
+ return try await supersededResult(created: result.created)
223
247
  }
224
248
 
225
249
  let newSnapshot = Snapshot(
@@ -234,7 +258,7 @@ public extension SwissKnife {
234
258
  return true
235
259
  }
236
260
  guard applied else {
237
- throw CancellationError()
261
+ return try await supersededResult(created: result.created)
238
262
  }
239
263
  // Push the user-id into the rest of the SDK so subscriptions and
240
264
  // attributes get the new identity.
@@ -248,6 +272,21 @@ public extension SwissKnife {
248
272
  return LogInResult(customerInfo: info, created: result.created)
249
273
  }
250
274
 
275
+ /// Describe an identity change that overtook an in-flight `logIn`.
276
+ ///
277
+ /// Reports the identity that WON, which is the only one the caller can
278
+ /// usefully act on: by the time this runs, the newer change is already
279
+ /// applied SDK-wide. Prefers the cached snapshot and only reaches the
280
+ /// network when there is none — at launch, which is precisely when
281
+ /// supersedes happen, the cache is usually still empty.
282
+ private static func supersededResult(created: Bool) async throws -> LogInResult {
283
+ if let cached = EntitlementsService.shared.current() {
284
+ return LogInResult(customerInfo: cached, created: created, superseded: true)
285
+ }
286
+ let info = try await EntitlementsService.shared.refresh()
287
+ return LogInResult(customerInfo: info, created: created, superseded: true)
288
+ }
289
+
251
290
  /// Revert to anonymous. The DeviceID is NOT regenerated — Phase 1
252
291
  /// keeps it stable across logout (analytics continuity for the
253
292
  /// same physical install). Use `wipe()` for a full identity reset.
@@ -255,6 +294,16 @@ public extension SwissKnife {
255
294
  // Core gate — see `logIn(_:)`.
256
295
  guard SwissKnife.isCoreConfigured else { throw PurchasesError.notConfigured }
257
296
  let previous = current
297
+ // NOTE: this bumps even when already anonymous, and that is
298
+ // deliberate. Skipping the bump looks like a free optimisation for
299
+ // the launch-time "signed out before the first sign-in resolved"
300
+ // case, but a `logIn` may be IN FLIGHT with nothing committed yet:
301
+ // the host said log out, so it must win over that login too, and a
302
+ // no-op here would let the login land afterwards and re-identify.
303
+ // `test_logIn_thenImmediate_logOut_doesNotReidentify` pins it.
304
+ //
305
+ // The bump costs nothing now that being superseded returns a
306
+ // flagged result instead of throwing `CancellationError`.
258
307
  let anonId = previous.anonymousId
259
308
  let newSnapshot = Snapshot(anonymousId: anonId, userId: nil)
260
309
  // Bump generation BEFORE clearing state so any in-flight `logIn`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-swiss-knife/react-native-sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Subscriptions-only React Native SDK for App Swiss Knife — a drop-in replacement for RevenueCat's react-native-purchases public API.",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/commonjs/index.js",