@app-swiss-knife/react-native-sdk 0.4.0 → 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.
Files changed (177) hide show
  1. package/CHANGELOG.md +385 -2
  2. package/LICENSE +21 -0
  3. package/README.md +229 -42
  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 +7 -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/java/com/appswissknife/SwissKnife.kt +107 -38
  14. package/android/vendor/java/com/appswissknife/analytics/SKAnalytics.kt +180 -115
  15. package/android/vendor/java/com/appswissknife/attributes/AttributesClient.kt +16 -18
  16. package/android/vendor/java/com/appswissknife/attributes/SetAttributesWorker.kt +13 -13
  17. package/android/vendor/java/com/appswissknife/attribution/Attribution.kt +56 -25
  18. package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +1 -1
  19. package/android/vendor/java/com/appswissknife/crashreporting/SKCrashReporting.kt +365 -206
  20. package/android/vendor/java/com/appswissknife/entitlements/EntitlementsRepository.kt +195 -26
  21. package/android/vendor/java/com/appswissknife/identity/Identity.kt +31 -6
  22. package/android/vendor/java/com/appswissknife/models/PurchasesError.kt +5 -0
  23. package/android/vendor/java/com/appswissknife/net/BackendHttpClient.kt +56 -31
  24. package/android/vendor/java/com/appswissknife/net/IngestClient.kt +673 -87
  25. package/android/vendor/java/com/appswissknife/net/OfflineQueueStore.kt +214 -30
  26. package/android/vendor/java/com/appswissknife/notifications/NotificationRenderer.kt +195 -0
  27. package/android/vendor/java/com/appswissknife/notifications/PermissionRequestActivity.kt +60 -0
  28. package/android/vendor/java/com/appswissknife/notifications/PermissionStatus.kt +41 -0
  29. package/android/vendor/java/com/appswissknife/notifications/PushEventQueue.kt +143 -0
  30. package/android/vendor/java/com/appswissknife/notifications/PushPayload.kt +72 -0
  31. package/android/vendor/java/com/appswissknife/notifications/PushRegistration.kt +89 -0
  32. package/android/vendor/java/com/appswissknife/notifications/SwissKnifeMessagingService.kt +57 -0
  33. package/android/vendor/java/com/appswissknife/notifications/SwissKnifeNotifications.kt +438 -0
  34. package/android/vendor/java/com/appswissknife/offerings/OfferingsRepository.kt +266 -64
  35. package/android/vendor/java/com/appswissknife/performance/SKPerformance.kt +1 -0
  36. package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +545 -88
  37. package/android/vendor/java/com/appswissknife/purchases/PlayPriceEnrichmentProvider.kt +55 -24
  38. package/android/vendor/java/com/appswissknife/purchases/ProductKindHint.kt +21 -0
  39. package/android/vendor/java/com/appswissknife/purchases/PurchasesGateway.kt +14 -0
  40. package/android/vendor-rustore/AndroidManifest.xml +59 -0
  41. package/android/vendor-rustore/java/com/appswissknife/rustore/RuStoreGateway.kt +428 -0
  42. package/android/vendor-rustore/java/com/appswissknife/rustore/RuStoreInitProvider.kt +43 -0
  43. package/android/vendor-rustore/java/com/appswissknife/rustore/RuStorePriceEnrichmentProvider.kt +85 -0
  44. package/app.plugin.js +287 -0
  45. package/ios/SwissKnifePurchases.m +20 -0
  46. package/ios/SwissKnifePurchases.swift +97 -3
  47. package/ios/SwissKnifePushBootstrap.m +34 -0
  48. package/ios/vendor/SwissKnifeiOS/Analytics/SKAnalytics.swift +138 -89
  49. package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +1 -1
  50. package/ios/vendor/SwissKnifeiOS/CrashReporting/SKCrashReporting.swift +345 -44
  51. package/ios/vendor/SwissKnifeiOS/Net/BackendBackoffGate.swift +43 -2
  52. package/ios/vendor/SwissKnifeiOS/Net/IngestClient.swift +495 -16
  53. package/ios/vendor/SwissKnifeiOS/Net/OfflineQueueStore.swift +231 -23
  54. package/ios/vendor/SwissKnifeiOS/Notifications/PushPayload.swift +87 -0
  55. package/ios/vendor/SwissKnifeiOS/Notifications/PushRegistrar.swift +322 -0
  56. package/ios/vendor/SwissKnifeiOS/Notifications/SwissKnife+Notifications.swift +403 -0
  57. package/ios/vendor/SwissKnifeiOS/Performance/SKPerformance.swift +1 -0
  58. package/ios/vendor/SwissKnifeiOS/Services/EntitlementsService.swift +11 -7
  59. package/ios/vendor/SwissKnifeiOS/Services/PurchaseService.swift +38 -7
  60. package/ios/vendor/SwissKnifeiOS/SwissKnife.swift +34 -6
  61. package/lib/commonjs/attribution.js +4 -3
  62. package/lib/commonjs/attribution.js.map +1 -1
  63. package/lib/commonjs/identity.js +12 -11
  64. package/lib/commonjs/identity.js.map +1 -1
  65. package/lib/commonjs/index.js +16 -5
  66. package/lib/commonjs/index.js.map +1 -1
  67. package/lib/commonjs/internal/config.js +105 -8
  68. package/lib/commonjs/internal/config.js.map +1 -1
  69. package/lib/commonjs/internal/telemetry-context.js +70 -0
  70. package/lib/commonjs/internal/telemetry-context.js.map +1 -0
  71. package/lib/commonjs/modules/analytics.js +18 -25
  72. package/lib/commonjs/modules/analytics.js.map +1 -1
  73. package/lib/commonjs/modules/crash-reporting.js +27 -6
  74. package/lib/commonjs/modules/crash-reporting.js.map +1 -1
  75. package/lib/commonjs/modules/log.js +1 -1
  76. package/lib/commonjs/modules/notifications.js +500 -0
  77. package/lib/commonjs/modules/notifications.js.map +1 -0
  78. package/lib/commonjs/modules/performance.js +57 -8
  79. package/lib/commonjs/modules/performance.js.map +1 -1
  80. package/lib/commonjs/native/module.js +6 -0
  81. package/lib/commonjs/native/module.js.map +1 -1
  82. package/lib/commonjs/native/spec.js +12 -5
  83. package/lib/commonjs/native/spec.js.map +1 -1
  84. package/lib/commonjs/purchases.js +4 -4
  85. package/lib/commonjs/types.js +12 -15
  86. package/lib/commonjs/types.js.map +1 -1
  87. package/lib/module/attribution.js +4 -3
  88. package/lib/module/attribution.js.map +1 -1
  89. package/lib/module/identity.js +12 -11
  90. package/lib/module/identity.js.map +1 -1
  91. package/lib/module/index.js +8 -4
  92. package/lib/module/index.js.map +1 -1
  93. package/lib/module/internal/config.js +103 -8
  94. package/lib/module/internal/config.js.map +1 -1
  95. package/lib/module/internal/telemetry-context.js +63 -0
  96. package/lib/module/internal/telemetry-context.js.map +1 -0
  97. package/lib/module/modules/analytics.js +18 -25
  98. package/lib/module/modules/analytics.js.map +1 -1
  99. package/lib/module/modules/crash-reporting.js +27 -6
  100. package/lib/module/modules/crash-reporting.js.map +1 -1
  101. package/lib/module/modules/log.js +1 -1
  102. package/lib/module/modules/notifications.js +491 -0
  103. package/lib/module/modules/notifications.js.map +1 -0
  104. package/lib/module/modules/performance.js +57 -8
  105. package/lib/module/modules/performance.js.map +1 -1
  106. package/lib/module/native/module.js +6 -1
  107. package/lib/module/native/module.js.map +1 -1
  108. package/lib/module/native/spec.js +11 -4
  109. package/lib/module/native/spec.js.map +1 -1
  110. package/lib/module/purchases.js +4 -4
  111. package/lib/module/types.js +12 -15
  112. package/lib/module/types.js.map +1 -1
  113. package/lib/typescript/commonjs/attribution.d.ts +3 -2
  114. package/lib/typescript/commonjs/attribution.d.ts.map +1 -1
  115. package/lib/typescript/commonjs/identity.d.ts.map +1 -1
  116. package/lib/typescript/commonjs/index.d.ts +2 -0
  117. package/lib/typescript/commonjs/index.d.ts.map +1 -1
  118. package/lib/typescript/commonjs/internal/config.d.ts +16 -2
  119. package/lib/typescript/commonjs/internal/config.d.ts.map +1 -1
  120. package/lib/typescript/commonjs/internal/telemetry-context.d.ts +22 -0
  121. package/lib/typescript/commonjs/internal/telemetry-context.d.ts.map +1 -0
  122. package/lib/typescript/commonjs/modules/analytics.d.ts +8 -11
  123. package/lib/typescript/commonjs/modules/analytics.d.ts.map +1 -1
  124. package/lib/typescript/commonjs/modules/crash-reporting.d.ts +18 -5
  125. package/lib/typescript/commonjs/modules/crash-reporting.d.ts.map +1 -1
  126. package/lib/typescript/commonjs/modules/notifications.d.ts +110 -0
  127. package/lib/typescript/commonjs/modules/notifications.d.ts.map +1 -0
  128. package/lib/typescript/commonjs/modules/performance.d.ts +13 -0
  129. package/lib/typescript/commonjs/modules/performance.d.ts.map +1 -1
  130. package/lib/typescript/commonjs/native/module.d.ts +2 -0
  131. package/lib/typescript/commonjs/native/module.d.ts.map +1 -1
  132. package/lib/typescript/commonjs/native/spec.d.ts +33 -4
  133. package/lib/typescript/commonjs/native/spec.d.ts.map +1 -1
  134. package/lib/typescript/commonjs/purchases.d.ts +4 -4
  135. package/lib/typescript/commonjs/types.d.ts +4 -5
  136. package/lib/typescript/commonjs/types.d.ts.map +1 -1
  137. package/lib/typescript/module/attribution.d.ts +3 -2
  138. package/lib/typescript/module/attribution.d.ts.map +1 -1
  139. package/lib/typescript/module/identity.d.ts.map +1 -1
  140. package/lib/typescript/module/index.d.ts +2 -0
  141. package/lib/typescript/module/index.d.ts.map +1 -1
  142. package/lib/typescript/module/internal/config.d.ts +16 -2
  143. package/lib/typescript/module/internal/config.d.ts.map +1 -1
  144. package/lib/typescript/module/internal/telemetry-context.d.ts +22 -0
  145. package/lib/typescript/module/internal/telemetry-context.d.ts.map +1 -0
  146. package/lib/typescript/module/modules/analytics.d.ts +8 -11
  147. package/lib/typescript/module/modules/analytics.d.ts.map +1 -1
  148. package/lib/typescript/module/modules/crash-reporting.d.ts +18 -5
  149. package/lib/typescript/module/modules/crash-reporting.d.ts.map +1 -1
  150. package/lib/typescript/module/modules/notifications.d.ts +110 -0
  151. package/lib/typescript/module/modules/notifications.d.ts.map +1 -0
  152. package/lib/typescript/module/modules/performance.d.ts +13 -0
  153. package/lib/typescript/module/modules/performance.d.ts.map +1 -1
  154. package/lib/typescript/module/native/module.d.ts +2 -0
  155. package/lib/typescript/module/native/module.d.ts.map +1 -1
  156. package/lib/typescript/module/native/spec.d.ts +33 -4
  157. package/lib/typescript/module/native/spec.d.ts.map +1 -1
  158. package/lib/typescript/module/purchases.d.ts +4 -4
  159. package/lib/typescript/module/types.d.ts +4 -5
  160. package/lib/typescript/module/types.d.ts.map +1 -1
  161. package/package.json +12 -4
  162. package/src/attribution.ts +4 -3
  163. package/src/identity.ts +12 -11
  164. package/src/index.ts +16 -4
  165. package/src/internal/config.ts +113 -8
  166. package/src/internal/telemetry-context.ts +76 -0
  167. package/src/modules/analytics.ts +24 -33
  168. package/src/modules/crash-reporting.ts +50 -9
  169. package/src/modules/log.ts +1 -1
  170. package/src/modules/notifications.ts +557 -0
  171. package/src/modules/performance.ts +94 -14
  172. package/src/native/module.ts +6 -0
  173. package/src/native/spec.ts +45 -10
  174. package/src/purchases.ts +4 -4
  175. package/src/types.ts +12 -15
  176. package/android/vendor/java/com/appswissknife/analytics/EventQueueStore.kt +0 -326
  177. 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
 
@@ -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 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
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
- ```xml
233
- <key>NSUserTrackingUsageDescription</key>
234
- <string>We use this identifier to attribute your install to the correct campaign.</string>
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
- ### 3. That's it
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
- The SDK automatically:
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
- - 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
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
- // Auto-collect (ATT prompt + IDFA on iOS, advertising id + referrer on Android)
254
- // and register the install.
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
- ## Custom Storage
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
- By default, the SDK uses `@react-native-async-storage/async-storage` for persistence. You can provide a custom storage adapter:
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
- ```typescript
269
- import { StorageAdapter } from "@app-swiss-knife/react-native-sdk";
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
- 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
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
 
@@ -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,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
- 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. 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) },