@layers/react-native 3.2.6 → 3.2.8
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 +81 -12
- package/dist/debug-overlay.d.mts +1 -1
- package/dist/debug-overlay.d.ts +1 -1
- package/dist/{index-BJ3l4nsV.d.ts → index-BNM5Q_2v.d.ts} +63 -2
- package/dist/{index-BJ3l4nsV.d.ts.map → index-BNM5Q_2v.d.ts.map} +1 -1
- package/dist/{index-BFkSi3wX.d.mts → index-BaCWtOOT.d.mts} +63 -2
- package/dist/{index-BFkSi3wX.d.mts.map → index-BaCWtOOT.d.mts.map} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +1 -1
- package/dist/react.mjs +1 -1
- package/dist/{src-BRZ3Lfl5.mjs → src-BxA1wIJ6.mjs} +147 -9
- package/dist/src-BxA1wIJ6.mjs.map +1 -0
- package/dist/{src-DPSm18ng.js → src-D_EHJJlX.js} +146 -8
- package/package.json +2 -2
- package/dist/src-BRZ3Lfl5.mjs.map +0 -1
|
@@ -909,7 +909,34 @@ var SurveysModule = class {
|
|
|
909
909
|
|
|
910
910
|
//#endregion
|
|
911
911
|
//#region src/index.ts
|
|
912
|
-
|
|
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.8";
|
|
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
|
|
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");
|
|
@@ -2182,14 +2260,16 @@ async function createAsyncStoragePersistence(appId) {
|
|
|
2182
2260
|
if (AsyncStorage) {
|
|
2183
2261
|
const sdkKeys = (await AsyncStorage.getAllKeys()).filter((k) => k.startsWith(prefix));
|
|
2184
2262
|
if (sdkKeys.length > 0) {
|
|
2185
|
-
const pairs = await AsyncStorage
|
|
2263
|
+
const pairs = await readManyFromAsyncStorage(AsyncStorage, sdkKeys);
|
|
2186
2264
|
for (const [key, value] of pairs) if (value) {
|
|
2187
2265
|
const shortKey = key.slice(prefix.length);
|
|
2188
2266
|
memoryStore.set(shortKey, base64Decode(value));
|
|
2189
2267
|
}
|
|
2190
2268
|
}
|
|
2191
2269
|
}
|
|
2192
|
-
} catch {
|
|
2270
|
+
} catch (error) {
|
|
2271
|
+
warnPersistencePreloadFailed(error);
|
|
2272
|
+
}
|
|
2193
2273
|
return {
|
|
2194
2274
|
write(key, data) {
|
|
2195
2275
|
memoryStore.set(key, new Uint8Array(data));
|
|
@@ -2267,6 +2347,38 @@ async function deleteFromAsyncStorage(key) {
|
|
|
2267
2347
|
await AsyncStorage.removeItem(key);
|
|
2268
2348
|
} catch {}
|
|
2269
2349
|
}
|
|
2350
|
+
let _warnedAsyncStorageBatchShape = false;
|
|
2351
|
+
let _warnedPersistencePreloadFailed = false;
|
|
2352
|
+
/**
|
|
2353
|
+
* Batch-read `keys` through whichever multi-key API the installed AsyncStorage
|
|
2354
|
+
* exposes.
|
|
2355
|
+
*
|
|
2356
|
+
* v3.0.0 removed `multiGet` in favour of `getMany`, and changed the return
|
|
2357
|
+
* type with it: `multiGet` answers `[key, value][]`, `getMany` answers
|
|
2358
|
+
* `Record<key, value | null>`. Calling the v1/v2 name unconditionally threw
|
|
2359
|
+
* `TypeError: AsyncStorage.multiGet is not a function` on v3 — and because
|
|
2360
|
+
* `>=1.21.0` admits v3, and npm's `latest` has been v3 since v3.0.0, that was
|
|
2361
|
+
* the default install.
|
|
2362
|
+
*/
|
|
2363
|
+
async function readManyFromAsyncStorage(storage, keys) {
|
|
2364
|
+
if (typeof storage.multiGet === "function") return (await storage.multiGet(keys)).map(([key, value]) => [key, value ?? null]);
|
|
2365
|
+
if (typeof storage.getMany === "function") {
|
|
2366
|
+
const record = await storage.getMany([...keys]);
|
|
2367
|
+
return keys.map((key) => [key, record?.[key] ?? null]);
|
|
2368
|
+
}
|
|
2369
|
+
warnAsyncStorageBatchShape();
|
|
2370
|
+
return Promise.all(keys.map(async (key) => [key, await storage.getItem(key)]));
|
|
2371
|
+
}
|
|
2372
|
+
function warnAsyncStorageBatchShape() {
|
|
2373
|
+
if (_warnedAsyncStorageBatchShape) return;
|
|
2374
|
+
_warnedAsyncStorageBatchShape = true;
|
|
2375
|
+
console.warn("[Layers] @react-native-async-storage/async-storage exposes neither multiGet (v1/v2) nor getMany (v3) — falling back to one read per key to restore persisted identity and queued events. If launches start reporting as new installs, pin async-storage to a version this SDK recognises (>=1.21.0).");
|
|
2376
|
+
}
|
|
2377
|
+
function warnPersistencePreloadFailed(error) {
|
|
2378
|
+
if (_warnedPersistencePreloadFailed) return;
|
|
2379
|
+
_warnedPersistencePreloadFailed = true;
|
|
2380
|
+
console.warn("[Layers] could not read persisted SDK state back from AsyncStorage — this launch starts with a fresh identity and an empty event queue, and will report itself as a new install. Check @react-native-async-storage/async-storage compatibility; the SDK supports v1.21+, v2 and v3.", error);
|
|
2381
|
+
}
|
|
2270
2382
|
let _asyncStorage = void 0;
|
|
2271
2383
|
let _asyncStoragePromise = null;
|
|
2272
2384
|
async function loadAsyncStorage() {
|
|
@@ -2529,6 +2641,32 @@ const INSTALL_REFERRER_ATTRIBUTION_PARAMS = new Set([
|
|
|
2529
2641
|
"click_id"
|
|
2530
2642
|
]);
|
|
2531
2643
|
/**
|
|
2644
|
+
* Decode one `application/x-www-form-urlencoded` token from a URL query
|
|
2645
|
+
* component. This is the single decoding rule every Layers SDK implements
|
|
2646
|
+
* (Kotlin, Swift, Dart, C#, and here):
|
|
2647
|
+
*
|
|
2648
|
+
* - `+` -> space (ad platforms emit `running+shoes` for "running shoes")
|
|
2649
|
+
* - `%XX` -> the byte 0xXX (then UTF-8)
|
|
2650
|
+
* - one pass: neither output feeds the other, so `%2B` yields a literal `+`
|
|
2651
|
+
*
|
|
2652
|
+
* The order below is load-bearing. Percent-decoding FIRST and then swapping
|
|
2653
|
+
* `+` for a space turns `%2B` into a space — a double decode that silently
|
|
2654
|
+
* corrupts any campaign name containing a real plus sign. Swapping `+` for
|
|
2655
|
+
* its own escape on the still-encoded token makes that impossible.
|
|
2656
|
+
*
|
|
2657
|
+
* Applies to the QUERY component only. Path and fragment are RFC 3986, where
|
|
2658
|
+
* `+` is an ordinary character.
|
|
2659
|
+
*
|
|
2660
|
+
* Never throws: a malformed escape (e.g. `%ZZ`) yields the raw token.
|
|
2661
|
+
*/
|
|
2662
|
+
function decodeFormUrlComponent(encoded) {
|
|
2663
|
+
try {
|
|
2664
|
+
return decodeURIComponent(encoded.replace(/\+/g, "%20"));
|
|
2665
|
+
} catch {
|
|
2666
|
+
return encoded;
|
|
2667
|
+
}
|
|
2668
|
+
}
|
|
2669
|
+
/**
|
|
2532
2670
|
* Parse a raw Play Install Referrer string into a map of recognized attribution
|
|
2533
2671
|
* params. Accepts either a bare query string (`a=1&b=2`) or a full URL.
|
|
2534
2672
|
* Returns an empty object on parse failure.
|
|
@@ -2543,11 +2681,11 @@ function parseInstallReferrerUrl(referrer) {
|
|
|
2543
2681
|
if (!qs.includes("=") && qs.includes("%3D")) qs = decodeURIComponent(qs);
|
|
2544
2682
|
for (const pair of qs.split("&")) {
|
|
2545
2683
|
const eq = pair.indexOf("=");
|
|
2546
|
-
if (eq >= 0)
|
|
2547
|
-
const key =
|
|
2548
|
-
const value =
|
|
2684
|
+
if (eq >= 0) {
|
|
2685
|
+
const key = decodeFormUrlComponent(pair.slice(0, eq));
|
|
2686
|
+
const value = decodeFormUrlComponent(pair.slice(eq + 1));
|
|
2549
2687
|
if (value && INSTALL_REFERRER_ATTRIBUTION_PARAMS.has(key)) out[key] = value;
|
|
2550
|
-
}
|
|
2688
|
+
}
|
|
2551
2689
|
}
|
|
2552
2690
|
} catch {}
|
|
2553
2691
|
return out;
|
|
@@ -2667,4 +2805,4 @@ function useLayersExpoRouterTracking(sdkInstance, usePathname, useGlobalSearchPa
|
|
|
2667
2805
|
|
|
2668
2806
|
//#endregion
|
|
2669
2807
|
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-
|
|
2808
|
+
//# sourceMappingURL=src-BxA1wIJ6.mjs.map
|