@app-swiss-knife/react-native-sdk 0.4.0 → 0.5.1
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/CHANGELOG.md +473 -2
- package/LICENSE +21 -0
- package/README.md +279 -47
- package/SwissKnifePurchases.podspec +1 -1
- package/android/build.gradle +24 -2
- package/android/consumer-rules.pro +12 -0
- package/android/src/main/AndroidManifest.xml +15 -1
- package/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingModule.kt +5 -4
- package/android/src/main/java/com/swissknife/purchases/SwissKnifeJson.kt +20 -2
- package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesModule.kt +168 -6
- package/android/src/play/java/com/swissknife/purchases/StoreIntentHandler.kt +7 -0
- package/android/src/rustore/java/com/swissknife/purchases/StoreIntentHandler.kt +9 -0
- package/android/vendor/GENERATED.md +1 -0
- package/android/vendor/java/com/appswissknife/SwissKnife.kt +111 -38
- package/android/vendor/java/com/appswissknife/analytics/SKAnalytics.kt +180 -115
- package/android/vendor/java/com/appswissknife/attributes/AttributesClient.kt +16 -18
- package/android/vendor/java/com/appswissknife/attributes/SetAttributesWorker.kt +13 -13
- package/android/vendor/java/com/appswissknife/attribution/Attribution.kt +56 -25
- package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +1 -1
- package/android/vendor/java/com/appswissknife/crashreporting/SKCrashReporting.kt +365 -206
- package/android/vendor/java/com/appswissknife/entitlements/EntitlementsRepository.kt +195 -26
- package/android/vendor/java/com/appswissknife/identity/Identity.kt +31 -6
- package/android/vendor/java/com/appswissknife/models/PurchasesError.kt +5 -0
- package/android/vendor/java/com/appswissknife/net/BackendHttpClient.kt +56 -31
- package/android/vendor/java/com/appswissknife/net/IngestClient.kt +673 -87
- package/android/vendor/java/com/appswissknife/net/OfflineQueueStore.kt +214 -30
- package/android/vendor/java/com/appswissknife/notifications/NotificationRenderer.kt +195 -0
- package/android/vendor/java/com/appswissknife/notifications/PermissionRequestActivity.kt +60 -0
- package/android/vendor/java/com/appswissknife/notifications/PermissionStatus.kt +41 -0
- package/android/vendor/java/com/appswissknife/notifications/PushEventQueue.kt +143 -0
- package/android/vendor/java/com/appswissknife/notifications/PushPayload.kt +72 -0
- package/android/vendor/java/com/appswissknife/notifications/PushRegistration.kt +89 -0
- package/android/vendor/java/com/appswissknife/notifications/SwissKnifeMessagingService.kt +57 -0
- package/android/vendor/java/com/appswissknife/notifications/SwissKnifeNotifications.kt +438 -0
- package/android/vendor/java/com/appswissknife/offerings/OfferingsRepository.kt +312 -65
- package/android/vendor/java/com/appswissknife/performance/SKPerformance.kt +1 -0
- package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +705 -96
- package/android/vendor/java/com/appswissknife/purchases/PlayPriceEnrichmentProvider.kt +55 -24
- package/android/vendor/java/com/appswissknife/purchases/ProductKindHint.kt +29 -0
- package/android/vendor/java/com/appswissknife/purchases/PurchasesGateway.kt +24 -0
- package/android/vendor-rustore/AndroidManifest.xml +59 -0
- package/android/vendor-rustore/java/com/appswissknife/rustore/RuStoreGateway.kt +428 -0
- package/android/vendor-rustore/java/com/appswissknife/rustore/RuStoreInitProvider.kt +43 -0
- package/android/vendor-rustore/java/com/appswissknife/rustore/RuStorePriceEnrichmentProvider.kt +85 -0
- package/app.plugin.js +343 -0
- package/ios/SwissKnifeJSON.swift +24 -2
- package/ios/SwissKnifePurchases.m +20 -0
- package/ios/SwissKnifePurchases.swift +97 -3
- package/ios/SwissKnifePushBootstrap.m +34 -0
- package/ios/vendor/GENERATED.md +1 -0
- package/ios/vendor/SwissKnifeiOS/Analytics/SKAnalytics.swift +138 -89
- package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +1 -1
- package/ios/vendor/SwissKnifeiOS/CrashReporting/SKCrashReporting.swift +345 -44
- package/ios/vendor/SwissKnifeiOS/Net/BackendBackoffGate.swift +43 -2
- package/ios/vendor/SwissKnifeiOS/Net/IngestClient.swift +495 -16
- package/ios/vendor/SwissKnifeiOS/Net/OfflineQueueStore.swift +231 -23
- package/ios/vendor/SwissKnifeiOS/Notifications/PushPayload.swift +87 -0
- package/ios/vendor/SwissKnifeiOS/Notifications/PushRegistrar.swift +322 -0
- package/ios/vendor/SwissKnifeiOS/Notifications/SwissKnife+Notifications.swift +403 -0
- package/ios/vendor/SwissKnifeiOS/Performance/SKPerformance.swift +1 -0
- package/ios/vendor/SwissKnifeiOS/Services/EntitlementsService.swift +11 -7
- package/ios/vendor/SwissKnifeiOS/Services/OfferingsService.swift +37 -5
- package/ios/vendor/SwissKnifeiOS/Services/PurchaseService.swift +38 -7
- package/ios/vendor/SwissKnifeiOS/SwissKnife.swift +34 -6
- package/ios/vendor/SwissKnifeiOS/Types.swift +31 -1
- package/ios-notification-service/SwissKnifeNotificationService.podspec +37 -0
- package/ios-notification-service/vendor/GENERATED.md +11 -0
- package/ios-notification-service/vendor/SwissKnifeNotificationService/SwissKnifeNotificationServiceExtension.swift +177 -0
- package/lib/commonjs/attribution.js +4 -3
- package/lib/commonjs/attribution.js.map +1 -1
- package/lib/commonjs/identity.js +12 -11
- package/lib/commonjs/identity.js.map +1 -1
- package/lib/commonjs/index.js +16 -5
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal/config.js +105 -8
- package/lib/commonjs/internal/config.js.map +1 -1
- package/lib/commonjs/internal/telemetry-context.js +70 -0
- package/lib/commonjs/internal/telemetry-context.js.map +1 -0
- package/lib/commonjs/modules/analytics.js +18 -25
- package/lib/commonjs/modules/analytics.js.map +1 -1
- package/lib/commonjs/modules/crash-reporting.js +27 -6
- package/lib/commonjs/modules/crash-reporting.js.map +1 -1
- package/lib/commonjs/modules/log.js +1 -1
- package/lib/commonjs/modules/notifications.js +500 -0
- package/lib/commonjs/modules/notifications.js.map +1 -0
- package/lib/commonjs/modules/performance.js +57 -8
- package/lib/commonjs/modules/performance.js.map +1 -1
- package/lib/commonjs/native/module.js +6 -0
- package/lib/commonjs/native/module.js.map +1 -1
- package/lib/commonjs/native/spec.js +12 -5
- package/lib/commonjs/native/spec.js.map +1 -1
- package/lib/commonjs/purchases.js +4 -4
- package/lib/commonjs/types.js +12 -15
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/attribution.js +4 -3
- package/lib/module/attribution.js.map +1 -1
- package/lib/module/identity.js +12 -11
- package/lib/module/identity.js.map +1 -1
- package/lib/module/index.js +8 -4
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal/config.js +103 -8
- package/lib/module/internal/config.js.map +1 -1
- package/lib/module/internal/telemetry-context.js +63 -0
- package/lib/module/internal/telemetry-context.js.map +1 -0
- package/lib/module/modules/analytics.js +18 -25
- package/lib/module/modules/analytics.js.map +1 -1
- package/lib/module/modules/crash-reporting.js +27 -6
- package/lib/module/modules/crash-reporting.js.map +1 -1
- package/lib/module/modules/log.js +1 -1
- package/lib/module/modules/notifications.js +491 -0
- package/lib/module/modules/notifications.js.map +1 -0
- package/lib/module/modules/performance.js +57 -8
- package/lib/module/modules/performance.js.map +1 -1
- package/lib/module/native/module.js +6 -1
- package/lib/module/native/module.js.map +1 -1
- package/lib/module/native/spec.js +11 -4
- package/lib/module/native/spec.js.map +1 -1
- package/lib/module/purchases.js +4 -4
- package/lib/module/types.js +12 -15
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/commonjs/attribution.d.ts +3 -2
- package/lib/typescript/commonjs/attribution.d.ts.map +1 -1
- package/lib/typescript/commonjs/identity.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +2 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/config.d.ts +16 -2
- package/lib/typescript/commonjs/internal/config.d.ts.map +1 -1
- package/lib/typescript/commonjs/internal/telemetry-context.d.ts +22 -0
- package/lib/typescript/commonjs/internal/telemetry-context.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/analytics.d.ts +8 -11
- package/lib/typescript/commonjs/modules/analytics.d.ts.map +1 -1
- package/lib/typescript/commonjs/modules/crash-reporting.d.ts +18 -5
- package/lib/typescript/commonjs/modules/crash-reporting.d.ts.map +1 -1
- package/lib/typescript/commonjs/modules/notifications.d.ts +110 -0
- package/lib/typescript/commonjs/modules/notifications.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/performance.d.ts +13 -0
- package/lib/typescript/commonjs/modules/performance.d.ts.map +1 -1
- package/lib/typescript/commonjs/native/module.d.ts +2 -0
- package/lib/typescript/commonjs/native/module.d.ts.map +1 -1
- package/lib/typescript/commonjs/native/spec.d.ts +33 -4
- package/lib/typescript/commonjs/native/spec.d.ts.map +1 -1
- package/lib/typescript/commonjs/purchases.d.ts +4 -4
- package/lib/typescript/commonjs/types.d.ts +4 -5
- package/lib/typescript/commonjs/types.d.ts.map +1 -1
- package/lib/typescript/module/attribution.d.ts +3 -2
- package/lib/typescript/module/attribution.d.ts.map +1 -1
- package/lib/typescript/module/identity.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +2 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/internal/config.d.ts +16 -2
- package/lib/typescript/module/internal/config.d.ts.map +1 -1
- package/lib/typescript/module/internal/telemetry-context.d.ts +22 -0
- package/lib/typescript/module/internal/telemetry-context.d.ts.map +1 -0
- package/lib/typescript/module/modules/analytics.d.ts +8 -11
- package/lib/typescript/module/modules/analytics.d.ts.map +1 -1
- package/lib/typescript/module/modules/crash-reporting.d.ts +18 -5
- package/lib/typescript/module/modules/crash-reporting.d.ts.map +1 -1
- package/lib/typescript/module/modules/notifications.d.ts +110 -0
- package/lib/typescript/module/modules/notifications.d.ts.map +1 -0
- package/lib/typescript/module/modules/performance.d.ts +13 -0
- package/lib/typescript/module/modules/performance.d.ts.map +1 -1
- package/lib/typescript/module/native/module.d.ts +2 -0
- package/lib/typescript/module/native/module.d.ts.map +1 -1
- package/lib/typescript/module/native/spec.d.ts +33 -4
- package/lib/typescript/module/native/spec.d.ts.map +1 -1
- package/lib/typescript/module/purchases.d.ts +4 -4
- package/lib/typescript/module/types.d.ts +4 -5
- package/lib/typescript/module/types.d.ts.map +1 -1
- package/package.json +13 -4
- package/src/attribution.ts +4 -3
- package/src/identity.ts +12 -11
- package/src/index.ts +16 -4
- package/src/internal/config.ts +113 -8
- package/src/internal/telemetry-context.ts +76 -0
- package/src/modules/analytics.ts +24 -33
- package/src/modules/crash-reporting.ts +50 -9
- package/src/modules/log.ts +1 -1
- package/src/modules/notifications.ts +557 -0
- package/src/modules/performance.ts +94 -14
- package/src/native/module.ts +6 -0
- package/src/native/spec.ts +45 -10
- package/src/purchases.ts +4 -4
- package/src/types.ts +12 -15
- package/android/vendor/java/com/appswissknife/analytics/EventQueueStore.kt +0 -326
- package/android/vendor/java/com/appswissknife/analytics/FlushEventsWorker.kt +0 -296
|
@@ -12,11 +12,16 @@ import com.appswissknife.models.CustomerInfo
|
|
|
12
12
|
import com.appswissknife.models.PurchasesError
|
|
13
13
|
import com.appswissknife.models.PurchasesErrorCode
|
|
14
14
|
import com.appswissknife.models.StoreProduct
|
|
15
|
+
import android.content.Intent
|
|
16
|
+
import com.appswissknife.notifications.NotificationOpen
|
|
17
|
+
import com.facebook.react.bridge.ActivityEventListener
|
|
18
|
+
import com.facebook.react.bridge.Arguments
|
|
15
19
|
import com.facebook.react.bridge.Promise
|
|
16
20
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
17
21
|
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
18
22
|
import com.facebook.react.bridge.ReactMethod
|
|
19
23
|
import com.facebook.react.bridge.ReadableMap
|
|
24
|
+
import com.facebook.react.bridge.WritableMap
|
|
20
25
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
21
26
|
|
|
22
27
|
class SwissKnifePurchasesModule(
|
|
@@ -26,11 +31,41 @@ class SwissKnifePurchasesModule(
|
|
|
26
31
|
// Must match src/native/module.ts MODULE_NAME exactly.
|
|
27
32
|
override fun getName(): String = "SwissKnifePurchases"
|
|
28
33
|
|
|
34
|
+
companion object {
|
|
35
|
+
// Must match PUSH_OPENED_EVENT in src/native/spec.ts.
|
|
36
|
+
const val PUSH_OPENED_EVENT = "SwissKnife-PushOpened"
|
|
37
|
+
}
|
|
38
|
+
|
|
29
39
|
// The single CustomerInfo bridge listener. Removed + re-added on every
|
|
30
40
|
// configure() so re-configuring does not stack duplicate listeners
|
|
31
41
|
// (which would emit duplicate CustomerInfo events to JS).
|
|
32
42
|
private var customerInfoListener: ((CustomerInfo) -> Unit)? = null
|
|
33
43
|
|
|
44
|
+
// ----- Push (swiss-push) -----
|
|
45
|
+
//
|
|
46
|
+
// Depends on the Android native SDK's `SwissKnife.notifications` API
|
|
47
|
+
// (packages/swiss-knife-android, com.appswissknife.notifications.*).
|
|
48
|
+
private var pushListener: ((NotificationOpen) -> Unit)? = null
|
|
49
|
+
|
|
50
|
+
private val pushIntentListener = object : ActivityEventListener {
|
|
51
|
+
override fun onActivityResult(
|
|
52
|
+
activity: android.app.Activity, requestCode: Int, resultCode: Int, data: Intent?
|
|
53
|
+
) { /* not used */ }
|
|
54
|
+
|
|
55
|
+
// A tap on a system-tray notification while the app is already running.
|
|
56
|
+
// handleIntent tracks `opened` and dispatches to the listener registered
|
|
57
|
+
// in ensurePushListener(), which emits to JS.
|
|
58
|
+
override fun onNewIntent(intent: Intent) {
|
|
59
|
+
StoreIntentHandler.handle(intent)
|
|
60
|
+
try { SwissKnife.notifications.handleIntent(intent) } catch (_: Throwable) {}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
init {
|
|
65
|
+
reactContext.addActivityEventListener(pushIntentListener)
|
|
66
|
+
reactContext.currentActivity?.intent?.let(StoreIntentHandler::handle)
|
|
67
|
+
}
|
|
68
|
+
|
|
34
69
|
// ----- Lifecycle -----
|
|
35
70
|
|
|
36
71
|
@ReactMethod
|
|
@@ -205,11 +240,12 @@ class SwissKnifePurchasesModule(
|
|
|
205
240
|
// Do NOT re-point JS at them. They bottom out in the deprecated
|
|
206
241
|
// `SwissKnife.*` facades, which on THIS platform are not equivalent to the
|
|
207
242
|
// iOS ones: `SwissKnife.logOut` goes straight to the purchases gateway
|
|
208
|
-
// instead of `Identity.logOut
|
|
209
|
-
// `SwissKnife.isAnonymous()` read gateway
|
|
210
|
-
//
|
|
211
|
-
//
|
|
212
|
-
// `
|
|
243
|
+
// instead of `Identity.logOut` (so it skips the push-token unlink), and
|
|
244
|
+
// `SwissKnife.appUserID` / `SwissKnife.isAnonymous()` read the gateway
|
|
245
|
+
// rather than `Identity.current()`. The gateway follows Identity
|
|
246
|
+
// (`Identity.reset()` / `Identity.wipe()` take it back to the anonymous
|
|
247
|
+
// user through `PurchasesGateway.resetToAnonymous`), but `Identity` is the
|
|
248
|
+
// source of truth. That split is what
|
|
213
249
|
// `packages/react-native-sdk/src/identity-parity.test.ts` exists to keep out
|
|
214
250
|
// of the JS surface.
|
|
215
251
|
|
|
@@ -483,10 +519,136 @@ class SwissKnifePurchasesModule(
|
|
|
483
519
|
}
|
|
484
520
|
}
|
|
485
521
|
|
|
522
|
+
// ----- Push notifications (swiss-push) -----
|
|
523
|
+
|
|
524
|
+
@ReactMethod
|
|
525
|
+
fun pushRequestPermission(provisional: Boolean, promise: Promise) {
|
|
526
|
+
// Android has no provisional authorization; the flag is accepted for
|
|
527
|
+
// cross-platform parity and ignored.
|
|
528
|
+
// RN 0.80+: same access path as the purchase flow above.
|
|
529
|
+
val activity = reactApplicationContext.currentActivity
|
|
530
|
+
if (activity == null) {
|
|
531
|
+
promise.reject("NO_ACTIVITY", "requestPermission needs a foreground Activity")
|
|
532
|
+
return
|
|
533
|
+
}
|
|
534
|
+
try {
|
|
535
|
+
SwissKnife.notifications.requestPermission(activity) { status ->
|
|
536
|
+
promise.resolve(status.wire)
|
|
537
|
+
}
|
|
538
|
+
} catch (e: Throwable) {
|
|
539
|
+
promise.reject("PUSH_PERMISSION_ERROR", e.message ?: "unknown", e)
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
@ReactMethod
|
|
544
|
+
fun pushPermissionStatus(promise: Promise) {
|
|
545
|
+
try {
|
|
546
|
+
promise.resolve(SwissKnife.notifications.permissionStatus().wire)
|
|
547
|
+
} catch (e: Throwable) {
|
|
548
|
+
promise.reject("PUSH_PERMISSION_ERROR", e.message ?: "unknown", e)
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/** Fetches the FCM token through the native SDK and registers the device. */
|
|
553
|
+
@ReactMethod
|
|
554
|
+
fun pushRegister(promise: Promise) {
|
|
555
|
+
try {
|
|
556
|
+
ensurePushListener()
|
|
557
|
+
SwissKnife.notifications.fetchAndRegisterToken()
|
|
558
|
+
promise.resolve(null)
|
|
559
|
+
} catch (e: Throwable) {
|
|
560
|
+
promise.reject("PUSH_REGISTER_ERROR", e.message ?: "unknown", e)
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
@ReactMethod
|
|
565
|
+
fun pushUnregister(promise: Promise) {
|
|
566
|
+
try {
|
|
567
|
+
SwissKnife.notifications.unregister()
|
|
568
|
+
promise.resolve(null)
|
|
569
|
+
} catch (e: Throwable) {
|
|
570
|
+
promise.reject("PUSH_UNREGISTER_ERROR", e.message ?: "unknown", e)
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* The tap that launched the app, once. The native SDK captures launch intents
|
|
576
|
+
* itself (ActivityLifecycleCallbacks) and buffers the open; it is replayed
|
|
577
|
+
* exactly once, either here or to the first opened-listener, never both.
|
|
578
|
+
*/
|
|
579
|
+
@ReactMethod
|
|
580
|
+
fun pushGetInitialNotification(promise: Promise) {
|
|
581
|
+
try {
|
|
582
|
+
replayLaunchIntent()
|
|
583
|
+
promise.resolve(SwissKnife.notifications.consumeInitialOpen()?.let { encodeOpen(it) })
|
|
584
|
+
} catch (e: Throwable) {
|
|
585
|
+
promise.reject("PUSH_INITIAL_ERROR", e.message ?: "unknown", e)
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/** Facts the JS-only registration path cannot know itself. */
|
|
590
|
+
@ReactMethod
|
|
591
|
+
fun pushDeviceInfo(promise: Promise) {
|
|
592
|
+
try {
|
|
593
|
+
val map = Arguments.createMap()
|
|
594
|
+
val pkg = reactContext.packageName
|
|
595
|
+
map.putString("bundleId", pkg)
|
|
596
|
+
val versionName = try {
|
|
597
|
+
reactContext.packageManager.getPackageInfo(pkg, 0).versionName
|
|
598
|
+
} catch (_: Throwable) {
|
|
599
|
+
null
|
|
600
|
+
}
|
|
601
|
+
if (versionName != null) map.putString("appVersion", versionName)
|
|
602
|
+
map.putString("osVersion", android.os.Build.VERSION.RELEASE ?: "")
|
|
603
|
+
promise.resolve(map)
|
|
604
|
+
} catch (e: Throwable) {
|
|
605
|
+
promise.reject("PUSH_DEVICE_INFO_ERROR", e.message ?: "unknown", e)
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* In React Native the native SDK is configured from JS, i.e. AFTER the launcher
|
|
611
|
+
* Activity was created and resumed, so its ActivityLifecycleCallbacks never saw
|
|
612
|
+
* the notification tap that cold-started the app. Feed the current Activity's
|
|
613
|
+
* intent through handleIntent once the bridge is up; the native SDK dedupes by
|
|
614
|
+
* delivery id, so a tap that was already seen is not tracked twice.
|
|
615
|
+
*/
|
|
616
|
+
private fun replayLaunchIntent() {
|
|
617
|
+
try {
|
|
618
|
+
SwissKnife.notifications.handleIntent(reactApplicationContext.currentActivity?.intent)
|
|
619
|
+
} catch (_: Throwable) {}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
private fun ensurePushListener() {
|
|
623
|
+
if (pushListener != null) return
|
|
624
|
+
val listener: (NotificationOpen) -> Unit = { open ->
|
|
625
|
+
reactContext
|
|
626
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
627
|
+
.emit(PUSH_OPENED_EVENT, encodeOpen(open))
|
|
628
|
+
}
|
|
629
|
+
pushListener = listener
|
|
630
|
+
SwissKnife.notifications.addOpenedListener(listener)
|
|
631
|
+
replayLaunchIntent()
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
private fun encodeOpen(open: NotificationOpen): WritableMap {
|
|
635
|
+
val map = Arguments.createMap()
|
|
636
|
+
open.messageId?.let { map.putString("messageId", it) }
|
|
637
|
+
open.deliveryId?.let { map.putString("deliveryId", it) }
|
|
638
|
+
open.link?.let { map.putString("link", it) }
|
|
639
|
+
open.actionId?.let { map.putString("actionId", it) }
|
|
640
|
+
val data = Arguments.createMap()
|
|
641
|
+
for ((k, v) in open.data) data.putString(k, v)
|
|
642
|
+
map.putMap("data", data)
|
|
643
|
+
return map
|
|
644
|
+
}
|
|
645
|
+
|
|
486
646
|
// ----- NativeEventEmitter book-keeping (no-op on Android; required by JS spec) -----
|
|
487
647
|
|
|
488
648
|
@ReactMethod
|
|
489
|
-
fun addListener(eventType: String) {
|
|
649
|
+
fun addListener(eventType: String) {
|
|
650
|
+
if (eventType == PUSH_OPENED_EVENT) ensurePushListener()
|
|
651
|
+
}
|
|
490
652
|
|
|
491
653
|
@ReactMethod
|
|
492
654
|
fun removeListeners(count: Double) { /* no-op */ }
|
|
@@ -4,6 +4,7 @@ Copied verbatim by packages/react-native-sdk/scripts/vendor-native.mjs from the
|
|
|
4
4
|
standalone native SDK sources in the monorepo. Edit those instead:
|
|
5
5
|
|
|
6
6
|
packages/swiss-knife-ios/Sources/SwissKnifeiOS/**
|
|
7
|
+
packages/swiss-knife-ios/Sources/SwissKnifeNotificationService/**
|
|
7
8
|
packages/swiss-knife-android/src/main/{java,res}/**
|
|
8
9
|
|
|
9
10
|
This directory is gitignored and regenerated on every `build` / `prepack`.
|
|
@@ -137,7 +137,7 @@ object SwissKnife {
|
|
|
137
137
|
logLevel: String? = null,
|
|
138
138
|
attribution: Attribution.Configuration = Attribution.Configuration(),
|
|
139
139
|
) {
|
|
140
|
-
|
|
140
|
+
if (rejectsBlankApiKey(apiKey, "configure")) return
|
|
141
141
|
configureCore(
|
|
142
142
|
context = context,
|
|
143
143
|
apiKey = apiKey,
|
|
@@ -189,7 +189,7 @@ object SwissKnife {
|
|
|
189
189
|
logLevel: String? = null,
|
|
190
190
|
attribution: Attribution.Configuration = Attribution.Configuration(),
|
|
191
191
|
) {
|
|
192
|
-
|
|
192
|
+
if (rejectsBlankApiKey(apiKey, "configureCore")) return
|
|
193
193
|
val serverUrl = proxyURL?.trimEnd('/').orEmpty()
|
|
194
194
|
// Phase 3 of the RC rip-and-replace — wire AttributesClient so the
|
|
195
195
|
// setEmail/setPhoneNumber/etc. methods below have somewhere to send to.
|
|
@@ -280,20 +280,27 @@ object SwissKnife {
|
|
|
280
280
|
proxyURL: String? = null,
|
|
281
281
|
useAmazon: Boolean = false,
|
|
282
282
|
) {
|
|
283
|
-
|
|
283
|
+
if (rejectsBlankApiKey(apiKey, "configurePurchases")) return
|
|
284
284
|
gateway.configure(context, apiKey, appUserID, proxyURL, useAmazon)
|
|
285
285
|
// Wire OfferingsRepository for any store that supplies a price-enrichment
|
|
286
|
-
// provider (Play via BillingClientGateway, RuStore via the add-on)
|
|
287
|
-
//
|
|
288
|
-
//
|
|
286
|
+
// provider (Play via BillingClientGateway, RuStore via the add-on); it then
|
|
287
|
+
// answers getOfferings() and getOfferingsForPaywall(). A gateway without
|
|
288
|
+
// one (the test FakePurchasesGateway) answers getOfferings() itself and
|
|
289
|
+
// never reaches a real store query, so the repository is cleared for it:
|
|
290
|
+
// one wired by an earlier configure in this process must not shadow it.
|
|
291
|
+
// A blank proxyURL means the SDK's default host, as on iOS.
|
|
289
292
|
val priceProvider = gateway.priceEnrichmentProvider()
|
|
290
|
-
|
|
291
|
-
|
|
293
|
+
val storeGateway = gateway
|
|
294
|
+
offeringsRepository = priceProvider?.let {
|
|
295
|
+
com.appswissknife.offerings.OfferingsRepository(
|
|
292
296
|
httpClient = com.appswissknife.net.BackendHttpClientAdapter(),
|
|
293
|
-
serverUrl = proxyURL
|
|
297
|
+
serverUrl = proxyURL?.trimEnd('/').orEmpty(),
|
|
294
298
|
apiKey = apiKey,
|
|
295
|
-
platformTags =
|
|
296
|
-
priceProvider =
|
|
299
|
+
platformTags = it.platformTags(),
|
|
300
|
+
priceProvider = it,
|
|
301
|
+
// The backend's product types reach the gateway that sells them (the
|
|
302
|
+
// Play gateway finds consumables an older SDK left unconsumed).
|
|
303
|
+
onServerProductTypes = storeGateway::onServerProductTypes,
|
|
297
304
|
)
|
|
298
305
|
}
|
|
299
306
|
// Same store-agnostic gate as the offerings wiring: real store gateways
|
|
@@ -321,6 +328,25 @@ object SwissKnife {
|
|
|
321
328
|
@Volatile
|
|
322
329
|
private var coreConfigured = false
|
|
323
330
|
|
|
331
|
+
/**
|
|
332
|
+
* True (after logging an error) when [apiKey] is empty or whitespace.
|
|
333
|
+
*
|
|
334
|
+
* Every entry point that takes the project's SDK key calls this first and
|
|
335
|
+
* returns without changing any state when it is true. A blank key is almost
|
|
336
|
+
* always a build-time value that was not set; throwing here used to crash the
|
|
337
|
+
* host app at launch, and wiring the SDK against it would mark it configured
|
|
338
|
+
* with a key the backend refuses. Left unconfigured, a later call with the
|
|
339
|
+
* real key still configures everything. iOS does the same.
|
|
340
|
+
*/
|
|
341
|
+
private fun rejectsBlankApiKey(apiKey: String, entryPoint: String): Boolean {
|
|
342
|
+
if (apiKey.isNotBlank()) return false
|
|
343
|
+
com.appswissknife.diagnostics.SKLog.error("swissknife") {
|
|
344
|
+
"SwissKnife.$entryPoint was called with an empty apiKey; nothing was configured. " +
|
|
345
|
+
"Pass the project's SDK key."
|
|
346
|
+
}
|
|
347
|
+
return true
|
|
348
|
+
}
|
|
349
|
+
|
|
324
350
|
/**
|
|
325
351
|
* Wire the observability backend (analytics / crash / performance ingest)
|
|
326
352
|
* WITHOUT requiring [configure] or the purchase engine. Idempotent — safe to
|
|
@@ -341,11 +367,18 @@ object SwissKnife {
|
|
|
341
367
|
*
|
|
342
368
|
* A blank [serverUrl] means "use the SDK default host", matching a null
|
|
343
369
|
* `proxyURL` on [configure].
|
|
370
|
+
*
|
|
371
|
+
* A blank [apiKey] is a logged no-op that does NOT count as the first call:
|
|
372
|
+
* nothing is wired and the once-guard stays open, so a later call with the
|
|
373
|
+
* real key (from [configureCore], or the React Native crash or analytics
|
|
374
|
+
* init) wires everything. Before, an empty key from the React Native
|
|
375
|
+
* `CrashReporting.init` latched the guard and wired the pipeline against it.
|
|
344
376
|
*/
|
|
345
377
|
@JvmStatic
|
|
346
378
|
@Synchronized
|
|
347
379
|
fun ensureObservabilityBackend(context: Context, apiKey: String, serverUrl: String) {
|
|
348
380
|
if (observabilityWired) return
|
|
381
|
+
if (rejectsBlankApiKey(apiKey, "ensureObservabilityBackend")) return
|
|
349
382
|
observabilityWired = true
|
|
350
383
|
// Configure Identity if the purchase `configure()` path hasn't already.
|
|
351
384
|
// Without this, the observability-only path (RuStore / analytics-without-
|
|
@@ -396,6 +429,7 @@ object SwissKnife {
|
|
|
396
429
|
)
|
|
397
430
|
}
|
|
398
431
|
runCatching { com.appswissknife.context.DeviceContextProvider.install(context) }
|
|
432
|
+
runCatching { com.appswissknife.notifications.SwissKnifeNotifications.attach(context) }
|
|
399
433
|
runCatching {
|
|
400
434
|
com.appswissknife.context.Session.shared(context).apply {
|
|
401
435
|
startObservingLifecycle()
|
|
@@ -411,13 +445,16 @@ object SwissKnife {
|
|
|
411
445
|
com.appswissknife.net.IngestClient.install(ingestClient)
|
|
412
446
|
com.appswissknife.context.Reachability.shared(context).installAsIngestObserver()
|
|
413
447
|
}
|
|
414
|
-
//
|
|
415
|
-
// trackPreBuiltEvent() early-
|
|
416
|
-
//
|
|
417
|
-
//
|
|
418
|
-
//
|
|
448
|
+
// SKAnalytics needs its appContext, WITHOUT which track() and
|
|
449
|
+
// trackPreBuiltEvent() early-return and silently drop every event (the
|
|
450
|
+
// React Native bridges never call SKAnalytics.initialize). A host that
|
|
451
|
+
// initialized analytics itself keeps its configuration: re-initializing
|
|
452
|
+
// with the defaults here used to drop its optOut, trackingSessionEvents
|
|
453
|
+
// and flush interval and track a second Session Start, so an opted-out
|
|
454
|
+
// user was tracked again. Either way the events held so far go to
|
|
455
|
+
// IngestClient.shared (installed above) → POST /ingest.
|
|
419
456
|
runCatching {
|
|
420
|
-
com.appswissknife.analytics.SKAnalytics.
|
|
457
|
+
com.appswissknife.analytics.SKAnalytics.initializeUnlessInitialized(
|
|
421
458
|
context,
|
|
422
459
|
com.appswissknife.analytics.SKAnalyticsConfiguration(
|
|
423
460
|
apiKey = apiKey,
|
|
@@ -453,6 +490,17 @@ object SwissKnife {
|
|
|
453
490
|
@JvmStatic
|
|
454
491
|
fun isAnonymous(): Boolean = gateway.isAnonymous()
|
|
455
492
|
|
|
493
|
+
/**
|
|
494
|
+
* [Identity.reset] and [Identity.wipe] left no user. The purchases gateway
|
|
495
|
+
* keeps a user id of its own (set by logIn) and that user's cached
|
|
496
|
+
* entitlements; this drops both, so [appUserID] and [getCustomerInfo]
|
|
497
|
+
* answer for the anonymous user. Mirror of iOS
|
|
498
|
+
* `SwissKnife.identityResetLocalState()`.
|
|
499
|
+
*/
|
|
500
|
+
internal fun identityResetLocalState() {
|
|
501
|
+
gateway.resetToAnonymous()
|
|
502
|
+
}
|
|
503
|
+
|
|
456
504
|
// ----- Reads / offerings (typed) -----
|
|
457
505
|
|
|
458
506
|
@JvmStatic
|
|
@@ -461,30 +509,32 @@ object SwissKnife {
|
|
|
461
509
|
}
|
|
462
510
|
|
|
463
511
|
/**
|
|
464
|
-
*
|
|
512
|
+
* The app's offerings: every active paywall as an [com.appswissknife.models.Offering],
|
|
513
|
+
* with [Offerings.current] the one the dashboard marks current (else the
|
|
514
|
+
* oldest active one). The same answer as iOS `SwissKnife.getOfferings()`, and
|
|
515
|
+
* what React Native's `Purchases.getOfferings()` returns on Android.
|
|
516
|
+
*
|
|
517
|
+
* Read from `/api/sdk/offerings` by [com.appswissknife.offerings.OfferingsRepository]
|
|
518
|
+
* and priced live by the store (Play, or RuStore with that add-on); a
|
|
519
|
+
* product the store cannot price keeps its dashboard price. Cached for an
|
|
520
|
+
* hour. Callbacks run on a background thread. Call it after [configure].
|
|
465
521
|
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
* Billing has no equivalent "offerings" concept - that belongs to
|
|
469
|
-
* [com.appswissknife.offerings.OfferingsRepository], which is keyed by
|
|
470
|
-
* paywall slug. Call [getOfferingsForPaywall] for production. This
|
|
471
|
-
* no-arg variant stays on the surface for RC parity (tests that inject
|
|
472
|
-
* a [FakePurchasesGateway] still drive it).
|
|
522
|
+
* A gateway that brings no store price provider (the test
|
|
523
|
+
* [com.appswissknife.purchases.FakePurchasesGateway]) answers it itself.
|
|
473
524
|
*/
|
|
474
525
|
@JvmStatic
|
|
475
526
|
fun getOfferings(onSuccess: (Offerings) -> Unit, onError: (PurchasesError) -> Unit) {
|
|
476
|
-
gateway.getOfferings(onSuccess, onError)
|
|
527
|
+
val repo = offeringsRepository ?: run { gateway.getOfferings(onSuccess, onError); return }
|
|
528
|
+
fetchOfferingsInBackground(onSuccess, onError) { repo.current() }
|
|
477
529
|
}
|
|
478
530
|
|
|
479
531
|
/**
|
|
480
|
-
*
|
|
481
|
-
* [
|
|
482
|
-
*
|
|
483
|
-
*
|
|
532
|
+
* The offering for one paywall, with the variant an experiment assigned this
|
|
533
|
+
* user, from `/api/sdk/paywalls/show`, priced like [getOfferings]. For a host
|
|
534
|
+
* that renders a specific paywall and runs paywall experiments; most apps
|
|
535
|
+
* call [getOfferings] and pick from [Offerings.all] or [Offerings.current].
|
|
484
536
|
*
|
|
485
|
-
* Must be called AFTER [configure].
|
|
486
|
-
* knowing which paywall slug to render (paywall selection is a product
|
|
487
|
-
* decision the SDK does not auto-resolve).
|
|
537
|
+
* Must be called AFTER [configure].
|
|
488
538
|
*/
|
|
489
539
|
@JvmStatic
|
|
490
540
|
fun getOfferingsForPaywall(
|
|
@@ -494,8 +544,17 @@ object SwissKnife {
|
|
|
494
544
|
) {
|
|
495
545
|
val repo = offeringsRepository
|
|
496
546
|
?: run { onError(PurchasesError.Unknown("SDK not configured")); return }
|
|
547
|
+
fetchOfferingsInBackground(onSuccess, onError) { repo.current(paywallSlug, appUserID) }
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/** Run [fetch] (network and store queries) off the caller's thread. */
|
|
551
|
+
private fun fetchOfferingsInBackground(
|
|
552
|
+
onSuccess: (Offerings) -> Unit,
|
|
553
|
+
onError: (PurchasesError) -> Unit,
|
|
554
|
+
fetch: () -> Offerings,
|
|
555
|
+
) {
|
|
497
556
|
Thread({
|
|
498
|
-
runCatching
|
|
557
|
+
runCatching(fetch)
|
|
499
558
|
.onSuccess(onSuccess)
|
|
500
559
|
.onFailure { onError(PurchasesError.NetworkError(it.message ?: "Network error", it)) }
|
|
501
560
|
}, "swissknife-offerings-fetch").apply { isDaemon = true }.start()
|
|
@@ -611,9 +670,22 @@ object SwissKnife {
|
|
|
611
670
|
@JvmStatic fun setDisplayName(displayName: String?) =
|
|
612
671
|
AttributesClient.instance.set("\$displayName", displayName)
|
|
613
672
|
|
|
673
|
+
/**
|
|
674
|
+
* Legacy attribute-only path (`$pushToken` user attribute). It does NOT
|
|
675
|
+
* register the device for delivery.
|
|
676
|
+
*/
|
|
677
|
+
@Deprecated(
|
|
678
|
+
"Use SwissKnife.notifications.registerToken(token) / fetchAndRegisterToken() - the device registry powers delivery.",
|
|
679
|
+
ReplaceWith("SwissKnife.notifications.registerToken(pushToken)"),
|
|
680
|
+
)
|
|
614
681
|
@JvmStatic fun setPushToken(pushToken: String?) =
|
|
615
682
|
AttributesClient.instance.set("\$pushToken", pushToken)
|
|
616
683
|
|
|
684
|
+
/** Push notifications (permission, FCM token registration, open tracking). */
|
|
685
|
+
@JvmStatic
|
|
686
|
+
val notifications: com.appswissknife.notifications.SwissKnifeNotifications
|
|
687
|
+
get() = com.appswissknife.notifications.SwissKnifeNotifications
|
|
688
|
+
|
|
617
689
|
// ----- Device identifier (RN bridge facade) -----
|
|
618
690
|
|
|
619
691
|
/**
|
|
@@ -682,10 +754,11 @@ object SwissKnife {
|
|
|
682
754
|
}
|
|
683
755
|
|
|
684
756
|
/**
|
|
685
|
-
* Kick off a flush of the
|
|
686
|
-
*
|
|
687
|
-
*
|
|
688
|
-
*
|
|
757
|
+
* Kick off a flush of the telemetry queue. Fire-and-forget: it hands any
|
|
758
|
+
* events held since before configure to [com.appswissknife.net.IngestClient]
|
|
759
|
+
* and schedules its WorkManager drain (`IngestFlushWorker`), which POSTs the
|
|
760
|
+
* queue to `/ingest` with the client's backoff and 4xx policy. A no-op until
|
|
761
|
+
* [configureCore] (or [configure]) has wired the ingest pipeline.
|
|
689
762
|
*/
|
|
690
763
|
@JvmStatic
|
|
691
764
|
fun flushEvents() {
|