@layers/react-native 3.2.6 → 3.2.7

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.
@@ -909,7 +909,34 @@ var SurveysModule = class {
909
909
 
910
910
  //#endregion
911
911
  //#region src/index.ts
912
- const SDK_VERSION = "3.2.6";
912
+ /**
913
+ * The surface `AppRegistry.js` registers at module scope in EVERY copy of
914
+ * react-native, duplicate or not, so it proves nothing on its own.
915
+ */
916
+ const LOGBOX_SURFACE_KEY = "LogBox";
917
+ /**
918
+ * Is this the copy of react-native the host app actually runs?
919
+ *
920
+ * `AppRegistry.registerComponent` is called by the app's entry file, so the
921
+ * live copy carries the app's own surface key alongside LogBox. A copy that
922
+ * only the SDK imported was never handed an application and carries LogBox
923
+ * alone.
924
+ *
925
+ * Returns `null` when the question cannot be answered (no AppRegistry, a
926
+ * shape we don't recognise). Callers must stay silent on `null` — inventing a
927
+ * diagnosis from missing evidence is worse than the silence this replaces.
928
+ */
929
+ function hostAppIsRegisteredOn(rn) {
930
+ try {
931
+ const keys = rn?.AppRegistry?.getAppKeys?.();
932
+ if (!Array.isArray(keys)) return null;
933
+ return keys.some((key) => typeof key === "string" && key !== LOGBOX_SURFACE_KEY);
934
+ } catch {
935
+ return null;
936
+ }
937
+ }
938
+ const DUPLICATE_REACT_NATIVE_MESSAGE = "[Layers] The SDK resolved a SECOND copy of react-native, not the one your app runs. React Native delivers native lifecycle events to a single copy, so this listener can never fire: $app_background and $app_foreground will not be emitted and the background crash-safety snapshot will not run, which loses every event queued since the last flush on any launch that ends in a kill. Fix the duplicate in your bundler — in a Metro monorepo set `resolver.disableHierarchicalLookup = true` and list every workspace node_modules in `resolver.nodeModulesPaths` — or hand the SDK your app's module: `new LayersReactNative({ ..., appState: AppState })` with AppState imported from 'react-native'.";
939
+ const SDK_VERSION = "3.2.7";
913
940
  var LayersReactNative = class LayersReactNative {
914
941
  core;
915
942
  eagerPersistence;
@@ -917,6 +944,7 @@ var LayersReactNative = class LayersReactNative {
917
944
  isOnline = true;
918
945
  enableDebug;
919
946
  appStateSubscription = null;
947
+ _lifecycleCheckTimer = null;
920
948
  netInfoUnsubscribe = null;
921
949
  config;
922
950
  userIdLocked = false;
@@ -1831,6 +1859,7 @@ var LayersReactNative = class LayersReactNative {
1831
1859
  */
1832
1860
  teardownRuntime() {
1833
1861
  this.stopConfigPolling();
1862
+ this.cancelLifecycleReachabilityCheck();
1834
1863
  if (this.appStateSubscription) {
1835
1864
  this.appStateSubscription.remove();
1836
1865
  this.appStateSubscription = null;
@@ -2093,13 +2122,27 @@ var LayersReactNative = class LayersReactNative {
2093
2122
  } catch {}
2094
2123
  } catch {}
2095
2124
  }
2125
+ /**
2126
+ * The `react-native` module as this package resolves it.
2127
+ *
2128
+ * A method rather than 16 scattered `require` calls at the lifecycle sites,
2129
+ * so the module the listener binds to and the module the reachability check
2130
+ * inspects are provably the same one.
2131
+ */
2132
+ requireReactNative() {
2133
+ return __require("react-native");
2134
+ }
2096
2135
  setupAppStateListener() {
2097
2136
  if (this.appStateSubscription) {
2098
2137
  this.appStateSubscription.remove();
2099
2138
  this.appStateSubscription = null;
2100
2139
  }
2140
+ this.cancelLifecycleReachabilityCheck();
2101
2141
  try {
2102
- const { AppState } = __require("react-native");
2142
+ const injected = this.config.appState;
2143
+ const rn = injected ? null : this.requireReactNative();
2144
+ const AppState = injected ?? rn?.AppState;
2145
+ if (!AppState) throw new Error("react-native AppState is unavailable");
2103
2146
  let lastEmittedState = null;
2104
2147
  this.appStateSubscription = AppState.addEventListener("change", (nextAppState) => {
2105
2148
  if (nextAppState === "background" || nextAppState === "inactive") {
@@ -2118,11 +2161,46 @@ var LayersReactNative = class LayersReactNative {
2118
2161
  if (this.isOnline) this.core.flushAsync().catch(() => {});
2119
2162
  }
2120
2163
  });
2164
+ if (rn) this.scheduleLifecycleReachabilityCheck(rn);
2121
2165
  } catch (e) {
2122
2166
  this.emitError(e);
2123
2167
  console.warn("[Layers] AppState listener failed to register — $app_background and the background crash-safety snapshot are disabled for this session:", e);
2124
2168
  }
2125
2169
  }
2170
+ /**
2171
+ * Ask, one tick later, whether the listener just registered can ever fire.
2172
+ *
2173
+ * `AppState.addEventListener` hands back a subscription object no matter
2174
+ * which copy of react-native you call it on, and a duplicate copy's
2175
+ * `RCTDeviceEventEmitter` is never fed by the native side — so the
2176
+ * subscription is real, well-formed, and permanently silent. That is the
2177
+ * exact state a release build of examples/expo was in: registration logged
2178
+ * success on every launch while `$app_background`, `$app_foreground` and
2179
+ * the crash-safety snapshot had not run once. Nothing in the SDK could see
2180
+ * it, and nothing in the app could either.
2181
+ *
2182
+ * The check is DEFERRED by a tick because it reads `AppRegistry`, which the
2183
+ * host populates from its entry file. An SDK constructed at module scope
2184
+ * ahead of `AppRegistry.registerComponent` would otherwise look like a
2185
+ * duplicate to itself — a false alarm about a healthy integration, which is
2186
+ * a worse failure than the one being fixed.
2187
+ */
2188
+ scheduleLifecycleReachabilityCheck(rn) {
2189
+ this.cancelLifecycleReachabilityCheck();
2190
+ this._lifecycleCheckTimer = setTimeout(() => {
2191
+ this._lifecycleCheckTimer = null;
2192
+ if (hostAppIsRegisteredOn(rn) !== false) return;
2193
+ const error = new Error(DUPLICATE_REACT_NATIVE_MESSAGE);
2194
+ this.emitError(error);
2195
+ console.warn(DUPLICATE_REACT_NATIVE_MESSAGE);
2196
+ }, 0);
2197
+ }
2198
+ cancelLifecycleReachabilityCheck() {
2199
+ if (this._lifecycleCheckTimer !== null) {
2200
+ clearTimeout(this._lifecycleCheckTimer);
2201
+ this._lifecycleCheckTimer = null;
2202
+ }
2203
+ }
2126
2204
  async configureSkanFromRemoteConfig() {
2127
2205
  try {
2128
2206
  const { Platform } = __require("react-native");
@@ -2529,6 +2607,32 @@ const INSTALL_REFERRER_ATTRIBUTION_PARAMS = new Set([
2529
2607
  "click_id"
2530
2608
  ]);
2531
2609
  /**
2610
+ * Decode one `application/x-www-form-urlencoded` token from a URL query
2611
+ * component. This is the single decoding rule every Layers SDK implements
2612
+ * (Kotlin, Swift, Dart, C#, and here):
2613
+ *
2614
+ * - `+` -> space (ad platforms emit `running+shoes` for "running shoes")
2615
+ * - `%XX` -> the byte 0xXX (then UTF-8)
2616
+ * - one pass: neither output feeds the other, so `%2B` yields a literal `+`
2617
+ *
2618
+ * The order below is load-bearing. Percent-decoding FIRST and then swapping
2619
+ * `+` for a space turns `%2B` into a space — a double decode that silently
2620
+ * corrupts any campaign name containing a real plus sign. Swapping `+` for
2621
+ * its own escape on the still-encoded token makes that impossible.
2622
+ *
2623
+ * Applies to the QUERY component only. Path and fragment are RFC 3986, where
2624
+ * `+` is an ordinary character.
2625
+ *
2626
+ * Never throws: a malformed escape (e.g. `%ZZ`) yields the raw token.
2627
+ */
2628
+ function decodeFormUrlComponent(encoded) {
2629
+ try {
2630
+ return decodeURIComponent(encoded.replace(/\+/g, "%20"));
2631
+ } catch {
2632
+ return encoded;
2633
+ }
2634
+ }
2635
+ /**
2532
2636
  * Parse a raw Play Install Referrer string into a map of recognized attribution
2533
2637
  * params. Accepts either a bare query string (`a=1&b=2`) or a full URL.
2534
2638
  * Returns an empty object on parse failure.
@@ -2543,11 +2647,11 @@ function parseInstallReferrerUrl(referrer) {
2543
2647
  if (!qs.includes("=") && qs.includes("%3D")) qs = decodeURIComponent(qs);
2544
2648
  for (const pair of qs.split("&")) {
2545
2649
  const eq = pair.indexOf("=");
2546
- if (eq >= 0) try {
2547
- const key = decodeURIComponent(pair.slice(0, eq));
2548
- const value = decodeURIComponent(pair.slice(eq + 1));
2650
+ if (eq >= 0) {
2651
+ const key = decodeFormUrlComponent(pair.slice(0, eq));
2652
+ const value = decodeFormUrlComponent(pair.slice(eq + 1));
2549
2653
  if (value && INSTALL_REFERRER_ATTRIBUTION_PARAMS.has(key)) out[key] = value;
2550
- } catch {}
2654
+ }
2551
2655
  }
2552
2656
  } catch {}
2553
2657
  return out;
@@ -2667,4 +2771,4 @@ function useLayersExpoRouterTracking(sdkInstance, usePathname, useGlobalSearchPa
2667
2771
 
2668
2772
  //#endregion
2669
2773
  export { addToWishlistEvent as $, registerExpoBackgroundFlush as A, trackPurchaseFailed as B, SurveysModule as C, BACKGROUND_FLUSH_MIN_INTERVAL_MINUTES as D, useLayersNavigationTracking as E, trackRevenueCatPurchase as F, superwallOnEvent as G, trackRemoveFromCart as H, trackAddToCart as I, superwallTrackPurchase as J, superwallTrackDismiss as K, trackBeginCheckout as L, isRevenueCatConnected as M, resetRevenueCatForTesting as N, BACKGROUND_FLUSH_TASK_NAME as O, syncRevenueCatAttributes as P, addToCartEvent as Q, trackOrder as R, useLayersExpoRouterTracking as S, resolveActiveRoute as T, trackSubscription as U, trackRefund as V, trackViewProduct as W, superwallUserAttributes as X, superwallTrackSkip as Y, StandardEvents as Z, parseDeepLink as _, buildBeginCheckoutEvent as a, registerEvent as at, setupDeepLinkListener as b, buildStartTrialEvent as c, shareEvent as ct, formatFbc as d, subscribeEvent as dt, initiateCheckoutEvent as et, getAdServicesToken as f, tutorialCompleteEvent as ft, getOrSetInstallId as g, getInstallReferrer as h, buildAddToCartEvent as i, purchaseEvent as it, connectRevenueCat as j, createBackgroundFlushHandler as k, buildSubscribeEvent as l, signUpEvent as lt, getGoogleAdvertisingId as m, viewItemEvent as mt, LayersEvent as n, levelStartEvent as nt, buildPurchaseEvent as o, screenViewEvent as ot, getFirstInstallTime as p, viewContentEvent as pt, superwallTrackPresentation as q, LayersReactNative as r, loginEvent as rt, buildRefundEvent as s, searchEvent as st, LayersError$1 as t, levelCompleteEvent as tt, buildViewItemEvent as u, startTrialEvent as ut, parseInstallReferrerUrl as v, createNavigationListener as w, shouldTreatAsNewInstall as x, readClipboardAttribution as y, trackPurchase as z };
2670
- //# sourceMappingURL=src-BRZ3Lfl5.mjs.map
2774
+ //# sourceMappingURL=src-A7xqoTvD.mjs.map