@tryheliumai/paywall-sdk-react-native 3.0.21 → 3.0.22

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.
@@ -0,0 +1,25 @@
1
+ package com.paywallsdkreactnative
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext
4
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
5
+ import com.facebook.react.bridge.ReactMethod
6
+ import com.facebook.react.bridge.Promise
7
+
8
+ class PaywallSdkReactNativeModule(reactContext: ReactApplicationContext) :
9
+ ReactContextBaseJavaModule(reactContext) {
10
+
11
+ override fun getName(): String {
12
+ return NAME
13
+ }
14
+
15
+ // Example method
16
+ // See https://reactnative.dev/docs/native-modules-android
17
+ @ReactMethod
18
+ fun multiply(a: Double, b: Double, promise: Promise) {
19
+ promise.resolve(a * b)
20
+ }
21
+
22
+ companion object {
23
+ const val NAME = "PaywallSdkReactNative"
24
+ }
25
+ }
@@ -8,7 +8,7 @@ import com.facebook.react.uimanager.ViewManager
8
8
 
9
9
  class PaywallSdkReactNativePackage : ReactPackage {
10
10
  override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11
- return listOf(HeliumBridge(reactContext))
11
+ return listOf(PaywallSdkReactNativeModule(reactContext))
12
12
  }
13
13
 
14
14
  override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryheliumai/paywall-sdk-react-native",
3
- "version": "3.0.21",
3
+ "version": "3.0.22",
4
4
  "description": "Paywall SDK Helium",
5
5
  "source": "./src/index.ts",
6
6
  "main": "./lib/commonjs/index.js",
@@ -1,312 +0,0 @@
1
- package com.paywallsdkreactnative
2
-
3
- import com.facebook.react.bridge.Arguments
4
- import com.facebook.react.bridge.Callback
5
- import com.facebook.react.bridge.Promise
6
- import com.facebook.react.bridge.ReactApplicationContext
7
- import com.facebook.react.bridge.ReactContextBaseJavaModule
8
- import com.facebook.react.bridge.ReactMethod
9
- import com.facebook.react.bridge.ReadableArray
10
- import com.facebook.react.bridge.ReadableMap
11
- import com.facebook.react.bridge.ReadableType
12
- import com.facebook.react.bridge.WritableMap
13
- import com.facebook.react.modules.core.DeviceEventManagerModule
14
-
15
- class HeliumBridge(private val reactContext: ReactApplicationContext) :
16
- ReactContextBaseJavaModule(reactContext) {
17
-
18
- companion object {
19
- const val NAME = "HeliumBridge"
20
-
21
- // Event names matching iOS implementation
22
- const val EVENT_PAYWALL_EVENT = "helium_paywall_event"
23
- const val EVENT_MAKE_PURCHASE = "helium_make_purchase"
24
- const val EVENT_RESTORE_PURCHASES = "helium_restore_purchases"
25
- const val EVENT_DOWNLOAD_STATE_CHANGED = "helium_download_state_changed"
26
- const val EVENT_PAYWALL_HANDLERS = "paywallEventHandlers"
27
- }
28
-
29
- override fun getName(): String = NAME
30
-
31
- // -------------------------------------------------------------------------
32
- // Event Emitter Support
33
- // -------------------------------------------------------------------------
34
-
35
- private var listenerCount = 0
36
-
37
- private fun sendEvent(eventName: String, params: WritableMap?) {
38
- reactContext
39
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
40
- .emit(eventName, params)
41
- }
42
-
43
- @ReactMethod
44
- fun addListener(eventType: String) {
45
- listenerCount++
46
- }
47
-
48
- @ReactMethod
49
- fun removeListeners(count: Double) {
50
- listenerCount -= count.toInt()
51
- if (listenerCount < 0) {
52
- listenerCount = 0
53
- }
54
- }
55
-
56
- // -------------------------------------------------------------------------
57
- // Initialization
58
- // -------------------------------------------------------------------------
59
-
60
- @ReactMethod
61
- fun initialize(config: ReadableMap, customVariableValues: ReadableMap) {
62
- // TODO: Initialize Helium SDK
63
- // Extract from config:
64
- // - apiKey: String (required)
65
- // - customUserId: String?
66
- // - customAPIEndpoint: String?
67
- // - customUserTraits: ReadableMap? (convert boolean markers)
68
- // - revenueCatAppUserId: String?
69
- // - fallbackBundleUrlString: String?
70
- // - fallbackBundleString: String?
71
- // - paywallLoadingConfig: ReadableMap? (convert boolean markers)
72
- // - useDefaultDelegate: Boolean
73
- }
74
-
75
- // -------------------------------------------------------------------------
76
- // Paywall Presentation
77
- // -------------------------------------------------------------------------
78
-
79
- @ReactMethod
80
- fun presentUpsell(
81
- trigger: String,
82
- customPaywallTraits: ReadableMap?,
83
- dontShowIfAlreadyEntitled: Boolean
84
- ) {
85
- // TODO: Present paywall for the given trigger
86
- // - Convert customPaywallTraits boolean markers to actual booleans
87
- // - Call native Helium SDK presentUpsell
88
- // - Set up event handlers to emit paywallEventHandlers events
89
- }
90
-
91
- @ReactMethod
92
- fun hideUpsell() {
93
- // TODO: Hide the currently displayed paywall
94
- }
95
-
96
- @ReactMethod
97
- fun hideAllUpsells() {
98
- // TODO: Hide all displayed paywalls
99
- }
100
-
101
- // -------------------------------------------------------------------------
102
- // Purchase Handling
103
- // -------------------------------------------------------------------------
104
-
105
- @ReactMethod
106
- fun handlePurchaseResponse(response: ReadableMap) {
107
- // TODO: Handle purchase response from JS
108
- // Extract:
109
- // - transactionId: String
110
- // - status: String ("completed", "purchased", "cancelled", "restored", "failed", "pending")
111
- // - error: String?
112
- // Resume the pending purchase continuation with the result
113
- }
114
-
115
- @ReactMethod
116
- fun handleRestoreResponse(response: ReadableMap) {
117
- // TODO: Handle restore response from JS
118
- // Extract:
119
- // - transactionId: String
120
- // - status: String ("restored" or "failed")
121
- // Resume the pending restore continuation with the result
122
- }
123
-
124
- // -------------------------------------------------------------------------
125
- // Fallback Handling
126
- // -------------------------------------------------------------------------
127
-
128
- @ReactMethod
129
- fun fallbackOpenOrCloseEvent(trigger: String?, isOpen: Boolean, viewType: String?) {
130
- // TODO: Track fallback open/close events for analytics
131
- }
132
-
133
- // -------------------------------------------------------------------------
134
- // Paywall Info
135
- // -------------------------------------------------------------------------
136
-
137
- @ReactMethod
138
- fun getFetchedTriggerNames(callback: Callback) {
139
- // TODO: Return array of fetched trigger names
140
- // callback([triggerNames])
141
- }
142
-
143
- @ReactMethod
144
- fun getPaywallInfo(trigger: String, callback: Callback) {
145
- // TODO: Get paywall info for trigger
146
- // On success: callback(null, paywallTemplateName, shouldShow)
147
- // On error: callback(errorMessage, null, null)
148
- }
149
-
150
- // -------------------------------------------------------------------------
151
- // Deep Links
152
- // -------------------------------------------------------------------------
153
-
154
- @ReactMethod
155
- fun handleDeepLink(urlString: String, callback: Callback) {
156
- // TODO: Handle deep link URL
157
- // callback(handled: Boolean)
158
- }
159
-
160
- // -------------------------------------------------------------------------
161
- // User Identity
162
- // -------------------------------------------------------------------------
163
-
164
- @ReactMethod
165
- fun setRevenueCatAppUserId(rcAppUserId: String) {
166
- // TODO: Set RevenueCat app user ID
167
- }
168
-
169
- @ReactMethod
170
- fun setCustomUserId(newUserId: String) {
171
- // TODO: Set custom user ID (override)
172
- }
173
-
174
- // -------------------------------------------------------------------------
175
- // Entitlements
176
- // -------------------------------------------------------------------------
177
-
178
- @ReactMethod
179
- fun hasEntitlementForPaywall(trigger: String, promise: Promise) {
180
- // TODO: Check if user has entitlement for paywall's products
181
- // promise.resolve(Boolean?) - true/false if known, null if not known
182
- }
183
-
184
- @ReactMethod
185
- fun hasAnyActiveSubscription(promise: Promise) {
186
- // TODO: Check if user has any active subscription
187
- // promise.resolve(Boolean)
188
- }
189
-
190
- @ReactMethod
191
- fun hasAnyEntitlement(promise: Promise) {
192
- // TODO: Check if user has any entitlement
193
- // promise.resolve(Boolean)
194
- }
195
-
196
- // -------------------------------------------------------------------------
197
- // Experiments
198
- // -------------------------------------------------------------------------
199
-
200
- @ReactMethod
201
- fun getExperimentInfoForTrigger(trigger: String, callback: Callback) {
202
- // TODO: Get experiment allocation info for trigger
203
- // On success: callback(true, experimentInfoMap)
204
- // On failure: callback(false, null)
205
- }
206
-
207
- // -------------------------------------------------------------------------
208
- // Restore Failed Dialog Configuration
209
- // -------------------------------------------------------------------------
210
-
211
- @ReactMethod
212
- fun disableRestoreFailedDialog() {
213
- // TODO: Disable the default restore failed dialog
214
- }
215
-
216
- @ReactMethod
217
- fun setCustomRestoreFailedStrings(
218
- customTitle: String?,
219
- customMessage: String?,
220
- customCloseButtonText: String?
221
- ) {
222
- // TODO: Set custom strings for restore failed dialog
223
- }
224
-
225
- // -------------------------------------------------------------------------
226
- // SDK Reset
227
- // -------------------------------------------------------------------------
228
-
229
- @ReactMethod
230
- fun resetHelium() {
231
- // TODO: Reset Helium SDK state entirely
232
- }
233
-
234
- // -------------------------------------------------------------------------
235
- // Appearance
236
- // -------------------------------------------------------------------------
237
-
238
- @ReactMethod
239
- fun setLightDarkModeOverride(mode: String) {
240
- // TODO: Set light/dark mode override
241
- // mode: "light", "dark", or "system"
242
- }
243
-
244
- // -------------------------------------------------------------------------
245
- // Helper Functions
246
- // -------------------------------------------------------------------------
247
-
248
- private companion object BooleanMarkers {
249
- const val TRUE_MARKER = "__helium_rn_bool_true__"
250
- const val FALSE_MARKER = "__helium_rn_bool_false__"
251
- }
252
-
253
- private fun convertMarkersToBooleans(input: ReadableMap?): Map<String, Any?>? {
254
- if (input == null) return null
255
-
256
- val result = mutableMapOf<String, Any?>()
257
- val iterator = input.keySetIterator()
258
-
259
- while (iterator.hasNextKey()) {
260
- val key = iterator.nextKey()
261
- result[key] = convertValueMarkersToBooleans(input, key)
262
- }
263
-
264
- return result
265
- }
266
-
267
- private fun convertValueMarkersToBooleans(map: ReadableMap, key: String): Any? {
268
- return when (map.getType(key)) {
269
- ReadableType.String -> {
270
- when (val stringValue = map.getString(key)) {
271
- TRUE_MARKER -> true
272
- FALSE_MARKER -> false
273
- else -> stringValue
274
- }
275
- }
276
- ReadableType.Map -> {
277
- convertMarkersToBooleans(map.getMap(key))
278
- }
279
- ReadableType.Array -> {
280
- convertArrayMarkersToBooleans(map.getArray(key))
281
- }
282
- ReadableType.Boolean -> map.getBoolean(key)
283
- ReadableType.Number -> map.getDouble(key)
284
- ReadableType.Null -> null
285
- }
286
- }
287
-
288
- private fun convertArrayMarkersToBooleans(array: ReadableArray?): List<Any?>? {
289
- if (array == null) return null
290
-
291
- return (0 until array.size()).map { index ->
292
- when (array.getType(index)) {
293
- ReadableType.String -> {
294
- when (val stringValue = array.getString(index)) {
295
- TRUE_MARKER -> true
296
- FALSE_MARKER -> false
297
- else -> stringValue
298
- }
299
- }
300
- ReadableType.Map -> {
301
- convertMarkersToBooleans(array.getMap(index))
302
- }
303
- ReadableType.Array -> {
304
- convertArrayMarkersToBooleans(array.getArray(index))
305
- }
306
- ReadableType.Boolean -> array.getBoolean(index)
307
- ReadableType.Number -> array.getDouble(index)
308
- ReadableType.Null -> null
309
- }
310
- }
311
- }
312
- }