@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
@@ -1,132 +1,103 @@
1
- import { TurboModuleRegistry, type TurboModule } from 'react-native';
1
+ import type { TurboModule, CodegenTypes } from 'react-native';
2
+ import { TurboModuleRegistry } from 'react-native';
2
3
 
3
4
  /**
4
- * AdShift React Native Plugin - Turbo Module Specification
5
+ * Deep link result as emitted by the native module.
5
6
  *
6
- * This interface defines the contract between JavaScript and native code.
7
- * Codegen generates native interfaces from this spec:
8
- * - iOS: NativeAdShiftReactNativePluginSpecJSI (C++)
9
- * - Android: NativeAdShiftReactNativePluginSpec (Kotlin)
7
+ * Every field except `params`, `isDeferred` and `status` is optional.
8
+ * `params` is always present (possibly empty).
9
+ */
10
+ export type NativeDeepLinkPayload = {
11
+ deepLink?: string;
12
+ deepLinkValue?: string;
13
+ params: { [key: string]: string };
14
+ isDeferred: boolean;
15
+ status: string;
16
+ errorMessage?: string;
17
+ deepLinkSub1?: string;
18
+ deepLinkSub2?: string;
19
+ deepLinkSub3?: string;
20
+ deepLinkSub4?: string;
21
+ deepLinkSub5?: string;
22
+ isFirstSession?: boolean;
23
+ };
24
+
25
+ /**
26
+ * TurboModule contract between JavaScript and native code.
10
27
  *
11
- * Note: Custom types (AdshiftConfig, etc.) are not supported in Turbo Module Spec.
12
- * We use `Object` here and add type safety in the wrapper layer (Adshift.ts).
28
+ * Complex inputs travel as `Object`; the JS layer (`Adshift.ts`) owns
29
+ * validation and typing. Results of deep link processing are delivered
30
+ * exclusively through `onDeepLink`.
13
31
  */
14
32
  export interface Spec extends TurboModule {
15
33
  // ============ Lifecycle ============
16
34
 
17
35
  /**
18
- * Initializes the SDK with configuration.
19
- * Must be called before start().
36
+ * Initializes the SDK.
20
37
  *
21
- * @param config - Configuration object containing:
22
- * - apiKey: string (required)
23
- * - isDebug?: boolean
24
- * - appOpenDebounceMs?: number
25
- * - disableSKAN?: boolean (iOS only)
26
- * - waitForATTBeforeStart?: boolean (iOS only)
27
- * - attTimeoutMs?: number (iOS only)
28
- * - collectOaid?: boolean (Android only)
38
+ * Config keys (all optional except `apiKey`): `apiKey`, `isDebug`,
39
+ * `appOpenDebounceMs`, `brandedDomains: string[]`, `metaAppId` (Android),
40
+ * `pushDeepLinkPaths: string[][]`, `autoHandleDeepLinks`,
41
+ * `disableSKAN` / `waitForATTBeforeStart` / `attTimeoutMs` (iOS),
42
+ * `collectOaid` (Android). Keys that are absent leave SDK defaults untouched.
29
43
  */
30
44
  initialize(config: Object): void;
31
45
 
32
46
  /**
33
- * Starts the SDK.
34
- * Validates API key, sends install event (if first launch), and begins tracking.
47
+ * Starts the SDK. Resolves once the SDK has started locally.
35
48
  *
36
- * @returns Promise resolving to result object or rejecting with error
49
+ * Result keys: `success: boolean`, `apiKeyValidationStatus?: string`
50
+ * (`pending` | `valid` | `invalid`), `errorCode?: string`,
51
+ * `errorMessage?: string`, `nativeCode?: number | string`.
37
52
  */
38
53
  start(): Promise<Object>;
39
54
 
40
- /**
41
- * Stops the SDK.
42
- * Pauses all tracking. Can be restarted with start().
43
- */
55
+ /** Suspends delivery. Can be resumed with `start()`. */
44
56
  stop(): void;
45
57
 
46
- /**
47
- * Checks if SDK is currently started.
48
- *
49
- * @returns true if SDK is running
50
- */
51
- isStarted(): boolean;
52
-
53
58
  // ============ Configuration ============
54
59
 
55
- /**
56
- * Sets custom user identifier for attribution.
57
- * Can be called before or after start().
58
- *
59
- * @param userId - Your user identifier
60
- */
61
60
  setCustomerUserId(userId: string): void;
62
61
 
63
- /**
64
- * Enables/disables debug logging at runtime.
65
- *
66
- * @param enabled - true to enable debug logs
67
- */
68
62
  setDebugEnabled(enabled: boolean): void;
69
63
 
70
- /**
71
- * Sets app open debounce time in milliseconds.
72
- * Used to deduplicate rapid app open events.
73
- *
74
- * @param ms - Debounce time in milliseconds
75
- */
76
64
  setAppOpenDebounceMs(ms: number): void;
77
65
 
66
+ /** Branded attribution domains. Must precede `start()`. */
67
+ setBrandedDomains(domains: string[]): void;
68
+
69
+ /** Meta app id for Meta deep link parsing. Android only; no-op on iOS. */
70
+ setMetaAppId(appId: string): void;
71
+
72
+ /** OAID read by the app itself. Android only; no-op on iOS. */
73
+ setOaidData(oaid: string): void;
74
+
78
75
  // ============ Consent (GDPR/DMA) ============
79
76
 
80
77
  /**
81
- * Sets user consent data manually.
82
- * Use for custom consent UI (not CMP).
83
- *
84
- * @param consent - Consent object containing:
85
- * - isUserSubjectToGDPR: boolean
86
- * - hasConsentForDataUsage: boolean
87
- * - hasConsentForAdsPersonalization: boolean
88
- * - hasConsentForAdStorage: boolean
78
+ * Consent keys: `isUserSubjectToGDPR: boolean`,
79
+ * `hasConsentForDataUsage` / `hasConsentForAdsPersonalization` /
80
+ * `hasConsentForAdStorage`: `boolean | null` (null = not decided).
89
81
  */
90
82
  setConsentData(consent: Object): void;
91
83
 
92
- /**
93
- * Enables/disables automatic TCF v2.2 data collection from CMP.
94
- * Call BEFORE start() to enable consent collection from CMPs
95
- * (Google Funding Choices, Didomi, etc.)
96
- *
97
- * @param enabled - true to enable TCF collection
98
- */
99
84
  enableTCFDataCollection(enabled: boolean): void;
100
85
 
101
- /**
102
- * Refreshes consent state from TCF/CMP or manual sources.
103
- * Call this after CMP dialog closes to pick up updated consent.
104
- *
105
- * @returns Promise resolving to consent snapshot
106
- */
86
+ enableGPPDataCollection(enabled: boolean): void;
87
+
88
+ /** Sharing key: `optOut: boolean`. */
89
+ setThirdPartySharing(sharing: Object): void;
90
+
91
+ clearThirdPartySharing(): void;
92
+
93
+ /** Resolves to a consent snapshot object. */
107
94
  refreshConsent(): Promise<Object>;
108
95
 
109
96
  // ============ Event Tracking ============
110
97
 
111
- /**
112
- * Tracks an in-app event with optional parameters.
113
- * Events are queued until SDK is started.
114
- *
115
- * @param eventName - Event name (use AdshiftEventType constants or custom string)
116
- * @param values - Optional event parameters (nullable)
117
- * @returns Promise resolving on success or rejecting with error
118
- */
98
+ /** Resolves once the event has been accepted by the SDK queue. */
119
99
  trackEvent(eventName: string, values: Object | null): Promise<void>;
120
100
 
121
- /**
122
- * Tracks a purchase event with standardized parameters.
123
- *
124
- * @param productId - Product identifier
125
- * @param price - Purchase amount
126
- * @param currency - ISO currency code (e.g., "USD")
127
- * @param token - Purchase token/receipt
128
- * @returns Promise resolving on success or rejecting with error
129
- */
130
101
  trackPurchase(
131
102
  productId: string,
132
103
  price: number,
@@ -134,42 +105,37 @@ export interface Spec extends TurboModule {
134
105
  token: string
135
106
  ): Promise<void>;
136
107
 
137
- // ============ Deep Links ============
138
-
139
108
  /**
140
- * Handles a deep link URL.
141
- * Extracts campaign parameters for attribution.
142
- *
143
- * @param url - Deep link URL string
144
- * @returns Promise resolving to deep link response object containing:
145
- * - deepLink?: string
146
- * - deepLinkValue?: string
147
- * - params?: Object
148
- * - isDeferred: boolean
149
- * - status: 'found' | 'notFound' | 'error'
150
- * - errorMessage?: string
151
- * - deepLinkSub1-5?: string
109
+ * Ad revenue keys: `monetizationNetwork`, `mediationNetwork`, `currency`,
110
+ * `revenue`, optional `adUnitId`, `precision`, `additionalParameters`.
152
111
  */
153
- handleDeepLink(url: string): Promise<Object>;
112
+ logAdRevenue(data: Object): Promise<void>;
154
113
 
155
- // ============ Event Emitter Support ============
156
- // Required for NativeEventEmitter to receive deep link events from native
114
+ // ============ Identity ============
157
115
 
158
- /**
159
- * Registers a listener for native events.
160
- * Called internally by NativeEventEmitter.
161
- *
162
- * @param eventType - Event name to listen for
163
- */
164
- addListener(eventType: string): void;
116
+ /** Resolves to the AdShift device id, or null before initialization. */
117
+ getAdShiftDeviceId(): Promise<string | null>;
118
+
119
+ // ============ Deep Links ============
165
120
 
166
121
  /**
167
- * Removes event listeners.
168
- * Called internally by NativeEventEmitter.
122
+ * Passes a URL to the SDK. Resolves once processing has completed;
123
+ * the result arrives through `onDeepLink`.
169
124
  *
170
- * @param count - Number of listeners to remove
125
+ * `fromLaunch` marks the URL that opened the app, as opposed to one opened
126
+ * while the app was running. Launch URLs are remembered for the lifetime of
127
+ * the process, so reloading JavaScript cannot book the same link twice,
128
+ * while a genuine second tap on the same link is still forwarded.
171
129
  */
172
- removeListeners(count: number): void;
130
+ handleDeepLink(url: string, fromLaunch: boolean): Promise<void>;
131
+
132
+ /** Registers a push payload key path that carries a deep link. */
133
+ addPushNotificationDeepLinkPath(path: string[]): void;
134
+
135
+ /** Resolves to true when the payload was recognised as an AdShift push. */
136
+ handlePushNotification(payload: Object): Promise<boolean>;
137
+
138
+ readonly onDeepLink: CodegenTypes.EventEmitter<NativeDeepLinkPayload>;
173
139
  }
174
140
 
175
141
  export default TurboModuleRegistry.getEnforcing<Spec>(
package/src/index.tsx CHANGED
@@ -1,33 +1,31 @@
1
1
  /**
2
2
  * AdShift React Native Plugin
3
3
  *
4
- * Mobile Attribution, Event Tracking, SKAdNetwork 4.0+, Deep Linking
5
- * and GDPR/TCF 2.2 Compliance.
4
+ * Mobile attribution, event tracking, SKAdNetwork, deep linking and
5
+ * GDPR/TCF 2.2 consent.
6
6
  *
7
7
  * @example
8
8
  * ```typescript
9
9
  * import {
10
10
  * Adshift,
11
+ * AdshiftEventParam,
11
12
  * AdshiftEventType,
12
13
  * AdshiftConsent,
13
14
  * AdshiftDeepLinkStatus,
14
15
  * } from '@adshift/react-native-plugin';
15
16
  *
16
- * // 1. Initialize
17
- * Adshift.initialize({ apiKey: 'your-api-key', isDebug: __DEV__ });
18
- *
19
- * // 2. Start tracking
20
- * await Adshift.start();
21
- *
22
- * // 3. Track events
23
- * await Adshift.trackEvent(AdshiftEventType.Purchase, { price: 9.99 });
24
- *
25
- * // 4. Handle deep links
26
- * const subscription = Adshift.onDeepLink((deepLink) => {
17
+ * Adshift.onDeepLink((deepLink) => {
27
18
  * if (deepLink.status === AdshiftDeepLinkStatus.Found) {
28
- * // Navigate based on deep link
19
+ * // route on deepLink.deepLinkValue / deepLink.params
29
20
  * }
30
21
  * });
22
+ *
23
+ * Adshift.initialize({ apiKey: 'your-api-key', isDebug: __DEV__ });
24
+ * await Adshift.start();
25
+ * await Adshift.trackEvent(AdshiftEventType.Purchase, {
26
+ * [AdshiftEventParam.Revenue]: 9.99,
27
+ * [AdshiftEventParam.Currency]: 'USD',
28
+ * });
31
29
  * ```
32
30
  *
33
31
  * @packageDocumentation
@@ -36,33 +34,50 @@
36
34
  // ============ Main SDK API ============
37
35
  export { Adshift, default } from './Adshift';
38
36
 
39
- // ============ Types from Adshift.ts ============
40
37
  export type {
41
38
  StartResult,
42
39
  EventValues,
43
40
  PurchaseParams,
44
41
  DeepLinkSubscription,
45
42
  DeepLinkCallback,
43
+ NativeSdkVersions,
44
+ AdshiftInfo,
46
45
  } from './Adshift';
47
46
 
48
47
  // ============ Config ============
49
48
  export type { AdshiftConfig } from './types';
50
- export { configToMap } from './types';
51
49
 
52
50
  // ============ Consent ============
53
- // Note: AdshiftConsent is both a type (interface) and value (helper object)
54
- export { AdshiftConsent, consentToMap } from './types';
55
- export type { AdshiftConsent as AdshiftConsentType } from './types';
51
+ // AdshiftConsent is both a type (interface) and a value (helper object).
52
+ export { AdshiftConsent } from './types';
53
+ export type {
54
+ AdshiftConsent as AdshiftConsentType,
55
+ ConsentFlag,
56
+ ConsentSnapshot,
57
+ ConsentSource,
58
+ } from './types';
59
+ // AdshiftThirdPartySharing is both a type (interface) and a value (helper object).
60
+ export { AdshiftThirdPartySharing } from './types';
61
+ export type { AdshiftThirdPartySharing as AdshiftThirdPartySharingType } from './types';
56
62
 
57
63
  // ============ Deep Link ============
58
- // Note: AdshiftDeepLink is both a type (interface) and value (helper object)
59
- export { AdshiftDeepLinkStatus, AdshiftDeepLink, deepLinkToMap } from './types';
64
+ // AdshiftDeepLink is both a type (interface) and a value (helper object).
65
+ export { AdshiftDeepLinkStatus, AdshiftDeepLink } from './types';
60
66
  export type { AdshiftDeepLink as AdshiftDeepLinkType } from './types';
61
67
 
62
- // ============ Event Types ============
68
+ // ============ Events ============
63
69
  export { AdshiftEventType, getAllEventTypes } from './types';
64
70
  export type { AdshiftEventTypeValue } from './types';
71
+ export { AdshiftEventParam, getAllEventParams } from './types';
72
+ export type { AdshiftEventParamValue } from './types';
73
+
74
+ // ============ Ad Revenue ============
75
+ export { AdshiftMediationNetwork } from './types';
76
+ export type { AdshiftMediationNetworkValue, AdRevenueParams } from './types';
77
+
78
+ // ============ Errors ============
79
+ export { AdshiftErrorCode, isAdshiftError } from './types';
80
+ export type { AdshiftError, AdshiftErrorInfo } from './types';
65
81
 
66
- // ============ Native Module (Advanced Usage) ============
67
- export { default as NativeAdShiftReactNativePlugin } from './NativeAdShiftReactNativePlugin';
68
- export type { Spec as AdShiftNativeSpec } from './NativeAdShiftReactNativePlugin';
82
+ // ============ Version ============
83
+ export { PLUGIN_VERSION } from './version';
@@ -0,0 +1,224 @@
1
+ /**
2
+ * Jest support for apps that use `@adshift/react-native-plugin`.
3
+ *
4
+ * The plugin resolves its native module at import time, which fails in a
5
+ * plain Jest environment. Register this mock in your Jest setup file:
6
+ *
7
+ * ```js
8
+ * // jest.setup.js
9
+ * jest.mock('@adshift/react-native-plugin', () =>
10
+ * require('@adshift/react-native-plugin/jest').createAdshiftMock()
11
+ * );
12
+ * ```
13
+ *
14
+ * Every method is a `jest.fn()` with a resolved default so tests can assert
15
+ * calls or override behaviour per test.
16
+ */
17
+
18
+ import { Platform } from 'react-native';
19
+
20
+ import type { AdshiftConfig } from '../types/AdshiftConfig';
21
+ import type { AdshiftConsent as AdshiftConsentType } from '../types/AdshiftConsent';
22
+ import { AdshiftConsent } from '../types/AdshiftConsent';
23
+ import type { AdshiftThirdPartySharing as AdshiftThirdPartySharingType } from '../types/AdshiftThirdPartySharing';
24
+ import { AdshiftThirdPartySharing } from '../types/AdshiftThirdPartySharing';
25
+ import type { AdshiftDeepLink as AdshiftDeepLinkType } from '../types/AdshiftDeepLink';
26
+ import {
27
+ AdshiftDeepLink,
28
+ AdshiftDeepLinkStatus,
29
+ } from '../types/AdshiftDeepLink';
30
+ import { AdshiftEventType, getAllEventTypes } from '../types/AdshiftEventType';
31
+ import {
32
+ AdshiftEventParam,
33
+ getAllEventParams,
34
+ } from '../types/AdshiftEventParam';
35
+ import { AdshiftMediationNetwork } from '../types/AdshiftAdRevenue';
36
+ import { NATIVE_SDK_VERSIONS } from '../nativeSdkVersions';
37
+ import {
38
+ AdshiftErrorCode,
39
+ createAdshiftError,
40
+ isAdshiftError,
41
+ } from '../types/AdshiftError';
42
+ import { PLUGIN_VERSION } from '../version';
43
+
44
+ type MockFn<T extends (...args: never[]) => unknown> = jest.Mock<
45
+ ReturnType<T>,
46
+ Parameters<T>
47
+ >;
48
+
49
+ type Listener = (deepLink: AdshiftDeepLinkType) => void;
50
+
51
+ /**
52
+ * Mocked `Adshift` object with test helpers.
53
+ */
54
+ export interface AdshiftMock {
55
+ initialize: MockFn<(config: AdshiftConfig) => void>;
56
+ start: MockFn<() => Promise<{ success: boolean }>>;
57
+ stop: MockFn<() => void>;
58
+ isStarted: MockFn<() => boolean>;
59
+ setCustomerUserId: MockFn<(userId: string) => void>;
60
+ setDebugEnabled: MockFn<(enabled: boolean) => void>;
61
+ setAppOpenDebounceMs: MockFn<(ms: number) => void>;
62
+ setBrandedDomains: MockFn<(domains: string[]) => void>;
63
+ setMetaAppId: MockFn<(appId: string) => void>;
64
+ setOaidData: MockFn<(oaid: string) => void>;
65
+ setConsentData: MockFn<(consent: AdshiftConsentType) => void>;
66
+ enableTCFDataCollection: MockFn<(enabled: boolean) => void>;
67
+ enableGPPDataCollection: MockFn<(enabled: boolean) => void>;
68
+ setThirdPartySharing: MockFn<(sharing: AdshiftThirdPartySharingType) => void>;
69
+ clearThirdPartySharing: MockFn<() => void>;
70
+ refreshConsent: MockFn<() => Promise<Record<string, unknown>>>;
71
+ trackEvent: MockFn<
72
+ (eventName: string, values?: Record<string, unknown>) => Promise<void>
73
+ >;
74
+ trackPurchase: MockFn<(params: Record<string, unknown>) => Promise<void>>;
75
+ logAdRevenue: MockFn<(params: Record<string, unknown>) => Promise<void>>;
76
+ getAdShiftDeviceId: MockFn<() => Promise<string | null>>;
77
+ handleDeepLink: MockFn<(url: string) => Promise<void>>;
78
+ addPushNotificationDeepLinkPath: MockFn<(path: string[]) => void>;
79
+ handlePushNotification: MockFn<
80
+ (payload: Record<string, unknown>) => Promise<boolean>
81
+ >;
82
+ onDeepLink: MockFn<(callback: Listener) => { remove: () => void }>;
83
+ getInfo: MockFn<
84
+ () => {
85
+ platform: string;
86
+ version: string;
87
+ nativeSdkVersions: { android: string; ios: string };
88
+ }
89
+ >;
90
+
91
+ /** Test helper: delivers a deep link to every registered listener. */
92
+ __emitDeepLink(deepLink: AdshiftDeepLinkType): void;
93
+ /**
94
+ * Test helper: returns the mock to the state it had when it was created —
95
+ * listeners gone, started flag down, recorded calls and any per-test
96
+ * behaviour dropped, default answers back in place.
97
+ */
98
+ __reset(): void;
99
+ }
100
+
101
+ /**
102
+ * Shape returned by `createAdshiftMock()`; mirrors the package exports.
103
+ */
104
+ export interface AdshiftModuleMock {
105
+ Adshift: AdshiftMock;
106
+ default: AdshiftMock;
107
+ AdshiftConsent: typeof AdshiftConsent;
108
+ AdshiftThirdPartySharing: typeof AdshiftThirdPartySharing;
109
+ AdshiftDeepLink: typeof AdshiftDeepLink;
110
+ AdshiftDeepLinkStatus: typeof AdshiftDeepLinkStatus;
111
+ AdshiftEventType: typeof AdshiftEventType;
112
+ getAllEventTypes: typeof getAllEventTypes;
113
+ AdshiftEventParam: typeof AdshiftEventParam;
114
+ getAllEventParams: typeof getAllEventParams;
115
+ AdshiftMediationNetwork: typeof AdshiftMediationNetwork;
116
+ AdshiftErrorCode: typeof AdshiftErrorCode;
117
+ isAdshiftError: typeof isAdshiftError;
118
+ PLUGIN_VERSION: string;
119
+ }
120
+
121
+ /**
122
+ * Creates a fresh mock of the package. Call inside `jest.mock()`.
123
+ */
124
+ export function createAdshiftMock(): AdshiftModuleMock {
125
+ const listeners = new Set<Listener>();
126
+ let started = false;
127
+
128
+ const mock = {
129
+ initialize: jest.fn(),
130
+ start: jest.fn(async () => {
131
+ started = true;
132
+ return { success: true, apiKeyValidationStatus: 'pending' as const };
133
+ }),
134
+ stop: jest.fn(() => {
135
+ started = false;
136
+ }),
137
+ isStarted: jest.fn(() => started),
138
+ setCustomerUserId: jest.fn(),
139
+ setDebugEnabled: jest.fn(),
140
+ setAppOpenDebounceMs: jest.fn(),
141
+ setBrandedDomains: jest.fn(),
142
+ setMetaAppId: jest.fn(),
143
+ setOaidData: jest.fn(),
144
+ setConsentData: jest.fn(),
145
+ enableTCFDataCollection: jest.fn(),
146
+ enableGPPDataCollection: jest.fn(),
147
+ setThirdPartySharing: jest.fn(),
148
+ clearThirdPartySharing: jest.fn(),
149
+ refreshConsent: jest.fn(async () => ({
150
+ source: 'none',
151
+ tcStringPresent: false,
152
+ cmpDetected: false,
153
+ appliedAtMillis: 0,
154
+ adIdentifiersAllowed: true,
155
+ })),
156
+ trackEvent: jest.fn(async () => undefined),
157
+ trackPurchase: jest.fn(async () => undefined),
158
+ logAdRevenue: jest.fn(async () => undefined),
159
+ getAdShiftDeviceId: jest.fn(async () => 'mock-device-id'),
160
+ handleDeepLink: jest.fn(async () => undefined),
161
+ addPushNotificationDeepLinkPath: jest.fn(),
162
+ handlePushNotification: jest.fn(async () => false),
163
+ onDeepLink: jest.fn((callback: Listener) => {
164
+ listeners.add(callback);
165
+ return {
166
+ remove: () => {
167
+ listeners.delete(callback);
168
+ },
169
+ };
170
+ }),
171
+ getInfo: jest.fn(() => ({
172
+ platform: Platform.OS,
173
+ version: PLUGIN_VERSION,
174
+ nativeSdkVersions: { ...NATIVE_SDK_VERSIONS },
175
+ })),
176
+ __emitDeepLink(deepLink: AdshiftDeepLinkType) {
177
+ for (const listener of Array.from(listeners)) {
178
+ listener(deepLink);
179
+ }
180
+ },
181
+ __reset() {
182
+ listeners.clear();
183
+ started = false;
184
+ restoreDefaults();
185
+ },
186
+ } as unknown as AdshiftMock;
187
+
188
+ // Held so `__reset()` can drop what a test recorded or overrode without
189
+ // taking the default answers with it.
190
+ const defaults = new Map<jest.Mock, (...args: never[]) => unknown>();
191
+ for (const value of Object.values(mock)) {
192
+ if (jest.isMockFunction(value)) {
193
+ defaults.set(value, value.getMockImplementation() as never);
194
+ }
195
+ }
196
+
197
+ function restoreDefaults(): void {
198
+ for (const [fn, implementation] of defaults) {
199
+ fn.mockReset();
200
+ if (implementation) {
201
+ fn.mockImplementation(implementation);
202
+ }
203
+ }
204
+ }
205
+
206
+ return {
207
+ Adshift: mock,
208
+ default: mock,
209
+ AdshiftConsent,
210
+ AdshiftThirdPartySharing,
211
+ AdshiftDeepLink,
212
+ AdshiftDeepLinkStatus,
213
+ AdshiftEventType,
214
+ getAllEventTypes,
215
+ AdshiftEventParam,
216
+ getAllEventParams,
217
+ AdshiftMediationNetwork,
218
+ AdshiftErrorCode,
219
+ isAdshiftError,
220
+ PLUGIN_VERSION,
221
+ };
222
+ }
223
+
224
+ export { AdshiftErrorCode, createAdshiftError, isAdshiftError };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Native SDK versions this plugin is pinned to.
3
+ *
4
+ * Kept in its own module so the Jest mock can report the same values without
5
+ * loading the native module, and so a release bumps them in one place.
6
+ */
7
+ export const NATIVE_SDK_VERSIONS = Object.freeze({
8
+ android: '3.2.0',
9
+ ios: '2.4.0',
10
+ });
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Mediation platform that reported the ad impression.
3
+ *
4
+ * Values are the identifiers used on the wire by the native SDKs.
5
+ */
6
+ export const AdshiftMediationNetwork = {
7
+ AppLovinMAX: 'applovin_max',
8
+ GoogleAdMob: 'google_admob',
9
+ IronSource: 'ironsource',
10
+ Chartboost: 'chartboost',
11
+ TopOn: 'topon',
12
+ TradPlus: 'tradplus',
13
+ AdMost: 'admost',
14
+ Appodeal: 'appodeal',
15
+ Fyber: 'fyber',
16
+ Unity: 'unity',
17
+ Yandex: 'yandex',
18
+ CustomMediation: 'custom_mediation',
19
+ DirectMonetization: 'direct_monetization_network',
20
+ Other: 'other',
21
+ } as const;
22
+
23
+ /**
24
+ * Type of all mediation network values.
25
+ */
26
+ export type AdshiftMediationNetworkValue =
27
+ (typeof AdshiftMediationNetwork)[keyof typeof AdshiftMediationNetwork];
28
+
29
+ /**
30
+ * Parameters for `Adshift.logAdRevenue()`.
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * await Adshift.logAdRevenue({
35
+ * monetizationNetwork: 'admob',
36
+ * mediationNetwork: AdshiftMediationNetwork.GoogleAdMob,
37
+ * currency: 'USD',
38
+ * revenue: 0.0125,
39
+ * adUnitId: 'ca-app-pub-1234/5678',
40
+ * });
41
+ * ```
42
+ */
43
+ export interface AdRevenueParams {
44
+ /** Ad network that served the impression, e.g. `admob`, `meta`. */
45
+ monetizationNetwork: string;
46
+ /** Mediation platform that reported the impression. */
47
+ mediationNetwork: AdshiftMediationNetworkValue;
48
+ /** ISO 4217 currency code, e.g. `USD`. */
49
+ currency: string;
50
+ /** Revenue of the single impression in `currency`. Must be positive. */
51
+ revenue: number;
52
+ /** Ad unit identifier, when available. */
53
+ adUnitId?: string;
54
+ /** Revenue precision reported by the network, e.g. `exact`, `estimated`. */
55
+ precision?: string;
56
+ /** Extra parameters attached to the event. */
57
+ additionalParameters?: Record<string, string | number | boolean>;
58
+ }