@rovenue/react-native-sdk 0.26.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/dist/version.cjs CHANGED
@@ -23,7 +23,7 @@ __export(version_exports, {
23
23
  SDK_VERSION: () => SDK_VERSION
24
24
  });
25
25
  module.exports = __toCommonJS(version_exports);
26
- var SDK_VERSION = "0.26.0";
26
+ var SDK_VERSION = "0.27.0";
27
27
  // Annotate the CommonJS export names for ESM import in node:
28
28
  0 && (module.exports = {
29
29
  SDK_VERSION
@@ -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.26.0\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACO,IAAM,cAAc;","names":[]}
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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACO,IAAM,cAAc;","names":[]}
@@ -1,4 +1,4 @@
1
1
  /** This package's version, as published — the same string `package.json` carries. */
2
- declare const SDK_VERSION = "0.26.0";
2
+ declare const SDK_VERSION = "0.27.0";
3
3
 
4
4
  export { SDK_VERSION };
package/dist/version.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  /** This package's version, as published — the same string `package.json` carries. */
2
- declare const SDK_VERSION = "0.26.0";
2
+ declare const SDK_VERSION = "0.27.0";
3
3
 
4
4
  export { SDK_VERSION };
package/dist/version.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SDK_VERSION
3
- } from "./chunk-BORMJJTI.js";
3
+ } from "./chunk-D2LZIJZP.js";
4
4
  export {
5
5
  SDK_VERSION
6
6
  };
@@ -34,6 +34,8 @@ final class RovenueFunnelExpoView: ExpoView {
34
34
  let onCustomActionRequested = EventDispatcher()
35
35
  let onPurchaseRequested = EventDispatcher()
36
36
  let onRestoreRequested = EventDispatcher()
37
+ let onPhotoSelectedEvent = EventDispatcher()
38
+ let onCheckRequested = EventDispatcher()
37
39
 
38
40
  // There is deliberately NO colorScheme prop. A funnel's colors come from the published screen, and the
39
41
  // Android funnel view has no dark-mode switch to honour one with — a
@@ -42,6 +44,12 @@ final class RovenueFunnelExpoView: ExpoView {
42
44
  var funnelIdentifier: String?
43
45
  var locale: String?
44
46
  var hasUrlHandler: Bool = false
47
+ /// Whether JS passed `onCheck`. Without one no handler is installed, so
48
+ /// the façade applies a check's `whenUnavailable` at once.
49
+ var hasCheckHandler: Bool = false
50
+ /// The host's values for the funnel's externals; a change resolves
51
+ /// again inside the view (they are part of its placement key).
52
+ var values: [String: String] = [:]
45
53
 
46
54
  /// ONE controller for this view's lifetime: its root view is replaced
47
55
  /// on a prop change, and SwiftUI keeps the placement view's state (the
@@ -63,6 +71,7 @@ final class RovenueFunnelExpoView: ExpoView {
63
71
  let root = RovenueFunnelView(
64
72
  placementId: funnelIdentifier ?? "",
65
73
  locale: locale,
74
+ values: values,
66
75
  handlers: handlers()
67
76
  )
68
77
  if let host {
@@ -135,7 +144,19 @@ final class RovenueFunnelExpoView: ExpoView {
135
144
  self?.onFunnelScreenChanged(["screenId": screen.screenId, "index": screen.index])
136
145
  },
137
146
  onCompleted: { [weak self] in self?.onFunnelCompleted([:]) },
138
- onDismissed: { [weak self] in self?.onFunnelDismissed([:]) }
147
+ onDismissed: { [weak self] in self?.onFunnelDismissed([:]) },
148
+ onPhotoSelected: { [weak self] key, photo in
149
+ self?.onPhotoSelectedEvent(["questionKey": key, "photo": FunnelCheckRequests.photoDTO(photo)])
150
+ },
151
+ onCheck: hasCheckHandler
152
+ ? { [weak self] request in
153
+ await FunnelCheckRequests.shared.ask { id in
154
+ // A view gone since the request answers nil at the
155
+ // timeout (the façade cancels the wait).
156
+ self?.onCheckRequested(["requestId": id, "request": FunnelCheckRequests.requestDTO(request)])
157
+ }
158
+ }
159
+ : nil
139
160
  )
140
161
  }
141
162
 
@@ -166,7 +166,9 @@ public class RovenueModule: Module {
166
166
  "onUrlRequested",
167
167
  "onCustomActionRequested",
168
168
  "onPurchaseRequested",
169
- "onRestoreRequested"
169
+ "onRestoreRequested",
170
+ "onPhotoSelectedEvent",
171
+ "onCheckRequested"
170
172
  )
171
173
  Prop("funnelIdentifier") { (view: RovenueFunnelExpoView, value: String?) in
172
174
  view.funnelIdentifier = value
@@ -177,6 +179,12 @@ public class RovenueModule: Module {
177
179
  Prop("hasUrlHandler") { (view: RovenueFunnelExpoView, value: Bool) in
178
180
  view.hasUrlHandler = value
179
181
  }
182
+ Prop("hasCheckHandler") { (view: RovenueFunnelExpoView, value: Bool) in
183
+ view.hasCheckHandler = value
184
+ }
185
+ Prop("values") { (view: RovenueFunnelExpoView, value: [String: String]?) in
186
+ view.values = value ?? [:]
187
+ }
180
188
  // The architecture-agnostic "props batch settled" hook. Expo
181
189
  // wires it into both ComponentData (old architecture) and
182
190
  // ExpoFabricView.viewDidUpdateProps (Fabric), which is why the
@@ -295,17 +303,23 @@ public class RovenueModule: Module {
295
303
  guard #available(iOS 15.0, macOS 12.0, *) else { return }
296
304
  await Rovenue.shared.preloadPlacement(placementId, locale: locale)
297
305
  }
298
- AsyncFunction("presentFunnel") { (presentationId: String, placement: String, locale: String?, styleJson: String?, callbacks: [String: Bool]) -> [String: Any?] in
306
+ AsyncFunction("presentFunnel") { (presentationId: String, placement: String, locale: String?, styleJson: String?, callbacks: [String: Bool], values: [String: String]?) -> [String: Any?] in
299
307
  guard #available(iOS 15.0, *) else {
300
308
  return ["result": "unavailable", "purchased": false, "reason": FunnelPresentResult.noPresenter]
301
309
  }
302
310
  return await self.presentFunnel(
303
311
  presentationId: presentationId, placement: placement, locale: locale,
304
- styleJson: styleJson, callbacks: callbacks)
312
+ styleJson: styleJson, callbacks: callbacks, values: values ?? [:])
305
313
  }
306
314
  AsyncFunction("resolveFunnelPurchaseRequest") { (requestId: String, purchased: Bool) in
307
315
  await FunnelPurchaseRequests.shared.resolve(requestId, purchased: purchased)
308
316
  }
317
+ AsyncFunction("resolveFunnelCheckRequest") { (requestId: String, outcomeJson: String?) in
318
+ await FunnelCheckRequests.shared.resolve(requestId, FunnelCheckRequests.outcome(outcomeJson))
319
+ }
320
+ AsyncFunction("releasePhoto") { (localUri: String) -> Bool in
321
+ Rovenue.releasePhoto(localUri)
322
+ }
309
323
  AsyncFunction("purchase") { (productId: String, productType: String, promotionalOfferId: String?, basePlanId: String?, offerId: String?) -> [String: Any?] in
310
324
  // basePlanId/offerId select a Play subscription offer on Android; ignored on iOS.
311
325
  guard #available(iOS 15.0, macOS 12.0, *) else {
@@ -407,11 +421,11 @@ public class RovenueModule: Module {
407
421
  }
408
422
  AsyncFunction("claimFunnelToken") { (token: String) -> [String: Any?] in
409
423
  let r = try await rovenueCall { try await Rovenue.shared.claimFunnelToken(token) }
410
- return ["subscriberId": r.subscriberId, "funnelAnswersJson": r.funnelAnswersJson]
424
+ return ["subscriberId": r.subscriberId, "funnelAnswersJson": r.funnelAnswersJson, "funnelPreselectedJson": r.funnelPreselectedJson]
411
425
  }
412
426
  AsyncFunction("claimFromClipboard") { () -> [String: Any?]? in
413
427
  guard let r = try await rovenueCall({ try await Rovenue.shared.claimFromClipboard() }) else { return nil }
414
- return ["subscriberId": r.subscriberId, "funnelAnswersJson": r.funnelAnswersJson]
428
+ return ["subscriberId": r.subscriberId, "funnelAnswersJson": r.funnelAnswersJson, "funnelPreselectedJson": r.funnelPreselectedJson]
415
429
  }
416
430
  AsyncFunction("claimInstall") { (params: [String: Any?]) -> [String: Any?]? in
417
431
  // Empty fields are filled by the façade from the device, so only
@@ -425,7 +439,7 @@ public class RovenueModule: Module {
425
439
  installReferrer: params["installReferrer"] as? String
426
440
  )
427
441
  guard let r = try await rovenueCall({ try await Rovenue.shared.claimInstall(p) }) else { return nil }
428
- return ["subscriberId": r.subscriberId, "funnelAnswersJson": r.funnelAnswersJson]
442
+ return ["subscriberId": r.subscriberId, "funnelAnswersJson": r.funnelAnswersJson, "funnelPreselectedJson": r.funnelPreselectedJson]
429
443
  }
430
444
  AsyncFunction("claimViaEmail") { (email: String) in
431
445
  try await rovenueCall { try await Rovenue.shared.claimViaEmail(email) }
@@ -467,6 +481,7 @@ public class RovenueModule: Module {
467
481
  self?.sendEvent("onFunnelClaimResolved", [
468
482
  "subscriberId": r.subscriberId,
469
483
  "funnelAnswersJson": r.funnelAnswersJson,
484
+ "funnelPreselectedJson": r.funnelPreselectedJson,
470
485
  ])
471
486
  }
472
487
  }
@@ -790,11 +805,86 @@ final class FunnelPurchaseRequests {
790
805
  }
791
806
  }
792
807
 
808
+ /// Photo check requests a funnel (presented, or a funnel view) is waiting
809
+ /// on, answered from JS by `resolveFunnelCheckRequest`. The façade bounds
810
+ /// the wait by the check's `timeoutMs` and then CANCELS the handler's task;
811
+ /// cancellation answers nil here, so a JS side that never answers leaks no
812
+ /// continuation, and its late answer finds no entry and is dropped.
813
+ /// Main-actor isolated: no lock.
814
+ @MainActor
815
+ final class FunnelCheckRequests {
816
+ static let shared = FunnelCheckRequests()
817
+ private var pending: [String: CheckedContinuation<FunnelCheckOutcome?, Never>] = [:]
818
+ private var serial = 0
819
+
820
+ /// Emits a request through `send` and waits for JS's answer, or for
821
+ /// the façade to cancel the wait.
822
+ func ask(_ send: @escaping (String) -> Void) async -> FunnelCheckOutcome? {
823
+ serial += 1
824
+ let requestId = "c\(serial)"
825
+ return await withTaskCancellationHandler {
826
+ await withCheckedContinuation { continuation in
827
+ // Already cancelled (the timeout fired before this hop):
828
+ // answer at once, emit nothing.
829
+ if Task.isCancelled {
830
+ continuation.resume(returning: nil)
831
+ return
832
+ }
833
+ pending[requestId] = continuation
834
+ send(requestId)
835
+ }
836
+ } onCancel: {
837
+ Task { @MainActor in FunnelCheckRequests.shared.resolve(requestId, nil) }
838
+ }
839
+ }
840
+
841
+ func resolve(_ requestId: String, _ outcome: FunnelCheckOutcome?) {
842
+ pending.removeValue(forKey: requestId)?.resume(returning: outcome)
843
+ }
844
+
845
+ /// JS's `{result,label?,reason?,steps}`; nil (the check's
846
+ /// `whenUnavailable`) for null or anything without a string `result`.
847
+ nonisolated static func outcome(_ json: String?) -> FunnelCheckOutcome? {
848
+ guard let json, let data = json.data(using: .utf8),
849
+ let object = (try? JSONSerialization.jsonObject(with: data)) as? [String: Any],
850
+ let result = object["result"] as? String
851
+ else { return nil }
852
+ return FunnelCheckOutcome(
853
+ result: result,
854
+ label: object["label"] as? String,
855
+ reason: object["reason"] as? String,
856
+ steps: (object["steps"] as? [String: Any])?.compactMapValues { $0 as? String } ?? [:])
857
+ }
858
+
859
+ /// A photo as JS's `FunnelPhotoRef` reads it.
860
+ nonisolated static func photoDTO(_ photo: FunnelPhotoRef) -> [String: Any] {
861
+ [
862
+ "localUri": photo.localUri,
863
+ "width": photo.width,
864
+ "height": photo.height,
865
+ "byteSize": photo.byteSize,
866
+ "mimeType": photo.mimeType,
867
+ ]
868
+ }
869
+
870
+ /// A check request as JS's `FunnelCheckRequest` reads it.
871
+ nonisolated static func requestDTO(_ request: FunnelCheckRequest) -> [String: Any] {
872
+ [
873
+ "checkKey": request.checkKey,
874
+ "steps": request.steps,
875
+ "photo": photoDTO(request.photo),
876
+ "locale": request.locale,
877
+ "attempt": request.attempt,
878
+ ]
879
+ }
880
+ }
881
+
793
882
  extension RovenueModule {
794
883
  @available(iOS 15.0, *)
795
884
  @MainActor
796
885
  func presentFunnel(
797
- presentationId: String, placement: String, locale: String?, styleJson: String?, callbacks: [String: Bool]
886
+ presentationId: String, placement: String, locale: String?, styleJson: String?, callbacks: [String: Bool],
887
+ values: [String: String] = [:]
798
888
  ) async -> [String: Any?] {
799
889
  let emit: ([String: Any?]) -> Void = { [weak self] body in
800
890
  var payload = body
@@ -821,14 +911,30 @@ extension RovenueModule {
821
911
  if callbacks["onCustomAction"] == true {
822
912
  handlers.onCustomAction = { id, params in emit(["type": "customAction", "actionId": id, "paramsJson": params]) }
823
913
  }
914
+ if callbacks["onPhotoSelected"] == true {
915
+ handlers.onPhotoSelected = { key, photo in
916
+ emit(["type": "photoSelected", "questionKey": key, "photo": FunnelCheckRequests.photoDTO(photo)])
917
+ }
918
+ }
919
+ // No JS checker: no handler, so the façade applies the check's
920
+ // `whenUnavailable` at once instead of waiting on a silent JS.
921
+ if callbacks["onCheck"] == true {
922
+ handlers.onCheck = { request in
923
+ await FunnelCheckRequests.shared.ask { id in
924
+ emit(["type": "checkRequest", "requestId": id, "request": FunnelCheckRequests.requestDTO(request)])
925
+ }
926
+ }
927
+ }
824
928
  let result = await Rovenue.shared.presentFunnel(
825
- placement: placement, locale: locale, style: Self.presentationOverride(styleJson), handlers: handlers)
929
+ placement: placement, locale: locale, style: Self.presentationOverride(styleJson), handlers: handlers,
930
+ values: values)
826
931
  return [
827
932
  "result": result.result.rawValue,
828
933
  "purchased": result.purchased,
829
934
  "customerInfo": result.customerInfo.map(Self.dtoFromPurchaseResult),
830
935
  "lastError": result.lastError.map(Self.errorDTO),
831
936
  "reason": result.reason,
937
+ "photos": result.photos.mapValues(FunnelCheckRequests.photoDTO),
832
938
  ]
833
939
  }
834
940
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rovenue/react-native-sdk",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "description": "Rovenue React Native SDK — subscriptions, entitlements, virtual currencies and funnels for Expo / React Native apps.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://rovenue.io",
@@ -1,7 +0,0 @@
1
- // src/version.ts
2
- var SDK_VERSION = "0.26.0";
3
-
4
- export {
5
- SDK_VERSION
6
- };
7
- //# sourceMappingURL=chunk-BORMJJTI.js.map