@adjoe/react-native-adjoe-sdk 0.0.0-stage → 5.1.3

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 (45) hide show
  1. package/README.md +33 -2
  2. package/android/build.gradle +93 -0
  3. package/android/src/main/AndroidManifest.xml +11 -0
  4. package/android/src/main/java/io/adjoe/sdk/reactnative/BasicUtil.kt +361 -0
  5. package/android/src/main/java/io/adjoe/sdk/reactnative/ErrorsUtil.kt +113 -0
  6. package/android/src/main/java/io/adjoe/sdk/reactnative/PlaytimeProtectionImpl.kt +150 -0
  7. package/android/src/main/java/io/adjoe/sdk/reactnative/PlaytimeStudioImpl.kt +313 -0
  8. package/android/src/main/java/io/adjoe/sdk/reactnative/RNPlaytimeSdkImpl.kt +173 -0
  9. package/android/src/main/java/io/adjoe/sdk/reactnative/RNPlaytimeSdkPackage.kt +55 -0
  10. package/android/src/main/java/io/adjoe/sdk/reactnative/StudioUtil.kt +421 -0
  11. package/android/src/main/java/io/adjoe/sdk/reactnative/Util.kt +40 -0
  12. package/android/src/newarch/java/io/adjoe/sdk/reactnative/RNPlaytimeProtection.kt +25 -0
  13. package/android/src/newarch/java/io/adjoe/sdk/reactnative/RNPlaytimeSdkModule.kt +57 -0
  14. package/android/src/newarch/java/io/adjoe/sdk/reactnative/RNPlaytimeStudio.kt +66 -0
  15. package/android/src/oldarch/java/io/adjoe/sdk/reactnative/RNPlaytimeProtection.kt +29 -0
  16. package/android/src/oldarch/java/io/adjoe/sdk/reactnative/RNPlaytimeSdkModule.kt +68 -0
  17. package/android/src/oldarch/java/io/adjoe/sdk/reactnative/RNPlaytimeStudio.kt +83 -0
  18. package/ios/AdjoeSdk.xcodeproj/project.pbxproj +281 -0
  19. package/ios/AdjoeSdk.xcodeproj/xcuserdata/hamid.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
  20. package/ios/AdjoeSdk.xcworkspace/contents.xcworkspacedata +7 -0
  21. package/ios/ErrorsUtil.swift +180 -0
  22. package/ios/PlaytimeProtectionImpl.swift +20 -0
  23. package/ios/PlaytimeSdkImpl.swift +173 -0
  24. package/ios/PlaytimeStudioImpl.swift +272 -0
  25. package/ios/RNPlaytimeBasic.mm +187 -0
  26. package/ios/RNPlaytimeHelpers.h +21 -0
  27. package/ios/RNPlaytimeHelpers.m +94 -0
  28. package/ios/RNPlaytimeProtection.mm +77 -0
  29. package/ios/RNPlaytimeStudio.mm +265 -0
  30. package/package.json +35 -4
  31. package/react-native-adjoe-sdk.podspec +30 -0
  32. package/src/Playtime.js +158 -0
  33. package/src/PlaytimeException.js +140 -0
  34. package/src/PlaytimeProtection.js +40 -0
  35. package/src/PlaytimeStudio.js +110 -0
  36. package/src/index.js +8 -0
  37. package/src/specs/NativePlaytimeProtection.ts +9 -0
  38. package/src/specs/NativePlaytimeStudio.ts +23 -0
  39. package/src/specs/NativeRNPlaytimeSdk.ts +17 -0
  40. package/src-ts/Playtime.d.ts +407 -0
  41. package/src-ts/PlaytimeException.d.ts +87 -0
  42. package/src-ts/PlaytimeProtection.d.ts +106 -0
  43. package/src-ts/PlaytimeStudio.d.ts +818 -0
  44. package/src-ts/index.d.ts +8 -0
  45. package/tsconfig.json +114 -0
package/README.md CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
2
1
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
2
+ This project is the property of adjoe GmbH and is published for the sole use of entities with which adjoe has a contractual agreement.
3
+ The unauthorized redistribution of any or all parts of this project is strictly prohibited.
4
+
5
+ # Add React Native module to your project
6
+
7
+ To integrate the adjoe React Native module into your React Native project, follow these steps:
8
+
9
+ 1. Open your project's `package.json` file.
10
+
11
+ 2. Add the adjoe as a dependency under the `dependencies` section. You can change the version number to the desired version of adjoe SDK you want to integrate.
12
+
13
+ ```yaml
14
+ dependencies: {
15
+ "react-native-adjoe-sdk": "https://github.com/adjoeio/adjoe-react-native-sdk#v5.1.3"
16
+ }
17
+
18
+ ```
19
+ 3. Open your `build.gradle` file in android folder and add the following section:
20
+
21
+ ```yaml
22
+ allprojects {
23
+ repositories {
24
+ maven {
25
+ url "https://releases.adjoe.io/maven"
26
+ }
27
+ }
28
+ }
29
+ ```
30
+
31
+ 4. Run the following command:
32
+ ```
33
+ npm install
34
+ ```
@@ -0,0 +1,93 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = { name, fallback ->
3
+ rootProject.ext.has(name) ? rootProject.ext.get(name) : fallback
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.1.1"
13
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion', '1.9.24')}"
14
+ }
15
+ }
16
+
17
+ def isNewArchitectureEnabled() {
18
+ return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
19
+ }
20
+
21
+ apply plugin: 'com.android.library'
22
+ apply plugin: 'org.jetbrains.kotlin.android'
23
+
24
+ apply plugin: 'com.facebook.react'
25
+
26
+ def safeExtGet(prop, fallback) {
27
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
28
+ }
29
+
30
+ android {
31
+ namespace "io.adjoe.sdk.reactnative"
32
+ compileSdk safeExtGet('compileSdkVersion', 35)
33
+
34
+ defaultConfig {
35
+ minSdk safeExtGet('minSdkVersion', 24)
36
+ targetSdk safeExtGet('targetSdkVersion', 35)
37
+
38
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
39
+ }
40
+
41
+ buildFeatures {
42
+ buildConfig true
43
+ }
44
+
45
+ compileOptions {
46
+ sourceCompatibility JavaVersion.VERSION_17
47
+ targetCompatibility JavaVersion.VERSION_17
48
+ }
49
+
50
+ kotlinOptions {
51
+ jvmTarget = "17"
52
+ }
53
+
54
+ lintOptions {
55
+ abortOnError false
56
+ }
57
+
58
+ sourceSets {
59
+ main {
60
+ if (isNewArchitectureEnabled()) {
61
+ java.srcDirs += [
62
+ "src/newarch/java",
63
+ "generated/java",
64
+ "generated/jni"
65
+ ]
66
+ } else {
67
+ java.srcDirs += [
68
+ "src/oldarch/java"
69
+ ]
70
+ }
71
+ }
72
+ }
73
+ }
74
+
75
+ react {
76
+ jsRootDir = file("../src/specs")
77
+ libraryName = "RNPlaytimeSdkSpec"
78
+ codegenJavaPackageName = "io.adjoe.sdk.reactnative"
79
+ }
80
+
81
+ repositories {
82
+ mavenCentral()
83
+ maven {
84
+ url "https://releases.adjoe.io/maven"
85
+ }
86
+ google()
87
+ }
88
+
89
+ dependencies {
90
+ implementation "com.facebook.react:react-android"
91
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:${getExtOrDefault('kotlinVersion', '1.9.24')}"
92
+ implementation 'io.adjoe:adjoe-sdk-android:5.1.3'
93
+ }
@@ -0,0 +1,11 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ xmlns:tools="http://schemas.android.com/tools">
3
+
4
+ <application>
5
+ <meta-data
6
+ android:name="wrapper"
7
+ android:value="RN"
8
+ tools:replace="android:value" />
9
+ </application>
10
+
11
+ </manifest>
@@ -0,0 +1,361 @@
1
+ package io.adjoe.sdk.reactnative
2
+
3
+ import android.os.Build
4
+ import android.text.TextUtils
5
+
6
+ import com.facebook.react.bridge.Arguments
7
+ import com.facebook.react.bridge.ReadableMap
8
+ import com.facebook.react.bridge.WritableArray
9
+ import com.facebook.react.bridge.WritableMap
10
+
11
+ import java.text.SimpleDateFormat
12
+ import java.time.Instant
13
+ import java.time.LocalDate
14
+ import java.time.OffsetDateTime
15
+ import java.time.ZoneOffset
16
+ import java.time.format.DateTimeFormatter
17
+ import java.util.Date
18
+ import java.util.Locale
19
+ import java.util.TimeZone
20
+
21
+ import io.adjoe.sdk.PlaytimeStatus
22
+ import io.adjoe.sdk.PlaytimeStatusDetails
23
+ import io.adjoe.sdk.PlaytimeExtensions
24
+ import io.adjoe.sdk.PlaytimeGender
25
+ import io.adjoe.sdk.PlaytimeUserProfile
26
+ import io.adjoe.sdk.PlaytimeCampaignsState
27
+ import io.adjoe.sdk.PlaytimeMetadata
28
+ import io.adjoe.sdk.PlaytimeEvent
29
+ import io.adjoe.sdk.InitOptions
30
+ import io.adjoe.sdk.CatalogOptions
31
+ import io.adjoe.sdk.CatalogPlacement
32
+ import io.adjoe.sdk.AppCategory
33
+
34
+ /**
35
+ * Helper for constructing SDK model objects from [ReadableMap]s and
36
+ * converting SDK status objects back into RN maps. Migrated from the
37
+ * original inner `BasicUtil` Java class.
38
+ */
39
+ object BasicUtil {
40
+
41
+ private fun genderToInt(gender: PlaytimeGender?): Int? {
42
+ return when (gender) {
43
+ PlaytimeGender.MALE -> 0
44
+ PlaytimeGender.FEMALE -> 1
45
+ PlaytimeGender.UNKNOWN -> 2
46
+ else -> null
47
+ }
48
+ }
49
+
50
+ private fun genderFromInt(value: Int?): PlaytimeGender? {
51
+ return when (value) {
52
+ 0 -> PlaytimeGender.MALE
53
+ 1 -> PlaytimeGender.FEMALE
54
+ 2 -> PlaytimeGender.UNKNOWN
55
+ else -> null
56
+ }
57
+ }
58
+
59
+ /**
60
+ * Reads an optional string for the given key, or null when absent.
61
+ */
62
+ private fun optString(map: ReadableMap?, key: String): String? {
63
+ if (map == null || !map.hasKey(key) || map.isNull(key)) return null
64
+ return map.getString(key)
65
+ }
66
+
67
+ /**
68
+ * Reads an optional nested map for the given key, or null when absent.
69
+ */
70
+ private fun optMap(map: ReadableMap?, key: String): ReadableMap? {
71
+ if (map == null || !map.hasKey(key) || map.isNull(key)) return null
72
+ return map.getMap(key)
73
+ }
74
+
75
+ /**
76
+ * Reads the `value` string of a sealed value map, or null when absent.
77
+ */
78
+ private fun sealedValueOf(map: ReadableMap?): String? {
79
+ if (map == null || !map.hasKey(JsonKey.VALUE)) return null
80
+ return map.getString(JsonKey.VALUE)
81
+ }
82
+
83
+ /**
84
+ * Whether a sealed value map is explicitly flagged as a publisher-supplied value.
85
+ */
86
+ private fun isSealedValueCustom(map: ReadableMap?): Boolean {
87
+ if (map == null || !map.hasKey(JsonKey.IS_CUSTOM)) return false
88
+ return map.getBoolean(JsonKey.IS_CUSTOM)
89
+ }
90
+
91
+ /**
92
+ * Reads a nested sealed value map (`{ value, isCustom }`) for the given key.
93
+ */
94
+ private fun sealedMap(map: ReadableMap?, key: String): ReadableMap? {
95
+ if (map == null || !map.hasKey(key)) return null
96
+ return map.getMap(key)
97
+ }
98
+
99
+ private fun catalogPlacementFrom(map: ReadableMap?): CatalogPlacement? {
100
+ val value = sealedValueOf(map) ?: return null
101
+ if (isSealedValueCustom(map)) return CatalogPlacement.Custom(value)
102
+ return when (value) {
103
+ "navbar" -> CatalogPlacement.Navbar
104
+ "icon" -> CatalogPlacement.Icon
105
+ "earn_tab" -> CatalogPlacement.EarnTab
106
+ "game_tab" -> CatalogPlacement.GameTab
107
+ "home_page" -> CatalogPlacement.HomePage
108
+ "notification_inbox" -> CatalogPlacement.NotificationInbox
109
+ "notification" -> CatalogPlacement.Notification
110
+ "mini_game" -> CatalogPlacement.MiniGame
111
+ "order_page" -> CatalogPlacement.OrderPage
112
+ "redeem_section" -> CatalogPlacement.RedeemSection
113
+ "scan_receipt" -> CatalogPlacement.ScanReceipt
114
+ "step_converter" -> CatalogPlacement.StepConverter
115
+ // A predefined value this wrapper version does not know yet: forward it
116
+ // verbatim instead of dropping it.
117
+ else -> CatalogPlacement.Custom(value)
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Builds a [CatalogPlacement] from the raw sealed value map passed by JavaScript.
123
+ */
124
+ fun constructCatalogPlacementFrom(map: ReadableMap?): CatalogPlacement? {
125
+ return catalogPlacementFrom(map)
126
+ }
127
+
128
+ private fun appCategoryFrom(map: ReadableMap?): AppCategory {
129
+ // AppCategory supports no custom values, so an absent or unrecognized value
130
+ // falls back to the schema default and `isCustom` is ignored entirely.
131
+ return when (sealedValueOf(map)) {
132
+ "gaming" -> AppCategory.GAMING
133
+ "non-gaming" -> AppCategory.NON_GAMING
134
+ "both" -> AppCategory.BOTH
135
+ else -> AppCategory.GAMING
136
+ }
137
+ }
138
+
139
+ fun constructPlaytimeExtensionsFrom(extensionMap: ReadableMap?): PlaytimeExtensions {
140
+ val extensions = PlaytimeExtensions.Builder()
141
+ if (extensionMap == null) return extensions.build()
142
+ return extensions
143
+ .setSubId1(optString(extensionMap, JsonKey.SUB_ID_1))
144
+ .setSubId2(optString(extensionMap, JsonKey.SUB_ID_2))
145
+ .setSubId3(optString(extensionMap, JsonKey.SUB_ID_3))
146
+ .setSubId4(optString(extensionMap, JsonKey.SUB_ID_4))
147
+ .setSubId5(optString(extensionMap, JsonKey.SUB_ID_5))
148
+ .build()
149
+ }
150
+
151
+ fun constructPlaytimeMetadataFrom(metadataMap: ReadableMap?): PlaytimeMetadata? {
152
+ if (metadataMap == null) return null
153
+ return PlaytimeMetadata(
154
+ metadata1 = optString(metadataMap, JsonKey.METADATA_1),
155
+ metadata2 = optString(metadataMap, JsonKey.METADATA_2),
156
+ )
157
+ }
158
+
159
+ /**
160
+ * Parses the ISO 8601 `birthday` string sent by JavaScript into a [Date].
161
+ *
162
+ * JS has no date type on the bridge, so the value arrives as a string (typically from
163
+ * `Date.prototype.toISOString()`) while the SDK models it as a [Date]. Accepts the
164
+ * fractional-seconds form (`2002-12-02T00:00:00.000Z`), the plain form
165
+ * (`2002-12-02T00:00:00Z`), an explicit UTC offset, and a bare calendar date
166
+ * (`2002-12-02`). An unparseable value yields null rather than throwing, so a bad
167
+ * birthday never fails initialization.
168
+ */
169
+ private fun parseBirthday(value: String?): Date? {
170
+ if (value == null || TextUtils.isEmpty(value)) return null
171
+
172
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
173
+ // Instant.parse only accepts an instant with a zone designator, so fall back to
174
+ // the offset and local-date forms before giving up.
175
+ try {
176
+ return Date.from(Instant.parse(value))
177
+ } catch (e: Exception) {
178
+ // Not an instant; try the remaining representations below.
179
+ }
180
+ try {
181
+ return Date.from(OffsetDateTime.parse(value).toInstant())
182
+ } catch (e: Exception) {
183
+ // Not an offset date time either.
184
+ }
185
+ try {
186
+ return Date.from(LocalDate.parse(value).atStartOfDay(ZoneOffset.UTC).toInstant())
187
+ } catch (e: Exception) {
188
+ return null
189
+ }
190
+ }
191
+
192
+ for (pattern in arrayOf(
193
+ "yyyy-MM-dd'T'HH:mm:ss.SSSX",
194
+ "yyyy-MM-dd'T'HH:mm:ssX",
195
+ "yyyy-MM-dd",
196
+ )) {
197
+ try {
198
+ val sdf = SimpleDateFormat(pattern, Locale.US)
199
+ sdf.timeZone = TimeZone.getTimeZone("UTC")
200
+ sdf.isLenient = false
201
+ return sdf.parse(value)
202
+ } catch (e: Exception) {
203
+ // Try the next pattern.
204
+ }
205
+ }
206
+ return null
207
+ }
208
+
209
+ /**
210
+ * Formats a native [Date] as an ISO 8601 UTC string, the representation used for
211
+ * date values crossing the TurboModule bridge.
212
+ */
213
+ private fun isoStringFrom(date: Date?): String? {
214
+ if (date == null) return null
215
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
216
+ try {
217
+ return DateTimeFormatter.ISO_INSTANT.format(date.toInstant())
218
+ } catch (e: Exception) {
219
+ // Fall through to the SimpleDateFormat based formatting below.
220
+ }
221
+ }
222
+ return try {
223
+ val sdf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US)
224
+ sdf.timeZone = TimeZone.getTimeZone("UTC")
225
+ sdf.format(date)
226
+ } catch (e: Exception) {
227
+ null
228
+ }
229
+ }
230
+
231
+ fun constructPlaytimeUserProfileFrom(userProfileMap: ReadableMap?): PlaytimeUserProfile? {
232
+ if (userProfileMap == null) return null
233
+
234
+ val playtimeGender = if (userProfileMap.hasKey(JsonKey.GENDER) && !userProfileMap.isNull(JsonKey.GENDER)) {
235
+ genderFromInt(userProfileMap.getInt(JsonKey.GENDER)) ?: PlaytimeGender.UNKNOWN
236
+ } else {
237
+ PlaytimeGender.UNKNOWN
238
+ }
239
+
240
+ val birthday = parseBirthday(optString(userProfileMap, JsonKey.BIRTHDAY))
241
+ return PlaytimeUserProfile(playtimeGender, birthday)
242
+ }
243
+
244
+ fun constructInitOptionsFrom(optionsMap: ReadableMap?): InitOptions {
245
+ val sdkHash = optString(optionsMap, JsonKey.SDK_HASH) ?: ""
246
+ return InitOptions(
247
+ sdkHash = sdkHash,
248
+ userId = optString(optionsMap, JsonKey.USER_ID),
249
+ userProfile = constructPlaytimeUserProfileFrom(optMap(optionsMap, JsonKey.USER_PROFILE)),
250
+ extensions = constructPlaytimeExtensionsFrom(optMap(optionsMap, JsonKey.EXTENSIONS)),
251
+ language = optString(optionsMap, JsonKey.LANGUAGE),
252
+ uaNetwork = optString(optionsMap, JsonKey.UA_NETWORK),
253
+ uaChannel = optString(optionsMap, JsonKey.UA_CHANNEL),
254
+ uaCampaignName = optString(optionsMap, JsonKey.UA_CAMPAIGN_NAME),
255
+ country = optString(optionsMap, JsonKey.COUNTRY),
256
+ )
257
+ }
258
+
259
+ fun constructCatalogOptionsFrom(map: ReadableMap?): CatalogOptions {
260
+ return CatalogOptions(
261
+ placement = catalogPlacementFrom(sealedMap(map, JsonKey.PLACEMENT)),
262
+ category = appCategoryFrom(sealedMap(map, JsonKey.CATEGORY)),
263
+ promotionTag = optString(map, JsonKey.PROMOTION_TAG),
264
+ metadata = constructPlaytimeMetadataFrom(optMap(map, JsonKey.METADATA)),
265
+ )
266
+ }
267
+
268
+ fun playtimeEventToReadableMap(event: PlaytimeEvent?): ReadableMap? {
269
+ if (event == null) return null
270
+ val eventMap = Arguments.createMap()
271
+ eventMap.putString(JsonKey.NAME, event.name)
272
+ eventMap.putString(JsonKey.OCCURRED_AT, isoStringFrom(event.occurredAt))
273
+ return eventMap
274
+ }
275
+
276
+ fun statusToReadableMap(status: PlaytimeStatus): ReadableMap {
277
+ val statusMap = Arguments.createMap()
278
+ statusMap.putString(JsonKey.VERSION, status.version)
279
+ statusMap.putBoolean(JsonKey.IS_INITIALIZED, status.isInitialized)
280
+ statusMap.putString(JsonKey.USER_ID, status.userId)
281
+ statusMap.putBoolean(JsonKey.IS_TOS_ACCEPTED, status.isTosAccepted)
282
+ statusMap.putMap(JsonKey.DETAILS, statusDetailsToReadableMap(status.details))
283
+ statusMap.putBoolean(JsonKey.IS_USAGE_PERMISSION_ACCEPTED, status.isUsagePermissionAccepted)
284
+ return statusMap
285
+ }
286
+
287
+ private fun campaignsStateToInt(state: PlaytimeCampaignsState): Int {
288
+ return when (state) {
289
+ PlaytimeCampaignsState.READY -> 0
290
+ PlaytimeCampaignsState.BLOCKED -> 1
291
+ PlaytimeCampaignsState.VPN_DETECTED -> 2
292
+ PlaytimeCampaignsState.GEO_MISMATCH -> 3
293
+ PlaytimeCampaignsState.NOT_INITIALIZED -> 4
294
+ }
295
+ }
296
+
297
+ private fun campaignsStateToArray(campaignStates: List<PlaytimeCampaignsState>?): WritableArray {
298
+ val array = Arguments.createArray()
299
+ if (campaignStates != null) {
300
+ for (state in campaignStates) {
301
+ array.pushInt(campaignsStateToInt(state))
302
+ }
303
+ }
304
+ return array
305
+ }
306
+
307
+ fun statusDetailsToReadableMap(details: PlaytimeStatusDetails): ReadableMap {
308
+ val detailsMap = Arguments.createMap()
309
+ detailsMap.putBoolean(JsonKey.IS_FRAUD, details.isFraud)
310
+ detailsMap.putBoolean(JsonKey.CAMPAIGNS_AVAILABLE, details.campaignsAvailable)
311
+ detailsMap.putArray(JsonKey.CAMPAIGNS_STATE, campaignsStateToArray(details.campaignsState))
312
+ detailsMap.putIntOrNull(details.testGroup, JsonKey.TEST_GROUP)
313
+ return detailsMap
314
+ }
315
+
316
+ object JsonKey {
317
+ const val VERSION = "version"
318
+ const val IS_INITIALIZED = "isInitialized"
319
+ const val USER_ID = "userId"
320
+ const val IS_TOS_ACCEPTED = "isTosAccepted"
321
+ const val IS_USAGE_PERMISSION_ACCEPTED = "isUsagePermissionAccepted"
322
+ const val DETAILS = "details"
323
+ const val IS_FRAUD = "isFraud"
324
+ const val CAMPAIGNS_AVAILABLE = "campaignsAvailable"
325
+ const val CAMPAIGNS_STATE = "campaignsState"
326
+ const val TEST_GROUP = "testGroup"
327
+
328
+ const val SDK_HASH = "sdkHash"
329
+ const val USER_PROFILE = "userProfile"
330
+ const val EXTENSIONS = "extensions"
331
+ const val LANGUAGE = "language"
332
+
333
+ const val GENDER = "gender"
334
+ const val BIRTHDAY = "birthday"
335
+
336
+ const val NAME = "name"
337
+ const val OCCURRED_AT = "occurredAt"
338
+
339
+ const val SUB_ID_1 = "subId1"
340
+ const val SUB_ID_2 = "subId2"
341
+ const val SUB_ID_3 = "subId3"
342
+ const val SUB_ID_4 = "subId4"
343
+ const val SUB_ID_5 = "subId5"
344
+
345
+ const val METADATA = "metadata"
346
+ const val METADATA_1 = "metadata1"
347
+ const val METADATA_2 = "metadata2"
348
+
349
+ const val PLACEMENT = "placement"
350
+ const val CATEGORY = "category"
351
+ const val PROMOTION_TAG = "promotionTag"
352
+ const val UA_NETWORK = "uaNetwork"
353
+ const val UA_CHANNEL = "uaChannel"
354
+ const val UA_CAMPAIGN_NAME = "uaCampaignName"
355
+ const val COUNTRY = "country"
356
+
357
+ // Keys of a sealed value map, e.g. `{ "value": "icon", "isCustom": false }`.
358
+ const val VALUE = "value"
359
+ const val IS_CUSTOM = "isCustom"
360
+ }
361
+ }
@@ -0,0 +1,113 @@
1
+ package io.adjoe.sdk.reactnative
2
+
3
+ import com.facebook.react.bridge.Arguments
4
+ import com.facebook.react.bridge.Promise
5
+ import com.facebook.react.bridge.WritableMap
6
+ import io.adjoe.sdk.PlaytimeErrorType
7
+ import io.adjoe.sdk.PlaytimeException
8
+
9
+ object ErrorsUtil {
10
+
11
+ /** Keys used in the rejection `userInfo` payload. */
12
+ object UserInfoKey {
13
+ const val CODE = "code"
14
+ const val ERROR_TYPE = "errorType"
15
+ const val IS_RETRYABLE = "isRetryable"
16
+ }
17
+
18
+ /**
19
+ * Builds a generic error for a failed wrapper function.
20
+ *
21
+ * @param functionName the name of the bridge function that failed.
22
+ * @param reason an optional detail appended to the message.
23
+ */
24
+ fun getFunctionError(functionName: String, reason: String? = null): PlaytimeException {
25
+ if (reason.isNullOrEmpty()) {
26
+ return PlaytimeException(
27
+ message = "Error occurred during $functionName",
28
+ cause = null,
29
+ errorType = PlaytimeErrorType.UNKNOWN,
30
+ isRetryable = false
31
+ )
32
+ }
33
+
34
+ return PlaytimeException(
35
+ message = "Error occurred during $functionName: $reason",
36
+ cause = null,
37
+ errorType = PlaytimeErrorType.UNKNOWN,
38
+ isRetryable = false
39
+ )
40
+ }
41
+
42
+ /** The current activity was required but unavailable. */
43
+ fun getActivityIsNullError(): PlaytimeException {
44
+ return PlaytimeException(
45
+ message = "activity is null",
46
+ cause = null,
47
+ errorType = PlaytimeErrorType.UNKNOWN,
48
+ isRetryable = false
49
+ )
50
+ }
51
+
52
+ /** The campaign referenced by JS could not be resolved from the cache. */
53
+ fun campaignIsNullError(): PlaytimeException {
54
+ return PlaytimeException(
55
+ message = "campaign is null",
56
+ cause = null,
57
+ errorType = PlaytimeErrorType.UNKNOWN,
58
+ isRetryable = false
59
+ )
60
+ }
61
+
62
+ /**
63
+ * Coerces an arbitrary [Throwable] into a [PlaytimeException].
64
+ *
65
+ * If the throwable already is a [PlaytimeException] it is returned
66
+ * unchanged, which preserves the classification (`errorType`,
67
+ * `isRetryable`, `code`) produced by the native SDK. This matters because
68
+ * `PlaytimeResponseError.getError()` is statically typed as
69
+ * `java.lang.Exception`, so the concrete type is only known at runtime.
70
+ */
71
+ fun toPlaytimeException(throwable: Throwable?): PlaytimeException {
72
+ if (throwable is PlaytimeException) {
73
+ return throwable
74
+ }
75
+
76
+ return PlaytimeException(
77
+ message = throwable?.message ?: "Unknown error occurred",
78
+ cause = throwable,
79
+ errorType = PlaytimeErrorType.UNKNOWN,
80
+ isRetryable = false
81
+ )
82
+ }
83
+
84
+ /** Serializes the structured error fields into the rejection `userInfo`. */
85
+ fun toUserInfo(exception: PlaytimeException): WritableMap {
86
+ val userInfo = Arguments.createMap()
87
+
88
+ if (exception.code.isNullOrEmpty()) {
89
+ userInfo.putNull(UserInfoKey.CODE)
90
+ } else {
91
+ userInfo.putString(UserInfoKey.CODE, exception.code)
92
+ }
93
+ userInfo.putString(UserInfoKey.ERROR_TYPE, exception.errorType.name)
94
+ userInfo.putBoolean(UserInfoKey.IS_RETRYABLE, exception.isRetryable)
95
+
96
+ return userInfo
97
+ }
98
+
99
+ /** Rejects [promise] with the structured representation of [exception]. */
100
+ fun reject(promise: Promise, exception: PlaytimeException) {
101
+ promise.reject(
102
+ exception.errorType.name,
103
+ exception.message,
104
+ exception,
105
+ toUserInfo(exception)
106
+ )
107
+ }
108
+
109
+ /** Convenience: coerce any throwable and reject with it. */
110
+ fun reject(promise: Promise, throwable: Throwable?) {
111
+ reject(promise, toPlaytimeException(throwable))
112
+ }
113
+ }