@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,111 +1,122 @@
1
1
  /**
2
- * Status of a deep link resolution.
2
+ * Status of a deep link result.
3
3
  */
4
4
  export enum AdshiftDeepLinkStatus {
5
- /** Deep link was found and resolved successfully. */
5
+ /** The link was processed and delivered. */
6
6
  Found = 'found',
7
7
 
8
- /** No deep link was found (e.g., organic install). */
8
+ /** No deep link was found (e.g. organic install, deferred lookup empty). */
9
9
  NotFound = 'notFound',
10
10
 
11
- /** Error occurred while resolving deep link. */
11
+ /** An error occurred while resolving the deep link. */
12
12
  Error = 'error',
13
13
  }
14
14
 
15
15
  /**
16
- * Response from deep link handling.
16
+ * Deep link delivered through `Adshift.onDeepLink()`.
17
17
  *
18
- * Contains the resolved deep link URL, parameters, and status.
18
+ * Every link that enters the app and reaches the SDK produces a result with
19
+ * `status: 'found'`. Route on `deepLinkValue`, `params` or the URL itself.
19
20
  *
20
21
  * @example
21
22
  * ```typescript
22
- * const deepLink = await Adshift.handleDeepLink(url);
23
- * if (deepLink.status === AdshiftDeepLinkStatus.Found) {
24
- * const productId = deepLink.params?.['product_id'];
25
- * // Navigate to product
26
- * }
23
+ * Adshift.onDeepLink((deepLink) => {
24
+ * if (deepLink.status === AdshiftDeepLinkStatus.Found) {
25
+ * const productId = deepLink.params?.product_id;
26
+ * }
27
+ * });
27
28
  * ```
28
29
  */
29
30
  export interface AdshiftDeepLink {
30
- /** The deep link URL string. */
31
31
  deepLink?: string;
32
32
 
33
- /**
34
- * Standardized resolved value for routing.
35
- * This is the main routing value extracted from the deep link.
36
- */
33
+ /** Standardized routing value (`deep_link_value`). */
37
34
  deepLinkValue?: string;
38
35
 
39
- /** Query parameters extracted from the deep link. */
40
- params?: Record<string, unknown>;
41
-
42
36
  /**
43
- * Whether this is a deferred deep link.
44
- *
45
- * Deferred deep links are resolved after app install,
46
- * typically from ad campaigns.
37
+ * Query parameters of the link. On Android `deep_link_sub1` … `sub5` also
38
+ * appear here; on iOS they are only available as the `deepLinkSubN` fields
39
+ * below, which both platforms fill.
47
40
  */
41
+ params?: Record<string, string>;
42
+
43
+ /** Whether this result comes from deferred deep linking (first launch). */
48
44
  isDeferred: boolean;
49
45
 
50
- /** Status of the deep link resolution. */
51
46
  status: AdshiftDeepLinkStatus;
52
47
 
53
- /** Error message if status is Error. */
48
+ /** Error message when `status` is `error`. */
54
49
  errorMessage?: string;
55
50
 
56
- // ============ Custom sub-parameters (OneLink style) ============
51
+ /**
52
+ * Whether the result belongs to the first session after install. Android
53
+ * reports it for every result, deferred or not; undefined on iOS.
54
+ */
55
+ isFirstSession?: boolean;
57
56
 
58
- /** Custom sub-parameter 1. */
57
+ /** Custom sub-parameter 1 (`deep_link_sub1`). */
59
58
  deepLinkSub1?: string;
60
59
 
61
- /** Custom sub-parameter 2. */
60
+ /** Custom sub-parameter 2 (`deep_link_sub2`). */
62
61
  deepLinkSub2?: string;
63
62
 
64
- /** Custom sub-parameter 3. */
63
+ /** Custom sub-parameter 3 (`deep_link_sub3`). */
65
64
  deepLinkSub3?: string;
66
65
 
67
- /** Custom sub-parameter 4. */
66
+ /** Custom sub-parameter 4 (`deep_link_sub4`). */
68
67
  deepLinkSub4?: string;
69
68
 
70
- /** Custom sub-parameter 5. */
69
+ /** Custom sub-parameter 5 (`deep_link_sub5`). */
71
70
  deepLinkSub5?: string;
72
71
  }
73
72
 
73
+ const SUB_KEYS = [
74
+ 'deepLinkSub1',
75
+ 'deepLinkSub2',
76
+ 'deepLinkSub3',
77
+ 'deepLinkSub4',
78
+ 'deepLinkSub5',
79
+ ] as const;
80
+
74
81
  /**
75
- * Helper functions for creating AdshiftDeepLink objects.
82
+ * Helper functions for creating `AdshiftDeepLink` objects.
76
83
  */
77
84
  export const AdshiftDeepLink = {
78
- /**
79
- * Creates a successful deep link response.
80
- */
81
85
  found(options: {
82
86
  deepLink: string;
83
87
  deepLinkValue?: string;
84
- params?: Record<string, unknown>;
88
+ params?: Record<string, string>;
85
89
  isDeferred?: boolean;
90
+ isFirstSession?: boolean;
86
91
  deepLinkSub1?: string;
87
92
  deepLinkSub2?: string;
88
93
  deepLinkSub3?: string;
89
94
  deepLinkSub4?: string;
90
95
  deepLinkSub5?: string;
91
96
  }): AdshiftDeepLink {
92
- return {
97
+ const result: AdshiftDeepLink = {
93
98
  deepLink: options.deepLink,
94
- deepLinkValue: options.deepLinkValue,
95
- params: options.params,
96
99
  isDeferred: options.isDeferred ?? false,
97
100
  status: AdshiftDeepLinkStatus.Found,
98
- deepLinkSub1: options.deepLinkSub1,
99
- deepLinkSub2: options.deepLinkSub2,
100
- deepLinkSub3: options.deepLinkSub3,
101
- deepLinkSub4: options.deepLinkSub4,
102
- deepLinkSub5: options.deepLinkSub5,
103
101
  };
102
+ if (options.deepLinkValue !== undefined) {
103
+ result.deepLinkValue = options.deepLinkValue;
104
+ }
105
+ if (options.params !== undefined) {
106
+ result.params = options.params;
107
+ }
108
+ if (options.isFirstSession !== undefined) {
109
+ result.isFirstSession = options.isFirstSession;
110
+ }
111
+ for (const key of SUB_KEYS) {
112
+ const value = options[key];
113
+ if (value !== undefined) {
114
+ result[key] = value;
115
+ }
116
+ }
117
+ return result;
104
118
  },
105
119
 
106
- /**
107
- * Creates a "not found" deep link response.
108
- */
109
120
  notFound(): AdshiftDeepLink {
110
121
  return {
111
122
  isDeferred: false,
@@ -113,9 +124,6 @@ export const AdshiftDeepLink = {
113
124
  };
114
125
  },
115
126
 
116
- /**
117
- * Creates an error deep link response.
118
- */
119
127
  error(message: string): AdshiftDeepLink {
120
128
  return {
121
129
  isDeferred: false,
@@ -125,70 +133,83 @@ export const AdshiftDeepLink = {
125
133
  },
126
134
 
127
135
  /**
128
- * Creates deep link from a plain object (native bridge response).
136
+ * Creates a deep link from a native bridge object.
137
+ *
138
+ * @internal
129
139
  */
130
140
  fromMap(map: Record<string, unknown>): AdshiftDeepLink {
131
- const statusStr = (map.status as string) ?? 'notFound';
132
- let status: AdshiftDeepLinkStatus;
133
-
134
- switch (statusStr) {
135
- case 'found':
136
- status = AdshiftDeepLinkStatus.Found;
137
- break;
138
- case 'error':
139
- status = AdshiftDeepLinkStatus.Error;
140
- break;
141
- default:
142
- status = AdshiftDeepLinkStatus.NotFound;
143
- }
144
-
145
- return {
146
- deepLink: (map.deepLink ?? map.deeplink) as string | undefined,
147
- deepLinkValue: (map.deepLinkValue ?? map.deep_link_value) as
148
- | string
149
- | undefined,
150
- params: (map.params ?? map.queryParams) as
151
- | Record<string, unknown>
152
- | undefined,
153
- isDeferred: (map.isDeferred as boolean) ?? false,
154
- status,
155
- errorMessage: (map.errorMessage ?? map.error) as string | undefined,
156
- deepLinkSub1: (map.deepLinkSub1 ?? map.deep_link_sub1 ?? map.sub1) as
157
- | string
158
- | undefined,
159
- deepLinkSub2: (map.deepLinkSub2 ?? map.deep_link_sub2 ?? map.sub2) as
160
- | string
161
- | undefined,
162
- deepLinkSub3: (map.deepLinkSub3 ?? map.deep_link_sub3 ?? map.sub3) as
163
- | string
164
- | undefined,
165
- deepLinkSub4: (map.deepLinkSub4 ?? map.deep_link_sub4 ?? map.sub4) as
166
- | string
167
- | undefined,
168
- deepLinkSub5: (map.deepLinkSub5 ?? map.deep_link_sub5 ?? map.sub5) as
169
- | string
170
- | undefined,
141
+ const params = readParams(map.params);
142
+ const result: AdshiftDeepLink = {
143
+ isDeferred: map.isDeferred === true,
144
+ status: readStatus(map.status),
171
145
  };
146
+ if (typeof map.deepLink === 'string') {
147
+ result.deepLink = map.deepLink;
148
+ }
149
+ const value = map.deepLinkValue ?? params?.deep_link_value;
150
+ if (typeof value === 'string') {
151
+ result.deepLinkValue = value;
152
+ }
153
+ if (params !== undefined) {
154
+ result.params = params;
155
+ }
156
+ if (typeof map.errorMessage === 'string') {
157
+ result.errorMessage = map.errorMessage;
158
+ }
159
+ if (typeof map.isFirstSession === 'boolean') {
160
+ result.isFirstSession = map.isFirstSession;
161
+ }
162
+ SUB_KEYS.forEach((key, index) => {
163
+ const sub = map[key] ?? params?.[`deep_link_sub${index + 1}`];
164
+ if (typeof sub === 'string') {
165
+ result[key] = sub;
166
+ }
167
+ });
168
+ return result;
172
169
  },
173
170
  };
174
171
 
172
+ function readStatus(value: unknown): AdshiftDeepLinkStatus {
173
+ switch (value) {
174
+ case 'found':
175
+ return AdshiftDeepLinkStatus.Found;
176
+ case 'error':
177
+ return AdshiftDeepLinkStatus.Error;
178
+ default:
179
+ return AdshiftDeepLinkStatus.NotFound;
180
+ }
181
+ }
182
+
183
+ function readParams(value: unknown): Record<string, string> | undefined {
184
+ if (typeof value !== 'object' || value === null) {
185
+ return undefined;
186
+ }
187
+ const out: Record<string, string> = {};
188
+ let count = 0;
189
+ for (const [key, raw] of Object.entries(value as Record<string, unknown>)) {
190
+ if (raw === null || raw === undefined) continue;
191
+ out[key] = typeof raw === 'string' ? raw : String(raw);
192
+ count++;
193
+ }
194
+ return count > 0 ? out : undefined;
195
+ }
196
+
175
197
  /**
176
- * Converts AdshiftDeepLink to a plain object for native bridge communication.
198
+ * Converts `AdshiftDeepLink` to a plain object.
199
+ *
200
+ * @internal
177
201
  */
178
202
  export function deepLinkToMap(
179
203
  deepLink: AdshiftDeepLink
180
204
  ): Record<string, unknown> {
181
- return {
182
- deepLink: deepLink.deepLink,
183
- deepLinkValue: deepLink.deepLinkValue,
184
- params: deepLink.params,
205
+ const map: Record<string, unknown> = {
185
206
  isDeferred: deepLink.isDeferred,
186
207
  status: deepLink.status,
187
- errorMessage: deepLink.errorMessage,
188
- deepLinkSub1: deepLink.deepLinkSub1,
189
- deepLinkSub2: deepLink.deepLinkSub2,
190
- deepLinkSub3: deepLink.deepLinkSub3,
191
- deepLinkSub4: deepLink.deepLinkSub4,
192
- deepLinkSub5: deepLink.deepLinkSub5,
193
208
  };
209
+ for (const [key, value] of Object.entries(deepLink)) {
210
+ if (value !== undefined && !(key in map)) {
211
+ map[key] = value;
212
+ }
213
+ }
214
+ return map;
194
215
  }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Platform-neutral error codes used by every rejected promise and by
3
+ * `StartResult.errorCode`.
4
+ */
5
+ export enum AdshiftErrorCode {
6
+ /** `Adshift.initialize()` has not been called. */
7
+ NotInitialized = 'NOT_INITIALIZED',
8
+ /** The SDK is stopped; call `Adshift.start()` first. */
9
+ NotStarted = 'NOT_STARTED',
10
+ /** The API key was rejected by the AdShift backend. */
11
+ InvalidApiKey = 'INVALID_API_KEY',
12
+ /** Tracking is disabled for this app on the AdShift side. */
13
+ OptedOut = 'OPTED_OUT',
14
+ /** The event queue is full; the call was not accepted. */
15
+ QueueFull = 'QUEUE_FULL',
16
+ /** A parameter failed validation. */
17
+ InvalidArgument = 'INVALID_ARGUMENT',
18
+ /** Any other failure. See `userInfo.nativeCode` for the platform code. */
19
+ Unknown = 'UNKNOWN',
20
+ }
21
+
22
+ /**
23
+ * Platform-specific details attached to an `AdshiftError`.
24
+ */
25
+ export interface AdshiftErrorInfo {
26
+ /** Raw code reported by the native SDK, when available. */
27
+ nativeCode?: number | string;
28
+ /** Error domain on iOS, when available. */
29
+ nativeDomain?: string;
30
+ }
31
+
32
+ /**
33
+ * Error thrown or rejected by the AdShift plugin.
34
+ *
35
+ * `code` is always one of `AdshiftErrorCode`; the original native code, when
36
+ * there is one, is available in `userInfo.nativeCode`.
37
+ */
38
+ export interface AdshiftError extends Error {
39
+ code: AdshiftErrorCode;
40
+ userInfo: AdshiftErrorInfo;
41
+ }
42
+
43
+ const CODES = new Set<string>(Object.values(AdshiftErrorCode));
44
+
45
+ /**
46
+ * Type guard for errors produced by the plugin.
47
+ */
48
+ export function isAdshiftError(error: unknown): error is AdshiftError {
49
+ return (
50
+ typeof error === 'object' &&
51
+ error !== null &&
52
+ typeof (error as { code?: unknown }).code === 'string' &&
53
+ CODES.has((error as { code: string }).code)
54
+ );
55
+ }
56
+
57
+ /**
58
+ * Builds an `AdshiftError` from a code and message.
59
+ *
60
+ * @internal
61
+ */
62
+ export function createAdshiftError(
63
+ code: AdshiftErrorCode,
64
+ message: string,
65
+ userInfo: AdshiftErrorInfo = {}
66
+ ): AdshiftError {
67
+ const error = new Error(message) as AdshiftError;
68
+ error.name = 'AdshiftError';
69
+ error.code = code;
70
+ error.userInfo = userInfo;
71
+ return error;
72
+ }
73
+
74
+ /**
75
+ * Normalises a promise rejection coming from the native module into an
76
+ * `AdshiftError`. Native modules reject with `{ code, message, userInfo }`.
77
+ *
78
+ * @internal
79
+ */
80
+ export function toAdshiftError(error: unknown): AdshiftError {
81
+ if (isAdshiftError(error)) {
82
+ if (!error.userInfo) {
83
+ error.userInfo = {};
84
+ }
85
+ return error;
86
+ }
87
+ const raw = error as {
88
+ code?: unknown;
89
+ message?: unknown;
90
+ userInfo?: Record<string, unknown> | null;
91
+ } | null;
92
+ const message =
93
+ typeof raw?.message === 'string' ? raw.message : 'Unknown error';
94
+ const info: AdshiftErrorInfo = {};
95
+ const nativeCode = raw?.userInfo?.nativeCode;
96
+ if (typeof nativeCode === 'number' || typeof nativeCode === 'string') {
97
+ info.nativeCode = nativeCode;
98
+ }
99
+ const nativeDomain = raw?.userInfo?.nativeDomain;
100
+ if (typeof nativeDomain === 'string') {
101
+ info.nativeDomain = nativeDomain;
102
+ }
103
+ if (info.nativeCode === undefined && typeof raw?.code === 'string') {
104
+ info.nativeCode = raw.code;
105
+ }
106
+ return createAdshiftError(AdshiftErrorCode.Unknown, message, info);
107
+ }
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Standard parameter names for the `values` passed to `Adshift.trackEvent()`.
3
+ *
4
+ * Reports aggregate these names. Any other key is kept with the event as a
5
+ * custom parameter, so a misspelled or invented name is stored but never
6
+ * counted — use the constants for anything a report has to add up, revenue
7
+ * above all.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * await Adshift.trackEvent(AdshiftEventType.Purchase, {
12
+ * [AdshiftEventParam.Revenue]: 9.99,
13
+ * [AdshiftEventParam.Currency]: 'USD',
14
+ * [AdshiftEventParam.ContentId]: 'SKU123',
15
+ * size: 'XL', // custom parameters are fine alongside them
16
+ * });
17
+ * ```
18
+ */
19
+ export const AdshiftEventParam = {
20
+ // ============ Commerce ============
21
+
22
+ Price: 'as_price',
23
+
24
+ /** The number reports read as revenue. Always pair it with `Currency`. */
25
+ Revenue: 'as_revenue',
26
+
27
+ /** Revenue you expect rather than money already taken. */
28
+ ProjectedRevenue: 'as_projected_revenue',
29
+
30
+ /** ISO 4217 code, e.g. `USD`. */
31
+ Currency: 'as_currency',
32
+
33
+ Quantity: 'as_quantity',
34
+
35
+ ReceiptId: 'as_receipt_id',
36
+
37
+ /** Your own order identifier, for matching purchases with your records. */
38
+ OrderId: 'as_order_id',
39
+
40
+ CouponCode: 'as_coupon_code',
41
+
42
+ PaymentInfoAvailable: 'as_payment_info_available',
43
+
44
+ Validated: 'as_validated',
45
+
46
+ // ============ Content ============
47
+
48
+ ContentType: 'as_content_type',
49
+
50
+ ContentId: 'as_content_id',
51
+
52
+ ContentList: 'as_content_list',
53
+
54
+ Content: 'as_content',
55
+
56
+ Class: 'as_class',
57
+
58
+ Description: 'as_description',
59
+
60
+ SearchString: 'as_search_string',
61
+
62
+ // ============ Ratings and reviews ============
63
+
64
+ RatingValue: 'as_rating_value',
65
+
66
+ MaxRatingValue: 'as_max_rating_value',
67
+
68
+ ReviewText: 'as_review_text',
69
+
70
+ // ============ User and progress ============
71
+
72
+ CustomerUserId: 'as_customer_user_id',
73
+
74
+ RegistrationMethod: 'as_registration_method',
75
+
76
+ Level: 'as_level',
77
+
78
+ Score: 'as_score',
79
+
80
+ Success: 'as_success',
81
+
82
+ TutorialId: 'as_tutorial_id',
83
+
84
+ AchievementId: 'as_achievement_id',
85
+
86
+ VirtualCurrencyName: 'as_virtual_currency_name',
87
+
88
+ // ============ App and links ============
89
+
90
+ DeepLink: 'as_deep_link',
91
+
92
+ OldVersion: 'as_old_version',
93
+
94
+ NewVersion: 'as_new_version',
95
+
96
+ Channel: 'as_channel',
97
+
98
+ TouchObj: 'as_touch_obj',
99
+
100
+ // ============ Dates and places ============
101
+
102
+ DateA: 'as_date_a',
103
+
104
+ DateB: 'as_date_b',
105
+
106
+ EventStart: 'as_event_start',
107
+
108
+ EventEnd: 'as_event_end',
109
+
110
+ Latitude: 'as_lat',
111
+
112
+ Longitude: 'as_long',
113
+
114
+ City: 'as_city',
115
+
116
+ Region: 'as_region',
117
+
118
+ Country: 'as_country',
119
+
120
+ DestinationA: 'as_destination_a',
121
+
122
+ DestinationB: 'as_destination_b',
123
+
124
+ DestinationList: 'as_destination_list',
125
+
126
+ // ============ Travel ============
127
+
128
+ DepartingDepartureDate: 'as_departing_departure_date',
129
+
130
+ ReturningDepartureDate: 'as_returning_departure_date',
131
+
132
+ DepartingArrivalDate: 'as_departing_arrival_date',
133
+
134
+ ReturningArrivalDate: 'as_returning_arrival_date',
135
+
136
+ TravelStart: 'as_travel_start',
137
+
138
+ TravelEnd: 'as_travel_end',
139
+
140
+ SuggestedDestinations: 'as_suggested_destinations',
141
+
142
+ SuggestedHotels: 'as_suggested_hotels',
143
+
144
+ NumAdults: 'as_num_adults',
145
+
146
+ NumChildren: 'as_num_children',
147
+
148
+ NumInfants: 'as_num_infants',
149
+
150
+ UserScore: 'as_user_score',
151
+
152
+ HotelScore: 'as_hotel_score',
153
+
154
+ PurchaseCurrency: 'as_purchase_currency',
155
+
156
+ PreferredStarRatings: 'as_preferred_star_ratings',
157
+
158
+ PreferredPriceRange: 'as_preferred_price_range',
159
+
160
+ PreferredNeighborhoods: 'as_preferred_neighborhoods',
161
+
162
+ PreferredNumStops: 'as_preferred_num_stops',
163
+
164
+ // ============ Free-form slots ============
165
+
166
+ Param1: 'as_param_1',
167
+
168
+ Param2: 'as_param_2',
169
+
170
+ Param3: 'as_param_3',
171
+
172
+ Param4: 'as_param_4',
173
+
174
+ Param5: 'as_param_5',
175
+
176
+ Param6: 'as_param_6',
177
+
178
+ Param7: 'as_param_7',
179
+
180
+ Param8: 'as_param_8',
181
+
182
+ Param9: 'as_param_9',
183
+
184
+ Param10: 'as_param_10',
185
+
186
+ // ============ Ad revenue ============
187
+ // `logAdRevenue()` fills Revenue, Currency, AdRevenueSource and
188
+ // AdRevenueNetworkName from its own arguments and drops them from
189
+ // `additionalParameters`. The rest below are yours to pass.
190
+
191
+ AdRevenueSource: 'as_adrev_source',
192
+
193
+ AdRevenueNetworkName: 'as_adrev_network_name',
194
+
195
+ AdRevenueMediatedNetworkName: 'as_adrev_mediated_network_name',
196
+
197
+ AdRevenueAdType: 'as_adrev_ad_type',
198
+
199
+ AdRevenueAdSize: 'as_adrev_ad_size',
200
+
201
+ AdRevenuePlacementId: 'as_adrev_placement_id',
202
+
203
+ AdRevenueAdUnitId: 'as_adrev_ad_unit_id',
204
+
205
+ AdRevenuePrecision: 'as_adrev_precision',
206
+ } as const;
207
+
208
+ export type AdshiftEventParamValue =
209
+ (typeof AdshiftEventParam)[keyof typeof AdshiftEventParam];
210
+
211
+ /**
212
+ * Returns all standard parameter names as an array.
213
+ */
214
+ export function getAllEventParams(): AdshiftEventParamValue[] {
215
+ return Object.values(AdshiftEventParam);
216
+ }