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