@app-swiss-knife/react-native-sdk 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/CHANGELOG.md +473 -2
  2. package/LICENSE +21 -0
  3. package/README.md +279 -47
  4. package/SwissKnifePurchases.podspec +1 -1
  5. package/android/build.gradle +24 -2
  6. package/android/consumer-rules.pro +12 -0
  7. package/android/src/main/AndroidManifest.xml +15 -1
  8. package/android/src/main/java/com/swissknife/crashreporting/SKCrashReportingModule.kt +5 -4
  9. package/android/src/main/java/com/swissknife/purchases/SwissKnifeJson.kt +20 -2
  10. package/android/src/main/java/com/swissknife/purchases/SwissKnifePurchasesModule.kt +168 -6
  11. package/android/src/play/java/com/swissknife/purchases/StoreIntentHandler.kt +7 -0
  12. package/android/src/rustore/java/com/swissknife/purchases/StoreIntentHandler.kt +9 -0
  13. package/android/vendor/GENERATED.md +1 -0
  14. package/android/vendor/java/com/appswissknife/SwissKnife.kt +111 -38
  15. package/android/vendor/java/com/appswissknife/analytics/SKAnalytics.kt +180 -115
  16. package/android/vendor/java/com/appswissknife/attributes/AttributesClient.kt +16 -18
  17. package/android/vendor/java/com/appswissknife/attributes/SetAttributesWorker.kt +13 -13
  18. package/android/vendor/java/com/appswissknife/attribution/Attribution.kt +56 -25
  19. package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +1 -1
  20. package/android/vendor/java/com/appswissknife/crashreporting/SKCrashReporting.kt +365 -206
  21. package/android/vendor/java/com/appswissknife/entitlements/EntitlementsRepository.kt +195 -26
  22. package/android/vendor/java/com/appswissknife/identity/Identity.kt +31 -6
  23. package/android/vendor/java/com/appswissknife/models/PurchasesError.kt +5 -0
  24. package/android/vendor/java/com/appswissknife/net/BackendHttpClient.kt +56 -31
  25. package/android/vendor/java/com/appswissknife/net/IngestClient.kt +673 -87
  26. package/android/vendor/java/com/appswissknife/net/OfflineQueueStore.kt +214 -30
  27. package/android/vendor/java/com/appswissknife/notifications/NotificationRenderer.kt +195 -0
  28. package/android/vendor/java/com/appswissknife/notifications/PermissionRequestActivity.kt +60 -0
  29. package/android/vendor/java/com/appswissknife/notifications/PermissionStatus.kt +41 -0
  30. package/android/vendor/java/com/appswissknife/notifications/PushEventQueue.kt +143 -0
  31. package/android/vendor/java/com/appswissknife/notifications/PushPayload.kt +72 -0
  32. package/android/vendor/java/com/appswissknife/notifications/PushRegistration.kt +89 -0
  33. package/android/vendor/java/com/appswissknife/notifications/SwissKnifeMessagingService.kt +57 -0
  34. package/android/vendor/java/com/appswissknife/notifications/SwissKnifeNotifications.kt +438 -0
  35. package/android/vendor/java/com/appswissknife/offerings/OfferingsRepository.kt +312 -65
  36. package/android/vendor/java/com/appswissknife/performance/SKPerformance.kt +1 -0
  37. package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +705 -96
  38. package/android/vendor/java/com/appswissknife/purchases/PlayPriceEnrichmentProvider.kt +55 -24
  39. package/android/vendor/java/com/appswissknife/purchases/ProductKindHint.kt +29 -0
  40. package/android/vendor/java/com/appswissknife/purchases/PurchasesGateway.kt +24 -0
  41. package/android/vendor-rustore/AndroidManifest.xml +59 -0
  42. package/android/vendor-rustore/java/com/appswissknife/rustore/RuStoreGateway.kt +428 -0
  43. package/android/vendor-rustore/java/com/appswissknife/rustore/RuStoreInitProvider.kt +43 -0
  44. package/android/vendor-rustore/java/com/appswissknife/rustore/RuStorePriceEnrichmentProvider.kt +85 -0
  45. package/app.plugin.js +343 -0
  46. package/ios/SwissKnifeJSON.swift +24 -2
  47. package/ios/SwissKnifePurchases.m +20 -0
  48. package/ios/SwissKnifePurchases.swift +97 -3
  49. package/ios/SwissKnifePushBootstrap.m +34 -0
  50. package/ios/vendor/GENERATED.md +1 -0
  51. package/ios/vendor/SwissKnifeiOS/Analytics/SKAnalytics.swift +138 -89
  52. package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +1 -1
  53. package/ios/vendor/SwissKnifeiOS/CrashReporting/SKCrashReporting.swift +345 -44
  54. package/ios/vendor/SwissKnifeiOS/Net/BackendBackoffGate.swift +43 -2
  55. package/ios/vendor/SwissKnifeiOS/Net/IngestClient.swift +495 -16
  56. package/ios/vendor/SwissKnifeiOS/Net/OfflineQueueStore.swift +231 -23
  57. package/ios/vendor/SwissKnifeiOS/Notifications/PushPayload.swift +87 -0
  58. package/ios/vendor/SwissKnifeiOS/Notifications/PushRegistrar.swift +322 -0
  59. package/ios/vendor/SwissKnifeiOS/Notifications/SwissKnife+Notifications.swift +403 -0
  60. package/ios/vendor/SwissKnifeiOS/Performance/SKPerformance.swift +1 -0
  61. package/ios/vendor/SwissKnifeiOS/Services/EntitlementsService.swift +11 -7
  62. package/ios/vendor/SwissKnifeiOS/Services/OfferingsService.swift +37 -5
  63. package/ios/vendor/SwissKnifeiOS/Services/PurchaseService.swift +38 -7
  64. package/ios/vendor/SwissKnifeiOS/SwissKnife.swift +34 -6
  65. package/ios/vendor/SwissKnifeiOS/Types.swift +31 -1
  66. package/ios-notification-service/SwissKnifeNotificationService.podspec +37 -0
  67. package/ios-notification-service/vendor/GENERATED.md +11 -0
  68. package/ios-notification-service/vendor/SwissKnifeNotificationService/SwissKnifeNotificationServiceExtension.swift +177 -0
  69. package/lib/commonjs/attribution.js +4 -3
  70. package/lib/commonjs/attribution.js.map +1 -1
  71. package/lib/commonjs/identity.js +12 -11
  72. package/lib/commonjs/identity.js.map +1 -1
  73. package/lib/commonjs/index.js +16 -5
  74. package/lib/commonjs/index.js.map +1 -1
  75. package/lib/commonjs/internal/config.js +105 -8
  76. package/lib/commonjs/internal/config.js.map +1 -1
  77. package/lib/commonjs/internal/telemetry-context.js +70 -0
  78. package/lib/commonjs/internal/telemetry-context.js.map +1 -0
  79. package/lib/commonjs/modules/analytics.js +18 -25
  80. package/lib/commonjs/modules/analytics.js.map +1 -1
  81. package/lib/commonjs/modules/crash-reporting.js +27 -6
  82. package/lib/commonjs/modules/crash-reporting.js.map +1 -1
  83. package/lib/commonjs/modules/log.js +1 -1
  84. package/lib/commonjs/modules/notifications.js +500 -0
  85. package/lib/commonjs/modules/notifications.js.map +1 -0
  86. package/lib/commonjs/modules/performance.js +57 -8
  87. package/lib/commonjs/modules/performance.js.map +1 -1
  88. package/lib/commonjs/native/module.js +6 -0
  89. package/lib/commonjs/native/module.js.map +1 -1
  90. package/lib/commonjs/native/spec.js +12 -5
  91. package/lib/commonjs/native/spec.js.map +1 -1
  92. package/lib/commonjs/purchases.js +4 -4
  93. package/lib/commonjs/types.js +12 -15
  94. package/lib/commonjs/types.js.map +1 -1
  95. package/lib/module/attribution.js +4 -3
  96. package/lib/module/attribution.js.map +1 -1
  97. package/lib/module/identity.js +12 -11
  98. package/lib/module/identity.js.map +1 -1
  99. package/lib/module/index.js +8 -4
  100. package/lib/module/index.js.map +1 -1
  101. package/lib/module/internal/config.js +103 -8
  102. package/lib/module/internal/config.js.map +1 -1
  103. package/lib/module/internal/telemetry-context.js +63 -0
  104. package/lib/module/internal/telemetry-context.js.map +1 -0
  105. package/lib/module/modules/analytics.js +18 -25
  106. package/lib/module/modules/analytics.js.map +1 -1
  107. package/lib/module/modules/crash-reporting.js +27 -6
  108. package/lib/module/modules/crash-reporting.js.map +1 -1
  109. package/lib/module/modules/log.js +1 -1
  110. package/lib/module/modules/notifications.js +491 -0
  111. package/lib/module/modules/notifications.js.map +1 -0
  112. package/lib/module/modules/performance.js +57 -8
  113. package/lib/module/modules/performance.js.map +1 -1
  114. package/lib/module/native/module.js +6 -1
  115. package/lib/module/native/module.js.map +1 -1
  116. package/lib/module/native/spec.js +11 -4
  117. package/lib/module/native/spec.js.map +1 -1
  118. package/lib/module/purchases.js +4 -4
  119. package/lib/module/types.js +12 -15
  120. package/lib/module/types.js.map +1 -1
  121. package/lib/typescript/commonjs/attribution.d.ts +3 -2
  122. package/lib/typescript/commonjs/attribution.d.ts.map +1 -1
  123. package/lib/typescript/commonjs/identity.d.ts.map +1 -1
  124. package/lib/typescript/commonjs/index.d.ts +2 -0
  125. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  126. package/lib/typescript/commonjs/internal/config.d.ts +16 -2
  127. package/lib/typescript/commonjs/internal/config.d.ts.map +1 -1
  128. package/lib/typescript/commonjs/internal/telemetry-context.d.ts +22 -0
  129. package/lib/typescript/commonjs/internal/telemetry-context.d.ts.map +1 -0
  130. package/lib/typescript/commonjs/modules/analytics.d.ts +8 -11
  131. package/lib/typescript/commonjs/modules/analytics.d.ts.map +1 -1
  132. package/lib/typescript/commonjs/modules/crash-reporting.d.ts +18 -5
  133. package/lib/typescript/commonjs/modules/crash-reporting.d.ts.map +1 -1
  134. package/lib/typescript/commonjs/modules/notifications.d.ts +110 -0
  135. package/lib/typescript/commonjs/modules/notifications.d.ts.map +1 -0
  136. package/lib/typescript/commonjs/modules/performance.d.ts +13 -0
  137. package/lib/typescript/commonjs/modules/performance.d.ts.map +1 -1
  138. package/lib/typescript/commonjs/native/module.d.ts +2 -0
  139. package/lib/typescript/commonjs/native/module.d.ts.map +1 -1
  140. package/lib/typescript/commonjs/native/spec.d.ts +33 -4
  141. package/lib/typescript/commonjs/native/spec.d.ts.map +1 -1
  142. package/lib/typescript/commonjs/purchases.d.ts +4 -4
  143. package/lib/typescript/commonjs/types.d.ts +4 -5
  144. package/lib/typescript/commonjs/types.d.ts.map +1 -1
  145. package/lib/typescript/module/attribution.d.ts +3 -2
  146. package/lib/typescript/module/attribution.d.ts.map +1 -1
  147. package/lib/typescript/module/identity.d.ts.map +1 -1
  148. package/lib/typescript/module/index.d.ts +2 -0
  149. package/lib/typescript/module/index.d.ts.map +1 -1
  150. package/lib/typescript/module/internal/config.d.ts +16 -2
  151. package/lib/typescript/module/internal/config.d.ts.map +1 -1
  152. package/lib/typescript/module/internal/telemetry-context.d.ts +22 -0
  153. package/lib/typescript/module/internal/telemetry-context.d.ts.map +1 -0
  154. package/lib/typescript/module/modules/analytics.d.ts +8 -11
  155. package/lib/typescript/module/modules/analytics.d.ts.map +1 -1
  156. package/lib/typescript/module/modules/crash-reporting.d.ts +18 -5
  157. package/lib/typescript/module/modules/crash-reporting.d.ts.map +1 -1
  158. package/lib/typescript/module/modules/notifications.d.ts +110 -0
  159. package/lib/typescript/module/modules/notifications.d.ts.map +1 -0
  160. package/lib/typescript/module/modules/performance.d.ts +13 -0
  161. package/lib/typescript/module/modules/performance.d.ts.map +1 -1
  162. package/lib/typescript/module/native/module.d.ts +2 -0
  163. package/lib/typescript/module/native/module.d.ts.map +1 -1
  164. package/lib/typescript/module/native/spec.d.ts +33 -4
  165. package/lib/typescript/module/native/spec.d.ts.map +1 -1
  166. package/lib/typescript/module/purchases.d.ts +4 -4
  167. package/lib/typescript/module/types.d.ts +4 -5
  168. package/lib/typescript/module/types.d.ts.map +1 -1
  169. package/package.json +13 -4
  170. package/src/attribution.ts +4 -3
  171. package/src/identity.ts +12 -11
  172. package/src/index.ts +16 -4
  173. package/src/internal/config.ts +113 -8
  174. package/src/internal/telemetry-context.ts +76 -0
  175. package/src/modules/analytics.ts +24 -33
  176. package/src/modules/crash-reporting.ts +50 -9
  177. package/src/modules/log.ts +1 -1
  178. package/src/modules/notifications.ts +557 -0
  179. package/src/modules/performance.ts +94 -14
  180. package/src/native/module.ts +6 -0
  181. package/src/native/spec.ts +45 -10
  182. package/src/purchases.ts +4 -4
  183. package/src/types.ts +12 -15
  184. package/android/vendor/java/com/appswissknife/analytics/EventQueueStore.kt +0 -326
  185. 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` · `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. |
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
 
@@ -24,11 +31,12 @@ has to exist on any registry for a consumer app to build.
24
31
  `scripts/vendor-native.mjs` runs on `build` and `prepack` and copies the
25
32
  native sources into this package:
26
33
 
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`) |
34
+ | From | To | Compiled by |
35
+ | ---------------------------------------------------------------- | --------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
36
+ | `packages/swiss-knife-ios/Sources/SwissKnifeiOS` | `ios/vendor/SwissKnifeiOS` | `SwissKnifePurchases.podspec` (`source_files = ios/**`) |
37
+ | `packages/swiss-knife-android/src/main/java` | `android/vendor/java` | `android/build.gradle` (`sourceSets.main.java.srcDirs`) |
38
+ | `packages/swiss-knife-android/src/main/res` | `android/vendor/res` | `android/build.gradle` (`sourceSets.main.res.srcDirs`) |
39
+ | `packages/swiss-knife-ios/Sources/SwissKnifeNotificationService` | `ios-notification-service/vendor/SwissKnifeNotificationService` | `ios-notification-service/SwissKnifeNotificationService.podspec` (extension target only) |
32
40
 
33
41
  The vendored trees are **git-ignored build artifacts** (same status as `lib/`)
34
42
  but ARE included in the tarball. The single source of truth stays in
@@ -70,10 +78,9 @@ with a single auditable code path.
70
78
  Expo Go is **not supported** — this SDK contains native Kotlin/Swift code that
71
79
  requires a custom dev build.
72
80
 
73
- An Expo config plugin (`app.plugin.js`) is planned for SP-3. Until then:
74
-
75
81
  1. Run `expo prebuild` (or use a custom dev build / EAS Build).
76
82
  2. The native modules are auto-linked via React Native's standard autolinking.
83
+ 3. For push notifications add the config plugin — see [Push notifications](#push-notifications).
77
84
 
78
85
  ---
79
86
 
@@ -99,7 +106,8 @@ import {
99
106
  Attributes,
100
107
  } from "@app-swiss-knife/react-native-sdk";
101
108
 
102
- // Once, at app start.
109
+ // Once, at app start. `Purchases.configure` is the same function, so
110
+ // react-native-purchases-style code works unchanged.
103
111
  SwissKnife.configure({
104
112
  apiKey: "sk_...",
105
113
  proxyURL: "https://your-swiss-knife-host",
@@ -217,31 +225,28 @@ await Attribution.registerInstall(); // explicit — core never does this for yo
217
225
 
218
226
  ## IDFA/GAID Collection (Advertising ID)
219
227
 
220
- 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.
221
-
222
- ### 1. Install peer dependencies
228
+ The SDK can send the device advertising ID with the install for deterministic
229
+ attribution matching. It is optional: without it, attribution falls back to
230
+ fingerprint matching (and, on Android, the install referrer when the app
231
+ supplies it natively).
223
232
 
224
- ```bash
225
- npm install react-native-device-info react-native-tracking-transparency
226
- ```
233
+ - **iOS:** `Attribution.requestAndRegister()` shows the App Tracking
234
+ Transparency prompt and reads the IDFA when the user allows it. Add
235
+ `NSUserTrackingUsageDescription` to your `Info.plist`:
227
236
 
228
- ### 2. iOS: Add tracking permission description
237
+ ```xml
238
+ <key>NSUserTrackingUsageDescription</key>
239
+ <string>We use this identifier to attribute your install to the correct campaign.</string>
240
+ ```
229
241
 
230
- Add `NSUserTrackingUsageDescription` to your `Info.plist`:
242
+ - **Android:** the SDK collects neither the advertising ID (GAID) nor the
243
+ install referrer on its own: it adds no Play services dependency. Read a
244
+ consented advertising ID in your app and pass it to
245
+ `Attribution.registerInstall(advertisingId)`, or register native collectors
246
+ with `Attribution.setCollectors(...)` in the Android SDK before configure.
231
247
 
232
- ```xml
233
- <key>NSUserTrackingUsageDescription</key>
234
- <string>We use this identifier to attribute your install to the correct campaign.</string>
235
- ```
236
-
237
- ### 3. That's it
238
-
239
- The SDK automatically:
240
-
241
- - Requests App Tracking Transparency permission on iOS before reading IDFA
242
- - Reads GAID on Android (no extra permission needed)
243
- - Includes `advertising_id` in the install attribution request
244
- - Falls back gracefully if the user denies tracking or the libraries are not installed
248
+ The install request includes `advertising_id` only when one was collected, and
249
+ a denied prompt or a missing id falls back gracefully.
245
250
 
246
251
  You can also drive it yourself through the `Attribution` namespace — prompt
247
252
  orchestration and the idempotency cache live natively, so a second call returns
@@ -250,8 +255,8 @@ the cached resolution without re-prompting or re-POSTing:
250
255
  ```typescript
251
256
  import { Attribution } from "@app-swiss-knife/react-native-sdk";
252
257
 
253
- // Auto-collect (ATT prompt + IDFA on iOS, advertising id + referrer on Android)
254
- // and register the install.
258
+ // Register the install: ATT prompt + IDFA on iOS; on Android only what native
259
+ // collectors supply (none by default).
255
260
  const resolved = await Attribution.requestAndRegister();
256
261
 
257
262
  // Or collect consent yourself and hand us the id (pass null if denied):
@@ -261,26 +266,253 @@ await Attribution.registerInstall(advertisingId);
261
266
  const current = await Attribution.resolved();
262
267
  ```
263
268
 
264
- ## Custom Storage
269
+ ## Push notifications
270
+
271
+ Push v1 sends directly through APNs and FCM from the Swiss Knife server (no
272
+ Expo relay). The SDK registers this install's token, links it to the current
273
+ user, and reports `received` / `opened` / `action` events. Two integration
274
+ modes share one API, `Notifications`:
275
+
276
+ | | Native mode | Manual mode |
277
+ | --------------------- | ------------------------ | ------------------------------------------- |
278
+ | Who owns the OS token | Swiss Knife SDK | your app (`expo-notifications`, RNFirebase) |
279
+ | Use when | you have no push library | you already have one |
280
+
281
+ Server credentials (APNs `.p8` key, FCM service account) are stored per app on
282
+ the Swiss Knife server; send with the `push_send` tool / REST API.
283
+
284
+ ### Setup (Expo)
285
+
286
+ ```jsonc
287
+ // app.json
288
+ {
289
+ "expo": {
290
+ "ios": { "bundleIdentifier": "com.example.app" },
291
+ "android": {
292
+ "package": "com.example.app",
293
+ "googleServicesFile": "./google-services.json",
294
+ },
295
+ "plugins": [
296
+ [
297
+ "@app-swiss-knife/react-native-sdk",
298
+ {
299
+ "ios": { "mode": "production" }, // or "development"
300
+ "android": {
301
+ "defaultChannel": { "id": "default", "name": "General" },
302
+ },
303
+ },
304
+ ],
305
+ ],
306
+ },
307
+ }
308
+ ```
309
+
310
+ The plugin adds the `aps-environment` entitlement (default `development`, like
311
+ `expo-notifications`: Xcode's distribution export rewrites it to `production` for
312
+ App Store/TestFlight builds — confirm on your first TestFlight build via the
313
+ device's `environment` in the dashboard) and the `remote-notification`
314
+ background mode on iOS, and the `POST_NOTIFICATIONS` permission plus
315
+ `com.appswissknife.notifications.SwissKnifeMessagingService` on Android (set
316
+ `android.registerMessagingService: false` to skip the service; it is skipped
317
+ automatically, with a warning, when `expo-notifications` or
318
+ `@react-native-firebase/messaging` is present, since two services cannot both own
319
+ FCM — in that case use manual mode below: `registerDeviceToken` plus
320
+ `trackReceived`/`trackOpened`), and adds
321
+ `com.google.firebase:firebase-messaging` to the app module (the SDK declares it
322
+ `compileOnly` so apps that do not use push do not inherit Firebase).
323
+ `android.googleServicesFile` (plugin option or `expo.android.googleServicesFile`)
324
+ is handled by Expo's own mechanism. Bare React Native: make those same edits by
325
+ hand — register the service with a `com.google.firebase.MESSAGING_EVENT`
326
+ intent-filter, add `implementation "com.google.firebase:firebase-messaging:24.0.3"`
327
+ to your app module, and add `google-services.json` with the Google Services
328
+ Gradle plugin. (The React Native module's own manifest declares `POST_NOTIFICATIONS` and the
329
+ `PermissionRequestActivity` that `requestPermission` launches; nothing to add.)
330
+
331
+ ### Native mode
332
+
333
+ ```ts
334
+ import { Notifications } from "@app-swiss-knife/react-native-sdk";
335
+
336
+ const status = await Notifications.requestPermission({ provisional: false });
337
+ if (status === "authorized" || status === "provisional") {
338
+ await Notifications.registerForPushNotifications(); // iOS: APNs, Android: FCM
339
+ }
265
340
 
266
- By default, the SDK uses `@react-native-async-storage/async-storage` for persistence. You can provide a custom storage adapter:
341
+ const sub = Notifications.addNotificationOpenedListener((open) => {
342
+ if (open.link) Linking.openURL(open.link);
343
+ });
344
+ const launch = await Notifications.getInitialNotification(); // cold start, once
345
+ ```
267
346
 
268
- ```typescript
269
- import { StorageAdapter } from "@app-swiss-knife/react-native-sdk";
347
+ On iOS the SDK installs a `UNUserNotificationCenter` delegate proxy (forwarding
348
+ to any delegate that was set before it) and hooks the APNs-token callback when
349
+ you call `registerForPushNotifications()`. To catch a notification tap that
350
+ _cold-starts_ the app, call `registerForPushNotifications()` (or the native
351
+ `SwissKnife.Notifications.enableAutoIntegration()`) from
352
+ `application(_:didFinishLaunchingWithOptions:)`; otherwise iOS delivers the tap
353
+ before the delegate exists. Permission changes made in Settings, identity
354
+ changes (`Identity.logIn` / `logOut`) and token rotation re-upsert the device
355
+ automatically (unchanged state is never re-sent).
356
+
357
+ **Cold-start tap tracking needs an earlier run.** `registerForPushNotifications()`
358
+ persists the opt-in; only on _later_ launches does the native module install the
359
+ notification delegate before JS starts. So a tap that cold-starts the app is
360
+ captured only after `registerForPushNotifications()` has run on some previous
361
+ launch (which is always true for a device that already received a push).
362
+
363
+ **User link and relaunch.** The SDK's identity is in-memory: after a relaunch the
364
+ user is anonymous until your app calls `Identity.logIn(...)` again. The device
365
+ upsert therefore _omits_ `user_id` at launch (the server keeps the existing link)
366
+ and sends `user_id: null` (unlink) only on an explicit `Identity.logOut()` /
367
+ `reset()` / `wipe()`. Still call `logIn` on every launch that restores a session
368
+ so new/reinstalled devices get linked.
369
+
370
+ ### Manual mode (expo-notifications / Firebase)
371
+
372
+ Keep your push library; hand us the token and the payloads:
373
+
374
+ ```ts
375
+ import * as ExpoNotifications from "expo-notifications";
376
+ import { Notifications } from "@app-swiss-knife/react-native-sdk";
377
+ import { Platform } from "react-native";
378
+
379
+ const { data: token } = await ExpoNotifications.getDevicePushTokenAsync(); // raw APNs/FCM token
380
+ await Notifications.registerDeviceToken(
381
+ token,
382
+ Platform.OS === "ios" ? "apns" : "fcm"
383
+ );
384
+
385
+ // Tracking: pass `notification.request.content.data` (or the whole object).
386
+ ExpoNotifications.addNotificationReceivedListener((n) =>
387
+ Notifications.trackReceived(n)
388
+ );
389
+ ExpoNotifications.addNotificationResponseReceivedListener((r) => {
390
+ Notifications.trackOpened(r, {
391
+ actionId:
392
+ r.actionIdentifier !== ExpoNotifications.DEFAULT_ACTION_IDENTIFIER
393
+ ? r.actionIdentifier
394
+ : undefined,
395
+ });
396
+ });
397
+ ```
270
398
 
271
- class SecureStorageAdapter implements StorageAdapter {
272
- async get(key: string): Promise<string | null> {
273
- // your implementation
274
- }
275
- async set(key: string, value: string): Promise<void> {
276
- // your implementation
277
- }
278
- async remove(key: string): Promise<void> {
279
- // your implementation
399
+ Use `getDevicePushTokenAsync()`, **not** `getExpoPushTokenAsync()` — Swiss Knife
400
+ sends to APNs/FCM directly and needs the device token. Call
401
+ `registerDeviceToken` again after login/logout (or on each launch; identical
402
+ registrations are skipped) to keep the user link fresh. `Notifications.unregister()`
403
+ marks the device unregistered. Payload keys: `sk` (iOS) and `sk_*` (Android) are
404
+ recognised by `Notifications.extractPayload`; notifications that are not from
405
+ Swiss Knife are ignored.
406
+
407
+ ### Rich notifications: the Notification Service Extension (iOS)
408
+
409
+ Images (`image_url` in the send payload) need a Notification Service Extension,
410
+ because iOS only lets an extension modify a notification before it is shown.
411
+ The plugin does **not** generate the extension target (it needs an Xcode
412
+ project rewrite). Manual steps:
413
+
414
+ 1. Xcode → File → New → Target → _Notification Service Extension_.
415
+ 2. Add the `SwissKnifeNotificationService` pod, which ships in this package, to
416
+ **that target only**: in `ios/Podfile`, at the top level, then `pod install`.
417
+
418
+ ```ruby
419
+ target 'YourNotificationService' do
420
+ pod 'SwissKnifeNotificationService', :path => '../node_modules/@app-swiss-knife/react-native-sdk/ios-notification-service'
421
+ end
422
+ ```
423
+
424
+ The path is relative to `ios/`; in a monorepo that hoists `node_modules`,
425
+ point it at the folder where the package is actually installed.
426
+
427
+ It is deliberately separate from the SDK's pod and imports only Foundation +
428
+ UserNotifications, so the extension stays under its memory cap. (A native
429
+ app without React Native adds the `SwissKnifeNotificationService` product of
430
+ the Swift package in `packages/swiss-knife-ios` instead.)
431
+
432
+ 3. Replace the generated class:
433
+
434
+ ```swift
435
+ import SwissKnifeNotificationService
436
+
437
+ final class NotificationService: SwissKnifeNotificationServiceExtension {
438
+ // Optional: also record `received` for background/tray deliveries.
439
+ override var trackingConfiguration: TrackingConfiguration? {
440
+ .init(apiKey: "sk_live_…", baseURL: URL(string: "https://api.swiss-knife.dev")!)
280
441
  }
281
442
  }
282
443
  ```
283
444
 
445
+ It downloads `sk.img` (https only, ~20 s budget) and attaches it; on timeout the
446
+ notification is shown without the image. The extension and the app must share the
447
+ same bundle-id prefix and the extension's deployment target must be iOS 15+.
448
+
449
+ ### Native SDKs
450
+
451
+ iOS (`SwissKnife.Notifications`) and Android (`SwissKnife.notifications`) expose
452
+ the same API natively for non-React-Native apps; `SwissKnife.setPushToken` is
453
+ deprecated in favour of `registerDeviceToken`.
454
+
455
+ ## Storage
456
+
457
+ The SDK has no pluggable storage adapter. The optional peer
458
+ `@react-native-async-storage/async-storage` is resolved lazily to queue events
459
+ (analytics and crash reports) while the app is offline or crashing; without it
460
+ those queues are memory-only.
461
+
284
462
  ## License
285
463
 
286
464
  MIT
465
+
466
+ ### Optional RuStore billing (Android)
467
+
468
+ The npm package includes the native RuStore adapter. Enable it in Expo:
469
+
470
+ ```json
471
+ [
472
+ "@app-swiss-knife/react-native-sdk",
473
+ {
474
+ "android": {
475
+ "rustore": { "consoleAppId": "123456", "scheme": "myapp-pay" }
476
+ }
477
+ }
478
+ ]
479
+ ```
480
+
481
+ Prebuild configures the payment return deeplink and selects `swissKnifeStore=rustore`.
482
+ Without this option, builds use Play and do not load RuStore dependencies.
483
+
484
+ To ship one app config to both stores, choose the store per build with the
485
+ `SWISS_KNIFE_ANDROID_STORE` environment variable, which the config plugin reads
486
+ at prebuild:
487
+
488
+ | `SWISS_KNIFE_ANDROID_STORE` | Build |
489
+ | --------------------------- | ------------------------------------------------------------------------------------------------------------------- |
490
+ | unset or empty | RuStore when `android.rustore` is configured, Google Play otherwise (the behaviour above) |
491
+ | `play` | Google Play: `swissKnifeStore=play`, no RuStore strings or manifest entries, even with `android.rustore` configured |
492
+ | `rustore` | RuStore; prebuild fails, naming the missing fields, unless `android.rustore` has `consoleAppId` and `scheme` |
493
+
494
+ Any other value fails the prebuild, an iOS one included, since the plugin checks
495
+ the variable whenever it reads the app config. With EAS Build, set it in each
496
+ build profile's `env`; EAS runs prebuild with it when `android/` is not
497
+ committed (a bare project sets `swissKnifeStore` itself, see below):
498
+
499
+ ```json
500
+ {
501
+ "build": {
502
+ "production-play": {
503
+ "env": { "SWISS_KNIFE_ANDROID_STORE": "play" }
504
+ },
505
+ "production-rustore": {
506
+ "env": { "SWISS_KNIFE_ANDROID_STORE": "rustore" }
507
+ }
508
+ }
509
+ }
510
+ ```
511
+
512
+ Locally, `SWISS_KNIFE_ANDROID_STORE=play npx expo prebuild -p android --clean`;
513
+ `--clean` matters when switching stores, since prebuild without it keeps the
514
+ RuStore entries an earlier RuStore prebuild wrote into `android/`. Bare React
515
+ Native apps can set the `swissKnifeStore` Gradle property and provide RuStore's manifest metadata
516
+ (`console_app_id_value`, `sdk_pay_scheme_value`) plus the launcher Activity's
517
+ singleTask payment return intent filter. Backend credentials use `rustore_api_key`;
518
+ 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
 
@@ -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 { google(); mavenCentral() }
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
- // (flushEventQueue / sendEventPayload / sendSessionEvent) silently
51
- // falls back to the legacy /api/sdk/errors/* HTTP endpoints.
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 works via its legacy HTTP fallback.
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,13 @@ 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
- map.putString("productCategory", "SUBSCRIPTION")
117
- map.putString("productType", "AUTO_RENEWABLE_SUBSCRIPTION")
117
+ // A product the SDK knows is one-time (Play INAPP, or a dashboard product
118
+ // with no duration) is not labelled a subscription. Any other product keeps
119
+ // the subscription label.
120
+ val hint = product as? ProductKindHint
121
+ val oneTime = hint?.isOneTime == true
122
+ map.putString("productCategory", if (oneTime) "NON_SUBSCRIPTION" else "SUBSCRIPTION")
123
+ map.putString("productType", productTypeLabel(oneTime, hint?.productKind))
118
124
  map.putNullableString(
119
125
  "subscriptionPeriod",
120
126
  product.subscriptionPeriod?.let { periodToISOString(it) },
@@ -368,4 +374,16 @@ object SwissKnifeJson {
368
374
  private fun WritableMap.putNullableMap(key: String, value: WritableMap?) {
369
375
  if (value == null) putNull(key) else putMap(key, value)
370
376
  }
377
+ /**
378
+ * The `productType` label, as iOS reports it for the same product: a one-time
379
+ * product is CONSUMABLE or NON_CONSUMABLE when the server's catalogue names
380
+ * its type, UNKNOWN otherwise. Play has no non-renewing subscription, so
381
+ * every subscription is AUTO_RENEWABLE_SUBSCRIPTION.
382
+ */
383
+ internal fun productTypeLabel(oneTime: Boolean, kind: String?): String = when {
384
+ !oneTime -> "AUTO_RENEWABLE_SUBSCRIPTION"
385
+ kind == "consumable" -> "CONSUMABLE"
386
+ kind == "non_consumable" -> "NON_CONSUMABLE"
387
+ else -> "UNKNOWN"
388
+ }
371
389
  }