@app-swiss-knife/react-native-sdk 0.1.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/README.md +182 -0
- package/SwissKnifePurchases.podspec +40 -0
- package/android/build.gradle +89 -0
- package/android/gradle.properties +3 -0
- package/android/src/main/AndroidManifest.xml +26 -0
- package/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingModule.kt +216 -0
- package/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingPackage.kt +17 -0
- package/android/src/main/java/com/swissknife/purchases/Conversions.kt +15 -0
- package/android/src/main/java/com/swissknife/purchases/SwissKnifeJson.kt +371 -0
- package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesModule.kt +497 -0
- package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesPackage.kt +25 -0
- package/android/vendor/GENERATED.md +10 -0
- package/android/vendor/java/com/appswissknife/SwissKnife.kt +533 -0
- package/android/vendor/java/com/appswissknife/analytics/EventQueueStore.kt +326 -0
- package/android/vendor/java/com/appswissknife/analytics/FlushEventsWorker.kt +296 -0
- package/android/vendor/java/com/appswissknife/analytics/SKAnalytics.kt +503 -0
- package/android/vendor/java/com/appswissknife/attributes/AttributesClient.kt +188 -0
- package/android/vendor/java/com/appswissknife/attributes/SetAttributesWorker.kt +204 -0
- package/android/vendor/java/com/appswissknife/attribution/Attribution.kt +447 -0
- package/android/vendor/java/com/appswissknife/context/AppLifecycle.kt +120 -0
- package/android/vendor/java/com/appswissknife/context/Clock.kt +70 -0
- package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +138 -0
- package/android/vendor/java/com/appswissknife/context/IDs.kt +55 -0
- package/android/vendor/java/com/appswissknife/context/Reachability.kt +145 -0
- package/android/vendor/java/com/appswissknife/context/Session.kt +192 -0
- package/android/vendor/java/com/appswissknife/crashreporting/SKCrashReporting.kt +945 -0
- package/android/vendor/java/com/appswissknife/crashreporting/SKScreenshot.kt +201 -0
- package/android/vendor/java/com/appswissknife/device/DeviceID.kt +172 -0
- package/android/vendor/java/com/appswissknife/diagnostics/SKLog.kt +97 -0
- package/android/vendor/java/com/appswissknife/entitlements/EntitlementsRepository.kt +495 -0
- package/android/vendor/java/com/appswissknife/identity/Identity.kt +522 -0
- package/android/vendor/java/com/appswissknife/models/CustomerInfo.kt +67 -0
- package/android/vendor/java/com/appswissknife/models/Enums.kt +35 -0
- package/android/vendor/java/com/appswissknife/models/Offerings.kt +80 -0
- package/android/vendor/java/com/appswissknife/models/PurchasesError.kt +89 -0
- package/android/vendor/java/com/appswissknife/models/StoreTransaction.kt +17 -0
- package/android/vendor/java/com/appswissknife/net/BackendHttpClient.kt +507 -0
- package/android/vendor/java/com/appswissknife/net/ExponentialBackoff.kt +69 -0
- package/android/vendor/java/com/appswissknife/net/IngestClient.kt +582 -0
- package/android/vendor/java/com/appswissknife/net/OfflineQueueStore.kt +320 -0
- package/android/vendor/java/com/appswissknife/offerings/OfferingsRepository.kt +219 -0
- package/android/vendor/java/com/appswissknife/performance/SKFrameTracker.kt +94 -0
- package/android/vendor/java/com/appswissknife/performance/SKPerformance.kt +428 -0
- package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +560 -0
- package/android/vendor/java/com/appswissknife/purchases/PlayPriceEnrichmentProvider.kt +100 -0
- package/android/vendor/java/com/appswissknife/purchases/PriceEnrichmentProvider.kt +36 -0
- package/android/vendor/java/com/appswissknife/purchases/PurchasesGateway.kt +120 -0
- package/android/vendor/res/xml/swissknife_data_extraction_rules.xml +20 -0
- package/ios/SwissKnifeCrashReporting.m +32 -0
- package/ios/SwissKnifeCrashReporting.swift +186 -0
- package/ios/SwissKnifeJSON.swift +347 -0
- package/ios/SwissKnifePurchases.m +124 -0
- package/ios/SwissKnifePurchases.swift +523 -0
- package/ios/vendor/GENERATED.md +10 -0
- package/ios/vendor/SwissKnifeiOS/Analytics/SKAnalytics.swift +488 -0
- package/ios/vendor/SwissKnifeiOS/AttributesClient.swift +460 -0
- package/ios/vendor/SwissKnifeiOS/Attribution/Attribution.swift +307 -0
- package/ios/vendor/SwissKnifeiOS/Attribution/AttributionNetwork.swift +92 -0
- package/ios/vendor/SwissKnifeiOS/Attribution/AttributionState.swift +141 -0
- package/ios/vendor/SwissKnifeiOS/Context/AppLifecycle.swift +130 -0
- package/ios/vendor/SwissKnifeiOS/Context/Clock.swift +100 -0
- package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +190 -0
- package/ios/vendor/SwissKnifeiOS/Context/IDs.swift +64 -0
- package/ios/vendor/SwissKnifeiOS/Context/Reachability.swift +121 -0
- package/ios/vendor/SwissKnifeiOS/Context/Session.swift +223 -0
- package/ios/vendor/SwissKnifeiOS/CrashReporting/SKCrashReporting.swift +1287 -0
- package/ios/vendor/SwissKnifeiOS/CrashReporting/SKScreenshot.swift +175 -0
- package/ios/vendor/SwissKnifeiOS/DeviceID.swift +161 -0
- package/ios/vendor/SwissKnifeiOS/Diagnostics/SKLog.swift +128 -0
- package/ios/vendor/SwissKnifeiOS/Identity/Identity.swift +323 -0
- package/ios/vendor/SwissKnifeiOS/Identity/IdentityNetwork.swift +70 -0
- package/ios/vendor/SwissKnifeiOS/Net/BackendHttpClient.swift +329 -0
- package/ios/vendor/SwissKnifeiOS/Net/ExponentialBackoff.swift +87 -0
- package/ios/vendor/SwissKnifeiOS/Net/IngestClient.swift +681 -0
- package/ios/vendor/SwissKnifeiOS/Net/OfflineQueueStore.swift +409 -0
- package/ios/vendor/SwissKnifeiOS/Performance/SKFrameTracker.swift +89 -0
- package/ios/vendor/SwissKnifeiOS/Performance/SKPerformance.swift +440 -0
- package/ios/vendor/SwissKnifeiOS/Performance/SKURLSessionDelegate.swift +87 -0
- package/ios/vendor/SwissKnifeiOS/Services/EntitlementsService.swift +646 -0
- package/ios/vendor/SwissKnifeiOS/Services/OfferingsService.swift +458 -0
- package/ios/vendor/SwissKnifeiOS/Services/PurchaseService.swift +374 -0
- package/ios/vendor/SwissKnifeiOS/SwissKnife+Analytics.swift +46 -0
- package/ios/vendor/SwissKnifeiOS/SwissKnife+DeviceID.swift +30 -0
- package/ios/vendor/SwissKnifeiOS/SwissKnife+Session.swift +47 -0
- package/ios/vendor/SwissKnifeiOS/SwissKnife.swift +417 -0
- package/ios/vendor/SwissKnifeiOS/Types.swift +496 -0
- package/lib/commonjs/attribution.js +55 -0
- package/lib/commonjs/attribution.js.map +1 -0
- package/lib/commonjs/identity.js +126 -0
- package/lib/commonjs/identity.js.map +1 -0
- package/lib/commonjs/index.js +118 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/modules/analytics.js +646 -0
- package/lib/commonjs/modules/analytics.js.map +1 -0
- package/lib/commonjs/modules/attachments.js +169 -0
- package/lib/commonjs/modules/attachments.js.map +1 -0
- package/lib/commonjs/modules/crash-reporting.js +1327 -0
- package/lib/commonjs/modules/crash-reporting.js.map +1 -0
- package/lib/commonjs/modules/ids.js +50 -0
- package/lib/commonjs/modules/ids.js.map +1 -0
- package/lib/commonjs/modules/log.js +59 -0
- package/lib/commonjs/modules/log.js.map +1 -0
- package/lib/commonjs/modules/offline-store.js +44 -0
- package/lib/commonjs/modules/offline-store.js.map +1 -0
- package/lib/commonjs/modules/performance.js +494 -0
- package/lib/commonjs/modules/performance.js.map +1 -0
- package/lib/commonjs/native/module.js +41 -0
- package/lib/commonjs/native/module.js.map +1 -0
- package/lib/commonjs/native/spec.js +26 -0
- package/lib/commonjs/native/spec.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/purchases.js +194 -0
- package/lib/commonjs/purchases.js.map +1 -0
- package/lib/commonjs/types.js +236 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/module/attribution.js +51 -0
- package/lib/module/attribution.js.map +1 -0
- package/lib/module/identity.js +122 -0
- package/lib/module/identity.js.map +1 -0
- package/lib/module/index.js +36 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/modules/analytics.js +642 -0
- package/lib/module/modules/analytics.js.map +1 -0
- package/lib/module/modules/attachments.js +162 -0
- package/lib/module/modules/attachments.js.map +1 -0
- package/lib/module/modules/crash-reporting.js +1320 -0
- package/lib/module/modules/crash-reporting.js.map +1 -0
- package/lib/module/modules/ids.js +44 -0
- package/lib/module/modules/ids.js.map +1 -0
- package/lib/module/modules/log.js +54 -0
- package/lib/module/modules/log.js.map +1 -0
- package/lib/module/modules/offline-store.js +39 -0
- package/lib/module/modules/offline-store.js.map +1 -0
- package/lib/module/modules/performance.js +491 -0
- package/lib/module/modules/performance.js.map +1 -0
- package/lib/module/native/module.js +34 -0
- package/lib/module/native/module.js.map +1 -0
- package/lib/module/native/spec.js +22 -0
- package/lib/module/native/spec.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/purchases.js +187 -0
- package/lib/module/purchases.js.map +1 -0
- package/lib/module/types.js +230 -0
- package/lib/module/types.js.map +1 -0
- package/lib/typescript/commonjs/attribution.d.ts +24 -0
- package/lib/typescript/commonjs/attribution.d.ts.map +1 -0
- package/lib/typescript/commonjs/identity.d.ts +37 -0
- package/lib/typescript/commonjs/identity.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +15 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/analytics.d.ts +127 -0
- package/lib/typescript/commonjs/modules/analytics.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/attachments.d.ts +50 -0
- package/lib/typescript/commonjs/modules/attachments.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/crash-reporting.d.ts +175 -0
- package/lib/typescript/commonjs/modules/crash-reporting.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/ids.d.ts +17 -0
- package/lib/typescript/commonjs/modules/ids.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/log.d.ts +12 -0
- package/lib/typescript/commonjs/modules/log.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/offline-store.d.ts +9 -0
- package/lib/typescript/commonjs/modules/offline-store.d.ts.map +1 -0
- package/lib/typescript/commonjs/modules/performance.d.ts +75 -0
- package/lib/typescript/commonjs/modules/performance.d.ts.map +1 -0
- package/lib/typescript/commonjs/native/module.d.ts +6 -0
- package/lib/typescript/commonjs/native/module.d.ts.map +1 -0
- package/lib/typescript/commonjs/native/spec.d.ts +119 -0
- package/lib/typescript/commonjs/native/spec.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/purchases.d.ts +68 -0
- package/lib/typescript/commonjs/purchases.d.ts.map +1 -0
- package/lib/typescript/commonjs/types.d.ts +384 -0
- package/lib/typescript/commonjs/types.d.ts.map +1 -0
- package/lib/typescript/module/attribution.d.ts +24 -0
- package/lib/typescript/module/attribution.d.ts.map +1 -0
- package/lib/typescript/module/identity.d.ts +37 -0
- package/lib/typescript/module/identity.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +15 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/modules/analytics.d.ts +127 -0
- package/lib/typescript/module/modules/analytics.d.ts.map +1 -0
- package/lib/typescript/module/modules/attachments.d.ts +50 -0
- package/lib/typescript/module/modules/attachments.d.ts.map +1 -0
- package/lib/typescript/module/modules/crash-reporting.d.ts +175 -0
- package/lib/typescript/module/modules/crash-reporting.d.ts.map +1 -0
- package/lib/typescript/module/modules/ids.d.ts +17 -0
- package/lib/typescript/module/modules/ids.d.ts.map +1 -0
- package/lib/typescript/module/modules/log.d.ts +12 -0
- package/lib/typescript/module/modules/log.d.ts.map +1 -0
- package/lib/typescript/module/modules/offline-store.d.ts +9 -0
- package/lib/typescript/module/modules/offline-store.d.ts.map +1 -0
- package/lib/typescript/module/modules/performance.d.ts +75 -0
- package/lib/typescript/module/modules/performance.d.ts.map +1 -0
- package/lib/typescript/module/native/module.d.ts +6 -0
- package/lib/typescript/module/native/module.d.ts.map +1 -0
- package/lib/typescript/module/native/spec.d.ts +119 -0
- package/lib/typescript/module/native/spec.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/purchases.d.ts +68 -0
- package/lib/typescript/module/purchases.d.ts.map +1 -0
- package/lib/typescript/module/types.d.ts +384 -0
- package/lib/typescript/module/types.d.ts.map +1 -0
- package/package.json +115 -0
- package/react-native.config.js +23 -0
- package/src/attribution.ts +56 -0
- package/src/identity.ts +133 -0
- package/src/index.ts +54 -0
- package/src/modules/analytics.ts +689 -0
- package/src/modules/attachments.ts +222 -0
- package/src/modules/crash-reporting.ts +1577 -0
- package/src/modules/ids.ts +41 -0
- package/src/modules/log.ts +56 -0
- package/src/modules/offline-store.ts +51 -0
- package/src/modules/performance.ts +589 -0
- package/src/native/module.ts +47 -0
- package/src/native/spec.ts +183 -0
- package/src/purchases.ts +214 -0
- package/src/types.ts +470 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// packages/swiss-knife-android/src/main/java/com/appswissknife/purchases/PurchasesGateway.kt
|
|
2
|
+
package com.appswissknife.purchases
|
|
3
|
+
|
|
4
|
+
import android.app.Activity
|
|
5
|
+
import android.content.Context
|
|
6
|
+
import com.appswissknife.StoreTransactionResult
|
|
7
|
+
import com.appswissknife.models.CustomerInfo
|
|
8
|
+
import com.appswissknife.models.LogLevel
|
|
9
|
+
import com.appswissknife.models.Offerings
|
|
10
|
+
import com.appswissknife.models.Package
|
|
11
|
+
import com.appswissknife.models.PurchasesError
|
|
12
|
+
import com.appswissknife.models.StoreProduct
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Internal seam between [com.appswissknife.SwissKnife] and the underlying
|
|
16
|
+
* subscriptions/billing implementation.
|
|
17
|
+
*
|
|
18
|
+
* Phase 6 status: PHC is gone. The production implementation is
|
|
19
|
+
* [BillingClientGateway] which uses Google Play Billing v8 directly + our own
|
|
20
|
+
* `/api/sdk/subscriptions/validate` for receipt validation.
|
|
21
|
+
*
|
|
22
|
+
* Tests inject [com.appswissknife.purchases.FakePurchasesGateway] via
|
|
23
|
+
* [com.appswissknife.SwissKnife.setGateway] to assert behavior without
|
|
24
|
+
* spinning up Play Billing.
|
|
25
|
+
*
|
|
26
|
+
* **Threading.** Callbacks may fire on the main thread (UI-facing operations)
|
|
27
|
+
* or on a background pool (I/O completes there). Tests fake synchronous,
|
|
28
|
+
* same-thread completion by default for determinism — see
|
|
29
|
+
* [FakePurchasesGateway.useAsyncCallbacks].
|
|
30
|
+
*
|
|
31
|
+
* **Types.** All types crossing this interface are own data classes /
|
|
32
|
+
* interfaces from [com.appswissknife.models]. As of Phase 6 there are NO
|
|
33
|
+
* RevenueCat types on the public SDK surface anymore.
|
|
34
|
+
*/
|
|
35
|
+
interface PurchasesGateway {
|
|
36
|
+
|
|
37
|
+
/** Initialize the underlying SDK. May only be called once per process. */
|
|
38
|
+
fun configure(
|
|
39
|
+
context: Context,
|
|
40
|
+
apiKey: String,
|
|
41
|
+
appUserID: String?,
|
|
42
|
+
proxyURL: String?,
|
|
43
|
+
useAmazon: Boolean,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
/** Whether [configure] has completed successfully. */
|
|
47
|
+
fun isConfigured(): Boolean
|
|
48
|
+
|
|
49
|
+
/** Current app user identifier (anonymous-prefixed if not logged in). */
|
|
50
|
+
fun getAppUserID(): String
|
|
51
|
+
|
|
52
|
+
/** True iff the current user is anonymous (never explicitly logged in). */
|
|
53
|
+
fun isAnonymous(): Boolean
|
|
54
|
+
|
|
55
|
+
// --- Reads ----------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
fun getCustomerInfo(onSuccess: (CustomerInfo) -> Unit, onError: (PurchasesError) -> Unit)
|
|
58
|
+
fun getOfferings(onSuccess: (Offerings) -> Unit, onError: (PurchasesError) -> Unit)
|
|
59
|
+
|
|
60
|
+
// --- Purchases ------------------------------------------------------------
|
|
61
|
+
|
|
62
|
+
fun purchasePackage(
|
|
63
|
+
activity: Activity,
|
|
64
|
+
packageToPurchase: Package,
|
|
65
|
+
onSuccess: (StoreTransactionResult) -> Unit,
|
|
66
|
+
onError: (PurchasesError, userCancelled: Boolean) -> Unit,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
fun purchaseStoreProduct(
|
|
70
|
+
activity: Activity,
|
|
71
|
+
product: StoreProduct,
|
|
72
|
+
onSuccess: (StoreTransactionResult) -> Unit,
|
|
73
|
+
onError: (PurchasesError, userCancelled: Boolean) -> Unit,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
fun restorePurchases(onSuccess: (CustomerInfo) -> Unit, onError: (PurchasesError) -> Unit)
|
|
77
|
+
|
|
78
|
+
// --- Offerings price enrichment -------------------------------------------
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The store-specific price enrichment provider, used by
|
|
82
|
+
* [com.appswissknife.offerings.OfferingsRepository] to enrich backend paywall
|
|
83
|
+
* products with live prices and to know which backend `platform` rows belong
|
|
84
|
+
* to this store. `null` (default) means no live enrichment and no production
|
|
85
|
+
* offerings wiring — e.g. the test [FakePurchasesGateway]. Real store gateways
|
|
86
|
+
* (Play, RuStore) return a non-null provider.
|
|
87
|
+
*/
|
|
88
|
+
fun priceEnrichmentProvider(): PriceEnrichmentProvider? = null
|
|
89
|
+
|
|
90
|
+
// --- Identity -------------------------------------------------------------
|
|
91
|
+
|
|
92
|
+
fun logIn(
|
|
93
|
+
appUserID: String,
|
|
94
|
+
onSuccess: (CustomerInfo, created: Boolean) -> Unit,
|
|
95
|
+
onError: (PurchasesError) -> Unit,
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
fun logOut(onSuccess: (CustomerInfo) -> Unit, onError: (PurchasesError) -> Unit)
|
|
99
|
+
|
|
100
|
+
// --- Subscriber attributes ------------------------------------------------
|
|
101
|
+
//
|
|
102
|
+
// Removed in Phase 3 of the RC rip-and-replace. Attributes now flow to our
|
|
103
|
+
// own /api/sdk/users/attributes endpoint via
|
|
104
|
+
// [com.appswissknife.attributes.AttributesClient] instead of going through
|
|
105
|
+
// PHC's top-level set* functions. The public surface on
|
|
106
|
+
// [com.appswissknife.SwissKnife] is unchanged.
|
|
107
|
+
|
|
108
|
+
// --- Log level ------------------------------------------------------------
|
|
109
|
+
|
|
110
|
+
fun setLogLevel(level: LogLevel)
|
|
111
|
+
|
|
112
|
+
// --- Customer-info update stream -----------------------------------------
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Subscribe the gateway to push CustomerInfo updates to [listener].
|
|
116
|
+
* Listeners are kept until explicitly removed via [removeCustomerInfoListener].
|
|
117
|
+
*/
|
|
118
|
+
fun addCustomerInfoListener(listener: (CustomerInfo) -> Unit)
|
|
119
|
+
fun removeCustomerInfoListener(listener: (CustomerInfo) -> Unit)
|
|
120
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!--
|
|
3
|
+
Excludes the Swiss Knife persistent DeviceID SharedPreferences file from
|
|
4
|
+
both Auto Backup (cloud-backup) and Device-to-Device Transfer
|
|
5
|
+
(device-transfer). Carrying the device_id to a different physical device
|
|
6
|
+
would silently merge two users' analytics into one timeline.
|
|
7
|
+
|
|
8
|
+
Why both: cloud-backup covers Google Drive Auto Backup; device-transfer
|
|
9
|
+
covers the OEM device-setup transfer path (introduced on Android 12).
|
|
10
|
+
They are independently configured and a host app might enable one
|
|
11
|
+
without the other.
|
|
12
|
+
-->
|
|
13
|
+
<data-extraction-rules>
|
|
14
|
+
<cloud-backup>
|
|
15
|
+
<exclude domain="sharedpref" path="swissknife_device.xml" />
|
|
16
|
+
</cloud-backup>
|
|
17
|
+
<device-transfer>
|
|
18
|
+
<exclude domain="sharedpref" path="swissknife_device.xml" />
|
|
19
|
+
</device-transfer>
|
|
20
|
+
</data-extraction-rules>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// packages/react-native-sdk/ios/SwissKnifeCrashReporting.m
|
|
2
|
+
//
|
|
3
|
+
// ObjC bridge for the SKCrashReporting native module.
|
|
4
|
+
// Registers the Swift `SwissKnifeCrashReporting` class so it's available
|
|
5
|
+
// to RN JS as NativeModules.SKCrashReporting.
|
|
6
|
+
#import <React/RCTBridgeModule.h>
|
|
7
|
+
|
|
8
|
+
@interface RCT_EXTERN_MODULE(SKCrashReporting, NSObject)
|
|
9
|
+
|
|
10
|
+
RCT_EXTERN_METHOD(start:(NSDictionary *)config)
|
|
11
|
+
RCT_EXTERN_METHOD(setUser:(NSDictionary *)user)
|
|
12
|
+
RCT_EXTERN_METHOD(addBreadcrumb:(NSDictionary *)breadcrumb)
|
|
13
|
+
RCT_EXTERN_METHOD(setTag:(NSString *)key value:(NSString *)value)
|
|
14
|
+
|
|
15
|
+
// Masked screenshot capture (wave-2 contract C1).
|
|
16
|
+
// JS: NativeModules.SKCrashReporting.captureScreenshot(): Promise<string|null>
|
|
17
|
+
// Resolves base64 JPEG (no data: prefix, longest side <= 1600px, text inputs
|
|
18
|
+
// blacked out) or null; never rejects.
|
|
19
|
+
RCT_EXTERN_METHOD(captureScreenshot:(RCTPromiseResolveBlock)resolve
|
|
20
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
21
|
+
|
|
22
|
+
// Deliberate native crash triggers for e2e verification of the signal
|
|
23
|
+
// crash pipeline. JS: NativeModules.SKCrashReporting.crashNative()
|
|
24
|
+
RCT_EXTERN_METHOD(crashNative)
|
|
25
|
+
RCT_EXTERN_METHOD(crashNativeSegfault)
|
|
26
|
+
|
|
27
|
+
+ (BOOL)requiresMainQueueSetup
|
|
28
|
+
{
|
|
29
|
+
return NO;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@end
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// packages/react-native-sdk/ios/SwissKnifeCrashReporting.swift
|
|
2
|
+
//
|
|
3
|
+
// RN native module that delegates to SKCrashReporting.shared from the
|
|
4
|
+
// swiss-knife-ios SDK.
|
|
5
|
+
//
|
|
6
|
+
// IMPORTANT: SKCrashReporting is a PURE SWIFT class (no @objc / NSObject), so
|
|
7
|
+
// the old Obj-C reflection approach (`NSClassFromString` + `value(forKey:)` /
|
|
8
|
+
// `perform(_:)`) sent ObjC selectors to a `_SwiftObject` and aborted at launch
|
|
9
|
+
// with `-[_SwiftObject doesNotRecognizeSelector:]` (SIGABRT). We now call the
|
|
10
|
+
// typed Swift API directly.
|
|
11
|
+
//
|
|
12
|
+
// Two link modes, one source file:
|
|
13
|
+
// * CocoaPods (the RN package) — the SDK's Swift sources are VENDORED into
|
|
14
|
+
// this same module from ios/vendor/SwissKnifeiOS/**, so there is no
|
|
15
|
+
// `SwissKnifeiOS` module to import and the podspec defines
|
|
16
|
+
// SWISSKNIFE_VENDORED to keep the code paths live.
|
|
17
|
+
// * SPM / a separately-linked SwissKnifeiOS module — `canImport` is true and
|
|
18
|
+
// the import supplies the types.
|
|
19
|
+
// If somehow neither holds, the module degrades to a safe no-op (JS-side
|
|
20
|
+
// reporting still works) rather than failing to compile.
|
|
21
|
+
|
|
22
|
+
import Foundation
|
|
23
|
+
#if canImport(SwissKnifeiOS)
|
|
24
|
+
import SwissKnifeiOS
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
/// Resolve-once guard for promise methods that race a capture against a
|
|
28
|
+
/// timeout: whichever side finishes first wins, the loser is a no-op. Keeps
|
|
29
|
+
/// the RN promise from being resolved twice (which RN treats as a
|
|
30
|
+
/// programming error).
|
|
31
|
+
private final class SKResolveOnce {
|
|
32
|
+
private let lock = NSLock()
|
|
33
|
+
private var resolved = false
|
|
34
|
+
private let block: (Any?) -> Void
|
|
35
|
+
|
|
36
|
+
init(_ block: @escaping (Any?) -> Void) {
|
|
37
|
+
self.block = block
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func resolve(_ value: Any?) {
|
|
41
|
+
lock.lock()
|
|
42
|
+
let isFirst = !resolved
|
|
43
|
+
resolved = true
|
|
44
|
+
lock.unlock()
|
|
45
|
+
if isFirst { block(value) }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@objc(SKCrashReporting)
|
|
50
|
+
class SwissKnifeCrashReporting: NSObject {
|
|
51
|
+
|
|
52
|
+
@objc
|
|
53
|
+
func start(_ config: NSDictionary) {
|
|
54
|
+
guard let apiKey = config["apiKey"] as? String, !apiKey.isEmpty else { return }
|
|
55
|
+
#if SWISSKNIFE_VENDORED || canImport(SwissKnifeiOS)
|
|
56
|
+
let serverURL = (config["serverURL"] as? String) ?? ""
|
|
57
|
+
let environment = (config["environment"] as? String) ?? "production"
|
|
58
|
+
let release = config["release"] as? String
|
|
59
|
+
let maxBreadcrumbs = (config["maxBreadcrumbs"] as? Int) ?? 100
|
|
60
|
+
let sampleRate = (config["sampleRate"] as? Double) ?? 1.0
|
|
61
|
+
let tracesSampleRate = (config["tracesSampleRate"] as? Double) ?? 1.0
|
|
62
|
+
let enableAutoSessionTracking = (config["enableAutoSessionTracking"] as? Bool) ?? true
|
|
63
|
+
|
|
64
|
+
// Configure the top-level SDK so IngestClient has an api key + base URL
|
|
65
|
+
// for outgoing batches. CrashReporting layers on top of this.
|
|
66
|
+
SwissKnife.configure(
|
|
67
|
+
apiKey: apiKey,
|
|
68
|
+
proxyURL: serverURL.isEmpty ? nil : serverURL
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
let configuration = SKCrashReporting.Configuration(
|
|
72
|
+
apiKey: apiKey,
|
|
73
|
+
serverURL: serverURL,
|
|
74
|
+
environment: environment,
|
|
75
|
+
release: release,
|
|
76
|
+
maxBreadcrumbs: maxBreadcrumbs,
|
|
77
|
+
enableAutoSessionTracking: enableAutoSessionTracking,
|
|
78
|
+
beforeSend: nil,
|
|
79
|
+
sampleRate: sampleRate,
|
|
80
|
+
tracesSampleRate: tracesSampleRate
|
|
81
|
+
)
|
|
82
|
+
SKCrashReporting.shared.start(configuration: configuration)
|
|
83
|
+
#endif
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@objc
|
|
87
|
+
func setUser(_ user: NSDictionary?) {
|
|
88
|
+
#if SWISSKNIFE_VENDORED || canImport(SwissKnifeiOS)
|
|
89
|
+
guard let user else {
|
|
90
|
+
SKCrashReporting.shared.setUser(nil)
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
SKCrashReporting.shared.setUser(
|
|
94
|
+
SKUser(
|
|
95
|
+
id: user["id"] as? String,
|
|
96
|
+
email: user["email"] as? String,
|
|
97
|
+
username: user["username"] as? String
|
|
98
|
+
)
|
|
99
|
+
)
|
|
100
|
+
#endif
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@objc
|
|
104
|
+
func addBreadcrumb(_ breadcrumb: NSDictionary) {
|
|
105
|
+
#if SWISSKNIFE_VENDORED || canImport(SwissKnifeiOS)
|
|
106
|
+
let level = SKErrorLevel(rawValue: breadcrumb["level"] as? String ?? "info") ?? .info
|
|
107
|
+
SKCrashReporting.shared.addBreadcrumb(
|
|
108
|
+
SKBreadcrumb(
|
|
109
|
+
category: breadcrumb["category"] as? String ?? "rn.bridge",
|
|
110
|
+
message: breadcrumb["message"] as? String ?? "",
|
|
111
|
+
level: level,
|
|
112
|
+
data: breadcrumb["data"] as? [String: String]
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
#endif
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@objc
|
|
119
|
+
func setTag(_ key: NSString, value: NSString) {
|
|
120
|
+
#if SWISSKNIFE_VENDORED || canImport(SwissKnifeiOS)
|
|
121
|
+
SKCrashReporting.shared.setTag(key as String, value: value as String)
|
|
122
|
+
#endif
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// MARK: - Screenshot capture (wave-2 contract C1)
|
|
126
|
+
|
|
127
|
+
/// `NativeModules.SKCrashReporting.captureScreenshot(): Promise<string | null>`
|
|
128
|
+
///
|
|
129
|
+
/// Resolves a base64 JPEG (no `data:` prefix, longest side ≤ 1600px,
|
|
130
|
+
/// masked: black rects over UITextField/UITextView + secure-entry views) or
|
|
131
|
+
/// null. NEVER rejects — any failure resolves null. A ~150ms budget timer
|
|
132
|
+
/// races the main-thread capture; if the main thread is busy (or capture is
|
|
133
|
+
/// slow) the promise resolves null and the late capture result is dropped.
|
|
134
|
+
///
|
|
135
|
+
/// The blocks are typed as plain Swift closures (matching
|
|
136
|
+
/// RCTPromiseResolveBlock / RCTPromiseRejectBlock's ObjC block signatures)
|
|
137
|
+
/// so this file keeps compiling without importing React — consistent with
|
|
138
|
+
/// the rest of the module, which relies on RCT_EXTERN_METHOD in the .m.
|
|
139
|
+
@objc
|
|
140
|
+
func captureScreenshot(
|
|
141
|
+
_ resolve: @escaping (Any?) -> Void,
|
|
142
|
+
rejecter reject: @escaping (String?, String?, Error?) -> Void
|
|
143
|
+
) {
|
|
144
|
+
_ = reject // contract: never rejects
|
|
145
|
+
let once = SKResolveOnce(resolve)
|
|
146
|
+
|
|
147
|
+
// Budget: fail to null after 150ms rather than blocking the JS caller
|
|
148
|
+
// behind a wedged main thread.
|
|
149
|
+
DispatchQueue.global(qos: .userInitiated).asyncAfter(deadline: .now() + 0.15) {
|
|
150
|
+
once.resolve(nil)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
#if SWISSKNIFE_VENDORED || canImport(SwissKnifeiOS)
|
|
154
|
+
DispatchQueue.main.async {
|
|
155
|
+
once.resolve(SKScreenshot.captureMaskedBase64())
|
|
156
|
+
}
|
|
157
|
+
#else
|
|
158
|
+
once.resolve(nil)
|
|
159
|
+
#endif
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// MARK: - Deliberate native crashes (e2e verification only)
|
|
163
|
+
|
|
164
|
+
/// Crash the app with SIGABRT via abort(). Exercises the SIGNAL path of
|
|
165
|
+
/// the native crash reporter (async-signal-safe marker + backtrace-bin
|
|
166
|
+
/// write, next-launch recovery + flush), NOT the NSException path.
|
|
167
|
+
/// Dispatched to the main queue so the bridge call returns to JS cleanly
|
|
168
|
+
/// before the process dies.
|
|
169
|
+
@objc
|
|
170
|
+
func crashNative() {
|
|
171
|
+
DispatchQueue.main.async {
|
|
172
|
+
abort()
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/// Crash the app with SIGSEGV/SIGBUS by writing through a near-NULL
|
|
177
|
+
/// pointer. Same next-launch recovery path as crashNative(), different
|
|
178
|
+
/// signal.
|
|
179
|
+
@objc
|
|
180
|
+
func crashNativeSegfault() {
|
|
181
|
+
DispatchQueue.main.async {
|
|
182
|
+
let pointer = UnsafeMutablePointer<Int>(bitPattern: 0x10)!
|
|
183
|
+
pointer.pointee = 42
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|