@rovenue/react-native-sdk 0.24.0 → 0.27.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.
- package/android/src/main/java/dev/rovenue/sdkrn/FunnelCheckRequests.kt +78 -0
- package/android/src/main/java/dev/rovenue/sdkrn/RovenueFunnelExpoView.kt +22 -1
- package/android/src/main/java/dev/rovenue/sdkrn/RovenueModule.kt +38 -8
- package/dist/chunk-D2LZIJZP.js +7 -0
- package/dist/{chunk-ETC46J2X.js.map → chunk-D2LZIJZP.js.map} +1 -1
- package/dist/index.cjs +81 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +123 -10
- package/dist/index.d.ts +123 -10
- package/dist/index.js +80 -9
- package/dist/index.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.mts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/ios/RovenueFunnelExpoView.swift +22 -1
- package/ios/RovenueModule.swift +118 -10
- package/package.json +1 -1
- package/dist/chunk-ETC46J2X.js +0 -7
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
package dev.rovenue.sdkrn
|
|
2
|
+
|
|
3
|
+
import dev.rovenue.sdk.funnelui.FunnelCheckRequest
|
|
4
|
+
import dev.rovenue.sdk.funnelui.FunnelPhotoRef
|
|
5
|
+
import dev.rovenue.sdk.generated.FunnelCheckOutcome
|
|
6
|
+
import java.util.concurrent.ConcurrentHashMap
|
|
7
|
+
import java.util.concurrent.atomic.AtomicLong
|
|
8
|
+
import kotlin.coroutines.resume
|
|
9
|
+
import kotlinx.coroutines.CancellableContinuation
|
|
10
|
+
import kotlinx.coroutines.suspendCancellableCoroutine
|
|
11
|
+
import org.json.JSONObject
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Photo check requests a funnel (presented, or a funnel view) is waiting on,
|
|
15
|
+
* answered from JS by `resolveFunnelCheckRequest`. Shared by the module and
|
|
16
|
+
* every view: the answer arrives through the module whichever emitted it.
|
|
17
|
+
*
|
|
18
|
+
* The façade bounds the wait by the check's `timeoutMs` and then cancels the
|
|
19
|
+
* handler's coroutine; cancellation drops the entry here, so a JS side that
|
|
20
|
+
* never answers leaks nothing, and its late answer finds no entry and is
|
|
21
|
+
* ignored.
|
|
22
|
+
*/
|
|
23
|
+
internal object FunnelCheckRequests {
|
|
24
|
+
private val pending = ConcurrentHashMap<String, CancellableContinuation<FunnelCheckOutcome?>>()
|
|
25
|
+
private val serial = AtomicLong()
|
|
26
|
+
|
|
27
|
+
/** Emits a request through [send] and suspends until JS answers or the façade cancels the wait. */
|
|
28
|
+
suspend fun ask(send: (requestId: String) -> Unit): FunnelCheckOutcome? {
|
|
29
|
+
val requestId = "c${serial.incrementAndGet()}"
|
|
30
|
+
return suspendCancellableCoroutine { continuation ->
|
|
31
|
+
pending[requestId] = continuation
|
|
32
|
+
continuation.invokeOnCancellation { pending.remove(requestId) }
|
|
33
|
+
send(requestId)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fun resolve(requestId: String, outcome: FunnelCheckOutcome?) {
|
|
38
|
+
val continuation = pending.remove(requestId) ?: return
|
|
39
|
+
if (continuation.isActive) continuation.resume(outcome)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* JS's `{result,label?,reason?,steps}`; null (the check's
|
|
44
|
+
* `whenUnavailable`) for null or anything without a string `result`.
|
|
45
|
+
*/
|
|
46
|
+
fun outcome(json: String?): FunnelCheckOutcome? {
|
|
47
|
+
val o = json?.let { runCatching { JSONObject(it) }.getOrNull() } ?: return null
|
|
48
|
+
val result = o.opt("result") as? String ?: return null
|
|
49
|
+
val steps = buildMap {
|
|
50
|
+
val s = o.optJSONObject("steps")
|
|
51
|
+
s?.keys()?.forEach { id -> (s.opt(id) as? String)?.let { put(id, it) } }
|
|
52
|
+
}
|
|
53
|
+
return FunnelCheckOutcome(
|
|
54
|
+
result = result,
|
|
55
|
+
label = o.opt("label") as? String,
|
|
56
|
+
reason = o.opt("reason") as? String,
|
|
57
|
+
steps = steps,
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A photo as JS's `FunnelPhotoRef` reads it (numbers as JS numbers). */
|
|
62
|
+
fun photoDto(photo: FunnelPhotoRef): Map<String, Any> = mapOf(
|
|
63
|
+
"localUri" to photo.localUri,
|
|
64
|
+
"width" to photo.width,
|
|
65
|
+
"height" to photo.height,
|
|
66
|
+
"byteSize" to photo.byteSize.toDouble(),
|
|
67
|
+
"mimeType" to photo.mimeType,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
/** A check request as JS's `FunnelCheckRequest` reads it. */
|
|
71
|
+
fun requestDto(request: FunnelCheckRequest): Map<String, Any> = mapOf(
|
|
72
|
+
"checkKey" to request.checkKey,
|
|
73
|
+
"steps" to request.steps,
|
|
74
|
+
"photo" to photoDto(request.photo),
|
|
75
|
+
"locale" to request.locale,
|
|
76
|
+
"attempt" to request.attempt,
|
|
77
|
+
)
|
|
78
|
+
}
|
|
@@ -62,11 +62,19 @@ class RovenueFunnelExpoView(context: Context, appContext: AppContext) :
|
|
|
62
62
|
private val onCustomActionRequested by EventDispatcher<Map<String, Any>>()
|
|
63
63
|
private val onPurchaseRequested by EventDispatcher<Map<String, Any>>()
|
|
64
64
|
private val onRestoreRequested by EventDispatcher<Map<String, Any>>()
|
|
65
|
+
private val onPhotoSelectedEvent by EventDispatcher<Map<String, Any>>()
|
|
66
|
+
private val onCheckRequested by EventDispatcher<Map<String, Any>>()
|
|
65
67
|
|
|
66
68
|
var funnelIdentifier: String? = null
|
|
67
69
|
var locale: String? = null
|
|
68
70
|
var hasUrlHandler: Boolean = false
|
|
69
71
|
|
|
72
|
+
/** Whether JS passed `onCheck`. Without one no handler is installed, so the façade applies a check's `whenUnavailable` at once. */
|
|
73
|
+
var hasCheckHandler: Boolean = false
|
|
74
|
+
|
|
75
|
+
/** The host's values for the funnel's externals; a change resolves again (they are part of the placement key). */
|
|
76
|
+
var values: Map<String, String> = emptyMap()
|
|
77
|
+
|
|
70
78
|
// ONE instance for this view's lifetime.
|
|
71
79
|
private val inner = RovenueFunnelView(context)
|
|
72
80
|
|
|
@@ -77,7 +85,7 @@ class RovenueFunnelExpoView(context: Context, appContext: AppContext) :
|
|
|
77
85
|
fun onViewDidUpdateProps() {
|
|
78
86
|
// An empty identifier is still handed over: the view reports it as
|
|
79
87
|
// `onUnavailable(empty_placement_id)` and draws nothing.
|
|
80
|
-
inner.setPlacement(funnelIdentifier ?: "", locale, handlers())
|
|
88
|
+
inner.setPlacement(funnelIdentifier ?: "", locale, handlers(), values)
|
|
81
89
|
}
|
|
82
90
|
|
|
83
91
|
private fun handlers() = FunnelHostHandlers(
|
|
@@ -134,6 +142,19 @@ class RovenueFunnelExpoView(context: Context, appContext: AppContext) :
|
|
|
134
142
|
},
|
|
135
143
|
onCompleted = { onFunnelCompleted(emptyMap()) },
|
|
136
144
|
onDismissed = { onFunnelDismissed(emptyMap()) },
|
|
145
|
+
onPhotoSelected = { key, photo ->
|
|
146
|
+
onPhotoSelectedEvent(mapOf("questionKey" to key, "photo" to FunnelCheckRequests.photoDto(photo)))
|
|
147
|
+
},
|
|
148
|
+
onCheck = if (hasCheckHandler) {
|
|
149
|
+
{ request ->
|
|
150
|
+
// The façade calls this off the main thread; events go out on it.
|
|
151
|
+
FunnelCheckRequests.ask { id ->
|
|
152
|
+
post { onCheckRequested(mapOf("requestId" to id, "request" to FunnelCheckRequests.requestDto(request))) }
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
null
|
|
157
|
+
},
|
|
137
158
|
)
|
|
138
159
|
|
|
139
160
|
private fun report(e: Throwable) {
|
|
@@ -146,6 +146,8 @@ class RovenueModule : Module() {
|
|
|
146
146
|
"onCustomActionRequested",
|
|
147
147
|
"onPurchaseRequested",
|
|
148
148
|
"onRestoreRequested",
|
|
149
|
+
"onPhotoSelectedEvent",
|
|
150
|
+
"onCheckRequested",
|
|
149
151
|
)
|
|
150
152
|
Prop("funnelIdentifier") { view: RovenueFunnelExpoView, value: String? ->
|
|
151
153
|
view.funnelIdentifier = value
|
|
@@ -156,6 +158,12 @@ class RovenueModule : Module() {
|
|
|
156
158
|
Prop("hasUrlHandler") { view: RovenueFunnelExpoView, value: Boolean ->
|
|
157
159
|
view.hasUrlHandler = value
|
|
158
160
|
}
|
|
161
|
+
Prop("hasCheckHandler") { view: RovenueFunnelExpoView, value: Boolean ->
|
|
162
|
+
view.hasCheckHandler = value
|
|
163
|
+
}
|
|
164
|
+
Prop("values") { view: RovenueFunnelExpoView, value: Map<String, String>? ->
|
|
165
|
+
view.values = value ?: emptyMap()
|
|
166
|
+
}
|
|
159
167
|
OnViewDidUpdateProps { view: RovenueFunnelExpoView ->
|
|
160
168
|
view.onViewDidUpdateProps()
|
|
161
169
|
}
|
|
@@ -175,8 +183,8 @@ class RovenueModule : Module() {
|
|
|
175
183
|
val u = Rovenue.shared.currentUser()
|
|
176
184
|
mapOf("rovenueId" to u.rovenueId, "appUserId" to u.appUserId)
|
|
177
185
|
}
|
|
178
|
-
AsyncFunction("identify") Coroutine { appUserId: String ->
|
|
179
|
-
try { Rovenue.shared.identify(appUserId) } catch (e: Throwable) { throw codedError(e) }
|
|
186
|
+
AsyncFunction("identify") Coroutine { appUserId: String, identityToken: String ->
|
|
187
|
+
try { Rovenue.shared.identify(appUserId, identityToken) } catch (e: Throwable) { throw codedError(e) }
|
|
180
188
|
}
|
|
181
189
|
// Returns at once on Android: the façade posts in the background and
|
|
182
190
|
// logs a failure rather than throwing.
|
|
@@ -257,18 +265,25 @@ class RovenueModule : Module() {
|
|
|
257
265
|
AsyncFunction("preloadPlacement") Coroutine { placementId: String, locale: String? ->
|
|
258
266
|
Rovenue.shared.preloadPlacement(placementId, locale)
|
|
259
267
|
}
|
|
260
|
-
AsyncFunction("presentFunnel") Coroutine { presentationId: String, placement: String, locale: String?, styleJson: String?, callbacks: Map<String, Boolean
|
|
268
|
+
AsyncFunction("presentFunnel") Coroutine { presentationId: String, placement: String, locale: String?, styleJson: String?, callbacks: Map<String, Boolean>, values: Map<String, String>? ->
|
|
261
269
|
val activity = appContext.currentActivity
|
|
262
270
|
if (activity == null) {
|
|
263
271
|
mapOf("result" to "unavailable", "purchased" to false, "reason" to FunnelPresentResult.NO_PRESENTER)
|
|
264
272
|
} else {
|
|
265
|
-
presentFunnelFrom(activity, presentationId, placement, locale, styleJson, callbacks)
|
|
273
|
+
presentFunnelFrom(activity, presentationId, placement, locale, styleJson, callbacks, values ?: emptyMap())
|
|
266
274
|
}
|
|
267
275
|
}
|
|
268
276
|
AsyncFunction("resolveFunnelPurchaseRequest") { requestId: String, purchased: Boolean ->
|
|
269
277
|
funnelPurchaseRequests.remove(requestId)?.complete(purchased)
|
|
270
278
|
Unit
|
|
271
279
|
}
|
|
280
|
+
AsyncFunction("resolveFunnelCheckRequest") { requestId: String, outcomeJson: String? ->
|
|
281
|
+
FunnelCheckRequests.resolve(requestId, FunnelCheckRequests.outcome(outcomeJson))
|
|
282
|
+
Unit
|
|
283
|
+
}
|
|
284
|
+
AsyncFunction("releasePhoto") { localUri: String ->
|
|
285
|
+
Rovenue.releasePhoto(localUri)
|
|
286
|
+
}
|
|
272
287
|
AsyncFunction("purchase") Coroutine { productId: String, productType: String, promotionalOfferId: String?, basePlanId: String?, offerId: String? ->
|
|
273
288
|
// promotionalOfferId is iOS-only (ignored here). basePlanId/offerId select a Play subscription offer.
|
|
274
289
|
// Play Billing needs the foreground Activity to launch the flow.
|
|
@@ -360,13 +375,13 @@ class RovenueModule : Module() {
|
|
|
360
375
|
AsyncFunction("claimFunnelToken") Coroutine { token: String ->
|
|
361
376
|
try {
|
|
362
377
|
val r = Rovenue.shared.claimFunnelToken(token)
|
|
363
|
-
mapOf("subscriberId" to r.subscriberId, "funnelAnswersJson" to r.funnelAnswersJson)
|
|
378
|
+
mapOf("subscriberId" to r.subscriberId, "funnelAnswersJson" to r.funnelAnswersJson, "funnelPreselectedJson" to r.funnelPreselectedJson)
|
|
364
379
|
} catch (e: Throwable) { throw codedError(e) }
|
|
365
380
|
}
|
|
366
381
|
AsyncFunction("claimFromClipboard") Coroutine { ->
|
|
367
382
|
try {
|
|
368
383
|
val r = Rovenue.shared.claimFromClipboard() ?: return@Coroutine null
|
|
369
|
-
mapOf("subscriberId" to r.subscriberId, "funnelAnswersJson" to r.funnelAnswersJson)
|
|
384
|
+
mapOf("subscriberId" to r.subscriberId, "funnelAnswersJson" to r.funnelAnswersJson, "funnelPreselectedJson" to r.funnelPreselectedJson)
|
|
370
385
|
} catch (e: Throwable) { throw codedError(e) }
|
|
371
386
|
}
|
|
372
387
|
AsyncFunction("claimInstall") Coroutine { params: Map<String, Any?> ->
|
|
@@ -382,7 +397,7 @@ class RovenueModule : Module() {
|
|
|
382
397
|
)
|
|
383
398
|
try {
|
|
384
399
|
val r = Rovenue.shared.claimInstall(p) ?: return@Coroutine null
|
|
385
|
-
mapOf("subscriberId" to r.subscriberId, "funnelAnswersJson" to r.funnelAnswersJson)
|
|
400
|
+
mapOf("subscriberId" to r.subscriberId, "funnelAnswersJson" to r.funnelAnswersJson, "funnelPreselectedJson" to r.funnelPreselectedJson)
|
|
386
401
|
} catch (e: Throwable) { throw codedError(e) }
|
|
387
402
|
}
|
|
388
403
|
AsyncFunction("claimViaEmail") Coroutine { email: String ->
|
|
@@ -403,6 +418,7 @@ class RovenueModule : Module() {
|
|
|
403
418
|
sendEvent("onFunnelClaimResolved", mapOf(
|
|
404
419
|
"subscriberId" to r.subscriberId,
|
|
405
420
|
"funnelAnswersJson" to r.funnelAnswersJson,
|
|
421
|
+
"funnelPreselectedJson" to r.funnelPreselectedJson,
|
|
406
422
|
))
|
|
407
423
|
}
|
|
408
424
|
}
|
|
@@ -445,6 +461,7 @@ class RovenueModule : Module() {
|
|
|
445
461
|
locale: String?,
|
|
446
462
|
styleJson: String?,
|
|
447
463
|
callbacks: Map<String, Boolean>,
|
|
464
|
+
values: Map<String, String>,
|
|
448
465
|
): Map<String, Any?> {
|
|
449
466
|
val emit: (Map<String, Any?>) -> Unit = { sendEvent("onFunnelPresentEvent", it + ("presentationId" to presentationId)) }
|
|
450
467
|
val handlers = FunnelPresentHandlers(
|
|
@@ -459,9 +476,21 @@ class RovenueModule : Module() {
|
|
|
459
476
|
onCustomAction = if (callbacks["onCustomAction"] == true) {
|
|
460
477
|
{ id, params -> emit(mapOf("type" to "customAction", "actionId" to id, "paramsJson" to params)) }
|
|
461
478
|
} else null,
|
|
479
|
+
onPhotoSelected = if (callbacks["onPhotoSelected"] == true) {
|
|
480
|
+
{ key, photo -> emit(mapOf("type" to "photoSelected", "questionKey" to key, "photo" to FunnelCheckRequests.photoDto(photo))) }
|
|
481
|
+
} else null,
|
|
482
|
+
// No JS checker: no handler, so the façade applies the check's
|
|
483
|
+
// `whenUnavailable` at once instead of waiting on a silent JS.
|
|
484
|
+
onCheck = if (callbacks["onCheck"] == true) {
|
|
485
|
+
{ request ->
|
|
486
|
+
FunnelCheckRequests.ask { id ->
|
|
487
|
+
emit(mapOf("type" to "checkRequest", "requestId" to id, "request" to FunnelCheckRequests.requestDto(request)))
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
} else null,
|
|
462
491
|
)
|
|
463
492
|
val result = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.Main) {
|
|
464
|
-
Rovenue.shared.presentFunnel(activity, placement, locale, presentationOverride(styleJson), handlers)
|
|
493
|
+
Rovenue.shared.presentFunnel(activity, placement, locale, presentationOverride(styleJson), handlers, values)
|
|
465
494
|
}
|
|
466
495
|
return mapOf(
|
|
467
496
|
"result" to result.result.wire,
|
|
@@ -469,6 +498,7 @@ class RovenueModule : Module() {
|
|
|
469
498
|
"customerInfo" to result.customerInfo?.let(::dtoFromPurchaseResult),
|
|
470
499
|
"lastError" to result.lastError?.let(::errorDto),
|
|
471
500
|
"reason" to result.reason,
|
|
501
|
+
"photos" to result.photos.mapValues { (_, photo) -> FunnelCheckRequests.photoDto(photo) },
|
|
472
502
|
)
|
|
473
503
|
}
|
|
474
504
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/version.ts"],"sourcesContent":["/** This package's version, as published — the same string `package.json` carries. */\nexport const SDK_VERSION = \"0.
|
|
1
|
+
{"version":3,"sources":["../src/version.ts"],"sourcesContent":["/** This package's version, as published — the same string `package.json` carries. */\nexport const SDK_VERSION = \"0.27.0\";\n"],"mappings":";AACO,IAAM,cAAc;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ __export(index_exports, {
|
|
|
29
29
|
extractFunnelToken: () => extractFunnelToken,
|
|
30
30
|
mapNativeError: () => mapNativeError,
|
|
31
31
|
presentFunnel: () => presentFunnel,
|
|
32
|
+
releasePhoto: () => releasePhoto,
|
|
32
33
|
serializeEnvelope: () => serializeEnvelope,
|
|
33
34
|
stripUndefined: () => stripUndefined,
|
|
34
35
|
useCurrentUser: () => useCurrentUser,
|
|
@@ -43,7 +44,7 @@ __export(index_exports, {
|
|
|
43
44
|
module.exports = __toCommonJS(index_exports);
|
|
44
45
|
|
|
45
46
|
// src/version.ts
|
|
46
|
-
var SDK_VERSION = "0.
|
|
47
|
+
var SDK_VERSION = "0.27.0";
|
|
47
48
|
|
|
48
49
|
// src/events.ts
|
|
49
50
|
var EVENT_WIRE_VERSION = 1;
|
|
@@ -94,6 +95,10 @@ var ERROR_KINDS = [
|
|
|
94
95
|
// The server cannot resolve this device's subscriber (corrupt merge
|
|
95
96
|
// chain, backend SUBSCRIBER_UNRESOLVABLE). Terminal: not retryable.
|
|
96
97
|
"SubscriberUnresolvable",
|
|
98
|
+
// The server refused the identity token identify() sent (backend
|
|
99
|
+
// IDENTITY_TOKEN_INVALID, 401): expired, or minted for another user,
|
|
100
|
+
// project or environment. Not retryable: identify again with a fresh token.
|
|
101
|
+
"IdentityTokenInvalid",
|
|
97
102
|
"PurchaseCanceled",
|
|
98
103
|
"ProductNotAvailable",
|
|
99
104
|
"AlreadyOwned",
|
|
@@ -566,8 +571,8 @@ async function call2(fn) {
|
|
|
566
571
|
async function currentUser() {
|
|
567
572
|
return call2(() => getNative().currentUser());
|
|
568
573
|
}
|
|
569
|
-
async function identify(appUserId) {
|
|
570
|
-
return call2(() => getNative().identify(appUserId));
|
|
574
|
+
async function identify(appUserId, identityToken) {
|
|
575
|
+
return call2(() => getNative().identify(appUserId, identityToken));
|
|
571
576
|
}
|
|
572
577
|
async function logOut() {
|
|
573
578
|
return call2(() => getNative().logOut());
|
|
@@ -720,6 +725,47 @@ async function setFallbackPlacements(json) {
|
|
|
720
725
|
return call6(() => getNative().setFallbackPlacements(json));
|
|
721
726
|
}
|
|
722
727
|
|
|
728
|
+
// src/api/funnel-photos.ts
|
|
729
|
+
async function releasePhoto(localUri) {
|
|
730
|
+
return getNative().releasePhoto(localUri);
|
|
731
|
+
}
|
|
732
|
+
function photoFrom(dto) {
|
|
733
|
+
return {
|
|
734
|
+
localUri: dto.localUri,
|
|
735
|
+
width: Number(dto.width),
|
|
736
|
+
height: Number(dto.height),
|
|
737
|
+
byteSize: Number(dto.byteSize),
|
|
738
|
+
mimeType: dto.mimeType
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
function photosFrom(dto) {
|
|
742
|
+
const out = {};
|
|
743
|
+
for (const [key, photo] of Object.entries(dto ?? {})) out[key] = photoFrom(photo);
|
|
744
|
+
return out;
|
|
745
|
+
}
|
|
746
|
+
function outcomeJson(outcome) {
|
|
747
|
+
if (typeof outcome !== "object" || outcome === null) return null;
|
|
748
|
+
const o = outcome;
|
|
749
|
+
if (typeof o.result !== "string") return null;
|
|
750
|
+
const steps = {};
|
|
751
|
+
if (typeof o.steps === "object" && o.steps !== null) {
|
|
752
|
+
for (const [id, status] of Object.entries(o.steps)) {
|
|
753
|
+
if (typeof status === "string") steps[id] = status;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return JSON.stringify({
|
|
757
|
+
result: o.result,
|
|
758
|
+
...typeof o.label === "string" ? { label: o.label } : {},
|
|
759
|
+
...typeof o.reason === "string" ? { reason: o.reason } : {},
|
|
760
|
+
steps
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
function answerCheckRequest(requestId, request, handler) {
|
|
764
|
+
const native = getNative();
|
|
765
|
+
const run = async () => handler ? handler({ ...request, photo: photoFrom(request.photo), attempt: Number(request.attempt) }) : null;
|
|
766
|
+
run().then((outcome) => native.resolveFunnelCheckRequest(requestId, outcomeJson(outcome))).catch(() => native.resolveFunnelCheckRequest(requestId, null));
|
|
767
|
+
}
|
|
768
|
+
|
|
723
769
|
// src/api/present-funnel.ts
|
|
724
770
|
var FUNNEL_PRESENT_EVENT = "onFunnelPresentEvent";
|
|
725
771
|
var presentationSerial = 0;
|
|
@@ -756,6 +802,12 @@ async function presentFunnel(options) {
|
|
|
756
802
|
case "customAction":
|
|
757
803
|
options.onCustomAction?.({ actionId: event.actionId, paramsJson: event.paramsJson });
|
|
758
804
|
break;
|
|
805
|
+
case "photoSelected":
|
|
806
|
+
options.onPhotoSelected?.(event.questionKey, photoFrom(event.photo));
|
|
807
|
+
break;
|
|
808
|
+
case "checkRequest":
|
|
809
|
+
answerCheckRequest(event.requestId, event.request, options.onCheck);
|
|
810
|
+
break;
|
|
759
811
|
}
|
|
760
812
|
});
|
|
761
813
|
try {
|
|
@@ -768,15 +820,19 @@ async function presentFunnel(options) {
|
|
|
768
820
|
onPurchase: Boolean(options.onPurchase),
|
|
769
821
|
onRestore: Boolean(options.onRestore),
|
|
770
822
|
onUrl: Boolean(options.onUrl),
|
|
771
|
-
onCustomAction: Boolean(options.onCustomAction)
|
|
772
|
-
|
|
823
|
+
onCustomAction: Boolean(options.onCustomAction),
|
|
824
|
+
onPhotoSelected: Boolean(options.onPhotoSelected),
|
|
825
|
+
onCheck: Boolean(options.onCheck)
|
|
826
|
+
},
|
|
827
|
+
options.values ?? {}
|
|
773
828
|
);
|
|
774
829
|
return {
|
|
775
830
|
result: dto.result,
|
|
776
831
|
purchased: dto.purchased,
|
|
777
832
|
...dto.customerInfo ? { customerInfo: dto.customerInfo } : {},
|
|
778
833
|
...dto.lastError ? { lastError: toError(dto.lastError) } : {},
|
|
779
|
-
...dto.reason ? { reason: dto.reason } : {}
|
|
834
|
+
...dto.reason ? { reason: dto.reason } : {},
|
|
835
|
+
photos: photosFrom(dto.photos)
|
|
780
836
|
};
|
|
781
837
|
} catch (e) {
|
|
782
838
|
throw fromNativeError(e);
|
|
@@ -893,7 +949,13 @@ function parse(n) {
|
|
|
893
949
|
funnelAnswers = JSON.parse(n.funnelAnswersJson);
|
|
894
950
|
} catch {
|
|
895
951
|
}
|
|
896
|
-
|
|
952
|
+
let funnelPreselected = [];
|
|
953
|
+
try {
|
|
954
|
+
const keys = JSON.parse(n.funnelPreselectedJson ?? "[]");
|
|
955
|
+
if (Array.isArray(keys)) funnelPreselected = keys.filter((k) => typeof k === "string");
|
|
956
|
+
} catch {
|
|
957
|
+
}
|
|
958
|
+
return { subscriberId: n.subscriberId, funnelAnswers, funnelPreselected };
|
|
897
959
|
}
|
|
898
960
|
async function claimFunnelToken(token) {
|
|
899
961
|
return call10(async () => parse(await getNative().claimFunnelToken(token)));
|
|
@@ -989,6 +1051,7 @@ var NativeFunnelView = (0, import_expo_modules_core2.requireNativeViewManager)(M
|
|
|
989
1051
|
// src/funnel-view/RovenueFunnelView.tsx
|
|
990
1052
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
991
1053
|
var styles = import_react_native2.StyleSheet.create({ fill: { flex: 1 } });
|
|
1054
|
+
var EMPTY_VALUES = {};
|
|
992
1055
|
function parseParams(json) {
|
|
993
1056
|
try {
|
|
994
1057
|
const parsed = JSON.parse(json);
|
|
@@ -1037,7 +1100,10 @@ function RovenueFunnelView(props) {
|
|
|
1037
1100
|
onUrl,
|
|
1038
1101
|
onCustomAction,
|
|
1039
1102
|
onPurchase,
|
|
1040
|
-
onRestore
|
|
1103
|
+
onRestore,
|
|
1104
|
+
values,
|
|
1105
|
+
onPhotoSelected,
|
|
1106
|
+
onCheck
|
|
1041
1107
|
} = props;
|
|
1042
1108
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1043
1109
|
NativeFunnelView,
|
|
@@ -1046,6 +1112,8 @@ function RovenueFunnelView(props) {
|
|
|
1046
1112
|
funnelIdentifier: placementIdentifier,
|
|
1047
1113
|
locale,
|
|
1048
1114
|
hasUrlHandler: onUrl !== void 0,
|
|
1115
|
+
hasCheckHandler: onCheck !== void 0,
|
|
1116
|
+
values: values ?? EMPTY_VALUES,
|
|
1049
1117
|
onFunnelLoaded: (e) => onLoaded?.(loadedFrom(e.nativeEvent)),
|
|
1050
1118
|
onFunnelUnavailable: (e) => onUnavailable?.(unavailableFrom(e.nativeEvent)),
|
|
1051
1119
|
onFunnelFailed: (e) => onError?.(mapNativeError(e.nativeEvent.code, e.nativeEvent.message)),
|
|
@@ -1058,7 +1126,9 @@ function RovenueFunnelView(props) {
|
|
|
1058
1126
|
params: parseParams(e.nativeEvent.params)
|
|
1059
1127
|
}),
|
|
1060
1128
|
onPurchaseRequested: (e) => onPurchase?.(e.nativeEvent.packageId),
|
|
1061
|
-
onRestoreRequested: () => onRestore?.()
|
|
1129
|
+
onRestoreRequested: () => onRestore?.(),
|
|
1130
|
+
onPhotoSelectedEvent: (e) => onPhotoSelected?.(e.nativeEvent.questionKey, photoFrom(e.nativeEvent.photo)),
|
|
1131
|
+
onCheckRequested: (e) => answerCheckRequest(e.nativeEvent.requestId, e.nativeEvent.request, onCheck)
|
|
1062
1132
|
}
|
|
1063
1133
|
);
|
|
1064
1134
|
}
|
|
@@ -1085,6 +1155,7 @@ var Rovenue = {
|
|
|
1085
1155
|
setFallbackPlacements,
|
|
1086
1156
|
preloadPlacement,
|
|
1087
1157
|
presentFunnel,
|
|
1158
|
+
releasePhoto,
|
|
1088
1159
|
track,
|
|
1089
1160
|
refreshRemoteConfig,
|
|
1090
1161
|
getRemoteConfig,
|
|
@@ -1139,6 +1210,7 @@ var Rovenue = {
|
|
|
1139
1210
|
extractFunnelToken,
|
|
1140
1211
|
mapNativeError,
|
|
1141
1212
|
presentFunnel,
|
|
1213
|
+
releasePhoto,
|
|
1142
1214
|
serializeEnvelope,
|
|
1143
1215
|
stripUndefined,
|
|
1144
1216
|
useCurrentUser,
|