@app-swiss-knife/react-native-sdk 0.3.2 → 0.5.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/CHANGELOG.md +465 -0
- package/LICENSE +21 -0
- package/README.md +229 -42
- 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 +7 -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/java/com/appswissknife/SwissKnife.kt +107 -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 +641 -208
- 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 +69 -35
- package/android/vendor/java/com/appswissknife/net/IngestClient.kt +756 -98
- 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 +266 -64
- package/android/vendor/java/com/appswissknife/performance/SKPerformance.kt +1 -0
- package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +545 -88
- package/android/vendor/java/com/appswissknife/purchases/PlayPriceEnrichmentProvider.kt +55 -24
- package/android/vendor/java/com/appswissknife/purchases/ProductKindHint.kt +21 -0
- package/android/vendor/java/com/appswissknife/purchases/PurchasesGateway.kt +14 -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 +287 -0
- package/ios/SwissKnifePurchases.m +20 -0
- package/ios/SwissKnifePurchases.swift +97 -3
- package/ios/SwissKnifePushBootstrap.m +34 -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 +531 -100
- 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/PurchaseService.swift +38 -7
- package/ios/vendor/SwissKnifeiOS/SwissKnife.swift +34 -6
- 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 +353 -31
- 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 +353 -31
- 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 +3 -1
- 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 +50 -12
- 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 +3 -1
- 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 +50 -12
- 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 +18 -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 +476 -67
- 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
package/README.md
CHANGED
|
@@ -11,9 +11,16 @@ This SDK is part of a three-package split:
|
|
|
11
11
|
|
|
12
12
|
| Package | Language | Purpose |
|
|
13
13
|
| -------------------------------------------------------------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------- |
|
|
14
|
-
| `packages/swiss-knife-android`
|
|
15
|
-
| `packages/swiss-knife-ios`
|
|
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.
|
|
14
|
+
| `packages/swiss-knife-android` (not published; vendored by this package) | Kotlin | Native Android SDK — Play Billing v8 directly, own typed model layer. Owns `configure`, proxyURL. |
|
|
15
|
+
| `packages/swiss-knife-ios` (not published; vendored by this package) | 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, on npm. **Vendors both native SDKs** into its own tarball. |
|
|
17
|
+
|
|
18
|
+
Only the npm package is published. A native (non-React-Native) app cannot
|
|
19
|
+
install the two native SDKs from SPM, CocoaPods or Maven today; it vendors their
|
|
20
|
+
sources out of this package's tarball (`ios/vendor/SwissKnifeiOS` as a local Swift
|
|
21
|
+
package, `android/vendor/java` and `android/vendor/res` as Kotlin source in the app
|
|
22
|
+
module). The `setup-native` skill of the Swiss-Knife plugin
|
|
23
|
+
(github.com/Remneys/swiss-knife-plugin) does that for you.
|
|
17
24
|
|
|
18
25
|
### How the bridge gets the native SDKs (vendoring)
|
|
19
26
|
|
|
@@ -70,10 +77,9 @@ with a single auditable code path.
|
|
|
70
77
|
Expo Go is **not supported** — this SDK contains native Kotlin/Swift code that
|
|
71
78
|
requires a custom dev build.
|
|
72
79
|
|
|
73
|
-
An Expo config plugin (`app.plugin.js`) is planned for SP-3. Until then:
|
|
74
|
-
|
|
75
80
|
1. Run `expo prebuild` (or use a custom dev build / EAS Build).
|
|
76
81
|
2. The native modules are auto-linked via React Native's standard autolinking.
|
|
82
|
+
3. For push notifications add the config plugin — see [Push notifications](#push-notifications).
|
|
77
83
|
|
|
78
84
|
---
|
|
79
85
|
|
|
@@ -99,7 +105,8 @@ import {
|
|
|
99
105
|
Attributes,
|
|
100
106
|
} from "@app-swiss-knife/react-native-sdk";
|
|
101
107
|
|
|
102
|
-
// Once, at app start.
|
|
108
|
+
// Once, at app start. `Purchases.configure` is the same function, so
|
|
109
|
+
// react-native-purchases-style code works unchanged.
|
|
103
110
|
SwissKnife.configure({
|
|
104
111
|
apiKey: "sk_...",
|
|
105
112
|
proxyURL: "https://your-swiss-knife-host",
|
|
@@ -217,31 +224,28 @@ await Attribution.registerInstall(); // explicit — core never does this for yo
|
|
|
217
224
|
|
|
218
225
|
## IDFA/GAID Collection (Advertising ID)
|
|
219
226
|
|
|
220
|
-
The SDK can
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
```bash
|
|
225
|
-
npm install react-native-device-info react-native-tracking-transparency
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
### 2. iOS: Add tracking permission description
|
|
229
|
-
|
|
230
|
-
Add `NSUserTrackingUsageDescription` to your `Info.plist`:
|
|
227
|
+
The SDK can send the device advertising ID with the install for deterministic
|
|
228
|
+
attribution matching. It is optional: without it, attribution falls back to
|
|
229
|
+
fingerprint matching (and, on Android, the install referrer when the app
|
|
230
|
+
supplies it natively).
|
|
231
231
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
```
|
|
232
|
+
- **iOS:** `Attribution.requestAndRegister()` shows the App Tracking
|
|
233
|
+
Transparency prompt and reads the IDFA when the user allows it. Add
|
|
234
|
+
`NSUserTrackingUsageDescription` to your `Info.plist`:
|
|
236
235
|
|
|
237
|
-
|
|
236
|
+
```xml
|
|
237
|
+
<key>NSUserTrackingUsageDescription</key>
|
|
238
|
+
<string>We use this identifier to attribute your install to the correct campaign.</string>
|
|
239
|
+
```
|
|
238
240
|
|
|
239
|
-
|
|
241
|
+
- **Android:** the SDK collects neither the advertising ID (GAID) nor the
|
|
242
|
+
install referrer on its own: it adds no Play services dependency. Read a
|
|
243
|
+
consented advertising ID in your app and pass it to
|
|
244
|
+
`Attribution.registerInstall(advertisingId)`, or register native collectors
|
|
245
|
+
with `Attribution.setCollectors(...)` in the Android SDK before configure.
|
|
240
246
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
- Includes `advertising_id` in the install attribution request
|
|
244
|
-
- Falls back gracefully if the user denies tracking or the libraries are not installed
|
|
247
|
+
The install request includes `advertising_id` only when one was collected, and
|
|
248
|
+
a denied prompt or a missing id falls back gracefully.
|
|
245
249
|
|
|
246
250
|
You can also drive it yourself through the `Attribution` namespace — prompt
|
|
247
251
|
orchestration and the idempotency cache live natively, so a second call returns
|
|
@@ -250,8 +254,8 @@ the cached resolution without re-prompting or re-POSTing:
|
|
|
250
254
|
```typescript
|
|
251
255
|
import { Attribution } from "@app-swiss-knife/react-native-sdk";
|
|
252
256
|
|
|
253
|
-
//
|
|
254
|
-
//
|
|
257
|
+
// Register the install: ATT prompt + IDFA on iOS; on Android only what native
|
|
258
|
+
// collectors supply (none by default).
|
|
255
259
|
const resolved = await Attribution.requestAndRegister();
|
|
256
260
|
|
|
257
261
|
// Or collect consent yourself and hand us the id (pass null if denied):
|
|
@@ -261,26 +265,209 @@ await Attribution.registerInstall(advertisingId);
|
|
|
261
265
|
const current = await Attribution.resolved();
|
|
262
266
|
```
|
|
263
267
|
|
|
264
|
-
##
|
|
268
|
+
## Push notifications
|
|
269
|
+
|
|
270
|
+
Push v1 sends directly through APNs and FCM from the Swiss Knife server (no
|
|
271
|
+
Expo relay). The SDK registers this install's token, links it to the current
|
|
272
|
+
user, and reports `received` / `opened` / `action` events. Two integration
|
|
273
|
+
modes share one API, `Notifications`:
|
|
274
|
+
|
|
275
|
+
| | Native mode | Manual mode |
|
|
276
|
+
| --------------------- | ------------------------ | ------------------------------------------- |
|
|
277
|
+
| Who owns the OS token | Swiss Knife SDK | your app (`expo-notifications`, RNFirebase) |
|
|
278
|
+
| Use when | you have no push library | you already have one |
|
|
279
|
+
|
|
280
|
+
Server credentials (APNs `.p8` key, FCM service account) are stored per app on
|
|
281
|
+
the Swiss Knife server; send with the `push_send` tool / REST API.
|
|
282
|
+
|
|
283
|
+
### Setup (Expo)
|
|
284
|
+
|
|
285
|
+
```jsonc
|
|
286
|
+
// app.json
|
|
287
|
+
{
|
|
288
|
+
"expo": {
|
|
289
|
+
"ios": { "bundleIdentifier": "com.example.app" },
|
|
290
|
+
"android": {
|
|
291
|
+
"package": "com.example.app",
|
|
292
|
+
"googleServicesFile": "./google-services.json",
|
|
293
|
+
},
|
|
294
|
+
"plugins": [
|
|
295
|
+
[
|
|
296
|
+
"@app-swiss-knife/react-native-sdk",
|
|
297
|
+
{
|
|
298
|
+
"ios": { "mode": "production" }, // or "development"
|
|
299
|
+
"android": {
|
|
300
|
+
"defaultChannel": { "id": "default", "name": "General" },
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
],
|
|
304
|
+
],
|
|
305
|
+
},
|
|
306
|
+
}
|
|
307
|
+
```
|
|
265
308
|
|
|
266
|
-
|
|
309
|
+
The plugin adds the `aps-environment` entitlement (default `development`, like
|
|
310
|
+
`expo-notifications`: Xcode's distribution export rewrites it to `production` for
|
|
311
|
+
App Store/TestFlight builds — confirm on your first TestFlight build via the
|
|
312
|
+
device's `environment` in the dashboard) and the `remote-notification`
|
|
313
|
+
background mode on iOS, and the `POST_NOTIFICATIONS` permission plus
|
|
314
|
+
`com.appswissknife.notifications.SwissKnifeMessagingService` on Android (set
|
|
315
|
+
`android.registerMessagingService: false` to skip the service; it is skipped
|
|
316
|
+
automatically, with a warning, when `expo-notifications` or
|
|
317
|
+
`@react-native-firebase/messaging` is present, since two services cannot both own
|
|
318
|
+
FCM — in that case use manual mode below: `registerDeviceToken` plus
|
|
319
|
+
`trackReceived`/`trackOpened`), and adds
|
|
320
|
+
`com.google.firebase:firebase-messaging` to the app module (the SDK declares it
|
|
321
|
+
`compileOnly` so apps that do not use push do not inherit Firebase).
|
|
322
|
+
`android.googleServicesFile` (plugin option or `expo.android.googleServicesFile`)
|
|
323
|
+
is handled by Expo's own mechanism. Bare React Native: make those same edits by
|
|
324
|
+
hand — register the service with a `com.google.firebase.MESSAGING_EVENT`
|
|
325
|
+
intent-filter, add `implementation "com.google.firebase:firebase-messaging:24.0.3"`
|
|
326
|
+
to your app module, and add `google-services.json` with the Google Services
|
|
327
|
+
Gradle plugin. (The React Native module's own manifest declares `POST_NOTIFICATIONS` and the
|
|
328
|
+
`PermissionRequestActivity` that `requestPermission` launches; nothing to add.)
|
|
329
|
+
|
|
330
|
+
### Native mode
|
|
331
|
+
|
|
332
|
+
```ts
|
|
333
|
+
import { Notifications } from "@app-swiss-knife/react-native-sdk";
|
|
334
|
+
|
|
335
|
+
const status = await Notifications.requestPermission({ provisional: false });
|
|
336
|
+
if (status === "authorized" || status === "provisional") {
|
|
337
|
+
await Notifications.registerForPushNotifications(); // iOS: APNs, Android: FCM
|
|
338
|
+
}
|
|
267
339
|
|
|
268
|
-
|
|
269
|
-
|
|
340
|
+
const sub = Notifications.addNotificationOpenedListener((open) => {
|
|
341
|
+
if (open.link) Linking.openURL(open.link);
|
|
342
|
+
});
|
|
343
|
+
const launch = await Notifications.getInitialNotification(); // cold start, once
|
|
344
|
+
```
|
|
270
345
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
346
|
+
On iOS the SDK installs a `UNUserNotificationCenter` delegate proxy (forwarding
|
|
347
|
+
to any delegate that was set before it) and hooks the APNs-token callback when
|
|
348
|
+
you call `registerForPushNotifications()`. To catch a notification tap that
|
|
349
|
+
_cold-starts_ the app, call `registerForPushNotifications()` (or the native
|
|
350
|
+
`SwissKnife.Notifications.enableAutoIntegration()`) from
|
|
351
|
+
`application(_:didFinishLaunchingWithOptions:)`; otherwise iOS delivers the tap
|
|
352
|
+
before the delegate exists. Permission changes made in Settings, identity
|
|
353
|
+
changes (`Identity.logIn` / `logOut`) and token rotation re-upsert the device
|
|
354
|
+
automatically (unchanged state is never re-sent).
|
|
355
|
+
|
|
356
|
+
**Cold-start tap tracking needs an earlier run.** `registerForPushNotifications()`
|
|
357
|
+
persists the opt-in; only on _later_ launches does the native module install the
|
|
358
|
+
notification delegate before JS starts. So a tap that cold-starts the app is
|
|
359
|
+
captured only after `registerForPushNotifications()` has run on some previous
|
|
360
|
+
launch (which is always true for a device that already received a push).
|
|
361
|
+
|
|
362
|
+
**User link and relaunch.** The SDK's identity is in-memory: after a relaunch the
|
|
363
|
+
user is anonymous until your app calls `Identity.logIn(...)` again. The device
|
|
364
|
+
upsert therefore _omits_ `user_id` at launch (the server keeps the existing link)
|
|
365
|
+
and sends `user_id: null` (unlink) only on an explicit `Identity.logOut()` /
|
|
366
|
+
`reset()` / `wipe()`. Still call `logIn` on every launch that restores a session
|
|
367
|
+
so new/reinstalled devices get linked.
|
|
368
|
+
|
|
369
|
+
### Manual mode (expo-notifications / Firebase)
|
|
370
|
+
|
|
371
|
+
Keep your push library; hand us the token and the payloads:
|
|
372
|
+
|
|
373
|
+
```ts
|
|
374
|
+
import * as ExpoNotifications from "expo-notifications";
|
|
375
|
+
import { Notifications } from "@app-swiss-knife/react-native-sdk";
|
|
376
|
+
import { Platform } from "react-native";
|
|
377
|
+
|
|
378
|
+
const { data: token } = await ExpoNotifications.getDevicePushTokenAsync(); // raw APNs/FCM token
|
|
379
|
+
await Notifications.registerDeviceToken(
|
|
380
|
+
token,
|
|
381
|
+
Platform.OS === "ios" ? "apns" : "fcm"
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
// Tracking: pass `notification.request.content.data` (or the whole object).
|
|
385
|
+
ExpoNotifications.addNotificationReceivedListener((n) =>
|
|
386
|
+
Notifications.trackReceived(n)
|
|
387
|
+
);
|
|
388
|
+
ExpoNotifications.addNotificationResponseReceivedListener((r) => {
|
|
389
|
+
Notifications.trackOpened(r, {
|
|
390
|
+
actionId:
|
|
391
|
+
r.actionIdentifier !== ExpoNotifications.DEFAULT_ACTION_IDENTIFIER
|
|
392
|
+
? r.actionIdentifier
|
|
393
|
+
: undefined,
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
Use `getDevicePushTokenAsync()`, **not** `getExpoPushTokenAsync()` — Swiss Knife
|
|
399
|
+
sends to APNs/FCM directly and needs the device token. Call
|
|
400
|
+
`registerDeviceToken` again after login/logout (or on each launch; identical
|
|
401
|
+
registrations are skipped) to keep the user link fresh. `Notifications.unregister()`
|
|
402
|
+
marks the device unregistered. Payload keys: `sk` (iOS) and `sk_*` (Android) are
|
|
403
|
+
recognised by `Notifications.extractPayload`; notifications that are not from
|
|
404
|
+
Swiss Knife are ignored.
|
|
405
|
+
|
|
406
|
+
### Rich notifications: the Notification Service Extension (iOS)
|
|
407
|
+
|
|
408
|
+
Images (`image_url` in the send payload) need a Notification Service Extension,
|
|
409
|
+
because iOS only lets an extension modify a notification before it is shown.
|
|
410
|
+
The plugin does **not** generate the extension target (it needs an Xcode
|
|
411
|
+
project rewrite). Manual steps:
|
|
412
|
+
|
|
413
|
+
1. Xcode → File → New → Target → _Notification Service Extension_.
|
|
414
|
+
2. Add the `SwissKnifeNotificationService` product of the Swift package
|
|
415
|
+
(`packages/swiss-knife-ios`, SPM) or the `SwissKnifeNotificationService` pod
|
|
416
|
+
to **that target only**. It is deliberately separate from `SwissKnifeiOS` and
|
|
417
|
+
imports only Foundation + UserNotifications, so the extension stays under
|
|
418
|
+
its memory cap. (Podfile: `target 'YourNSE' do pod 'SwissKnifeNotificationService', :path => '.../packages/swiss-knife-ios' end`.)
|
|
419
|
+
3. Replace the generated class:
|
|
420
|
+
|
|
421
|
+
```swift
|
|
422
|
+
import SwissKnifeNotificationService
|
|
423
|
+
|
|
424
|
+
final class NotificationService: SwissKnifeNotificationServiceExtension {
|
|
425
|
+
// Optional: also record `received` for background/tray deliveries.
|
|
426
|
+
override var trackingConfiguration: TrackingConfiguration? {
|
|
427
|
+
.init(apiKey: "sk_live_…", baseURL: URL(string: "https://api.swiss-knife.dev")!)
|
|
280
428
|
}
|
|
281
429
|
}
|
|
282
430
|
```
|
|
283
431
|
|
|
432
|
+
It downloads `sk.img` (https only, ~20 s budget) and attaches it; on timeout the
|
|
433
|
+
notification is shown without the image. The extension and the app must share the
|
|
434
|
+
same bundle-id prefix and the extension's deployment target must be iOS 15+.
|
|
435
|
+
|
|
436
|
+
### Native SDKs
|
|
437
|
+
|
|
438
|
+
iOS (`SwissKnife.Notifications`) and Android (`SwissKnife.notifications`) expose
|
|
439
|
+
the same API natively for non-React-Native apps; `SwissKnife.setPushToken` is
|
|
440
|
+
deprecated in favour of `registerDeviceToken`.
|
|
441
|
+
|
|
442
|
+
## Storage
|
|
443
|
+
|
|
444
|
+
The SDK has no pluggable storage adapter. The optional peer
|
|
445
|
+
`@react-native-async-storage/async-storage` is resolved lazily to queue events
|
|
446
|
+
(analytics and crash reports) while the app is offline or crashing; without it
|
|
447
|
+
those queues are memory-only.
|
|
448
|
+
|
|
284
449
|
## License
|
|
285
450
|
|
|
286
451
|
MIT
|
|
452
|
+
|
|
453
|
+
### Optional RuStore billing (Android)
|
|
454
|
+
|
|
455
|
+
The npm package includes the native RuStore adapter. Enable it in Expo:
|
|
456
|
+
|
|
457
|
+
```json
|
|
458
|
+
[
|
|
459
|
+
"@app-swiss-knife/react-native-sdk",
|
|
460
|
+
{
|
|
461
|
+
"android": {
|
|
462
|
+
"rustore": { "consoleAppId": "123456", "scheme": "myapp-pay" }
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
]
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
Prebuild configures the payment return deeplink and selects `swissKnifeStore=rustore`.
|
|
469
|
+
Without this option, builds use Play and do not load RuStore dependencies. Bare React
|
|
470
|
+
Native apps can set that Gradle property and provide RuStore's manifest metadata
|
|
471
|
+
(`console_app_id_value`, `sdk_pay_scheme_value`) plus the launcher Activity's
|
|
472
|
+
singleTask payment return intent filter. Backend credentials use `rustore_api_key`;
|
|
473
|
+
products and entitlements must be configured for platform `rustore`.
|
|
@@ -27,7 +27,7 @@ Pod::Spec.new do |s|
|
|
|
27
27
|
#
|
|
28
28
|
# Raising this number is a BREAKING change for consumers: CocoaPods fails
|
|
29
29
|
# resolution with "required a higher minimum deployment target" and the error
|
|
30
|
-
# never names the version. See integrations/claude-code-plugin/skills/setup.
|
|
30
|
+
# never names the version. See integrations/claude-code-plugin/skills/setup-sdk.
|
|
31
31
|
s.platforms = { :ios => "15.1" }
|
|
32
32
|
s.source = { :git => "https://github.com/Remneys/swiss-knife.git", :tag => "#{s.version}" }
|
|
33
33
|
|
package/android/build.gradle
CHANGED
|
@@ -15,6 +15,10 @@ def safeExtGet(prop, fallback) {
|
|
|
15
15
|
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
def billingStore = providers.gradleProperty("swissKnifeStore").getOrElse("play")
|
|
19
|
+
if (!(billingStore in ["play", "rustore"])) throw new GradleException("swissKnifeStore must be play or rustore")
|
|
20
|
+
def useRuStore = billingStore == "rustore"
|
|
21
|
+
|
|
18
22
|
android {
|
|
19
23
|
namespace "com.swissknife.purchases"
|
|
20
24
|
compileSdkVersion safeExtGet("compileSdkVersion", 35)
|
|
@@ -48,15 +52,26 @@ android {
|
|
|
48
52
|
// why the vendored Kotlin tree is registered there and not under `kotlin`.
|
|
49
53
|
sourceSets {
|
|
50
54
|
main {
|
|
51
|
-
java.srcDirs += ["vendor/java"]
|
|
55
|
+
java.srcDirs += ["vendor/java", "src/${billingStore}/java"]
|
|
56
|
+
if (useRuStore) {
|
|
57
|
+
java.srcDirs += ["vendor-rustore/java"]
|
|
58
|
+
manifest.srcFile "vendor-rustore/AndroidManifest.xml"
|
|
59
|
+
}
|
|
52
60
|
res.srcDirs += ["vendor/res"]
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
64
|
|
|
57
|
-
repositories {
|
|
65
|
+
repositories {
|
|
66
|
+
google(); mavenCentral()
|
|
67
|
+
if (useRuStore) maven { url = uri("https://nexus-external.rustore.ru/repository/maven-rustore-exposed") }
|
|
68
|
+
}
|
|
58
69
|
|
|
59
70
|
dependencies {
|
|
71
|
+
if (useRuStore) {
|
|
72
|
+
implementation platform("ru.rustore.sdk:bom:2026.04.01")
|
|
73
|
+
implementation "ru.rustore.sdk:pay"
|
|
74
|
+
}
|
|
60
75
|
implementation "com.facebook.react:react-android"
|
|
61
76
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
62
77
|
|
|
@@ -76,6 +91,13 @@ dependencies {
|
|
|
76
91
|
implementation "androidx.work:work-runtime-ktx:2.9.0"
|
|
77
92
|
// ProcessLifecycleOwner — com.appswissknife.context.AppLifecycle.
|
|
78
93
|
implementation "androidx.lifecycle:lifecycle-process:2.5.1"
|
|
94
|
+
// FCM — com.appswissknife.notifications.SwissKnifeMessagingService extends
|
|
95
|
+
// FirebaseMessagingService. compileOnly (mirrors packages/swiss-knife-android):
|
|
96
|
+
// apps that do not use push must not inherit Firebase. Apps that do get it
|
|
97
|
+
// from the Expo config plugin (which adds the same coordinate to the app
|
|
98
|
+
// module) or must declare `implementation "com.google.firebase:firebase-messaging:24.0.3"`
|
|
99
|
+
// themselves. See README "Push notifications".
|
|
100
|
+
compileOnly "com.google.firebase:firebase-messaging:24.0.3"
|
|
79
101
|
// Play Billing v8 — com.appswissknife.purchases.BillingClientGateway /
|
|
80
102
|
// PlayPriceEnrichmentProvider. Previously pulled in transitively through
|
|
81
103
|
// RevenueCat's purchases-hybrid-common; now a direct, first-party dep.
|
|
@@ -62,3 +62,15 @@
|
|
|
62
62
|
# so this is a belt-and-braces rule for non-RN/stripped consumers — but it costs
|
|
63
63
|
# nothing and turns a hard build failure into a no-op.
|
|
64
64
|
-dontwarn okhttp3.**
|
|
65
|
+
|
|
66
|
+
# ── Push notifications (com.appswissknife.notifications.*) ────────────────────
|
|
67
|
+
# Mirrors packages/swiss-knife-android/consumer-rules.pro: vendored sources do
|
|
68
|
+
# not carry the AAR's consumer rules, so they are restated here.
|
|
69
|
+
|
|
70
|
+
# firebase-messaging is compileOnly: apps without push do not ship it.
|
|
71
|
+
-dontwarn com.google.firebase.messaging.**
|
|
72
|
+
|
|
73
|
+
# Instantiated by the framework / WorkManager by class name.
|
|
74
|
+
-keep class com.appswissknife.notifications.SwissKnifeMessagingService { <init>(); }
|
|
75
|
+
-keep class com.appswissknife.notifications.PermissionRequestActivity { <init>(); }
|
|
76
|
+
-keep class com.appswissknife.notifications.PushEventsFlushWorker { <init>(android.content.Context, androidx.work.WorkerParameters); }
|
|
@@ -21,6 +21,20 @@
|
|
|
21
21
|
tools:replace="android:dataExtractionRules" — same as they would have had
|
|
22
22
|
to with the published AAR.
|
|
23
23
|
-->
|
|
24
|
+
<!-- Runtime notification permission on API 33+ (Notifications.requestPermission). -->
|
|
25
|
+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
|
26
|
+
|
|
24
27
|
<application
|
|
25
|
-
android:dataExtractionRules="@xml/swissknife_data_extraction_rules"
|
|
28
|
+
android:dataExtractionRules="@xml/swissknife_data_extraction_rules">
|
|
29
|
+
<!--
|
|
30
|
+
Transparent trampoline that owns the POST_NOTIFICATIONS dialog. The
|
|
31
|
+
vendoring script only copies the SDK's java/ and res/ trees, so the
|
|
32
|
+
library manifest's declaration never reaches this module: declare it
|
|
33
|
+
here or requestPermission throws ActivityNotFoundException.
|
|
34
|
+
-->
|
|
35
|
+
<activity
|
|
36
|
+
android:name="com.appswissknife.notifications.PermissionRequestActivity"
|
|
37
|
+
android:exported="false"
|
|
38
|
+
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
|
|
39
|
+
</application>
|
|
26
40
|
</manifest>
|
|
@@ -46,9 +46,9 @@ class SKCrashReportingModule(
|
|
|
46
46
|
|
|
47
47
|
// Seed the observability backend before SKCrashReporting.start so
|
|
48
48
|
// IngestClient has an api key + base URL. Without this,
|
|
49
|
-
// IngestClient.shared stays null and the Kotlin crash path
|
|
50
|
-
// (
|
|
51
|
-
//
|
|
49
|
+
// IngestClient.shared stays null and the Kotlin crash path holds
|
|
50
|
+
// every report (in memory, and crash files on disk) until something
|
|
51
|
+
// wires IngestClient: there is no direct HTTP fallback any more.
|
|
52
52
|
// ensureObservabilityBackend is the public, idempotent entry point
|
|
53
53
|
// (already used by the RN analytics init path) that wires
|
|
54
54
|
// BackendHttpClient + IngestClient + Session/Clock/Reachability with
|
|
@@ -68,7 +68,8 @@ class SKCrashReportingModule(
|
|
|
68
68
|
serverURL.trimEnd('/'),
|
|
69
69
|
)
|
|
70
70
|
} catch (e: Throwable) {
|
|
71
|
-
// Crash init below still
|
|
71
|
+
// Crash init below still captures, but sends nothing until
|
|
72
|
+
// IngestClient is wired (reports wait in memory and on disk).
|
|
72
73
|
println("[SwissKnife RN] observability backend wiring failed: ${e.message}")
|
|
73
74
|
}
|
|
74
75
|
|
|
@@ -23,6 +23,7 @@ import com.appswissknife.models.StoreProductDiscount
|
|
|
23
23
|
import com.appswissknife.models.StoreTransaction
|
|
24
24
|
import com.appswissknife.models.SubscriptionPeriod
|
|
25
25
|
import com.appswissknife.models.VerificationResult
|
|
26
|
+
import com.appswissknife.purchases.ProductKindHint
|
|
26
27
|
import com.facebook.react.bridge.Arguments
|
|
27
28
|
import com.facebook.react.bridge.WritableArray
|
|
28
29
|
import com.facebook.react.bridge.WritableMap
|
|
@@ -113,8 +114,12 @@ object SwissKnifeJson {
|
|
|
113
114
|
map.putString("priceString", product.price.formatted)
|
|
114
115
|
map.putDouble("price", product.price.amountMicros / 1_000_000.0)
|
|
115
116
|
map.putString("currencyCode", product.price.currencyCode)
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
// A product the SDK knows is one-time (Play INAPP, or a dashboard product
|
|
118
|
+
// with no duration) is not labelled a subscription. Consumable or not is
|
|
119
|
+
// not known here. Any other product keeps the subscription label.
|
|
120
|
+
val oneTime = (product as? ProductKindHint)?.isOneTime == true
|
|
121
|
+
map.putString("productCategory", if (oneTime) "NON_SUBSCRIPTION" else "SUBSCRIPTION")
|
|
122
|
+
map.putString("productType", if (oneTime) "UNKNOWN" else "AUTO_RENEWABLE_SUBSCRIPTION")
|
|
118
123
|
map.putNullableString(
|
|
119
124
|
"subscriptionPeriod",
|
|
120
125
|
product.subscriptionPeriod?.let { periodToISOString(it) },
|