@adshift/react-native-plugin 1.0.0 → 2.0.0

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.
Files changed (180) hide show
  1. package/AdShiftReactNativePlugin.podspec +11 -7
  2. package/CHANGELOG.md +122 -0
  3. package/README.md +506 -542
  4. package/android/build.gradle +17 -3
  5. package/android/consumer-rules.pro +21 -0
  6. package/android/src/main/java/com/adshift/reactnativeplugin/AdShiftReactNativePluginModule.kt +786 -229
  7. package/android/src/test/java/com/adshift/reactnativeplugin/ConsentSnapshotTest.kt +180 -0
  8. package/android/src/test/java/com/adshift/reactnativeplugin/DeepLinkDeliveryTest.kt +146 -0
  9. package/android/src/test/java/com/adshift/reactnativeplugin/InitializeOrderingTest.kt +111 -0
  10. package/android/src/test/java/com/adshift/reactnativeplugin/IntentLinkDedupTest.kt +168 -0
  11. package/android/src/test/java/com/adshift/reactnativeplugin/LaunchIntentForwardingTest.kt +106 -0
  12. package/android/src/test/java/com/adshift/reactnativeplugin/ModuleTestSupport.kt +167 -0
  13. package/android/src/test/java/com/adshift/reactnativeplugin/StartVerdictTest.kt +164 -0
  14. package/ios/AdShiftReactNativePlugin.h +7 -7
  15. package/ios/AdShiftReactNativePlugin.mm +200 -181
  16. package/ios/AdShiftReactNativePluginHelper.swift +584 -286
  17. package/ios/Core/BridgeRules.swift +82 -0
  18. package/lib/commonjs/Adshift.js +1135 -0
  19. package/lib/commonjs/Adshift.js.map +1 -0
  20. package/lib/commonjs/NativeAdShiftReactNativePlugin.js +22 -0
  21. package/lib/commonjs/NativeAdShiftReactNativePlugin.js.map +1 -0
  22. package/lib/commonjs/index.js +94 -0
  23. package/lib/commonjs/index.js.map +1 -0
  24. package/lib/commonjs/jest/index.js +164 -0
  25. package/lib/commonjs/jest/index.js.map +1 -0
  26. package/lib/commonjs/nativeSdkVersions.js +17 -0
  27. package/lib/commonjs/nativeSdkVersions.js.map +1 -0
  28. package/lib/commonjs/package.json +1 -0
  29. package/lib/commonjs/types/AdshiftAdRevenue.js +47 -0
  30. package/lib/commonjs/types/AdshiftAdRevenue.js.map +1 -0
  31. package/lib/commonjs/types/AdshiftConfig.js +45 -0
  32. package/lib/commonjs/types/AdshiftConfig.js.map +1 -0
  33. package/lib/commonjs/types/AdshiftConsent.js +113 -0
  34. package/lib/commonjs/types/AdshiftConsent.js.map +1 -0
  35. package/lib/commonjs/types/AdshiftConsentSnapshot.js +69 -0
  36. package/lib/commonjs/types/AdshiftConsentSnapshot.js.map +1 -0
  37. package/lib/commonjs/types/AdshiftDeepLink.js +154 -0
  38. package/lib/commonjs/types/AdshiftDeepLink.js.map +1 -0
  39. package/lib/commonjs/types/AdshiftError.js +91 -0
  40. package/lib/commonjs/types/AdshiftError.js.map +1 -0
  41. package/lib/commonjs/types/AdshiftEventParam.js +140 -0
  42. package/lib/commonjs/types/AdshiftEventParam.js.map +1 -0
  43. package/lib/commonjs/types/AdshiftEventType.js +88 -0
  44. package/lib/commonjs/types/AdshiftEventType.js.map +1 -0
  45. package/lib/commonjs/types/AdshiftThirdPartySharing.js +70 -0
  46. package/lib/commonjs/types/AdshiftThirdPartySharing.js.map +1 -0
  47. package/lib/commonjs/types/index.js +123 -0
  48. package/lib/commonjs/types/index.js.map +1 -0
  49. package/lib/commonjs/version.js +9 -0
  50. package/lib/commonjs/version.js.map +1 -0
  51. package/lib/module/Adshift.js +959 -296
  52. package/lib/module/Adshift.js.map +1 -1
  53. package/lib/module/NativeAdShiftReactNativePlugin.js +10 -7
  54. package/lib/module/NativeAdShiftReactNativePlugin.js.map +1 -1
  55. package/lib/module/index.js +26 -25
  56. package/lib/module/index.js.map +1 -1
  57. package/lib/module/jest/index.js +144 -0
  58. package/lib/module/jest/index.js.map +1 -0
  59. package/lib/module/nativeSdkVersions.js +13 -0
  60. package/lib/module/nativeSdkVersions.js.map +1 -0
  61. package/lib/module/types/AdshiftAdRevenue.js +43 -0
  62. package/lib/module/types/AdshiftAdRevenue.js.map +1 -0
  63. package/lib/module/types/AdshiftConfig.js +23 -26
  64. package/lib/module/types/AdshiftConfig.js.map +1 -1
  65. package/lib/module/types/AdshiftConsent.js +57 -50
  66. package/lib/module/types/AdshiftConsent.js.map +1 -1
  67. package/lib/module/types/AdshiftConsentSnapshot.js +65 -0
  68. package/lib/module/types/AdshiftConsentSnapshot.js.map +1 -0
  69. package/lib/module/types/AdshiftDeepLink.js +97 -67
  70. package/lib/module/types/AdshiftDeepLink.js.map +1 -1
  71. package/lib/module/types/AdshiftError.js +87 -0
  72. package/lib/module/types/AdshiftError.js.map +1 -0
  73. package/lib/module/types/AdshiftEventParam.js +135 -0
  74. package/lib/module/types/AdshiftEventParam.js.map +1 -0
  75. package/lib/module/types/AdshiftEventType.js +11 -36
  76. package/lib/module/types/AdshiftEventType.js.map +1 -1
  77. package/lib/module/types/AdshiftThirdPartySharing.js +65 -0
  78. package/lib/module/types/AdshiftThirdPartySharing.js.map +1 -0
  79. package/lib/module/types/index.js +9 -7
  80. package/lib/module/types/index.js.map +1 -1
  81. package/lib/module/version.js +5 -0
  82. package/lib/module/version.js.map +1 -0
  83. package/lib/typescript/commonjs/package.json +1 -0
  84. package/lib/typescript/commonjs/src/Adshift.d.ts +311 -0
  85. package/lib/typescript/commonjs/src/Adshift.d.ts.map +1 -0
  86. package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts +102 -0
  87. package/lib/typescript/commonjs/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -0
  88. package/lib/typescript/commonjs/src/index.d.ts +51 -0
  89. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  90. package/lib/typescript/commonjs/src/jest/index.d.ts +103 -0
  91. package/lib/typescript/commonjs/src/jest/index.d.ts.map +1 -0
  92. package/lib/typescript/commonjs/src/nativeSdkVersions.d.ts +11 -0
  93. package/lib/typescript/commonjs/src/nativeSdkVersions.d.ts.map +1 -0
  94. package/lib/typescript/commonjs/src/types/AdshiftAdRevenue.d.ts +56 -0
  95. package/lib/typescript/commonjs/src/types/AdshiftAdRevenue.d.ts.map +1 -0
  96. package/lib/typescript/commonjs/src/types/AdshiftConfig.d.ts +104 -0
  97. package/lib/typescript/commonjs/src/types/AdshiftConfig.d.ts.map +1 -0
  98. package/lib/typescript/commonjs/src/types/AdshiftConsent.d.ts +76 -0
  99. package/lib/typescript/commonjs/src/types/AdshiftConsent.d.ts.map +1 -0
  100. package/lib/typescript/commonjs/src/types/AdshiftConsentSnapshot.d.ts +56 -0
  101. package/lib/typescript/commonjs/src/types/AdshiftConsentSnapshot.d.ts.map +1 -0
  102. package/lib/typescript/commonjs/src/types/AdshiftDeepLink.d.ts +89 -0
  103. package/lib/typescript/commonjs/src/types/AdshiftDeepLink.d.ts.map +1 -0
  104. package/lib/typescript/commonjs/src/types/AdshiftError.d.ts +57 -0
  105. package/lib/typescript/commonjs/src/types/AdshiftError.d.ts.map +1 -0
  106. package/lib/typescript/commonjs/src/types/AdshiftEventParam.d.ts +111 -0
  107. package/lib/typescript/commonjs/src/types/AdshiftEventParam.d.ts.map +1 -0
  108. package/lib/typescript/{src → commonjs/src}/types/AdshiftEventType.d.ts +12 -35
  109. package/lib/typescript/commonjs/src/types/AdshiftEventType.d.ts.map +1 -0
  110. package/lib/typescript/commonjs/src/types/AdshiftThirdPartySharing.d.ts +53 -0
  111. package/lib/typescript/commonjs/src/types/AdshiftThirdPartySharing.d.ts.map +1 -0
  112. package/lib/typescript/commonjs/src/types/index.d.ts +17 -0
  113. package/lib/typescript/commonjs/src/types/index.d.ts.map +1 -0
  114. package/lib/typescript/commonjs/src/version.d.ts +2 -0
  115. package/lib/typescript/commonjs/src/version.d.ts.map +1 -0
  116. package/lib/typescript/module/src/Adshift.d.ts +311 -0
  117. package/lib/typescript/module/src/Adshift.d.ts.map +1 -0
  118. package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts +102 -0
  119. package/lib/typescript/module/src/NativeAdShiftReactNativePlugin.d.ts.map +1 -0
  120. package/lib/typescript/module/src/index.d.ts +51 -0
  121. package/lib/typescript/module/src/index.d.ts.map +1 -0
  122. package/lib/typescript/module/src/jest/index.d.ts +103 -0
  123. package/lib/typescript/module/src/jest/index.d.ts.map +1 -0
  124. package/lib/typescript/module/src/nativeSdkVersions.d.ts +11 -0
  125. package/lib/typescript/module/src/nativeSdkVersions.d.ts.map +1 -0
  126. package/lib/typescript/module/src/types/AdshiftAdRevenue.d.ts +56 -0
  127. package/lib/typescript/module/src/types/AdshiftAdRevenue.d.ts.map +1 -0
  128. package/lib/typescript/module/src/types/AdshiftConfig.d.ts +104 -0
  129. package/lib/typescript/module/src/types/AdshiftConfig.d.ts.map +1 -0
  130. package/lib/typescript/module/src/types/AdshiftConsent.d.ts +76 -0
  131. package/lib/typescript/module/src/types/AdshiftConsent.d.ts.map +1 -0
  132. package/lib/typescript/module/src/types/AdshiftConsentSnapshot.d.ts +56 -0
  133. package/lib/typescript/module/src/types/AdshiftConsentSnapshot.d.ts.map +1 -0
  134. package/lib/typescript/module/src/types/AdshiftDeepLink.d.ts +89 -0
  135. package/lib/typescript/module/src/types/AdshiftDeepLink.d.ts.map +1 -0
  136. package/lib/typescript/module/src/types/AdshiftError.d.ts +57 -0
  137. package/lib/typescript/module/src/types/AdshiftError.d.ts.map +1 -0
  138. package/lib/typescript/module/src/types/AdshiftEventParam.d.ts +111 -0
  139. package/lib/typescript/module/src/types/AdshiftEventParam.d.ts.map +1 -0
  140. package/lib/typescript/module/src/types/AdshiftEventType.d.ts +64 -0
  141. package/lib/typescript/module/src/types/AdshiftEventType.d.ts.map +1 -0
  142. package/lib/typescript/module/src/types/AdshiftThirdPartySharing.d.ts +53 -0
  143. package/lib/typescript/module/src/types/AdshiftThirdPartySharing.d.ts.map +1 -0
  144. package/lib/typescript/module/src/types/index.d.ts +17 -0
  145. package/lib/typescript/module/src/types/index.d.ts.map +1 -0
  146. package/lib/typescript/module/src/version.d.ts +2 -0
  147. package/lib/typescript/module/src/version.d.ts.map +1 -0
  148. package/package.json +49 -10
  149. package/src/Adshift.ts +1273 -342
  150. package/src/NativeAdShiftReactNativePlugin.ts +81 -115
  151. package/src/index.tsx +40 -25
  152. package/src/jest/index.ts +224 -0
  153. package/src/nativeSdkVersions.ts +10 -0
  154. package/src/types/AdshiftAdRevenue.ts +58 -0
  155. package/src/types/AdshiftConfig.ts +101 -53
  156. package/src/types/AdshiftConsent.ts +75 -72
  157. package/src/types/AdshiftConsentSnapshot.ts +103 -0
  158. package/src/types/AdshiftDeepLink.ts +123 -102
  159. package/src/types/AdshiftError.ts +107 -0
  160. package/src/types/AdshiftEventParam.ts +216 -0
  161. package/src/types/AdshiftEventType.ts +13 -35
  162. package/src/types/AdshiftThirdPartySharing.ts +63 -0
  163. package/src/types/index.ts +38 -6
  164. package/src/version.ts +2 -0
  165. package/lib/typescript/src/Adshift.d.ts +0 -335
  166. package/lib/typescript/src/Adshift.d.ts.map +0 -1
  167. package/lib/typescript/src/NativeAdShiftReactNativePlugin.d.ts +0 -143
  168. package/lib/typescript/src/NativeAdShiftReactNativePlugin.d.ts.map +0 -1
  169. package/lib/typescript/src/index.d.ts +0 -47
  170. package/lib/typescript/src/index.d.ts.map +0 -1
  171. package/lib/typescript/src/types/AdshiftConfig.d.ts +0 -74
  172. package/lib/typescript/src/types/AdshiftConfig.d.ts.map +0 -1
  173. package/lib/typescript/src/types/AdshiftConsent.d.ts +0 -88
  174. package/lib/typescript/src/types/AdshiftConsent.d.ts.map +0 -1
  175. package/lib/typescript/src/types/AdshiftDeepLink.d.ts +0 -93
  176. package/lib/typescript/src/types/AdshiftDeepLink.d.ts.map +0 -1
  177. package/lib/typescript/src/types/AdshiftEventType.d.ts.map +0 -1
  178. package/lib/typescript/src/types/index.d.ts +0 -5
  179. package/lib/typescript/src/types/index.d.ts.map +0 -1
  180. /package/lib/typescript/{package.json → module/package.json} +0 -0
@@ -0,0 +1,1135 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.Adshift = void 0;
7
+ var _reactNative = require("react-native");
8
+ var _NativeAdShiftReactNativePlugin = _interopRequireDefault(require("./NativeAdShiftReactNativePlugin.js"));
9
+ var _nativeSdkVersions = require("./nativeSdkVersions.js");
10
+ var _index = require("./types/index.js");
11
+ var _version = require("./version.js");
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ /**
14
+ * AdShift SDK for React Native.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import {
19
+ * Adshift,
20
+ * AdshiftEventParam,
21
+ * AdshiftEventType,
22
+ * } from '@adshift/react-native-plugin';
23
+ *
24
+ * // 1. Register the deep link listener (safe to do before initialize)
25
+ * const subscription = Adshift.onDeepLink((deepLink) => {
26
+ * // route on deepLink.deepLinkValue / deepLink.params
27
+ * });
28
+ *
29
+ * // 2. Initialize
30
+ * Adshift.initialize({ apiKey: 'your-api-key', isDebug: __DEV__ });
31
+ *
32
+ * // 3. Start
33
+ * const result = await Adshift.start();
34
+ *
35
+ * // 4. Track
36
+ * await Adshift.trackEvent(AdshiftEventType.Purchase, {
37
+ * [AdshiftEventParam.Revenue]: 9.99,
38
+ * [AdshiftEventParam.Currency]: 'USD',
39
+ * });
40
+ *
41
+ * // Later: subscription.remove();
42
+ * ```
43
+ */
44
+
45
+ // ============ Public types ============
46
+
47
+ /**
48
+ * Result of `Adshift.start()`.
49
+ *
50
+ * `success` reports whether the SDK started locally. Backend validation of
51
+ * the API key continues in the background; a rejected key is reported through
52
+ * `config.onError` as `INVALID_API_KEY`.
53
+ */
54
+
55
+ /** How far the API key check had got when `start()` resolved. */
56
+
57
+ /**
58
+ * Parameters for `Adshift.trackPurchase()`.
59
+ */
60
+
61
+ /**
62
+ * Subscription returned by `Adshift.onDeepLink()`.
63
+ */
64
+
65
+ /**
66
+ * Native SDK versions bundled with this plugin release.
67
+ */
68
+
69
+ /**
70
+ * Plugin information returned by `Adshift.getInfo()`.
71
+ */
72
+
73
+ // ============ Constants ============
74
+
75
+ const DEEP_LINK_BUFFER_LIMIT = 20;
76
+ const PENDING_CALL_LIMIT = 100;
77
+ /** Bounds how long `start()` waits for the URL the app was opened with. */
78
+ const INITIAL_URL_WAIT_MS = 3000;
79
+ /** How long one URL counts as the same link, whoever passed it in first. */
80
+ const AUTO_FORWARD_DEDUP_MS = 2000;
81
+ /**
82
+ * Mirrors a limit the SDK applies, so the warning below can name it. Raising it
83
+ * there without raising it here makes the warning wrong, not the behaviour.
84
+ */
85
+ const MAX_AD_REVENUE_PER_IMPRESSION = 10;
86
+ const MEDIATION_NETWORKS = new Set(Object.values(_index.AdshiftMediationNetwork));
87
+ /**
88
+ * Event names the SDK sends on its own. Sending them by hand would mix
89
+ * hand-made records into install and session counts, which cannot be undone
90
+ * once they are reported.
91
+ */
92
+ const RESERVED_EVENT_NAMES = new Set(['app_install', 'app_open']);
93
+
94
+ /**
95
+ * Configuration received before `initialize()`. Each entry holds the latest
96
+ * value for one setter, so the memory is bounded by the number of setters.
97
+ */
98
+
99
+ // ============ Internal state ============
100
+
101
+ let state = 'uninitialized';
102
+ let frozenConfig = null;
103
+ let startInFlight = null;
104
+ /** Incremented per start attempt so a superseded attempt cannot touch the state. */
105
+ let startEpoch = 0;
106
+ let nativeSubscription = null;
107
+ const listeners = new Set();
108
+ const deepLinkBuffer = [];
109
+ let replayScheduled = false;
110
+ const pendingCalls = [];
111
+ let linkingSubscription = null;
112
+ let initialUrlForward = null;
113
+ const autoForwarded = new Map();
114
+ let pendingSettings = {
115
+ pushDeepLinkPaths: []
116
+ };
117
+ let errorHandler = null;
118
+ /** Kept so `start()` can answer with the reason `initialize()` was refused. */
119
+ let configError = null;
120
+
121
+ // ============ Logging ============
122
+
123
+ function devWarn(message) {
124
+ if (typeof __DEV__ !== 'undefined' && __DEV__) {
125
+ console.warn(`[AdShift] ${message}`);
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Reports a call the plugin declined to make.
131
+ *
132
+ * Public methods that return nothing have no channel to answer through, so
133
+ * they never raise: raising would unwind a stack the caller did not choose,
134
+ * and React Native treats an error escaping an event handler or a native
135
+ * callback as fatal. The call is skipped and reported here instead.
136
+ */
137
+ function reportDeclined(error) {
138
+ devWarn(`${error.message} (${error.code})`);
139
+ if (!errorHandler) return;
140
+ try {
141
+ errorHandler(error);
142
+ } catch {
143
+ devWarn('config.onError threw; ignoring it.');
144
+ }
145
+ }
146
+
147
+ // ============ Errors ============
148
+
149
+ function notInitializedError() {
150
+ return (0, _index.createAdshiftError)(_index.AdshiftErrorCode.NotInitialized, 'AdShift SDK is not initialized. Call Adshift.initialize(config) first.');
151
+ }
152
+ function notStartedError() {
153
+ return (0, _index.createAdshiftError)(_index.AdshiftErrorCode.NotStarted, 'AdShift SDK is stopped. Call Adshift.start() first.');
154
+ }
155
+ function invalidArgument(message) {
156
+ return (0, _index.createAdshiftError)(_index.AdshiftErrorCode.InvalidArgument, message);
157
+ }
158
+ function isNonEmptyString(value) {
159
+ return typeof value === 'string' && value.trim().length > 0;
160
+ }
161
+ function isFiniteNumber(value) {
162
+ return typeof value === 'number' && Number.isFinite(value);
163
+ }
164
+ function isPlainObject(value) {
165
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
166
+ }
167
+ function isStringArray(value) {
168
+ return Array.isArray(value) && value.every(isNonEmptyString);
169
+ }
170
+
171
+ /**
172
+ * Plain names a caller is likely to invent, mapped onto the standard constant
173
+ * that carries the same meaning. Built from the constants so there is one list
174
+ * to keep, not two.
175
+ */
176
+ const STANDARD_PARAM_BY_PLAIN_NAME = (() => {
177
+ const index = new Map();
178
+ const standard = new Set((0, _index.getAllEventParams)());
179
+ for (const [key, value] of Object.entries(_index.AdshiftEventParam)) {
180
+ const bare = value.slice('as_'.length);
181
+ const aliases = [bare, bare.replace(/_([a-z0-9])/g, (_match, char) => char.toUpperCase()), key.charAt(0).toLowerCase() + key.slice(1)];
182
+ for (const alias of aliases) {
183
+ if (!standard.has(alias) && !index.has(alias)) {
184
+ index.set(alias, key);
185
+ }
186
+ }
187
+ }
188
+ return index;
189
+ })();
190
+ const reportedPlainParamNames = new Set();
191
+
192
+ /**
193
+ * Warns once per name when a value carries a plain name instead of the
194
+ * standard one. Sending it is allowed — it just stays a custom parameter.
195
+ */
196
+ function warnAboutPlainParamNames(values) {
197
+ if (values === undefined) return;
198
+ for (const key of Object.keys(values)) {
199
+ const standard = STANDARD_PARAM_BY_PLAIN_NAME.get(key);
200
+ if (standard === undefined || reportedPlainParamNames.has(key)) continue;
201
+ reportedPlainParamNames.add(key);
202
+ devWarn(`"${key}" is kept as a custom parameter. Use AdshiftEventParam.${standard} ` + `("${_index.AdshiftEventParam[standard]}") for a value reports should count.`);
203
+ }
204
+ }
205
+ function validateEventValues(values, name) {
206
+ if (values === undefined || values === null) return;
207
+ if (!isPlainObject(values)) {
208
+ throw invalidArgument(`AdShift SDK: ${name} must be an object`);
209
+ }
210
+ for (const [key, value] of Object.entries(values)) {
211
+ const type = typeof value;
212
+ if (type !== 'string' && type !== 'number' && type !== 'boolean') {
213
+ throw invalidArgument(`AdShift SDK: ${name}.${key} must be a string, number or boolean`);
214
+ }
215
+ if (type === 'number' && !Number.isFinite(value)) {
216
+ throw invalidArgument(`AdShift SDK: ${name}.${key} must be finite`);
217
+ }
218
+ }
219
+ }
220
+
221
+ // ============ Configuration received before initialize() ============
222
+
223
+ /**
224
+ * Folds settings received before `initialize()` into the config.
225
+ *
226
+ * The config wins for anything it states, because it is the later and more
227
+ * explicit declaration. Push key paths are additive, so they are merged.
228
+ * Settings that reach the SDK through a setter only are applied by
229
+ * `applyPendingSettings()` right after the native module is initialized.
230
+ */
231
+ function withPendingSettings(config) {
232
+ const merged = {
233
+ ...config
234
+ };
235
+ const pending = pendingSettings;
236
+ if (merged.isDebug === undefined && pending.debugEnabled !== undefined) {
237
+ merged.isDebug = pending.debugEnabled;
238
+ }
239
+ if (merged.appOpenDebounceMs === undefined && pending.appOpenDebounceMs !== undefined) {
240
+ merged.appOpenDebounceMs = pending.appOpenDebounceMs;
241
+ }
242
+ if (merged.brandedDomains === undefined && pending.brandedDomains) {
243
+ merged.brandedDomains = pending.brandedDomains;
244
+ }
245
+ if (merged.metaAppId === undefined && pending.metaAppId !== undefined) {
246
+ merged.metaAppId = pending.metaAppId;
247
+ }
248
+ if (pending.pushDeepLinkPaths.length > 0) {
249
+ merged.pushDeepLinkPaths = [...(merged.pushDeepLinkPaths ?? []), ...pending.pushDeepLinkPaths];
250
+ }
251
+ return merged;
252
+ }
253
+ function applyPendingSettings() {
254
+ const pending = pendingSettings;
255
+ pendingSettings = {
256
+ pushDeepLinkPaths: []
257
+ };
258
+ if (pending.customerUserId !== undefined) {
259
+ _NativeAdShiftReactNativePlugin.default.setCustomerUserId(pending.customerUserId);
260
+ }
261
+ if (pending.oaid !== undefined) {
262
+ _NativeAdShiftReactNativePlugin.default.setOaidData(pending.oaid);
263
+ }
264
+ if (pending.consent !== undefined) {
265
+ _NativeAdShiftReactNativePlugin.default.setConsentData((0, _index.consentToMap)(pending.consent));
266
+ }
267
+ if (pending.tcfEnabled !== undefined) {
268
+ _NativeAdShiftReactNativePlugin.default.enableTCFDataCollection(pending.tcfEnabled);
269
+ }
270
+ if (pending.gppEnabled !== undefined) {
271
+ _NativeAdShiftReactNativePlugin.default.enableGPPDataCollection(pending.gppEnabled);
272
+ }
273
+ if (pending.thirdPartySharing !== undefined) {
274
+ if (pending.thirdPartySharing === null) {
275
+ _NativeAdShiftReactNativePlugin.default.clearThirdPartySharing();
276
+ } else {
277
+ _NativeAdShiftReactNativePlugin.default.setThirdPartySharing((0, _index.thirdPartySharingToMap)(pending.thirdPartySharing));
278
+ }
279
+ }
280
+ }
281
+
282
+ // ============ Deep link delivery ============
283
+
284
+ function ensureNativeSubscription() {
285
+ if (nativeSubscription) return;
286
+ nativeSubscription = _NativeAdShiftReactNativePlugin.default.onDeepLink(payload => {
287
+ dispatchDeepLink(_index.AdshiftDeepLink.fromMap(payload));
288
+ });
289
+ }
290
+ function dispatchDeepLink(deepLink) {
291
+ // A result must never overtake one already waiting in the buffer: a deferred
292
+ // link delivered after a link tapped later would attribute the install to
293
+ // the wrong click.
294
+ if (listeners.size === 0 || deepLinkBuffer.length > 0) {
295
+ bufferDeepLink(deepLink);
296
+ scheduleReplay();
297
+ return;
298
+ }
299
+ deliver(deepLink);
300
+ }
301
+ function deliver(deepLink) {
302
+ for (const entry of Array.from(listeners)) {
303
+ if (!listeners.has(entry)) continue;
304
+ try {
305
+ entry.callback(deepLink);
306
+ } catch (error) {
307
+ devWarn(`onDeepLink listener threw: ${error instanceof Error ? error.message : String(error)}`);
308
+ }
309
+ }
310
+ }
311
+ function bufferDeepLink(deepLink) {
312
+ if (deepLinkBuffer.length >= DEEP_LINK_BUFFER_LIMIT) {
313
+ const evictable = deepLinkBuffer.findIndex(item => !item.isDeferred);
314
+ if (evictable >= 0) {
315
+ deepLinkBuffer.splice(evictable, 1);
316
+ } else if (deepLink.isDeferred) {
317
+ deepLinkBuffer.shift();
318
+ } else {
319
+ devWarn('Deep link buffer is full; dropping a direct deep link.');
320
+ return;
321
+ }
322
+ }
323
+ deepLinkBuffer.push(deepLink);
324
+ }
325
+ function scheduleReplay() {
326
+ if (replayScheduled) return;
327
+ replayScheduled = true;
328
+ Promise.resolve().then(() => {
329
+ replayScheduled = false;
330
+ if (listeners.size === 0 || deepLinkBuffer.length === 0) return;
331
+ const items = deepLinkBuffer.splice(0, deepLinkBuffer.length);
332
+ for (const item of items) {
333
+ deliver(item);
334
+ }
335
+ });
336
+ }
337
+
338
+ // ============ Automatic URL forwarding (iOS) ============
339
+
340
+ function autoForwardEnabled() {
341
+ return _reactNative.Platform.OS === 'ios' && frozenConfig !== null && frozenConfig.autoHandleDeepLinks !== false;
342
+ }
343
+ function startLinkingAutoForward() {
344
+ if (linkingSubscription) return;
345
+ linkingSubscription = _reactNative.Linking.addEventListener('url', ({
346
+ url
347
+ }) => {
348
+ if (state === 'uninitialized' || !autoForwardEnabled()) return;
349
+ // An app that handles `url` itself and calls handleDeepLink() sees the same
350
+ // event here, and the two are indistinguishable from a second tap. The
351
+ // short window treats them as one link; a tap that comes later is a
352
+ // separate click and is forwarded.
353
+ if (wasAutoForwardedRecently(url)) return;
354
+ forwardUrl(url, false).catch(() => undefined);
355
+ });
356
+ // The launch URL is read on every initialize(), so it comes back after a
357
+ // JavaScript reload as well. It is marked as such, and the native side keeps
358
+ // it for the lifetime of the process, so the link is booked once.
359
+ initialUrlForward = _reactNative.Linking.getInitialURL().then(url => url ? forwardUrl(url, true) : undefined).catch(() => undefined).finally(() => {
360
+ initialUrlForward = null;
361
+ });
362
+ }
363
+ async function forwardUrl(url, fromLaunch) {
364
+ if (!isNonEmptyString(url)) return;
365
+ pruneAutoForwarded();
366
+ autoForwarded.set(url, Date.now());
367
+ try {
368
+ await _NativeAdShiftReactNativePlugin.default.handleDeepLink(url, fromLaunch);
369
+ } catch (error) {
370
+ const mapped = (0, _index.toAdshiftError)(error);
371
+ if (mapped.code !== _index.AdshiftErrorCode.OptedOut) {
372
+ devWarn(`Automatic deep link forwarding failed: ${mapped.code}`);
373
+ }
374
+ }
375
+ }
376
+ function pruneAutoForwarded() {
377
+ const cutoff = Date.now() - AUTO_FORWARD_DEDUP_MS;
378
+ for (const [url, timestamp] of autoForwarded) {
379
+ if (timestamp < cutoff) {
380
+ autoForwarded.delete(url);
381
+ }
382
+ }
383
+ }
384
+ function wasAutoForwardedRecently(url) {
385
+ pruneAutoForwarded();
386
+ return autoForwarded.has(url);
387
+ }
388
+ async function waitForInitialUrlForward() {
389
+ const pending = initialUrlForward;
390
+ if (!pending) return;
391
+ let timer;
392
+ const timeout = new Promise(resolve => {
393
+ timer = setTimeout(resolve, INITIAL_URL_WAIT_MS);
394
+ });
395
+ try {
396
+ await Promise.race([pending, timeout]);
397
+ } finally {
398
+ if (timer !== undefined) clearTimeout(timer);
399
+ }
400
+ }
401
+
402
+ // ============ Start gating ============
403
+
404
+ function runWhenStarted(run) {
405
+ switch (state) {
406
+ case 'uninitialized':
407
+ return Promise.reject(notInitializedError());
408
+ case 'stopped':
409
+ return Promise.reject(notStartedError());
410
+ case 'started':
411
+ return run().catch(error => {
412
+ throw (0, _index.toAdshiftError)(error);
413
+ });
414
+ case 'initialized':
415
+ case 'starting':
416
+ if (pendingCalls.length >= PENDING_CALL_LIMIT) {
417
+ return Promise.reject((0, _index.createAdshiftError)(_index.AdshiftErrorCode.QueueFull, 'AdShift SDK: too many calls are waiting for start().'));
418
+ }
419
+ if (startEpoch === 0 && pendingCalls.length === 0) {
420
+ devWarn('Call queued until start() runs; it settles when the first start attempt finishes.');
421
+ }
422
+ return new Promise((resolve, reject) => {
423
+ pendingCalls.push({
424
+ run,
425
+ resolve: resolve,
426
+ reject
427
+ });
428
+ });
429
+ }
430
+ }
431
+ function flushPendingCalls() {
432
+ const calls = pendingCalls.splice(0, pendingCalls.length);
433
+ for (const call of calls) {
434
+ call.run().then(call.resolve).catch(error => call.reject((0, _index.toAdshiftError)(error)));
435
+ }
436
+ }
437
+ function rejectPendingCalls(error) {
438
+ const calls = pendingCalls.splice(0, pendingCalls.length);
439
+ for (const call of calls) {
440
+ call.reject(error);
441
+ }
442
+ }
443
+
444
+ /**
445
+ * Warns when the native SDK on the device is not the one this release was built
446
+ * against. Only iOS reports its version, so on Android the pin is guarded by a
447
+ * build-time test instead.
448
+ */
449
+ function checkNativeSdkVersion(reported) {
450
+ if (typeof reported !== 'string' || reported.length === 0) return;
451
+ const expected = _reactNative.Platform.OS === 'ios' ? _nativeSdkVersions.NATIVE_SDK_VERSIONS.ios : _reactNative.Platform.OS === 'android' ? _nativeSdkVersions.NATIVE_SDK_VERSIONS.android : null;
452
+ if (expected !== null && reported !== expected) {
453
+ devWarn(`Native SDK ${reported} differs from the version this plugin was built for (${expected}).`);
454
+ }
455
+ }
456
+ function readStartResult(raw) {
457
+ const map = isPlainObject(raw) ? raw : {};
458
+ checkNativeSdkVersion(map.sdkVersion);
459
+ const result = {
460
+ success: map.success === true
461
+ };
462
+ const validation = map.apiKeyValidationStatus;
463
+ if (validation === 'pending' || validation === 'valid' || validation === 'invalid') {
464
+ result.apiKeyValidationStatus = validation;
465
+ }
466
+ if (!result.success) {
467
+ const code = map.errorCode;
468
+ result.errorCode = typeof code === 'string' && Object.values(_index.AdshiftErrorCode).includes(code) ? code : _index.AdshiftErrorCode.Unknown;
469
+ result.errorMessage = typeof map.errorMessage === 'string' ? map.errorMessage : 'AdShift SDK failed to start.';
470
+ if (typeof map.nativeCode === 'number' || typeof map.nativeCode === 'string') {
471
+ result.nativeCode = map.nativeCode;
472
+ }
473
+ if (typeof map.nativeDomain === 'string') {
474
+ result.nativeDomain = map.nativeDomain;
475
+ }
476
+ }
477
+ return result;
478
+ }
479
+ async function performStart() {
480
+ const previous = state;
481
+ const epoch = ++startEpoch;
482
+ state = 'starting';
483
+ try {
484
+ await waitForInitialUrlForward();
485
+ const result = readStartResult(await _NativeAdShiftReactNativePlugin.default.start());
486
+ if (epoch !== startEpoch) {
487
+ // A newer start() owns the lifecycle now; report what native said and
488
+ // leave the state to the newer attempt.
489
+ return result;
490
+ }
491
+ if (state !== 'starting') {
492
+ // stop() was called while start() was in flight; honour the last call.
493
+ if (result.success) {
494
+ _NativeAdShiftReactNativePlugin.default.stop();
495
+ }
496
+ const error = notStartedError();
497
+ return {
498
+ success: false,
499
+ errorCode: error.code,
500
+ errorMessage: error.message
501
+ };
502
+ }
503
+ if (result.success) {
504
+ state = 'started';
505
+ flushPendingCalls();
506
+ if (result.apiKeyValidationStatus === 'invalid') {
507
+ // The SDK started locally, but nothing it sends will be accepted.
508
+ reportDeclined((0, _index.createAdshiftError)(_index.AdshiftErrorCode.InvalidApiKey, 'AdShift SDK: the backend rejected this API key; no data will be reported.'));
509
+ }
510
+ return result;
511
+ }
512
+ state = previous;
513
+ const error = (0, _index.createAdshiftError)(result.errorCode ?? _index.AdshiftErrorCode.Unknown, result.errorMessage ?? 'AdShift SDK failed to start.');
514
+ reportDeclined(error);
515
+ if (isTerminalStartFailure(error.code)) {
516
+ rejectPendingCalls(error);
517
+ }
518
+ return result;
519
+ } catch (error) {
520
+ const mapped = (0, _index.toAdshiftError)(error);
521
+ if (epoch === startEpoch && state === 'starting') {
522
+ state = previous;
523
+ }
524
+ const result = {
525
+ success: false,
526
+ errorCode: mapped.code,
527
+ errorMessage: mapped.message
528
+ };
529
+ // What the platform said travels with the result, the same way it does
530
+ // when the native side answers with a failure instead of rejecting.
531
+ if (mapped.userInfo.nativeCode !== undefined) {
532
+ result.nativeCode = mapped.userInfo.nativeCode;
533
+ }
534
+ if (mapped.userInfo.nativeDomain !== undefined) {
535
+ result.nativeDomain = mapped.userInfo.nativeDomain;
536
+ }
537
+ return result;
538
+ }
539
+ }
540
+
541
+ /**
542
+ * Whether a failed start rules out the calls waiting for it.
543
+ *
544
+ * A rejected key, an excluded device and a missing configuration cannot be
545
+ * fixed by trying again, so the waiting calls are answered. Anything else can
546
+ * be, and holding the calls is worth more than answering them quickly: the
547
+ * data survives until the app starts the SDK again.
548
+ */
549
+ function isTerminalStartFailure(code) {
550
+ return code === _index.AdshiftErrorCode.InvalidApiKey || code === _index.AdshiftErrorCode.OptedOut || code === _index.AdshiftErrorCode.NotInitialized;
551
+ }
552
+
553
+ // ============ Main SDK API ============
554
+
555
+ const Adshift = exports.Adshift = {
556
+ // ============ Lifecycle ============
557
+
558
+ /**
559
+ * Initializes the SDK.
560
+ *
561
+ * Call once, as early as possible (e.g. at module scope of `App.tsx`).
562
+ * The configuration is fixed on the first call; later calls are ignored.
563
+ *
564
+ * Never raises, because it is meant to run at module scope, where an error
565
+ * would stop the bundle from evaluating. An unusable config is reported
566
+ * through `config.onError` and answered by `start()`.
567
+ */
568
+ initialize(config) {
569
+ if (state !== 'uninitialized') {
570
+ devWarn('initialize() called more than once; the first config is kept.');
571
+ return;
572
+ }
573
+ errorHandler = isPlainObject(config) && typeof config.onError === 'function' ? config.onError : null;
574
+ const refuse = message => {
575
+ configError = invalidArgument(message);
576
+ reportDeclined(configError);
577
+ };
578
+ if (!isPlainObject(config) || !isNonEmptyString(config.apiKey)) {
579
+ refuse('AdShift SDK: apiKey is required in config');
580
+ return;
581
+ }
582
+ if (config.brandedDomains !== undefined && !isStringArray(config.brandedDomains)) {
583
+ refuse('AdShift SDK: brandedDomains must be an array of non-empty strings');
584
+ return;
585
+ }
586
+ if (config.pushDeepLinkPaths !== undefined && !(Array.isArray(config.pushDeepLinkPaths) && config.pushDeepLinkPaths.every(isStringArray))) {
587
+ refuse('AdShift SDK: pushDeepLinkPaths must be an array of string arrays');
588
+ return;
589
+ }
590
+ configError = null;
591
+ frozenConfig = Object.freeze(withPendingSettings(config));
592
+ try {
593
+ ensureNativeSubscription();
594
+ _NativeAdShiftReactNativePlugin.default.initialize((0, _index.configToMap)(frozenConfig));
595
+ state = 'initialized';
596
+ applyPendingSettings();
597
+ } catch (error) {
598
+ configError = (0, _index.toAdshiftError)(error);
599
+ state = 'uninitialized';
600
+ frozenConfig = null;
601
+ reportDeclined(configError);
602
+ return;
603
+ }
604
+ if (autoForwardEnabled()) {
605
+ startLinkingAutoForward();
606
+ }
607
+ },
608
+ /**
609
+ * Starts the SDK.
610
+ *
611
+ * Resolves once the SDK has started locally. Never rejects; inspect
612
+ * `result.success` and `result.errorCode`. Calls to `trackEvent`,
613
+ * `trackPurchase` and `logAdRevenue` made before this resolves are queued
614
+ * and dispatched afterwards. A start that fails with a reason retrying
615
+ * cannot fix rejects them instead; any other failure keeps them waiting for
616
+ * the next attempt.
617
+ */
618
+ start() {
619
+ if (state === 'uninitialized') {
620
+ const error = configError ?? notInitializedError();
621
+ return Promise.resolve({
622
+ success: false,
623
+ errorCode: error.code,
624
+ errorMessage: error.message
625
+ });
626
+ }
627
+ if (state === 'started') {
628
+ return Promise.resolve({
629
+ success: true
630
+ });
631
+ }
632
+ if (startInFlight) {
633
+ return startInFlight;
634
+ }
635
+ const attempt = performStart().finally(() => {
636
+ if (startInFlight === attempt) {
637
+ startInFlight = null;
638
+ }
639
+ });
640
+ startInFlight = attempt;
641
+ return attempt;
642
+ },
643
+ /**
644
+ * Stops the SDK. Tracking calls reject with `NOT_STARTED` until the next
645
+ * successful `start()`.
646
+ *
647
+ * Before `initialize()` there is nothing to stop: the call is reported and
648
+ * skipped.
649
+ */
650
+ stop() {
651
+ if (state === 'uninitialized') {
652
+ reportDeclined(notInitializedError());
653
+ return;
654
+ }
655
+ state = 'stopped';
656
+ // A later start() must not receive the promise of the attempt this stop cancels.
657
+ startInFlight = null;
658
+ rejectPendingCalls(notStartedError());
659
+ _NativeAdShiftReactNativePlugin.default.stop();
660
+ },
661
+ /**
662
+ * Whether `start()` has completed successfully and `stop()` has not been
663
+ * called since. Safe to call before `initialize()`.
664
+ */
665
+ isStarted() {
666
+ return state === 'started';
667
+ },
668
+ // ============ Configuration ============
669
+
670
+ /**
671
+ * Sets your own user identifier. Can be called before or after `start()`.
672
+ *
673
+ * Called before `initialize()`, the value is kept and applied afterwards.
674
+ * An empty identifier is reported and skipped; nothing is raised.
675
+ */
676
+ setCustomerUserId(userId) {
677
+ if (!isNonEmptyString(userId)) {
678
+ reportDeclined(invalidArgument('AdShift SDK: userId must be a non-empty string'));
679
+ return;
680
+ }
681
+ if (state === 'uninitialized') {
682
+ pendingSettings.customerUserId = userId;
683
+ return;
684
+ }
685
+ _NativeAdShiftReactNativePlugin.default.setCustomerUserId(userId);
686
+ },
687
+ /**
688
+ * Enables or disables verbose SDK logging at runtime.
689
+ *
690
+ * Called before `initialize()`, the value is kept and applied afterwards.
691
+ */
692
+ setDebugEnabled(enabled) {
693
+ if (state === 'uninitialized') {
694
+ pendingSettings.debugEnabled = enabled === true;
695
+ return;
696
+ }
697
+ _NativeAdShiftReactNativePlugin.default.setDebugEnabled(enabled === true);
698
+ },
699
+ /**
700
+ * Sets the debounce interval for automatic `app_open` events.
701
+ *
702
+ * Called before `initialize()`, the value is kept and applied afterwards.
703
+ * A negative interval is reported and skipped; nothing is raised.
704
+ */
705
+ setAppOpenDebounceMs(ms) {
706
+ if (!isFiniteNumber(ms) || ms < 0) {
707
+ reportDeclined(invalidArgument('AdShift SDK: ms must be a non-negative number'));
708
+ return;
709
+ }
710
+ if (state === 'uninitialized') {
711
+ pendingSettings.appOpenDebounceMs = ms;
712
+ return;
713
+ }
714
+ _NativeAdShiftReactNativePlugin.default.setAppOpenDebounceMs(ms);
715
+ },
716
+ /**
717
+ * Sets branded attribution domains. Must be called before `start()`.
718
+ *
719
+ * Called before `initialize()`, the domains are kept and applied with the
720
+ * config, so they are in place before the first link is processed.
721
+ */
722
+ setBrandedDomains(domains) {
723
+ if (!isStringArray(domains)) {
724
+ reportDeclined(invalidArgument('AdShift SDK: domains must be an array of non-empty strings'));
725
+ return;
726
+ }
727
+ if (state === 'uninitialized') {
728
+ pendingSettings.brandedDomains = [...domains];
729
+ return;
730
+ }
731
+ _NativeAdShiftReactNativePlugin.default.setBrandedDomains(domains);
732
+ },
733
+ /**
734
+ * Sets the Meta app id used to parse Meta App Links. No-op on iOS.
735
+ *
736
+ * Called before `initialize()`, the value is kept and applied afterwards.
737
+ */
738
+ setMetaAppId(appId) {
739
+ if (!isNonEmptyString(appId)) {
740
+ reportDeclined(invalidArgument('AdShift SDK: appId must be a non-empty string'));
741
+ return;
742
+ }
743
+ if (state === 'uninitialized') {
744
+ pendingSettings.metaAppId = appId;
745
+ return;
746
+ }
747
+ _NativeAdShiftReactNativePlugin.default.setMetaAppId(appId);
748
+ },
749
+ /**
750
+ * Hands over an OAID the app obtained itself, for Android devices without
751
+ * Google Play services. Set `collectOaid: false` when you supply it this
752
+ * way. No-op on iOS.
753
+ *
754
+ * Called before `initialize()`, the value is kept and applied afterwards.
755
+ */
756
+ setOaidData(oaid) {
757
+ if (!isNonEmptyString(oaid)) {
758
+ reportDeclined(invalidArgument('AdShift SDK: oaid must be a non-empty string'));
759
+ return;
760
+ }
761
+ if (state === 'uninitialized') {
762
+ pendingSettings.oaid = oaid;
763
+ return;
764
+ }
765
+ _NativeAdShiftReactNativePlugin.default.setOaidData(oaid);
766
+ },
767
+ // ============ Consent (GDPR/DMA) ============
768
+
769
+ /**
770
+ * Sets consent collected by your own UI. Use `AdshiftConsent.forGDPRUser()`
771
+ * or `AdshiftConsent.forNonGDPRUser()`.
772
+ *
773
+ * Called before `initialize()`, the consent is kept and applied afterwards.
774
+ */
775
+ setConsentData(consent) {
776
+ if (!isPlainObject(consent) || typeof consent.isUserSubjectToGDPR !== 'boolean') {
777
+ reportDeclined(invalidArgument('AdShift SDK: consent.isUserSubjectToGDPR must be a boolean'));
778
+ return;
779
+ }
780
+ if (state === 'uninitialized') {
781
+ pendingSettings.consent = consent;
782
+ return;
783
+ }
784
+ _NativeAdShiftReactNativePlugin.default.setConsentData((0, _index.consentToMap)(consent));
785
+ },
786
+ /**
787
+ * Enables or disables reading IAB TCF v2.2 consent from the CMP on device.
788
+ * Call before `start()`.
789
+ *
790
+ * Called before `initialize()`, the value is kept and applied afterwards.
791
+ */
792
+ enableTCFDataCollection(enabled) {
793
+ if (state === 'uninitialized') {
794
+ pendingSettings.tcfEnabled = enabled === true;
795
+ return;
796
+ }
797
+ _NativeAdShiftReactNativePlugin.default.enableTCFDataCollection(enabled === true);
798
+ },
799
+ /**
800
+ * Enables reading an IAB GPP string written by the CMP on device, used for US
801
+ * state privacy signals. Off until called with `true`.
802
+ *
803
+ * The GPP string rides on its own axis: it is forwarded alongside whatever
804
+ * decides the GDPR axis, including a consent set through `setConsentData()`,
805
+ * and it does not gate the advertising identifier on the device.
806
+ *
807
+ * Call before `start()`. Called before `initialize()`, the value is kept and
808
+ * applied afterwards.
809
+ */
810
+ enableGPPDataCollection(enabled) {
811
+ if (state === 'uninitialized') {
812
+ pendingSettings.gppEnabled = enabled === true;
813
+ return;
814
+ }
815
+ _NativeAdShiftReactNativePlugin.default.enableGPPDataCollection(enabled === true);
816
+ },
817
+ /**
818
+ * States what the app collected about passing this user's data on to
819
+ * advertising partners. Use `AdshiftThirdPartySharing.optedOut()` or
820
+ * `AdshiftThirdPartySharing.allowed()`.
821
+ *
822
+ * This is the answer to a different question than `setConsentData()`, and it
823
+ * has the opposite default: nothing said here means sharing is allowed, so
824
+ * only call it once the user has actually been asked. Setting `allowed()` at
825
+ * startup as a default records a declaration the user never made, and events
826
+ * already sent cannot be recalled when a real answer arrives.
827
+ *
828
+ * Nothing is gated on the device either way — this travels with the events for
829
+ * the backend to act on.
830
+ *
831
+ * Called before `initialize()`, the answer is kept and applied afterwards.
832
+ */
833
+ setThirdPartySharing(sharing) {
834
+ if (!isPlainObject(sharing) || typeof sharing.optOut !== 'boolean') {
835
+ reportDeclined(invalidArgument('AdShift SDK: sharing.optOut must be a boolean'));
836
+ return;
837
+ }
838
+ if (state === 'uninitialized') {
839
+ pendingSettings.thirdPartySharing = sharing;
840
+ return;
841
+ }
842
+ _NativeAdShiftReactNativePlugin.default.setThirdPartySharing((0, _index.thirdPartySharingToMap)(sharing));
843
+ },
844
+ /**
845
+ * Withdraws the answer set by `setThirdPartySharing()`.
846
+ *
847
+ * Subsequent events state nothing on this axis, which is not the same as
848
+ * stating that sharing is allowed: the first leaves the decision to your
849
+ * dashboard configuration, the second is the app's own declaration and is
850
+ * recorded as such.
851
+ *
852
+ * Called before `initialize()`, this cancels a `setThirdPartySharing()` that
853
+ * was also queued.
854
+ */
855
+ clearThirdPartySharing() {
856
+ if (state === 'uninitialized') {
857
+ pendingSettings.thirdPartySharing = null;
858
+ return;
859
+ }
860
+ _NativeAdShiftReactNativePlugin.default.clearThirdPartySharing();
861
+ },
862
+ /**
863
+ * Re-reads consent from the CMP or manual source and returns the snapshot.
864
+ * Call after the CMP dialog closes.
865
+ *
866
+ * @returns Rejects with `AdshiftError` (`NOT_INITIALIZED`).
867
+ */
868
+ async refreshConsent() {
869
+ if (state === 'uninitialized') {
870
+ throw notInitializedError();
871
+ }
872
+ try {
873
+ const raw = await _NativeAdShiftReactNativePlugin.default.refreshConsent();
874
+ return (0, _index.consentSnapshotFromMap)(isPlainObject(raw) ? raw : {});
875
+ } catch (error) {
876
+ throw (0, _index.toAdshiftError)(error);
877
+ }
878
+ },
879
+ // ============ Event Tracking ============
880
+
881
+ /**
882
+ * Tracks an in-app event.
883
+ *
884
+ * `app_install` and `app_open` are reserved: the SDK sends them itself and
885
+ * passing them here rejects with `INVALID_ARGUMENT`.
886
+ *
887
+ * Resolves once the SDK has accepted the event. A call made between
888
+ * `initialize()` and a successful `start()` waits for the start: it is sent
889
+ * when the SDK starts, and rejects when the start fails for a reason
890
+ * retrying cannot fix (rejected key, excluded device) or after `stop()`.
891
+ * A start that failed for any other reason keeps the call waiting for the
892
+ * next attempt, so `start()` belongs on every launch path.
893
+ *
894
+ * @returns Rejects with `AdshiftError` (`NOT_INITIALIZED`, `NOT_STARTED`,
895
+ * `INVALID_API_KEY`, `OPTED_OUT`, `QUEUE_FULL`, `INVALID_ARGUMENT`).
896
+ */
897
+ trackEvent(eventName, values) {
898
+ if (!isNonEmptyString(eventName)) {
899
+ return Promise.reject(invalidArgument('AdShift SDK: eventName must be a non-empty string'));
900
+ }
901
+ if (RESERVED_EVENT_NAMES.has(eventName.trim().toLowerCase())) {
902
+ return Promise.reject(invalidArgument(`AdShift SDK: "${eventName}" is reserved and sent by the SDK; use your own event name`));
903
+ }
904
+ try {
905
+ validateEventValues(values, 'values');
906
+ } catch (error) {
907
+ return Promise.reject(error);
908
+ }
909
+ warnAboutPlainParamNames(values);
910
+ return runWhenStarted(() => _NativeAdShiftReactNativePlugin.default.trackEvent(eventName, values ?? null));
911
+ },
912
+ /**
913
+ * Tracks a purchase.
914
+ *
915
+ * @returns Rejects with `AdshiftError` (see `trackEvent`).
916
+ */
917
+ trackPurchase(params) {
918
+ if (!isPlainObject(params)) {
919
+ return Promise.reject(invalidArgument('AdShift SDK: params must be an object'));
920
+ }
921
+ const {
922
+ productId,
923
+ revenue,
924
+ currency,
925
+ transactionId
926
+ } = params;
927
+ if (!isNonEmptyString(productId)) {
928
+ return Promise.reject(invalidArgument('AdShift SDK: productId is required'));
929
+ }
930
+ if (!isFiniteNumber(revenue) || revenue < 0) {
931
+ return Promise.reject(invalidArgument('AdShift SDK: revenue must be a non-negative number'));
932
+ }
933
+ if (!isNonEmptyString(currency)) {
934
+ return Promise.reject(invalidArgument('AdShift SDK: currency is required'));
935
+ }
936
+ if (!isNonEmptyString(transactionId)) {
937
+ return Promise.reject(invalidArgument('AdShift SDK: transactionId is required'));
938
+ }
939
+ return runWhenStarted(() => _NativeAdShiftReactNativePlugin.default.trackPurchase(productId, revenue, currency, transactionId));
940
+ },
941
+ /**
942
+ * Logs ad revenue for a single impression.
943
+ *
944
+ * @returns Rejects with `AdshiftError` (see `trackEvent`).
945
+ */
946
+ logAdRevenue(params) {
947
+ if (!isPlainObject(params)) {
948
+ return Promise.reject(invalidArgument('AdShift SDK: params must be an object'));
949
+ }
950
+ const {
951
+ monetizationNetwork,
952
+ mediationNetwork,
953
+ currency,
954
+ revenue,
955
+ adUnitId,
956
+ precision,
957
+ additionalParameters
958
+ } = params;
959
+ if (!isNonEmptyString(monetizationNetwork)) {
960
+ return Promise.reject(invalidArgument('AdShift SDK: monetizationNetwork is required'));
961
+ }
962
+ if (!isNonEmptyString(mediationNetwork) || !MEDIATION_NETWORKS.has(mediationNetwork)) {
963
+ return Promise.reject(invalidArgument('AdShift SDK: mediationNetwork must be an AdshiftMediationNetwork value'));
964
+ }
965
+ if (!isNonEmptyString(currency)) {
966
+ return Promise.reject(invalidArgument('AdShift SDK: currency is required'));
967
+ }
968
+ if (currency.length !== 3) {
969
+ return Promise.reject(invalidArgument('AdShift SDK: currency must be a 3-letter ISO 4217 code'));
970
+ }
971
+ if (!isFiniteNumber(revenue) || revenue <= 0) {
972
+ return Promise.reject(invalidArgument('AdShift SDK: revenue must be a positive number'));
973
+ }
974
+ if (revenue > MAX_AD_REVENUE_PER_IMPRESSION) {
975
+ devWarn(`logAdRevenue: revenue above ${MAX_AD_REVENUE_PER_IMPRESSION} is not recorded. ` + 'Pass the revenue of a single impression, not an aggregate.');
976
+ }
977
+ if (adUnitId !== undefined && typeof adUnitId !== 'string') {
978
+ return Promise.reject(invalidArgument('AdShift SDK: adUnitId must be a string'));
979
+ }
980
+ if (precision !== undefined && typeof precision !== 'string') {
981
+ return Promise.reject(invalidArgument('AdShift SDK: precision must be a string'));
982
+ }
983
+ try {
984
+ validateEventValues(additionalParameters, 'additionalParameters');
985
+ } catch (error) {
986
+ return Promise.reject(error);
987
+ }
988
+ warnAboutPlainParamNames(additionalParameters);
989
+ const data = {
990
+ monetizationNetwork,
991
+ mediationNetwork,
992
+ currency,
993
+ revenue
994
+ };
995
+ if (adUnitId !== undefined) data.adUnitId = adUnitId;
996
+ if (precision !== undefined) data.precision = precision;
997
+ if (additionalParameters !== undefined) {
998
+ data.additionalParameters = additionalParameters;
999
+ }
1000
+ return runWhenStarted(() => _NativeAdShiftReactNativePlugin.default.logAdRevenue(data));
1001
+ },
1002
+ // ============ Identity ============
1003
+
1004
+ /**
1005
+ * Returns the AdShift device id, or `null` before `initialize()`.
1006
+ */
1007
+ async getAdShiftDeviceId() {
1008
+ if (state === 'uninitialized') {
1009
+ return null;
1010
+ }
1011
+ try {
1012
+ const value = await _NativeAdShiftReactNativePlugin.default.getAdShiftDeviceId();
1013
+ return typeof value === 'string' && value.length > 0 ? value : null;
1014
+ } catch (error) {
1015
+ throw (0, _index.toAdshiftError)(error);
1016
+ }
1017
+ },
1018
+ // ============ Deep Links ============
1019
+
1020
+ /**
1021
+ * Passes a URL to the SDK.
1022
+ *
1023
+ * Not needed when `autoHandleDeepLinks` is on (the default). The result is
1024
+ * delivered through `onDeepLink()`; the promise resolves once the SDK has
1025
+ * finished processing the URL.
1026
+ *
1027
+ * @returns Rejects with `AdshiftError` (`NOT_INITIALIZED`,
1028
+ * `INVALID_ARGUMENT`).
1029
+ */
1030
+ async handleDeepLink(url) {
1031
+ if (state === 'uninitialized') {
1032
+ throw notInitializedError();
1033
+ }
1034
+ if (!isNonEmptyString(url)) {
1035
+ throw invalidArgument('AdShift SDK: url must be a non-empty string');
1036
+ }
1037
+ if (wasAutoForwardedRecently(url)) {
1038
+ return;
1039
+ }
1040
+ // Recorded here as well, so automatic forwarding does not repeat a URL the
1041
+ // app passed in first.
1042
+ pruneAutoForwarded();
1043
+ autoForwarded.set(url, Date.now());
1044
+ try {
1045
+ await _NativeAdShiftReactNativePlugin.default.handleDeepLink(url, false);
1046
+ } catch (error) {
1047
+ const mapped = (0, _index.toAdshiftError)(error);
1048
+ if (mapped.code === _index.AdshiftErrorCode.OptedOut) {
1049
+ return;
1050
+ }
1051
+ throw mapped;
1052
+ }
1053
+ },
1054
+ /**
1055
+ * Adds a key path inside push payloads that carries an AdShift deep link.
1056
+ *
1057
+ * Called before `initialize()`, the path is kept and registered afterwards.
1058
+ * The first path you register takes over from the top-level `as_push_link`
1059
+ * the SDK reads on its own, so register that key too if you still need it.
1060
+ */
1061
+ addPushNotificationDeepLinkPath(path) {
1062
+ if (!isStringArray(path) || path.length === 0) {
1063
+ reportDeclined(invalidArgument('AdShift SDK: path must be a non-empty array of strings'));
1064
+ return;
1065
+ }
1066
+ if (state === 'uninitialized') {
1067
+ pendingSettings.pushDeepLinkPaths.push([...path]);
1068
+ return;
1069
+ }
1070
+ _NativeAdShiftReactNativePlugin.default.addPushNotificationDeepLinkPath(path);
1071
+ },
1072
+ /**
1073
+ * Passes a push notification payload to the SDK. Resolves to `true` when
1074
+ * the payload carried an AdShift deep link; the result then arrives
1075
+ * through `onDeepLink()`.
1076
+ *
1077
+ * @returns Rejects with `AdshiftError` (`NOT_INITIALIZED`,
1078
+ * `INVALID_ARGUMENT`).
1079
+ */
1080
+ async handlePushNotification(payload) {
1081
+ if (state === 'uninitialized') {
1082
+ throw notInitializedError();
1083
+ }
1084
+ if (!isPlainObject(payload)) {
1085
+ throw invalidArgument('AdShift SDK: payload must be an object');
1086
+ }
1087
+ try {
1088
+ return (await _NativeAdShiftReactNativePlugin.default.handlePushNotification(payload)) === true;
1089
+ } catch (error) {
1090
+ throw (0, _index.toAdshiftError)(error);
1091
+ }
1092
+ },
1093
+ /**
1094
+ * Registers a deep link listener.
1095
+ *
1096
+ * Safe to call before `initialize()`. Results that arrive while no
1097
+ * listener is registered are buffered and delivered to the first listener.
1098
+ * Every link that reaches the SDK (direct, deferred, push) is delivered.
1099
+ */
1100
+ onDeepLink(callback) {
1101
+ if (typeof callback !== 'function') {
1102
+ reportDeclined(invalidArgument('AdShift SDK: callback must be a function'));
1103
+ return {
1104
+ remove: () => {}
1105
+ };
1106
+ }
1107
+ const entry = {
1108
+ callback
1109
+ };
1110
+ const wasEmpty = listeners.size === 0;
1111
+ listeners.add(entry);
1112
+ if (wasEmpty && deepLinkBuffer.length > 0) {
1113
+ scheduleReplay();
1114
+ }
1115
+ return {
1116
+ remove: () => {
1117
+ listeners.delete(entry);
1118
+ }
1119
+ };
1120
+ },
1121
+ // ============ Info ============
1122
+
1123
+ getInfo() {
1124
+ return {
1125
+ platform: _reactNative.Platform.OS,
1126
+ version: _version.PLUGIN_VERSION,
1127
+ nativeSdkVersions: {
1128
+ ..._nativeSdkVersions.NATIVE_SDK_VERSIONS
1129
+ }
1130
+ };
1131
+ }
1132
+ };
1133
+ Object.freeze(Adshift);
1134
+ var _default = exports.default = Adshift;
1135
+ //# sourceMappingURL=Adshift.js.map