@layers/react-native 3.2.5 → 3.2.6

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skan-B0F6AX7g.mjs","names":["sharedCore: SkanCore | null"],"sources":["../src/skan.ts"],"sourcesContent":["// SKAN Module — iOS-only SKAdNetwork conversion value management.\n//\n// Thin facade over the Rust core's SKAN engine, which is the single source of\n// truth for rule evaluation, presets, the monotonic floor, and persistence. This\n// wrapper only bridges to the native iOS SKAdNetwork APIs (which the core cannot\n// call) and reports the native apply outcome back to the core via\n// `skanRecordConversionResult`. There is no parallel JS rule engine.\n\nexport interface SKANConversionRule {\n eventName: string;\n conditions?: Record<string, unknown>;\n conversionValue: number; // 0-63 for SKAN 3.0, 0-7 fine values in SKAN 4.0\n coarseValue?: 'low' | 'medium' | 'high'; // SKAN 4.0 only\n lockWindow?: boolean; // SKAN 4.0 only\n priority?: number;\n description?: string;\n}\n\nexport interface SKANPresetConfig {\n name: 'subscriptions' | 'engagement' | 'iap';\n rules: SKANConversionRule[];\n description: string;\n maxValue: number;\n}\n\nexport interface SKANMetrics {\n isSupported: boolean;\n version: string;\n currentValue: number | null;\n currentPreset: string | null;\n ruleCount: number;\n evaluationCount: number;\n}\n\n/**\n * The subset of the Rust core (`LayersCore`) the SKAN facade delegates to. The\n * core owns all rule evaluation, presets, and the monotonic floor.\n */\nexport interface SkanCore {\n skanSetPreset(preset: string): void;\n skanSetRules(rulesJson: string): void;\n skanProcessEvent(\n eventName: string,\n properties: Record<string, unknown> | null\n ): { fineValue: number; coarseValue: string | null; lockWindow: boolean } | null;\n skanRecordConversionResult(value: number, success: boolean): void;\n skanCurrentValue(): number;\n skanCurrentPreset(): string | null;\n skanIsEnabled(): boolean;\n}\n\ninterface NativeSKANModule {\n isAvailable(): Promise<boolean>;\n getVersion(): Promise<string>;\n registerAppForAdNetworkAttribution(): Promise<void>;\n updateConversionValue(value: number): Promise<void>;\n updatePostbackConversionValue(\n value: number,\n coarseValue?: string,\n lockWindow?: boolean\n ): Promise<void>;\n getCurrentConversionValue(): Promise<number | null>;\n}\n\nfunction getNativeModule(): NativeSKANModule | null {\n try {\n const { NativeModules, Platform } = require('react-native');\n if (Platform.OS === 'ios' && NativeModules.LayersSKAN) {\n return NativeModules.LayersSKAN as NativeSKANModule;\n }\n } catch {\n // Not available\n }\n return null;\n}\n\nlet sharedCore: SkanCore | null = null;\n\n/**\n * Wire the SKAN facade to the SDK's Rust core. Called by the SDK on init so that\n * a directly-constructed `new SKANManager()` and the SDK's own auto-config both\n * delegate to the same core engine.\n */\nexport function setSkanCore(core: SkanCore | null): void {\n sharedCore = core;\n}\n\n/**\n * Apply a native SKAN conversion update returned by the core, then report the\n * outcome so the core commits its monotonic floor only on success. Shared by the\n * facade and the SDK's track/screen forwarding.\n */\nexport async function applySkanDecision(\n core: SkanCore,\n native: NativeSKANModule | null,\n decision: { fineValue: number; coarseValue: string | null; lockWindow: boolean }\n): Promise<boolean> {\n if (!native) {\n // No native module (Android, or an iOS build without the LayersSKAN\n // bridge): nothing was posted to Apple. Committing the floor here recorded\n // conversion values that never left the device, and because the floor is\n // monotonic it then blocked the real postback if the bridge showed up\n // later. Report the failure so the core leaves the floor where it is.\n core.skanRecordConversionResult(decision.fineValue, false);\n return false;\n }\n try {\n if (decision.coarseValue) {\n await native.updatePostbackConversionValue(\n decision.fineValue,\n decision.coarseValue,\n decision.lockWindow\n );\n } else {\n await native.updateConversionValue(decision.fineValue);\n }\n core.skanRecordConversionResult(decision.fineValue, true);\n return true;\n } catch {\n // Native update failed — the core leaves the floor unchanged so the next\n // matching event re-issues it (no silently-lost value).\n core.skanRecordConversionResult(decision.fineValue, false);\n return false;\n }\n}\n\nexport class SKANManager {\n private nativeModule: NativeSKANModule | null;\n private core: SkanCore | null;\n private evaluationCount = 0;\n private onConversionUpdate?: (data: {\n event: string;\n previousValue: number;\n newValue: number;\n rule: SKANConversionRule;\n }) => void;\n\n constructor(\n onConversionUpdate?: (data: {\n event: string;\n previousValue: number;\n newValue: number;\n rule: SKANConversionRule;\n }) => void,\n core?: SkanCore | null\n ) {\n this.nativeModule = getNativeModule();\n this.core = core ?? sharedCore;\n if (onConversionUpdate) {\n this.onConversionUpdate = onConversionUpdate;\n }\n }\n\n /**\n * Initialize the manager. `arm` controls whether Apple's postback window is\n * registered — pass `false` on re-config so we don't re-arm mid-session\n * (re-registering would reset the OS conversion value). Returns `true` only if\n * the native register was attempted and succeeded (a rejection throws; an\n * unavailable/no-module case returns false).\n */\n async initialize(arm = true): Promise<boolean> {\n if (!this.nativeModule) return false;\n const available = await this.nativeModule.isAvailable();\n if (!available) return false;\n if (arm) {\n await this.nativeModule.registerAppForAdNetworkAttribution();\n return true;\n }\n return false;\n }\n\n isSupported(): boolean {\n return this.nativeModule !== null;\n }\n\n /** Load a built-in preset in the core (subscriptions/engagement/iap). */\n setPreset(preset: string): void {\n this.core?.skanSetPreset(preset);\n }\n\n /** Replace the core's active rules with a custom set. */\n setCustomRules(rules: SKANConversionRule[]): void {\n this.core?.skanSetRules(JSON.stringify(rules));\n }\n\n /**\n * Evaluate an event via the core. If the core returns an update, apply it to\n * native SKAdNetwork and report the result back so the core commits its floor\n * only on success.\n */\n async processEvent(eventName: string, properties: Record<string, unknown>): Promise<void> {\n this.evaluationCount += 1;\n const core = this.core;\n if (!core) return;\n const previousValue = core.skanCurrentValue();\n const decision = core.skanProcessEvent(eventName, properties ?? {});\n if (!decision) return;\n const applied = await applySkanDecision(core, this.nativeModule, decision);\n // Only notify on a confirmed apply — a failed native postback leaves the\n // core's floor un-advanced, so the consumer must not see it as posted.\n if (!applied) return;\n this.onConversionUpdate?.({\n event: eventName,\n previousValue,\n newValue: decision.fineValue,\n rule: {\n eventName,\n conversionValue: decision.fineValue,\n lockWindow: decision.lockWindow,\n ...(decision.coarseValue\n ? { coarseValue: decision.coarseValue as 'low' | 'medium' | 'high' }\n : {})\n }\n });\n }\n\n /** The highest SKAN conversion value posted so far (from the core). */\n getCurrentValue(): number {\n return this.core?.skanCurrentValue() ?? 0;\n }\n\n /** The active preset name (from the core), or null. */\n getCurrentPreset(): string | null {\n return this.core?.skanCurrentPreset() ?? null;\n }\n\n /**\n * The active rules. The core owns the rule set and does not expose it, so this\n * returns an empty array; use the core's metrics for introspection.\n */\n getCurrentRules(): SKANConversionRule[] {\n return [];\n }\n\n getMetrics(): SKANMetrics {\n return {\n isSupported: this.isSupported(),\n version: '4.0',\n currentValue: this.core?.skanCurrentValue() ?? 0,\n currentPreset: this.core?.skanCurrentPreset() ?? null,\n ruleCount: 0,\n evaluationCount: this.evaluationCount\n };\n }\n}\n"],"mappings":";;;AAgEA,SAAS,kBAA2C;AAClD,KAAI;EACF,MAAM,EAAE,eAAe,uBAAqB,eAAe;AAC3D,MAAI,SAAS,OAAO,SAAS,cAAc,WACzC,QAAO,cAAc;SAEjB;AAGR,QAAO;;AAGT,IAAIA,aAA8B;;;;;;AAOlC,SAAgB,YAAY,MAA6B;AACvD,cAAa;;;;;;;AAQf,eAAsB,kBACpB,MACA,QACA,UACkB;AAClB,KAAI,CAAC,QAAQ;AAMX,OAAK,2BAA2B,SAAS,WAAW,MAAM;AAC1D,SAAO;;AAET,KAAI;AACF,MAAI,SAAS,YACX,OAAM,OAAO,8BACX,SAAS,WACT,SAAS,aACT,SAAS,WACV;MAED,OAAM,OAAO,sBAAsB,SAAS,UAAU;AAExD,OAAK,2BAA2B,SAAS,WAAW,KAAK;AACzD,SAAO;SACD;AAGN,OAAK,2BAA2B,SAAS,WAAW,MAAM;AAC1D,SAAO;;;AAIX,IAAa,cAAb,MAAyB;CACvB,AAAQ;CACR,AAAQ;CACR,AAAQ,kBAAkB;CAC1B,AAAQ;CAOR,YACE,oBAMA,MACA;AACA,OAAK,eAAe,iBAAiB;AACrC,OAAK,OAAO,QAAQ;AACpB,MAAI,mBACF,MAAK,qBAAqB;;;;;;;;;CAW9B,MAAM,WAAW,MAAM,MAAwB;AAC7C,MAAI,CAAC,KAAK,aAAc,QAAO;AAE/B,MAAI,CADc,MAAM,KAAK,aAAa,aAAa,CACvC,QAAO;AACvB,MAAI,KAAK;AACP,SAAM,KAAK,aAAa,oCAAoC;AAC5D,UAAO;;AAET,SAAO;;CAGT,cAAuB;AACrB,SAAO,KAAK,iBAAiB;;;CAI/B,UAAU,QAAsB;AAC9B,OAAK,MAAM,cAAc,OAAO;;;CAIlC,eAAe,OAAmC;AAChD,OAAK,MAAM,aAAa,KAAK,UAAU,MAAM,CAAC;;;;;;;CAQhD,MAAM,aAAa,WAAmB,YAAoD;AACxF,OAAK,mBAAmB;EACxB,MAAM,OAAO,KAAK;AAClB,MAAI,CAAC,KAAM;EACX,MAAM,gBAAgB,KAAK,kBAAkB;EAC7C,MAAM,WAAW,KAAK,iBAAiB,WAAW,cAAc,EAAE,CAAC;AACnE,MAAI,CAAC,SAAU;AAIf,MAAI,CAHY,MAAM,kBAAkB,MAAM,KAAK,cAAc,SAAS,CAG5D;AACd,OAAK,qBAAqB;GACxB,OAAO;GACP;GACA,UAAU,SAAS;GACnB,MAAM;IACJ;IACA,iBAAiB,SAAS;IAC1B,YAAY,SAAS;IACrB,GAAI,SAAS,cACT,EAAE,aAAa,SAAS,aAA0C,GAClE,EAAE;IACP;GACF,CAAC;;;CAIJ,kBAA0B;AACxB,SAAO,KAAK,MAAM,kBAAkB,IAAI;;;CAI1C,mBAAkC;AAChC,SAAO,KAAK,MAAM,mBAAmB,IAAI;;;;;;CAO3C,kBAAwC;AACtC,SAAO,EAAE;;CAGX,aAA0B;AACxB,SAAO;GACL,aAAa,KAAK,aAAa;GAC/B,SAAS;GACT,cAAc,KAAK,MAAM,kBAAkB,IAAI;GAC/C,eAAe,KAAK,MAAM,mBAAmB,IAAI;GACjD,WAAW;GACX,iBAAiB,KAAK;GACvB"}
@@ -23,8 +23,8 @@ function setSkanCore(core) {
23
23
  */
24
24
  async function applySkanDecision(core, native, decision) {
25
25
  if (!native) {
26
- core.skanRecordConversionResult(decision.fineValue, true);
27
- return true;
26
+ core.skanRecordConversionResult(decision.fineValue, false);
27
+ return false;
28
28
  }
29
29
  try {
30
30
  if (decision.coarseValue) await native.updatePostbackConversionValue(decision.fineValue, decision.coarseValue, decision.lockWindow);
@@ -1 +1 @@
1
- {"version":3,"file":"skan-BljOFaeU.d.mts","names":[],"sources":["../src/skan.ts"],"sourcesContent":[],"mappings":";UAQiB,kBAAA;EAAA,SAAA,EAAA,MAAA;EAUA,UAAA,CAAA,EARF,MAQkB,CAAA,MAAA,EAAA,OAExB,CAAA;EAKQ,eAAW,EAAA,MAAA;EAaX,WAAQ,CAAA,EAAA,KAAA,GAKT,QAAM,GAAA,MAAA;EAQZ,UAAA,CAAA,EAAA,OAAgB;EACT,QAAA,CAAA,EAAA,MAAA;EACD,WAAA,CAAA,EAAA,MAAA;;AAEwB,UArCvB,gBAAA,CAqCuB;EAKnC,IAAA,EAAA,eAAA,GAAA,YAAA,GAAA,KAAA;EAC0B,KAAA,EAzCtB,kBAyCsB,EAAA;EAAO,WAAA,EAAA,MAAA;EAsBtB,QAAA,EAAA,MAAW;AAS3B;AACQ,UApES,WAAA,CAoET;EACE,WAAA,EAAA,OAAA;EAEP,OAAA,EAAA,MAAA;EAAO,YAAA,EAAA,MAAA,GAAA,IAAA;EA2BG,aAAA,EAAW,MAAA,GAAA,IAAA;EAgBZ,SAAA,EAAA,MAAA;EAED,eAAA,EAAA,MAAA;;;;;;AA0FK,UAjMC,QAAA,CAiMD;EAAW,aAAA,CAAA,MAAA,EAAA,MAAA,CAAA,EAAA,IAAA;;kDA5LX;;;;;;;;;;UAQN,gBAAA;iBACO;gBACD;wCACwB;wCACA;4FAKnC;+BAC0B;;;;;;;iBAsBf,WAAA,OAAkB;;;;;;iBASZ,iBAAA,OACd,kBACE;;;;IAEP;cA2BU,WAAA;;;;;;;;;UAgBD;qBAED;;;;;;;;6BAgBqB;;;;;wBAqBR;;;;;;8CAS4B,0BAA0B;;;;;;;;;qBAwCzD;gBAIL"}
1
+ {"version":3,"file":"skan-BljOFaeU.d.mts","names":[],"sources":["../src/skan.ts"],"sourcesContent":[],"mappings":";UAQiB,kBAAA;EAAA,SAAA,EAAA,MAAA;EAUA,UAAA,CAAA,EARF,MAQkB,CAAA,MAAA,EAAA,OAExB,CAAA;EAKQ,eAAW,EAAA,MAAA;EAaX,WAAQ,CAAA,EAAA,KAAA,GAKT,QAAM,GAAA,MAAA;EAQZ,UAAA,CAAA,EAAA,OAAgB;EACT,QAAA,CAAA,EAAA,MAAA;EACD,WAAA,CAAA,EAAA,MAAA;;AAEwB,UArCvB,gBAAA,CAqCuB;EAKnC,IAAA,EAAA,eAAA,GAAA,YAAA,GAAA,KAAA;EAC0B,KAAA,EAzCtB,kBAyCsB,EAAA;EAAO,WAAA,EAAA,MAAA;EAsBtB,QAAA,EAAA,MAAW;AAS3B;AACQ,UApES,WAAA,CAoET;EACE,WAAA,EAAA,OAAA;EAEP,OAAA,EAAA,MAAA;EAAO,YAAA,EAAA,MAAA,GAAA,IAAA;EA8BG,aAAA,EAAW,MAAA,GAAA,IAAA;EAgBZ,SAAA,EAAA,MAAA;EAED,eAAA,EAAA,MAAA;;;;;;AA0FK,UApMC,QAAA,CAoMD;EAAW,aAAA,CAAA,MAAA,EAAA,MAAA,CAAA,EAAA,IAAA;;kDA/LX;;;;;;;;;;UAQN,gBAAA;iBACO;gBACD;wCACwB;wCACA;4FAKnC;+BAC0B;;;;;;;iBAsBf,WAAA,OAAkB;;;;;;iBASZ,iBAAA,OACd,kBACE;;;;IAEP;cA8BU,WAAA;;;;;;;;;UAgBD;qBAED;;;;;;;;6BAgBqB;;;;;wBAqBR;;;;;;8CAS4B,0BAA0B;;;;;;;;;qBAwCzD;gBAIL"}
@@ -1 +1 @@
1
- {"version":3,"file":"skan-DnKHcXAj.d.ts","names":[],"sources":["../src/skan.ts"],"sourcesContent":[],"mappings":";UAQiB,kBAAA;EAAA,SAAA,EAAA,MAAA;EAUA,UAAA,CAAA,EARF,MAQkB,CAAA,MAAA,EAAA,OAExB,CAAA;EAKQ,eAAW,EAAA,MAAA;EAaX,WAAQ,CAAA,EAAA,KAAA,GAAA,QAKH,GAAA,MAAA;EAQZ,UAAA,CAAA,EAAA,OAAgB;EACT,QAAA,CAAA,EAAA,MAAA;EACD,WAAA,CAAA,EAAA,MAAA;;AAEwB,UArCvB,gBAAA,CAqCuB;EAKnC,IAAA,EAAA,eAAA,GAAA,YAAA,GAAA,KAAA;EAC0B,KAAA,EAzCtB,kBAyCsB,EAAA;EAAO,WAAA,EAAA,MAAA;EAsBtB,QAAA,EAAA,MAAW;AAS3B;AACQ,UApES,WAAA,CAoET;EACE,WAAA,EAAA,OAAA;EAEP,OAAA,EAAA,MAAA;EAAO,YAAA,EAAA,MAAA,GAAA,IAAA;EA2BG,aAAA,EAAW,MAAA,GAAA,IAAA;EAgBZ,SAAA,EAAA,MAAA;EAED,eAAA,EAAA,MAAA;;;;;;AA0FK,UAjMC,QAAA,CAiMD;EAAW,aAAA,CAAA,MAAA,EAAA,MAAA,CAAA,EAAA,IAAA;;kDA5LX;;;;;;;;;;UAQN,gBAAA;iBACO;gBACD;wCACwB;wCACA;4FAKnC;+BAC0B;;;;;;;iBAsBf,WAAA,OAAkB;;;;;;iBASZ,iBAAA,OACd,kBACE;;;;IAEP;cA2BU,WAAA;;;;;;;;;UAgBD;qBAED;;;;;;;;6BAgBqB;;;;;wBAqBR;;;;;;8CAS4B,0BAA0B;;;;;;;;;qBAwCzD;gBAIL"}
1
+ {"version":3,"file":"skan-DnKHcXAj.d.ts","names":[],"sources":["../src/skan.ts"],"sourcesContent":[],"mappings":";UAQiB,kBAAA;EAAA,SAAA,EAAA,MAAA;EAUA,UAAA,CAAA,EARF,MAQkB,CAAA,MAAA,EAAA,OAExB,CAAA;EAKQ,eAAW,EAAA,MAAA;EAaX,WAAQ,CAAA,EAAA,KAAA,GAAA,QAKH,GAAA,MAAA;EAQZ,UAAA,CAAA,EAAA,OAAgB;EACT,QAAA,CAAA,EAAA,MAAA;EACD,WAAA,CAAA,EAAA,MAAA;;AAEwB,UArCvB,gBAAA,CAqCuB;EAKnC,IAAA,EAAA,eAAA,GAAA,YAAA,GAAA,KAAA;EAC0B,KAAA,EAzCtB,kBAyCsB,EAAA;EAAO,WAAA,EAAA,MAAA;EAsBtB,QAAA,EAAA,MAAW;AAS3B;AACQ,UApES,WAAA,CAoET;EACE,WAAA,EAAA,OAAA;EAEP,OAAA,EAAA,MAAA;EAAO,YAAA,EAAA,MAAA,GAAA,IAAA;EA8BG,aAAA,EAAW,MAAA,GAAA,IAAA;EAgBZ,SAAA,EAAA,MAAA;EAED,eAAA,EAAA,MAAA;;;;;;AA0FK,UApMC,QAAA,CAoMD;EAAW,aAAA,CAAA,MAAA,EAAA,MAAA,CAAA,EAAA,IAAA;;kDA/LX;;;;;;;;;;UAQN,gBAAA;iBACO;gBACD;wCACwB;wCACA;4FAKnC;+BAC0B;;;;;;;iBAsBf,WAAA,OAAkB;;;;;;iBASZ,iBAAA,OACd,kBACE;;;;IAEP;cA8BU,WAAA;;;;;;;;;UAgBD;qBAED;;;;;;;;6BAgBqB;;;;;wBAqBR;;;;;;8CAS4B,0BAA0B;;;;;;;;;qBAwCzD;gBAIL"}
package/dist/skan.js CHANGED
@@ -1,4 +1,4 @@
1
- const require_skan = require('./skan-D0DUw-6o.js');
1
+ const require_skan = require('./skan-BRhw9sPC.js');
2
2
 
3
3
  exports.SKANManager = require_skan.SKANManager;
4
4
  exports.applySkanDecision = require_skan.applySkanDecision;
package/dist/skan.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { n as applySkanDecision, r as setSkanCore, t as SKANManager } from "./skan-CYTZtEAI.mjs";
1
+ import { n as applySkanDecision, r as setSkanCore, t as SKANManager } from "./skan-B0F6AX7g.mjs";
2
2
 
3
3
  export { SKANManager, applySkanDecision, setSkanCore };
@@ -1,6 +1,6 @@
1
1
  import { t as __require } from "./chunk-COTuXS2J.mjs";
2
2
  import { a as requestTrackingAuthorization, n as getAdvertisingId, r as getVendorId } from "./att-CnlG_CuV.mjs";
3
- import { r as setSkanCore, t as SKANManager } from "./skan-CYTZtEAI.mjs";
3
+ import { r as setSkanCore, t as SKANManager } from "./skan-B0F6AX7g.mjs";
4
4
  import { FetchHttpClient, LayersCore, LayersError as LayersError$1, LayersEvent, MemoryPersistence, addToCartEvent as buildAddToCartEvent, beginCheckoutEvent as buildBeginCheckoutEvent, initWasm, purchaseEvent as buildPurchaseEvent, refundEvent as buildRefundEvent, startTrialEvent as buildStartTrialEvent, subscribeEvent as buildSubscribeEvent, viewItemEvent as buildViewItemEvent } from "@layers/core-wasm";
5
5
 
6
6
  //#region src/standard-events.ts
@@ -909,7 +909,7 @@ var SurveysModule = class {
909
909
 
910
910
  //#endregion
911
911
  //#region src/index.ts
912
- const SDK_VERSION = "3.2.5";
912
+ const SDK_VERSION = "3.2.6";
913
913
  var LayersReactNative = class LayersReactNative {
914
914
  core;
915
915
  eagerPersistence;
@@ -927,6 +927,9 @@ var LayersReactNative = class LayersReactNative {
927
927
  static MAX_RECENT_EVENTS = 20;
928
928
  _recentEvents = [];
929
929
  _isInitialized = false;
930
+ _initPromise = null;
931
+ _initGeneration = 0;
932
+ _runtimeGeneration = 0;
930
933
  _configPollTimer = null;
931
934
  static CONFIG_POLL_INTERVAL_MS = 3e5;
932
935
  _adServicesToken = null;
@@ -968,16 +971,136 @@ var LayersReactNative = class LayersReactNative {
968
971
  persistence: this.eagerPersistence
969
972
  });
970
973
  setSkanCore(this.core);
974
+ this.applyEagerDeviceContext();
971
975
  if (this.appUserId) {
972
976
  this.core.identify(this.appUserId);
973
977
  this.userIdLocked = true;
974
978
  }
975
979
  }
980
+ /**
981
+ * Best-effort device context available at construction time — no `await`,
982
+ * so it can run in the constructor before any pre-init event is tracked.
983
+ * Only the synchronously readable fields; the rest arrive with
984
+ * initializeDeviceInfo().
985
+ */
986
+ applyEagerDeviceContext() {
987
+ const context = {
988
+ platform: "react-native",
989
+ osVersion: "unknown",
990
+ deviceModel: "unknown",
991
+ locale: "en-US"
992
+ };
993
+ try {
994
+ const { Platform, Dimensions } = __require("react-native");
995
+ context.platform = Platform.OS === "ios" ? "ios" : Platform.OS === "android" ? "android" : "react-native";
996
+ context.osVersion = typeof Platform.Version === "string" ? Platform.Version : String(Platform.Version);
997
+ context.locale = getLocale();
998
+ if (Platform.OS === "android") {
999
+ const brand = Platform.constants?.Brand ?? "";
1000
+ const model = Platform.constants?.Model ?? "";
1001
+ const deviceModel = brand && model ? `${brand} ${model}` : model || brand;
1002
+ if (deviceModel) context.deviceModel = deviceModel;
1003
+ }
1004
+ try {
1005
+ const window = Dimensions.get("window");
1006
+ context.screenSize = `${Math.round(window.width)}x${Math.round(window.height)}`;
1007
+ } catch {}
1008
+ try {
1009
+ context.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
1010
+ } catch {}
1011
+ } catch {}
1012
+ try {
1013
+ this.core.setDeviceContext(context);
1014
+ } catch {}
1015
+ }
1016
+ /**
1017
+ * The platform this instance runs on: 'ios' | 'android' | 'react-native'.
1018
+ * Reads the device context the constructor stamped (applyEagerDeviceContext)
1019
+ * and falls back to a direct `Platform.OS` read, so it answers correctly
1020
+ * before init() has completed.
1021
+ */
1022
+ currentPlatform() {
1023
+ try {
1024
+ const platform = this.core.getDeviceContext().platform;
1025
+ if (platform) return platform;
1026
+ } catch {}
1027
+ try {
1028
+ const { Platform } = __require("react-native");
1029
+ return String(Platform.OS);
1030
+ } catch {
1031
+ return "react-native";
1032
+ }
1033
+ }
1034
+ /**
1035
+ * Initialize the SDK. Idempotent: concurrent calls await the same in-flight
1036
+ * run, and a completed init() returns immediately. shutdown() releases the
1037
+ * latch, so shutdown() → init() re-initializes.
1038
+ */
976
1039
  async init() {
1040
+ if (this._initPromise) return this._initPromise;
1041
+ const promise = this.runInit(this._initGeneration);
1042
+ this._initPromise = promise;
1043
+ try {
1044
+ await promise;
1045
+ } catch (e) {
1046
+ if (this._initPromise === promise) this._initPromise = null;
1047
+ throw e;
1048
+ }
1049
+ }
1050
+ /**
1051
+ * True when a shutdown() landed after this init() run started. The caller
1052
+ * must return immediately.
1053
+ *
1054
+ * Without this gate init() ran to completion on an abandoned instance: it
1055
+ * built a second live core (the AsyncStorage rebuild below), installed the
1056
+ * AppState/NetInfo/deep-link listeners and the 300s config-poll timer on it,
1057
+ * and tracked a duplicate `app_open` — one orphaned SDK, with its own
1058
+ * timers, per remount. React 18 StrictMode mounts → unmounts → remounts
1059
+ * every effect, so the Expo `LayersProvider` (which calls shutdown() in
1060
+ * cleanup while init() is still awaiting) hit this on every dev launch.
1061
+ *
1062
+ * **This check has no side effects, deliberately.** It used to tear the
1063
+ * runtime down on any generation mismatch, which is wrong the moment two
1064
+ * runs overlap: init A → shutdown → init B completes → A finally reaches a
1065
+ * checkpoint and demolishes *B's* listeners, core and timer, leaving an SDK
1066
+ * that reported `isInitialized === true` and delivered nothing. Cleanup
1067
+ * belongs to shutdown() (which owns everything installed at the moment it
1068
+ * runs) and to {@link abandonRun} (which proves ownership by generation
1069
+ * first).
1070
+ */
1071
+ isRunAbandoned(generation) {
1072
+ return generation !== this._initGeneration;
1073
+ }
1074
+ /**
1075
+ * Abandon this run and release only the resources it installed itself.
1076
+ *
1077
+ * Every install site below is *synchronously* adjacent to its preceding
1078
+ * checkpoint — no `await` sits between "still current?" and the assignment —
1079
+ * so a shutdown() can never slip in between the two, and anything this run
1080
+ * did install was already torn down by that shutdown(). The ownership check
1081
+ * is what keeps that true if a future edit ever puts an await in between:
1082
+ * the run cleans up only while it is still the runtime's owner.
1083
+ */
1084
+ abandonRun(generation) {
1085
+ if (this._runtimeGeneration !== generation) return;
1086
+ this.teardownRuntime();
1087
+ }
1088
+ /**
1089
+ * Checkpoint used at every await boundary in runInit(): report whether this
1090
+ * run has been abandoned and, if so, release only what it still owns.
1091
+ */
1092
+ initAborted(generation) {
1093
+ if (!this.isRunAbandoned(generation)) return false;
1094
+ this.abandonRun(generation);
1095
+ return true;
1096
+ }
1097
+ async runInit(generation) {
977
1098
  const initStartTime = Date.now();
978
1099
  if (typeof WebAssembly !== "undefined") await initWasm();
1100
+ if (this.initAborted(generation)) return;
979
1101
  try {
980
1102
  const persistence = await createAsyncStoragePersistence(this.config.appId);
1103
+ if (this.initAborted(generation)) return;
981
1104
  const httpClient = new FetchHttpClient();
982
1105
  const migrationState = this.core.exportMigrationState();
983
1106
  this.core.shutdown();
@@ -1009,16 +1132,20 @@ var LayersReactNative = class LayersReactNative {
1009
1132
  persistence
1010
1133
  });
1011
1134
  this.core.applyMigrationState(migrationState);
1135
+ this._runtimeGeneration = generation;
1012
1136
  setSkanCore(this.core);
1013
1137
  if (this.appUserId) this.core.identify(this.appUserId);
1014
1138
  } catch {}
1015
1139
  await this.restoreAttributionData();
1016
1140
  await this.initializeDeviceInfo();
1141
+ if (this.initAborted(generation)) return;
1142
+ this._runtimeGeneration = generation;
1017
1143
  this.setupAppStateListener();
1018
1144
  this.setupNetInfoListener();
1019
1145
  const mainThreadDurationMs = Date.now() - initStartTime;
1020
1146
  await this.core.fetchRemoteConfig().catch(() => {});
1021
1147
  await this.configureSkanFromRemoteConfig();
1148
+ if (this.initAborted(generation)) return;
1022
1149
  this.startConfigPolling();
1023
1150
  let clipboardData = null;
1024
1151
  try {
@@ -1032,13 +1159,28 @@ var LayersReactNative = class LayersReactNative {
1032
1159
  if (clipboardEnabled) clipboardData = await readClipboardAttribution();
1033
1160
  }
1034
1161
  } catch {}
1162
+ if (this.initAborted(generation)) return;
1035
1163
  if (this.config.autoTrackAppOpen !== false) {
1036
1164
  const appOpenProps = {};
1037
1165
  let isFirstLaunchByFlag = true;
1038
1166
  try {
1039
1167
  const AsyncStorage = await loadAsyncStorage();
1040
1168
  if (AsyncStorage) {
1041
- if (await AsyncStorage.getItem(FIRST_LAUNCH_TRACKED_KEY) === "true") isFirstLaunchByFlag = false;
1169
+ const scopedKey = firstLaunchTrackedKey(this.config.appId);
1170
+ let flag = await AsyncStorage.getItem(scopedKey);
1171
+ let adoptLegacy = false;
1172
+ if (flag === null) {
1173
+ const legacy = await AsyncStorage.getItem(FIRST_LAUNCH_TRACKED_KEY_LEGACY);
1174
+ if (legacy === "true") {
1175
+ flag = legacy;
1176
+ adoptLegacy = true;
1177
+ }
1178
+ }
1179
+ if (flag === "true") isFirstLaunchByFlag = false;
1180
+ if (adoptLegacy) try {
1181
+ await AsyncStorage.setItem(scopedKey, "true");
1182
+ await AsyncStorage.removeItem(FIRST_LAUNCH_TRACKED_KEY_LEGACY);
1183
+ } catch {}
1042
1184
  }
1043
1185
  } catch {}
1044
1186
  const isFirstLaunch = await shouldTreatAsNewInstall(isFirstLaunchByFlag, this._hadPriorSdkState, this.enableDebug);
@@ -1047,10 +1189,6 @@ var LayersReactNative = class LayersReactNative {
1047
1189
  if (isFirstLaunch && !hasAttribution) try {
1048
1190
  await this.resolveClickFromFingerprint();
1049
1191
  } catch {}
1050
- if (isFirstLaunch) try {
1051
- const AsyncStorage = await loadAsyncStorage();
1052
- if (AsyncStorage) await AsyncStorage.setItem(FIRST_LAUNCH_TRACKED_KEY, "true");
1053
- } catch {}
1054
1192
  if (clipboardData) {
1055
1193
  appOpenProps.clipboard_attribution_url = clipboardData.clickUrl;
1056
1194
  appOpenProps.clipboard_click_id = clipboardData.clickId;
@@ -1064,8 +1202,13 @@ var LayersReactNative = class LayersReactNative {
1064
1202
  if (this._installReferrerParams) {
1065
1203
  for (const [key, value] of Object.entries(this._installReferrerParams)) if (appOpenProps[key] === void 0) appOpenProps[key] = value;
1066
1204
  }
1205
+ if (this.initAborted(generation)) return;
1067
1206
  if (isFirstLaunch) this.track("app_install", appOpenProps);
1068
1207
  this.track("app_open", appOpenProps);
1208
+ if (isFirstLaunch) try {
1209
+ const AsyncStorage = await loadAsyncStorage();
1210
+ if (AsyncStorage) await AsyncStorage.setItem(firstLaunchTrackedKey(this.config.appId), "true");
1211
+ } catch {}
1069
1212
  if (this.config.autoTrackAppUpdate !== false) try {
1070
1213
  const currentVersion = this.core.getDeviceContext().appVersion ?? appOpenProps.app_version;
1071
1214
  if (currentVersion && typeof currentVersion === "string") {
@@ -1081,6 +1224,7 @@ var LayersReactNative = class LayersReactNative {
1081
1224
  }
1082
1225
  } catch {}
1083
1226
  }
1227
+ if (this.initAborted(generation)) return;
1084
1228
  if (this.config.autoTrackDeepLinks !== false) this.setupDeepLinkAutoTracking();
1085
1229
  this._isInitialized = true;
1086
1230
  const totalDurationMs = Date.now() - initStartTime;
@@ -1331,6 +1475,10 @@ var LayersReactNative = class LayersReactNative {
1331
1475
  * Returns the ATT status string.
1332
1476
  */
1333
1477
  async requestTrackingPermission() {
1478
+ if (this.currentPlatform() === "android") {
1479
+ if (this.enableDebug) console.log("[Layers] requestTrackingPermission() is a no-op on Android — ATT is iOS-only; consent left untouched.");
1480
+ return "not_determined";
1481
+ }
1334
1482
  let status;
1335
1483
  try {
1336
1484
  const ExpoTT = await import("./TrackingTransparency-DunpgkgS.mjs").catch(() => null);
@@ -1659,6 +1807,29 @@ var LayersReactNative = class LayersReactNative {
1659
1807
  if (this.enableDebug && this.errorListeners.size === 0) console.warn("[Layers]", err.message);
1660
1808
  }
1661
1809
  shutdown() {
1810
+ this._initGeneration += 1;
1811
+ this._initPromise = null;
1812
+ this._isInitialized = false;
1813
+ this._runtimeGeneration = this._initGeneration;
1814
+ this.teardownRuntime();
1815
+ this._attributionDeeplinkId = null;
1816
+ this._attributionGclid = null;
1817
+ this._attributionFbclid = null;
1818
+ this._attributionFbc = null;
1819
+ this._attributionTtclid = null;
1820
+ this._attributionMsclkid = null;
1821
+ this._initListener = null;
1822
+ this._skanManager = null;
1823
+ this._skanArmed = false;
1824
+ setSkanCore(null);
1825
+ }
1826
+ /**
1827
+ * Remove every listener and timer this instance installed, then shut the
1828
+ * core down. Shared by shutdown() and the mid-init abort path, so it must be
1829
+ * safe to call twice — every handle is nulled and the core's own shutdown()
1830
+ * is a no-op once it has run.
1831
+ */
1832
+ teardownRuntime() {
1662
1833
  this.stopConfigPolling();
1663
1834
  if (this.appStateSubscription) {
1664
1835
  this.appStateSubscription.remove();
@@ -1672,17 +1843,9 @@ var LayersReactNative = class LayersReactNative {
1672
1843
  this.deepLinkUnsubscribe();
1673
1844
  this.deepLinkUnsubscribe = null;
1674
1845
  }
1675
- this._attributionDeeplinkId = null;
1676
- this._attributionGclid = null;
1677
- this._attributionFbclid = null;
1678
- this._attributionFbc = null;
1679
- this._attributionTtclid = null;
1680
- this._attributionMsclkid = null;
1681
- this._initListener = null;
1682
- this._skanManager = null;
1683
- this._skanArmed = false;
1684
- setSkanCore(null);
1685
- this.core.shutdown();
1846
+ try {
1847
+ this.core.shutdown();
1848
+ } catch {}
1686
1849
  }
1687
1850
  /**
1688
1851
  * Store attribution data that will be attached to all subsequent events.
@@ -1796,6 +1959,10 @@ var LayersReactNative = class LayersReactNative {
1796
1959
  }
1797
1960
  _trackedDeepLinkUrls = /* @__PURE__ */ new Set();
1798
1961
  setupDeepLinkAutoTracking() {
1962
+ if (this.deepLinkUnsubscribe) {
1963
+ this.deepLinkUnsubscribe();
1964
+ this.deepLinkUnsubscribe = null;
1965
+ }
1799
1966
  this.deepLinkUnsubscribe = setupDeepLinkListener((data) => {
1800
1967
  if (this._trackedDeepLinkUrls.has(data.url)) return;
1801
1968
  this._trackedDeepLinkUrls.add(data.url);
@@ -1927,6 +2094,10 @@ var LayersReactNative = class LayersReactNative {
1927
2094
  } catch {}
1928
2095
  }
1929
2096
  setupAppStateListener() {
2097
+ if (this.appStateSubscription) {
2098
+ this.appStateSubscription.remove();
2099
+ this.appStateSubscription = null;
2100
+ }
1930
2101
  try {
1931
2102
  const { AppState } = __require("react-native");
1932
2103
  let lastEmittedState = null;
@@ -1947,7 +2118,10 @@ var LayersReactNative = class LayersReactNative {
1947
2118
  if (this.isOnline) this.core.flushAsync().catch(() => {});
1948
2119
  }
1949
2120
  });
1950
- } catch {}
2121
+ } catch (e) {
2122
+ this.emitError(e);
2123
+ console.warn("[Layers] AppState listener failed to register — $app_background and the background crash-safety snapshot are disabled for this session:", e);
2124
+ }
1951
2125
  }
1952
2126
  async configureSkanFromRemoteConfig() {
1953
2127
  try {
@@ -1987,6 +2161,10 @@ var LayersReactNative = class LayersReactNative {
1987
2161
  } catch {}
1988
2162
  }
1989
2163
  setupNetInfoListener() {
2164
+ if (this.netInfoUnsubscribe) {
2165
+ this.netInfoUnsubscribe();
2166
+ this.netInfoUnsubscribe = null;
2167
+ }
1990
2168
  try {
1991
2169
  this.netInfoUnsubscribe = __require("@react-native-community/netinfo").addEventListener((state) => {
1992
2170
  const wasOffline = !this.isOnline;
@@ -2109,7 +2287,23 @@ function getLocale() {
2109
2287
  return "en-US";
2110
2288
  }
2111
2289
  const INSTALL_ID_KEY = "layers_install_id";
2112
- const FIRST_LAUNCH_TRACKED_KEY = "@layers/first_launch_tracked";
2290
+ /**
2291
+ * Pre-scoping first-launch key. Read-only from here on: it is global, so a
2292
+ * staging→production `appId` switch made every app share one flag. We still
2293
+ * consult it so installs that predate the scoping don't re-fire `app_install`
2294
+ * on upgrade, but nothing writes it any more.
2295
+ */
2296
+ const FIRST_LAUNCH_TRACKED_KEY_LEGACY = "@layers/first_launch_tracked";
2297
+ /**
2298
+ * First-launch flag, scoped by `appId` to match the engine's app-scoped
2299
+ * identity state (`layers_sdk_<appId>_identity_state`). With a single global
2300
+ * key the two disagreed: switching `appId` made the engine re-emit
2301
+ * `$first_open` (fresh identity state) while the wrapper suppressed
2302
+ * `app_install` (flag already set) — a first-open with no install.
2303
+ */
2304
+ function firstLaunchTrackedKey(appId) {
2305
+ return `@layers/first_launch_tracked_${appId}`;
2306
+ }
2113
2307
  /**
2114
2308
  * Last-known app_version persisted across launches. Used to detect
2115
2309
  * `$app_update` (version increment) vs. `$first_open` (no prior value).
@@ -2123,17 +2317,34 @@ const LAST_APP_VERSION_KEY = "@layers/last_app_version";
2123
2317
  * new install — and suppresses `is_first_launch = true`.
2124
2318
  */
2125
2319
  const INSTALL_EVENT_MAX_DIFF_MS = 1440 * 60 * 1e3;
2320
+ /**
2321
+ * Process-lifetime install ID used when AsyncStorage is unavailable. Minting a
2322
+ * fresh UUID per call made every launch — and every call within a launch —
2323
+ * look like a different install: rotating `install_id`, `app_install` +
2324
+ * `$first_open` on every start, no attribution persistence. Memoizing at least
2325
+ * keeps a single session internally consistent.
2326
+ */
2327
+ let _ephemeralInstallId = null;
2328
+ let _warnedNoAsyncStorage = false;
2329
+ function ephemeralInstallId() {
2330
+ if (!_warnedNoAsyncStorage) {
2331
+ _warnedNoAsyncStorage = true;
2332
+ console.warn("[Layers] @react-native-async-storage/async-storage is not installed — install ID, first-launch state and the offline event queue cannot persist. Every app launch will look like a new install. Install the package to enable persistent identity.");
2333
+ }
2334
+ _ephemeralInstallId ??= generateUUID();
2335
+ return _ephemeralInstallId;
2336
+ }
2126
2337
  async function getOrSetInstallId() {
2127
2338
  try {
2128
2339
  const AsyncStorage = await loadAsyncStorage();
2129
- if (!AsyncStorage) return generateUUID();
2340
+ if (!AsyncStorage) return ephemeralInstallId();
2130
2341
  const existing = await AsyncStorage.getItem(INSTALL_ID_KEY);
2131
2342
  if (existing) return existing;
2132
2343
  const newId = generateUUID();
2133
2344
  await AsyncStorage.setItem(INSTALL_ID_KEY, newId);
2134
2345
  return newId;
2135
2346
  } catch {
2136
- return generateUUID();
2347
+ return ephemeralInstallId();
2137
2348
  }
2138
2349
  }
2139
2350
  function generateUUID() {
@@ -2416,6 +2627,7 @@ function parseDeepLink(url) {
2416
2627
  }
2417
2628
  }
2418
2629
  const _expoRouterPreviousPath = /* @__PURE__ */ new WeakMap();
2630
+ const _expoRouterLastTracked = /* @__PURE__ */ new WeakMap();
2419
2631
  /**
2420
2632
  * Hook that emits `$screen_view` for every Expo Router pathname change.
2421
2633
  *
@@ -2426,11 +2638,16 @@ const _expoRouterPreviousPath = /* @__PURE__ */ new WeakMap();
2426
2638
  * — no need to join adjacent rows.
2427
2639
  */
2428
2640
  function useLayersExpoRouterTracking(sdkInstance, usePathname, useGlobalSearchParams) {
2641
+ if (sdkInstance != null && typeof sdkInstance.screen !== "function") throw new TypeError("useLayersExpoRouterTracking: expected a LayersReactNative instance (or null before init).");
2429
2642
  const { useEffect } = __require("react");
2430
2643
  const pathname = usePathname();
2431
2644
  const params = useGlobalSearchParams();
2645
+ const paramsString = JSON.stringify(params);
2432
2646
  useEffect(() => {
2647
+ if (sdkInstance == null) return;
2433
2648
  if (pathname) {
2649
+ const routeKey = `${pathname}${paramsString}`;
2650
+ if (_expoRouterLastTracked.get(sdkInstance) === routeKey) return;
2434
2651
  const properties = {};
2435
2652
  Object.entries(params).forEach(([key, value]) => {
2436
2653
  properties[key] = Array.isArray(value) ? value.join(",") : value;
@@ -2439,10 +2656,15 @@ function useLayersExpoRouterTracking(sdkInstance, usePathname, useGlobalSearchPa
2439
2656
  if (previous && previous !== pathname) properties.previous_screen_name = previous;
2440
2657
  sdkInstance.screen(pathname, properties);
2441
2658
  _expoRouterPreviousPath.set(sdkInstance, pathname);
2659
+ _expoRouterLastTracked.set(sdkInstance, routeKey);
2442
2660
  }
2443
- }, [pathname, JSON.stringify(params)]);
2661
+ }, [
2662
+ sdkInstance,
2663
+ pathname,
2664
+ paramsString
2665
+ ]);
2444
2666
  }
2445
2667
 
2446
2668
  //#endregion
2447
2669
  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 };
2448
- //# sourceMappingURL=src-CiemkTIn.mjs.map
2670
+ //# sourceMappingURL=src-BRZ3Lfl5.mjs.map