@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
package/README.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# @app-swiss-knife/react-native-sdk
|
|
2
|
+
|
|
3
|
+
React Native subscriptions SDK for [App Swiss Knife](https://github.com/Remneys/swiss-knife) —
|
|
4
|
+
a drop-in replacement for RevenueCat's `react-native-purchases` public API.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Three-package architecture
|
|
9
|
+
|
|
10
|
+
This SDK is part of a three-package split:
|
|
11
|
+
|
|
12
|
+
| Package | Language | Purpose |
|
|
13
|
+
| -------------------------------------------------------------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------- |
|
|
14
|
+
| `packages/swiss-knife-android` · `com.appswissknife:swiss-knife-android:0.1.0` | Kotlin | Native Android SDK — Play Billing v8 directly, own typed model layer. Owns `configure`, proxyURL. |
|
|
15
|
+
| `packages/swiss-knife-ios` · Pod `SwissKnifeiOS 0.1.0` | Swift | Native iOS SDK — StoreKit 2 directly, own typed model layer. Owns `configure`, proxyURL. |
|
|
16
|
+
| `packages/react-native-sdk` · `@app-swiss-knife/react-native-sdk` (this package) | TypeScript + Kotlin/Swift bridge | React Native bridge. **Vendors both native SDKs** into its own tarball. |
|
|
17
|
+
|
|
18
|
+
### How the bridge gets the native SDKs (vendoring)
|
|
19
|
+
|
|
20
|
+
The npm tarball is **self-contained**: neither the CocoaPods pod
|
|
21
|
+
`SwissKnifeiOS` nor the Maven artifact `com.appswissknife:swiss-knife-android`
|
|
22
|
+
has to exist on any registry for a consumer app to build.
|
|
23
|
+
|
|
24
|
+
`scripts/vendor-native.mjs` runs on `build` and `prepack` and copies the
|
|
25
|
+
native sources into this package:
|
|
26
|
+
|
|
27
|
+
| From | To | Compiled by |
|
|
28
|
+
| ------------------------------------------------ | -------------------------- | ------------------------------------------------------- |
|
|
29
|
+
| `packages/swiss-knife-ios/Sources/SwissKnifeiOS` | `ios/vendor/SwissKnifeiOS` | `SwissKnifePurchases.podspec` (`source_files = ios/**`) |
|
|
30
|
+
| `packages/swiss-knife-android/src/main/java` | `android/vendor/java` | `android/build.gradle` (`sourceSets.main.java.srcDirs`) |
|
|
31
|
+
| `packages/swiss-knife-android/src/main/res` | `android/vendor/res` | `android/build.gradle` (`sourceSets.main.res.srcDirs`) |
|
|
32
|
+
|
|
33
|
+
The vendored trees are **git-ignored build artifacts** (same status as `lib/`)
|
|
34
|
+
but ARE included in the tarball. The single source of truth stays in
|
|
35
|
+
`packages/swiss-knife-ios` / `packages/swiss-knife-android` — never edit
|
|
36
|
+
anything under `ios/vendor` or `android/vendor`.
|
|
37
|
+
|
|
38
|
+
- **Android** — every bridge method calls `com.appswissknife.SwissKnife.<method>`
|
|
39
|
+
and JSON-encodes the resulting `com.appswissknife.models.*` values into the
|
|
40
|
+
`WritableMap` shape the JS-side `src/types.ts` declares (via `SwissKnifeJson`).
|
|
41
|
+
The vendored Kotlin's own dependencies (androidx annotation / security-crypto /
|
|
42
|
+
work / lifecycle-process, Play Billing v8, okhttp `compileOnly`) are declared
|
|
43
|
+
directly in `android/build.gradle` and all resolve from `google()` /
|
|
44
|
+
`mavenCentral()`.
|
|
45
|
+
|
|
46
|
+
- **iOS** — every bridge method calls `SwissKnife.<method>` and JSON-encodes the
|
|
47
|
+
resulting typed values into the `[String: Any]` shape JS expects (via
|
|
48
|
+
`SwissKnifeJSON`). Because the vendored Swift compiles into the **same** pod
|
|
49
|
+
module as the bridge, the bridge files use
|
|
50
|
+
`#if canImport(SwissKnifeiOS) / import SwissKnifeiOS` (false, and unnecessary,
|
|
51
|
+
in the pod) and the podspec defines `SWISSKNIFE_VENDORED` so conditional code
|
|
52
|
+
paths stay live. The vendored Swift imports only system frameworks — zero
|
|
53
|
+
third-party pods.
|
|
54
|
+
|
|
55
|
+
Phase 7 of the SDK rip-and-replace removed every RevenueCat / PHC dependency
|
|
56
|
+
from the bridge — neither the iOS pod graph nor the Android AAR graph pulls
|
|
57
|
+
RC in any more. The native SDKs own purchases end-to-end via StoreKit 2 /
|
|
58
|
+
Play Billing v8 directly, with receipts validated by our own backend.
|
|
59
|
+
|
|
60
|
+
This means **proxyURL re-routing and diagnostics/device-id hardening** are
|
|
61
|
+
enforced once in each native SDK, covering both native-app and RN consumers
|
|
62
|
+
with a single auditable code path.
|
|
63
|
+
|
|
64
|
+
### Expo support
|
|
65
|
+
|
|
66
|
+
Expo Go is **not supported** — this SDK contains native Kotlin/Swift code that
|
|
67
|
+
requires a custom dev build.
|
|
68
|
+
|
|
69
|
+
An Expo config plugin (`app.plugin.js`) is planned for SP-3. Until then:
|
|
70
|
+
|
|
71
|
+
1. Run `expo prebuild` (or use a custom dev build / EAS Build).
|
|
72
|
+
2. The native modules are auto-linked via React Native's standard autolinking.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Installation
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm install @app-swiss-knife/react-native-sdk
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Peer Dependencies
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npm install @react-native-async-storage/async-storage react-native-webview
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Quick Start
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { SwissKnifeClient } from "@app-swiss-knife/react-native-sdk";
|
|
92
|
+
|
|
93
|
+
const client = new SwissKnifeClient({
|
|
94
|
+
apiKey: "your-api-key",
|
|
95
|
+
baseURL: "https://your-app.com",
|
|
96
|
+
debug: true, // Enable request/response logging
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Fetch SDK config
|
|
100
|
+
const config = await client.get("/api/sdk/config");
|
|
101
|
+
|
|
102
|
+
// Track events
|
|
103
|
+
await client.post("/api/sdk/events/batch", {
|
|
104
|
+
user_id: "user-123",
|
|
105
|
+
events: [
|
|
106
|
+
{
|
|
107
|
+
name: "app_open",
|
|
108
|
+
properties: { screen: "home" },
|
|
109
|
+
timestamp: new Date().toISOString(),
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Evaluate feature flags
|
|
115
|
+
const flags = await client.get("/api/sdk/flags/evaluate", {
|
|
116
|
+
user_id: "user-123",
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## IDFA/GAID Collection (Advertising ID)
|
|
121
|
+
|
|
122
|
+
The SDK can collect the device advertising ID (IDFA on iOS, GAID on Android) for deterministic attribution matching. This is optional — if not configured, attribution falls back to fingerprint/referrer matching.
|
|
123
|
+
|
|
124
|
+
### 1. Install peer dependencies
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
npm install react-native-device-info react-native-tracking-transparency
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 2. iOS: Add tracking permission description
|
|
131
|
+
|
|
132
|
+
Add `NSUserTrackingUsageDescription` to your `Info.plist`:
|
|
133
|
+
|
|
134
|
+
```xml
|
|
135
|
+
<key>NSUserTrackingUsageDescription</key>
|
|
136
|
+
<string>We use this identifier to attribute your install to the correct campaign.</string>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 3. That's it
|
|
140
|
+
|
|
141
|
+
The SDK automatically:
|
|
142
|
+
|
|
143
|
+
- Requests App Tracking Transparency permission on iOS before reading IDFA
|
|
144
|
+
- Reads GAID on Android (no extra permission needed)
|
|
145
|
+
- Includes `advertising_id` in the install attribution request
|
|
146
|
+
- Falls back gracefully if the user denies tracking or the libraries are not installed
|
|
147
|
+
|
|
148
|
+
You can also use the helpers directly:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import {
|
|
152
|
+
requestTrackingPermission,
|
|
153
|
+
getAdvertisingId,
|
|
154
|
+
} from "@app-swiss-knife/react-native-sdk";
|
|
155
|
+
|
|
156
|
+
const status = await requestTrackingPermission(); // 'authorized' | 'denied' | 'not-determined' | 'restricted'
|
|
157
|
+
const { id, isLimitedAdTracking } = await getAdvertisingId();
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Custom Storage
|
|
161
|
+
|
|
162
|
+
By default, the SDK uses `@react-native-async-storage/async-storage` for persistence. You can provide a custom storage adapter:
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { StorageAdapter } from "@app-swiss-knife/react-native-sdk";
|
|
166
|
+
|
|
167
|
+
class SecureStorageAdapter implements StorageAdapter {
|
|
168
|
+
async get(key: string): Promise<string | null> {
|
|
169
|
+
// your implementation
|
|
170
|
+
}
|
|
171
|
+
async set(key: string, value: string): Promise<void> {
|
|
172
|
+
// your implementation
|
|
173
|
+
}
|
|
174
|
+
async remove(key: string): Promise<void> {
|
|
175
|
+
// your implementation
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
MIT
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# packages/react-native-sdk/SwissKnifePurchases.podspec
|
|
2
|
+
require "json"
|
|
3
|
+
|
|
4
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
5
|
+
|
|
6
|
+
Pod::Spec.new do |s|
|
|
7
|
+
s.name = "SwissKnifePurchases"
|
|
8
|
+
s.version = package["version"]
|
|
9
|
+
s.summary = package["description"]
|
|
10
|
+
s.homepage = "https://github.com/Remneys/swiss-knife"
|
|
11
|
+
s.license = "MIT"
|
|
12
|
+
s.authors = "App Swiss Knife"
|
|
13
|
+
s.platforms = { :ios => "16.0" }
|
|
14
|
+
s.source = { :git => "https://github.com/Remneys/swiss-knife.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
# `ios/**` covers BOTH the RN bridge files and the vendored native SDK under
|
|
17
|
+
# `ios/vendor/SwissKnifeiOS/` (generated by scripts/vendor-native.mjs at
|
|
18
|
+
# build/prepack time and shipped inside the npm tarball).
|
|
19
|
+
#
|
|
20
|
+
# Everything compiles into ONE Swift module (`SwissKnifePurchases`), so the
|
|
21
|
+
# bridge no longer does `import SwissKnifeiOS` — see SWISSKNIFE_VENDORED below.
|
|
22
|
+
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
23
|
+
s.swift_version = "5.9"
|
|
24
|
+
|
|
25
|
+
# Self-contained: the SDK's Swift sources are compiled in-tree, so there is NO
|
|
26
|
+
# `s.dependency "SwissKnifeiOS"` and nothing to resolve from CocoaPods trunk.
|
|
27
|
+
# The vendored sources import only system frameworks (Foundation, StoreKit,
|
|
28
|
+
# UIKit, Security, Network, AdSupport, AppTrackingTransparency, os) — zero
|
|
29
|
+
# third-party pods.
|
|
30
|
+
#
|
|
31
|
+
# SWISSKNIFE_VENDORED tells the bridge files that the SDK types live in this
|
|
32
|
+
# same module (so `canImport(SwissKnifeiOS)` is correctly false but the code
|
|
33
|
+
# paths must stay live). Native/SPM consumers of the same bridge sources see
|
|
34
|
+
# the flag unset and fall back to `import SwissKnifeiOS`.
|
|
35
|
+
s.pod_target_xcconfig = {
|
|
36
|
+
"SWIFT_ACTIVE_COMPILATION_CONDITIONS" => "$(inherited) SWISSKNIFE_VENDORED",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
s.dependency "React-Core"
|
|
40
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// packages/react-native-sdk/android/build.gradle
|
|
2
|
+
buildscript {
|
|
3
|
+
ext.kotlin_version = ext.has("kotlinVersion") ? ext.kotlinVersion : "1.9.24"
|
|
4
|
+
repositories { google(); mavenCentral() }
|
|
5
|
+
dependencies {
|
|
6
|
+
classpath "com.android.tools.build:gradle:8.5.2"
|
|
7
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
apply plugin: "com.android.library"
|
|
12
|
+
apply plugin: "kotlin-android"
|
|
13
|
+
|
|
14
|
+
def safeExtGet(prop, fallback) {
|
|
15
|
+
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
android {
|
|
19
|
+
namespace "com.swissknife.purchases"
|
|
20
|
+
compileSdkVersion safeExtGet("compileSdkVersion", 35)
|
|
21
|
+
|
|
22
|
+
defaultConfig {
|
|
23
|
+
minSdkVersion safeExtGet("minSdkVersion", 24)
|
|
24
|
+
targetSdkVersion safeExtGet("targetSdkVersion", 35)
|
|
25
|
+
}
|
|
26
|
+
compileOptions {
|
|
27
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
28
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
29
|
+
}
|
|
30
|
+
kotlinOptions { jvmTarget = "17" }
|
|
31
|
+
testOptions { unitTests.returnDefaultValues = true }
|
|
32
|
+
|
|
33
|
+
// Self-contained build: the Swiss Knife Android SDK (`com.appswissknife.**`)
|
|
34
|
+
// is VENDORED into this module rather than resolved as a Maven artifact.
|
|
35
|
+
// scripts/vendor-native.mjs copies it from
|
|
36
|
+
// packages/swiss-knife-android/src/main/{java,res} at build/prepack time and
|
|
37
|
+
// the result ships inside the npm tarball, so nothing has to exist on Maven
|
|
38
|
+
// Central / JitPack / mavenLocal for a consumer app to compile.
|
|
39
|
+
//
|
|
40
|
+
// NOTE: the Kotlin plugin compiles .kt found under `java.srcDirs`, which is
|
|
41
|
+
// why the vendored Kotlin tree is registered there and not under `kotlin`.
|
|
42
|
+
sourceSets {
|
|
43
|
+
main {
|
|
44
|
+
java.srcDirs += ["vendor/java"]
|
|
45
|
+
res.srcDirs += ["vendor/res"]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
repositories { google(); mavenCentral() }
|
|
51
|
+
|
|
52
|
+
dependencies {
|
|
53
|
+
implementation "com.facebook.react:react-android"
|
|
54
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
55
|
+
|
|
56
|
+
// ── Dependencies of the VENDORED SDK sources ────────────────────────────
|
|
57
|
+
// These used to arrive transitively via `com.appswissknife:swiss-knife-android`.
|
|
58
|
+
// They must mirror packages/swiss-knife-android/build.gradle — if that file
|
|
59
|
+
// gains a dependency, add it here too. All of them resolve from google() /
|
|
60
|
+
// mavenCentral(), which every Android app already configures; nothing here
|
|
61
|
+
// is an artifact we have to publish ourselves.
|
|
62
|
+
|
|
63
|
+
// @VisibleForTesting + nullability annotations on the gateway seam.
|
|
64
|
+
implementation "androidx.annotation:annotation:1.8.2"
|
|
65
|
+
// EncryptedSharedPreferences (Tink-backed AES-256-GCM) for the persistent
|
|
66
|
+
// device-id store — com.appswissknife.device.DeviceID.
|
|
67
|
+
implementation "androidx.security:security-crypto:1.1.0-alpha06"
|
|
68
|
+
// WorkManager — FlushEventsWorker / SetAttributesWorker.
|
|
69
|
+
implementation "androidx.work:work-runtime-ktx:2.9.0"
|
|
70
|
+
// ProcessLifecycleOwner — com.appswissknife.context.AppLifecycle.
|
|
71
|
+
implementation "androidx.lifecycle:lifecycle-process:2.5.1"
|
|
72
|
+
// Play Billing v8 — com.appswissknife.purchases.BillingClientGateway /
|
|
73
|
+
// PlayPriceEnrichmentProvider. Previously pulled in transitively through
|
|
74
|
+
// RevenueCat's purchases-hybrid-common; now a direct, first-party dep.
|
|
75
|
+
// `api` because BillingClientGateway's public seam exposes Play Billing types.
|
|
76
|
+
api "com.android.billingclient:billing:8.0.0"
|
|
77
|
+
// OkHttp: compileOnly so SKBreadcrumbInterceptor / the performance
|
|
78
|
+
// instrumentation compile, while consumers bring their own okhttp at runtime.
|
|
79
|
+
// Declared as `require` (not a hard version) because AGP's consistent
|
|
80
|
+
// resolution pins compileClasspath to whatever runtimeClasspath resolved.
|
|
81
|
+
// React Native brings okhttp 4.9.2 at runtime, so a hard `4.12.0` here makes
|
|
82
|
+
// debugCompileClasspath unresolvable ("strictly 4.9.2" vs 4.12.0). Only
|
|
83
|
+
// okhttp3.Interceptor / okhttp3.Response are used, both stable since 3.x.
|
|
84
|
+
compileOnly("com.squareup.okhttp3:okhttp") {
|
|
85
|
+
version { require "4.9.2" }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
testImplementation "junit:junit:4.13.2"
|
|
89
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<!-- packages/react-native-sdk/android/src/main/AndroidManifest.xml -->
|
|
2
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
package="com.swissknife.purchases">
|
|
4
|
+
<!-- Required by Play Billing v8. -->
|
|
5
|
+
<uses-permission android:name="com.android.vending.BILLING" />
|
|
6
|
+
|
|
7
|
+
<!--
|
|
8
|
+
Mirrors packages/swiss-knife-android/src/main/AndroidManifest.xml. The SDK
|
|
9
|
+
is vendored into this Gradle module rather than linked as an AAR, so this
|
|
10
|
+
manifest has to carry what the AAR's manifest would otherwise have merged
|
|
11
|
+
into the host app.
|
|
12
|
+
|
|
13
|
+
dataExtractionRules excludes the SDK's persistent device-id
|
|
14
|
+
SharedPreferences file from cloud backup + device transfer. We deliberately
|
|
15
|
+
do NOT set android:allowBackup: as a library we don't want to override the
|
|
16
|
+
host app's global backup choice. The per-file exclusion in
|
|
17
|
+
res/xml/swissknife_data_extraction_rules.xml (vendored into vendor/res)
|
|
18
|
+
achieves the goal narrowly.
|
|
19
|
+
|
|
20
|
+
Host apps that set their own android:dataExtractionRules must add
|
|
21
|
+
tools:replace="android:dataExtractionRules" — same as they would have had
|
|
22
|
+
to with the published AAR.
|
|
23
|
+
-->
|
|
24
|
+
<application
|
|
25
|
+
android:dataExtractionRules="@xml/swissknife_data_extraction_rules" />
|
|
26
|
+
</manifest>
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// packages/react-native-sdk/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingModule.kt
|
|
2
|
+
//
|
|
3
|
+
// RN native module that delegates to the swiss-knife-android crash reporting SDK.
|
|
4
|
+
//
|
|
5
|
+
// This module compiles directly against `com.appswissknife.crashreporting.*`
|
|
6
|
+
// (the AAR is already a dependency, used by SwissKnifePurchasesModule). The
|
|
7
|
+
// previous reflection-based approach selected `Class.getConstructors().first()`
|
|
8
|
+
// for the Kotlin data classes Configuration/SKUser/SKBreadcrumb — but those all
|
|
9
|
+
// have default parameter values, so the compiler emits a synthetic `$default`
|
|
10
|
+
// constructor with extra (bitmask + marker) params. `.first()` had no ordering
|
|
11
|
+
// guarantee and could pick the synthetic one, throwing "wrong number of
|
|
12
|
+
// arguments" that the broad catch swallowed → crash init, setUser, and every
|
|
13
|
+
// breadcrumb silently no-op'd. Typed calls remove that whole failure mode.
|
|
14
|
+
|
|
15
|
+
package com.swissknife.crashreporting
|
|
16
|
+
|
|
17
|
+
import android.os.Handler
|
|
18
|
+
import android.os.Looper
|
|
19
|
+
import com.appswissknife.SwissKnife
|
|
20
|
+
import com.appswissknife.crashreporting.SKBreadcrumb
|
|
21
|
+
import com.appswissknife.crashreporting.SKCrashReporting
|
|
22
|
+
import com.appswissknife.crashreporting.SKErrorLevel
|
|
23
|
+
import com.appswissknife.crashreporting.SKScreenshot
|
|
24
|
+
import com.appswissknife.crashreporting.SKUser
|
|
25
|
+
import com.facebook.react.bridge.Dynamic
|
|
26
|
+
import com.facebook.react.bridge.Promise
|
|
27
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
28
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
29
|
+
import com.facebook.react.bridge.ReactMethod
|
|
30
|
+
import com.facebook.react.bridge.ReadableMap
|
|
31
|
+
import com.facebook.react.bridge.ReadableType
|
|
32
|
+
import com.facebook.react.bridge.UiThreadUtil
|
|
33
|
+
|
|
34
|
+
class SKCrashReportingModule(
|
|
35
|
+
reactContext: ReactApplicationContext
|
|
36
|
+
) : ReactContextBaseJavaModule(reactContext) {
|
|
37
|
+
|
|
38
|
+
override fun getName(): String = "SKCrashReporting"
|
|
39
|
+
|
|
40
|
+
@ReactMethod
|
|
41
|
+
fun start(config: ReadableMap) {
|
|
42
|
+
val apiKey = config.getString("apiKey") ?: return
|
|
43
|
+
val serverURL = config.getString("serverURL") ?: ""
|
|
44
|
+
val environment = config.getString("environment") ?: "production"
|
|
45
|
+
val release = config.getString("release")
|
|
46
|
+
|
|
47
|
+
// Mirror the iOS bridge (SwissKnifeCrashReporting.swift), which calls
|
|
48
|
+
// SwissKnife.configure(apiKey:proxyURL:) before SKCrashReporting.start
|
|
49
|
+
// so IngestClient has an api key + base URL. Without this,
|
|
50
|
+
// IngestClient.shared stays null and the Kotlin crash path
|
|
51
|
+
// (flushEventQueue / sendEventPayload / sendSessionEvent) silently
|
|
52
|
+
// falls back to the legacy /api/sdk/errors/* HTTP endpoints.
|
|
53
|
+
// ensureObservabilityBackend is the public, idempotent entry point
|
|
54
|
+
// (already used by the RN analytics init path) that wires
|
|
55
|
+
// BackendHttpClient + IngestClient + Session/Clock/Reachability with
|
|
56
|
+
// the same apiKey/serverURL params — without dragging in the
|
|
57
|
+
// purchases/billing engine as a side effect of crash init.
|
|
58
|
+
try {
|
|
59
|
+
SwissKnife.ensureObservabilityBackend(
|
|
60
|
+
reactApplicationContext.applicationContext,
|
|
61
|
+
apiKey,
|
|
62
|
+
serverURL.trimEnd('/'),
|
|
63
|
+
)
|
|
64
|
+
} catch (e: Throwable) {
|
|
65
|
+
// Crash init below still works via its legacy HTTP fallback.
|
|
66
|
+
println("[SwissKnife RN] observability backend wiring failed: ${e.message}")
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
SKCrashReporting.init(
|
|
71
|
+
reactApplicationContext.applicationContext,
|
|
72
|
+
SKCrashReporting.Configuration(
|
|
73
|
+
apiKey = apiKey,
|
|
74
|
+
serverURL = serverURL,
|
|
75
|
+
environment = environment,
|
|
76
|
+
release = release,
|
|
77
|
+
),
|
|
78
|
+
)
|
|
79
|
+
println("[SwissKnife RN] Native crash reporting initialized via RN bridge")
|
|
80
|
+
} catch (e: Throwable) {
|
|
81
|
+
println("[SwissKnife RN] native crash init failed: ${e.message}")
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@ReactMethod
|
|
86
|
+
fun setUser(user: ReadableMap?) {
|
|
87
|
+
try {
|
|
88
|
+
SKCrashReporting.setUser(
|
|
89
|
+
user?.let {
|
|
90
|
+
SKUser(
|
|
91
|
+
id = it.getString("id"),
|
|
92
|
+
email = it.getString("email"),
|
|
93
|
+
username = it.getString("username"),
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
)
|
|
97
|
+
} catch (e: Throwable) {
|
|
98
|
+
println("[SwissKnife RN] setUser forward failed: ${e.message}")
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@ReactMethod
|
|
103
|
+
fun addBreadcrumb(breadcrumb: ReadableMap) {
|
|
104
|
+
try {
|
|
105
|
+
SKCrashReporting.addBreadcrumb(
|
|
106
|
+
SKBreadcrumb(
|
|
107
|
+
category = breadcrumb.getString("category"),
|
|
108
|
+
message = breadcrumb.getString("message"),
|
|
109
|
+
level = parseLevel(breadcrumb.getString("level")),
|
|
110
|
+
data = readStringMap(breadcrumb.getMap("data")),
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
} catch (e: Throwable) {
|
|
114
|
+
println("[SwissKnife RN] addBreadcrumb forward failed: ${e.message}")
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@ReactMethod
|
|
119
|
+
fun setTag(key: String, value: String) {
|
|
120
|
+
try {
|
|
121
|
+
SKCrashReporting.setTag(key, value)
|
|
122
|
+
} catch (e: Throwable) {
|
|
123
|
+
println("[SwissKnife RN] setTag forward failed: ${e.message}")
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Masked screenshot capture (wave-2 contract C1).
|
|
129
|
+
* JS: NativeModules.SKCrashReporting.captureScreenshot(): Promise<string|null>
|
|
130
|
+
*
|
|
131
|
+
* Resolves a base64 JPEG (no `data:` prefix, longest side <= 1600px,
|
|
132
|
+
* EditText instances blacked out) or null. NEVER rejects — a missing
|
|
133
|
+
* activity, any capture failure, or the ~150ms budget overrun all
|
|
134
|
+
* resolve null. Delegates to [SKScreenshot] in swiss-knife-android,
|
|
135
|
+
* which guarantees the callback fires exactly once.
|
|
136
|
+
*/
|
|
137
|
+
@ReactMethod
|
|
138
|
+
fun captureScreenshot(promise: Promise) {
|
|
139
|
+
try {
|
|
140
|
+
// AGP 8's Kotlin stubs for getCurrentActivity() mean the module
|
|
141
|
+
// property isn't synthesized — same pattern as the purchases
|
|
142
|
+
// module: read it off reactApplicationContext.
|
|
143
|
+
val activity = reactApplicationContext.currentActivity
|
|
144
|
+
if (activity == null) {
|
|
145
|
+
promise.resolve(null)
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
UiThreadUtil.runOnUiThread {
|
|
149
|
+
try {
|
|
150
|
+
SKScreenshot.captureMasked(activity) { base64 ->
|
|
151
|
+
promise.resolve(base64)
|
|
152
|
+
}
|
|
153
|
+
} catch (t: Throwable) {
|
|
154
|
+
// SKScreenshot.captureMasked itself never throws AND
|
|
155
|
+
// guarantees a single callback, so reaching this means
|
|
156
|
+
// the capture never started — resolving is safe.
|
|
157
|
+
promise.resolve(null)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} catch (t: Throwable) {
|
|
161
|
+
promise.resolve(null)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Deliberately crash the app with an uncaught RuntimeException on the
|
|
167
|
+
* main thread — e2e verification of the native crash pipeline
|
|
168
|
+
* (crash-time write-to-disk + session "crashed" close, recovery + send
|
|
169
|
+
* on next init). Parity with the iOS bridge's crashNative().
|
|
170
|
+
* JS: NativeModules.SKCrashReporting.crashNative()
|
|
171
|
+
*/
|
|
172
|
+
@ReactMethod
|
|
173
|
+
fun crashNative() {
|
|
174
|
+
Handler(Looper.getMainLooper()).post {
|
|
175
|
+
throw RuntimeException("SwissKnife test crash (crashNative)")
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Map a JS log level onto the native [SKErrorLevel] enum, normalizing the
|
|
181
|
+
* common aliases. The previous reflection path used `Enum.valueOf`, which
|
|
182
|
+
* threw on any non-enum string (e.g. "warn", "log", "critical") and dropped
|
|
183
|
+
* the whole breadcrumb; we default unknown levels to INFO instead.
|
|
184
|
+
*/
|
|
185
|
+
private fun parseLevel(raw: String?): SKErrorLevel = when (raw?.lowercase()) {
|
|
186
|
+
"debug", "trace", "verbose" -> SKErrorLevel.DEBUG
|
|
187
|
+
"info", "log" -> SKErrorLevel.INFO
|
|
188
|
+
"warn", "warning" -> SKErrorLevel.WARNING
|
|
189
|
+
"error" -> SKErrorLevel.ERROR
|
|
190
|
+
"fatal", "critical" -> SKErrorLevel.FATAL
|
|
191
|
+
else -> SKErrorLevel.INFO
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Marshal the breadcrumb `data` ReadableMap into a `Map<String, String>`.
|
|
196
|
+
* The reflection path passed `null` and discarded all structured data;
|
|
197
|
+
* here we stringify scalar values so they survive to the native crumb.
|
|
198
|
+
*/
|
|
199
|
+
private fun readStringMap(map: ReadableMap?): Map<String, String>? {
|
|
200
|
+
if (map == null) return null
|
|
201
|
+
val out = HashMap<String, String>()
|
|
202
|
+
val iterator = map.keySetIterator()
|
|
203
|
+
while (iterator.hasNextKey()) {
|
|
204
|
+
val key = iterator.nextKey()
|
|
205
|
+
val dynamic: Dynamic = map.getDynamic(key)
|
|
206
|
+
val value: String? = when (dynamic.type) {
|
|
207
|
+
ReadableType.String -> dynamic.asString()
|
|
208
|
+
ReadableType.Number -> dynamic.asDouble().toString()
|
|
209
|
+
ReadableType.Boolean -> dynamic.asBoolean().toString()
|
|
210
|
+
else -> null
|
|
211
|
+
}
|
|
212
|
+
if (value != null) out[key] = value
|
|
213
|
+
}
|
|
214
|
+
return if (out.isEmpty()) null else out
|
|
215
|
+
}
|
|
216
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// packages/react-native-sdk/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingPackage.kt
|
|
2
|
+
package com.swissknife.crashreporting
|
|
3
|
+
|
|
4
|
+
import com.facebook.react.ReactPackage
|
|
5
|
+
import com.facebook.react.bridge.NativeModule
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.uimanager.ViewManager
|
|
8
|
+
|
|
9
|
+
class SKCrashReportingPackage : ReactPackage {
|
|
10
|
+
override fun createNativeModules(
|
|
11
|
+
reactContext: ReactApplicationContext
|
|
12
|
+
): List<NativeModule> = listOf(SKCrashReportingModule(reactContext))
|
|
13
|
+
|
|
14
|
+
override fun createViewManagers(
|
|
15
|
+
reactContext: ReactApplicationContext
|
|
16
|
+
): List<ViewManager<*, *>> = emptyList()
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// packages/react-native-sdk/android/src/main/java/com/swissknife/purchases/Conversions.kt
|
|
2
|
+
package com.swissknife.purchases
|
|
3
|
+
|
|
4
|
+
import com.facebook.react.bridge.ReadableMap
|
|
5
|
+
|
|
6
|
+
// Subscriber attributes are string|null. Drops non-string values defensively.
|
|
7
|
+
fun ReadableMap.toStringMap(): Map<String, String?> {
|
|
8
|
+
val out = HashMap<String, String?>()
|
|
9
|
+
val it = keySetIterator()
|
|
10
|
+
while (it.hasNextKey()) {
|
|
11
|
+
val key = it.nextKey()
|
|
12
|
+
out[key] = if (isNull(key)) null else getString(key)
|
|
13
|
+
}
|
|
14
|
+
return out
|
|
15
|
+
}
|