@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.
- package/CHANGELOG.md +473 -2
- package/LICENSE +21 -0
- package/README.md +279 -47
- 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 +20 -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/GENERATED.md +1 -0
- package/android/vendor/java/com/appswissknife/SwissKnife.kt +111 -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 +365 -206
- 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 +56 -31
- package/android/vendor/java/com/appswissknife/net/IngestClient.kt +673 -87
- 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 +312 -65
- package/android/vendor/java/com/appswissknife/performance/SKPerformance.kt +1 -0
- package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +705 -96
- package/android/vendor/java/com/appswissknife/purchases/PlayPriceEnrichmentProvider.kt +55 -24
- package/android/vendor/java/com/appswissknife/purchases/ProductKindHint.kt +29 -0
- package/android/vendor/java/com/appswissknife/purchases/PurchasesGateway.kt +24 -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 +343 -0
- package/ios/SwissKnifeJSON.swift +24 -2
- package/ios/SwissKnifePurchases.m +20 -0
- package/ios/SwissKnifePurchases.swift +97 -3
- package/ios/SwissKnifePushBootstrap.m +34 -0
- package/ios/vendor/GENERATED.md +1 -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 +345 -44
- 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/OfferingsService.swift +37 -5
- package/ios/vendor/SwissKnifeiOS/Services/PurchaseService.swift +38 -7
- package/ios/vendor/SwissKnifeiOS/SwissKnife.swift +34 -6
- package/ios/vendor/SwissKnifeiOS/Types.swift +31 -1
- package/ios-notification-service/SwissKnifeNotificationService.podspec +37 -0
- package/ios-notification-service/vendor/GENERATED.md +11 -0
- package/ios-notification-service/vendor/SwissKnifeNotificationService/SwissKnifeNotificationServiceExtension.swift +177 -0
- 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 +27 -6
- 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 +27 -6
- 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 +2 -0
- 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 +18 -5
- 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 +2 -0
- 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 +18 -5
- 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 +16 -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 +50 -9
- 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
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// packages/swiss-knife-android-rustore/src/main/java/com/appswissknife/rustore/RuStoreInitProvider.kt
|
|
2
|
+
package com.appswissknife.rustore
|
|
3
|
+
|
|
4
|
+
import android.content.ContentProvider
|
|
5
|
+
import android.content.ContentValues
|
|
6
|
+
import android.database.Cursor
|
|
7
|
+
import android.net.Uri
|
|
8
|
+
import com.appswissknife.SwissKnife
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Zero-config opt-in: a manifest-merged ContentProvider whose onCreate runs at
|
|
12
|
+
* process start (before Application.onCreate returns and well before
|
|
13
|
+
* SwissKnife.configure). Linking this add-on therefore swaps the base SDK's
|
|
14
|
+
* default Play gateway for the RuStoreGateway with no consumer code change. A
|
|
15
|
+
* build that doesn't depend on this module never merges the provider, so the
|
|
16
|
+
* base BillingClientGateway default holds.
|
|
17
|
+
*
|
|
18
|
+
* Standard "androidx.startup-style" no-op provider — it stores no data.
|
|
19
|
+
*/
|
|
20
|
+
class RuStoreInitProvider : ContentProvider() {
|
|
21
|
+
override fun onCreate(): Boolean {
|
|
22
|
+
SwissKnife.registerGatewayFactory { RuStoreGateway() }
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
override fun query(
|
|
27
|
+
uri: Uri,
|
|
28
|
+
projection: Array<out String>?,
|
|
29
|
+
selection: String?,
|
|
30
|
+
selectionArgs: Array<out String>?,
|
|
31
|
+
sortOrder: String?,
|
|
32
|
+
): Cursor? = null
|
|
33
|
+
|
|
34
|
+
override fun getType(uri: Uri): String? = null
|
|
35
|
+
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
|
|
36
|
+
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
|
37
|
+
override fun update(
|
|
38
|
+
uri: Uri,
|
|
39
|
+
values: ContentValues?,
|
|
40
|
+
selection: String?,
|
|
41
|
+
selectionArgs: Array<out String>?,
|
|
42
|
+
): Int = 0
|
|
43
|
+
}
|
package/android/vendor-rustore/java/com/appswissknife/rustore/RuStorePriceEnrichmentProvider.kt
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// packages/swiss-knife-android-rustore/src/main/java/com/appswissknife/rustore/RuStorePriceEnrichmentProvider.kt
|
|
2
|
+
//
|
|
3
|
+
// RuStore implementation of the base SDK's PriceEnrichmentProvider, on the
|
|
4
|
+
// RuStore **Pay** SDK. Lets OfferingsRepository enrich backend paywall products
|
|
5
|
+
// tagged platform "rustore" with live RuStore prices. RuStore types isolated here.
|
|
6
|
+
//
|
|
7
|
+
// Compile-verified against ru.rustore.sdk:pay:10.3.0 (Product getters + the
|
|
8
|
+
// value-class `.value` accessors for ProductId/Title/AmountLabel/Currency/Price).
|
|
9
|
+
package com.appswissknife.rustore
|
|
10
|
+
|
|
11
|
+
import android.util.Log
|
|
12
|
+
import com.appswissknife.models.Price
|
|
13
|
+
import com.appswissknife.models.StoreProduct
|
|
14
|
+
import com.appswissknife.models.StoreProductDiscount
|
|
15
|
+
import com.appswissknife.models.SubscriptionPeriod
|
|
16
|
+
import com.appswissknife.offerings.SimplePrice
|
|
17
|
+
import com.appswissknife.purchases.PriceEnrichmentProvider
|
|
18
|
+
import java.util.concurrent.CountDownLatch
|
|
19
|
+
import java.util.concurrent.TimeUnit
|
|
20
|
+
// RUSTORE SDK — Pay
|
|
21
|
+
import ru.rustore.sdk.pay.RuStorePayClient
|
|
22
|
+
import ru.rustore.sdk.pay.model.ProductId
|
|
23
|
+
|
|
24
|
+
class RuStorePriceEnrichmentProvider : PriceEnrichmentProvider {
|
|
25
|
+
|
|
26
|
+
override fun platformTags(): Set<String> = setOf("rustore")
|
|
27
|
+
|
|
28
|
+
override fun enrich(products: Map<String, String>): Map<String, StoreProduct> {
|
|
29
|
+
if (products.isEmpty()) return emptyMap()
|
|
30
|
+
|
|
31
|
+
val latch = CountDownLatch(1)
|
|
32
|
+
val out = HashMap<String, StoreProduct>()
|
|
33
|
+
// RUSTORE SDK — query live product details via the Pay product interactor.
|
|
34
|
+
// Blocks (≤5s) on the Task via a latch; the caller is already on
|
|
35
|
+
// OfferingsRepository's background thread.
|
|
36
|
+
RuStorePayClient.instance.getProductInteractor()
|
|
37
|
+
.getProducts(products.keys.map { ProductId(it) })
|
|
38
|
+
.addOnSuccessListener { resolved ->
|
|
39
|
+
for (p in resolved) {
|
|
40
|
+
val id = p.productId.value
|
|
41
|
+
out[id] = RuStoreStoreProduct(
|
|
42
|
+
id = id,
|
|
43
|
+
localizedTitle = runCatching { p.title.value }.getOrDefault("").ifEmpty { products[id].orEmpty() },
|
|
44
|
+
localizedDescription = runCatching { p.description?.value }.getOrNull() ?: products[id].orEmpty(),
|
|
45
|
+
priceLabel = runCatching { p.amountLabel.value }.getOrDefault(""),
|
|
46
|
+
currencyCode = runCatching { p.currency.value }.getOrDefault(""),
|
|
47
|
+
priceMinorUnits = runCatching { p.price?.value }.getOrNull(),
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
latch.countDown()
|
|
51
|
+
}
|
|
52
|
+
.addOnFailureListener { e ->
|
|
53
|
+
Log.w(TAG, "RuStore getProducts failed: ${e.message}")
|
|
54
|
+
latch.countDown()
|
|
55
|
+
}
|
|
56
|
+
runCatching { latch.await(5, TimeUnit.SECONDS) }
|
|
57
|
+
return out
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private companion object {
|
|
61
|
+
const val TAG = "SwissKnife.RuStore"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** StoreProduct backed by RuStore Pay product fields (already unwrapped to
|
|
66
|
+
* plain types so the value-class accessors stay isolated in enrich()). */
|
|
67
|
+
private class RuStoreStoreProduct(
|
|
68
|
+
override val id: String,
|
|
69
|
+
override val localizedTitle: String,
|
|
70
|
+
override val localizedDescription: String,
|
|
71
|
+
priceLabel: String,
|
|
72
|
+
currencyCode: String,
|
|
73
|
+
priceMinorUnits: Int?,
|
|
74
|
+
) : StoreProduct {
|
|
75
|
+
// RuStore `price` is an Int in minor currency units (kopecks).
|
|
76
|
+
// micros = minorUnits * 10_000 (1 unit = 100 minor units = 1_000_000 micros).
|
|
77
|
+
override val price: Price = SimplePrice(
|
|
78
|
+
formatted = priceLabel,
|
|
79
|
+
currencyCode = currencyCode,
|
|
80
|
+
amountMicros = (priceMinorUnits?.toLong() ?: 0L) * 10_000L,
|
|
81
|
+
)
|
|
82
|
+
override val subscriptionPeriod: SubscriptionPeriod? = null
|
|
83
|
+
override val introductoryDiscount: StoreProductDiscount? = null
|
|
84
|
+
override val discounts: List<StoreProductDiscount> = emptyList()
|
|
85
|
+
}
|
package/app.plugin.js
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expo config plugin for @app-swiss-knife/react-native-sdk push notifications.
|
|
3
|
+
*
|
|
4
|
+
* // app.json
|
|
5
|
+
* { "expo": { "plugins": [
|
|
6
|
+
* ["@app-swiss-knife/react-native-sdk", {
|
|
7
|
+
* "ios": { "mode": "development" },
|
|
8
|
+
* "android": { "googleServicesFile": "./google-services.json",
|
|
9
|
+
* "defaultChannel": { "id": "default", "name": "General" } }
|
|
10
|
+
* }]
|
|
11
|
+
* ] } }
|
|
12
|
+
*
|
|
13
|
+
* iOS
|
|
14
|
+
* - adds the `aps-environment` entitlement (`mode`: development | production,
|
|
15
|
+
* default `development`, same as expo-notifications — Xcode's distribution
|
|
16
|
+
* signing/export rewrites it to `production` for App Store/TestFlight builds;
|
|
17
|
+
* set `"production"` explicitly only for ad-hoc/enterprise builds that need it)
|
|
18
|
+
* - adds `remote-notification` to UIBackgroundModes
|
|
19
|
+
* - `notificationServiceExtension: true` is accepted but NOT generated (an
|
|
20
|
+
* extension target needs an Xcode project rewrite); a warning points at the
|
|
21
|
+
* manual steps in the README.
|
|
22
|
+
* Android
|
|
23
|
+
* - adds the POST_NOTIFICATIONS permission (Android 13+)
|
|
24
|
+
* - registers `com.appswissknife.notifications.SwissKnifeMessagingService`
|
|
25
|
+
* for `com.google.firebase.MESSAGING_EVENT` unless `registerMessagingService`
|
|
26
|
+
* is false. It defaults to false (with a warning) when expo-notifications or
|
|
27
|
+
* @react-native-firebase/messaging is in the project, because two services
|
|
28
|
+
* cannot both own FCM delivery: use the manual path then
|
|
29
|
+
* (Notifications.registerDeviceToken + trackReceived/trackOpened).
|
|
30
|
+
* - `googleServicesFile` is forwarded to Expo's own `android.googleServicesFile`
|
|
31
|
+
* (Expo copies the file and applies the google-services Gradle plugin); an
|
|
32
|
+
* explicit `expo.android.googleServicesFile` always wins.
|
|
33
|
+
* - adds `implementation "com.google.firebase:firebase-messaging:<ver>"` to the
|
|
34
|
+
* app module (the SDK declares it compileOnly so non-push apps stay clean)
|
|
35
|
+
* - `defaultChannel` is written as manifest meta-data
|
|
36
|
+
* (`com.appswissknife.notifications.default_channel_{id,name}`).
|
|
37
|
+
* - store: the `swissKnifeStore` Gradle property, plus RuStore's strings and
|
|
38
|
+
* manifest entries for a RuStore build. `SWISS_KNIFE_ANDROID_STORE`
|
|
39
|
+
* (`play` | `rustore`, read at prebuild, e.g. from an EAS build profile's
|
|
40
|
+
* `env`) picks it; unset, `android.rustore` being configured means RuStore
|
|
41
|
+
* (see resolveAndroidStore).
|
|
42
|
+
*
|
|
43
|
+
* The pure mutation helpers below are exported for unit tests; `expo/config-plugins`
|
|
44
|
+
* is loaded lazily so they can be used without Expo installed.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
const MESSAGING_SERVICE = "com.appswissknife.notifications.SwissKnifeMessagingService";
|
|
48
|
+
const POST_NOTIFICATIONS = "android.permission.POST_NOTIFICATIONS";
|
|
49
|
+
const FCM_ACTION = "com.google.firebase.MESSAGING_EVENT";
|
|
50
|
+
const FIREBASE_MESSAGING = "com.google.firebase:firebase-messaging:24.0.3";
|
|
51
|
+
const CHANNEL_ID_KEY = "com.appswissknife.notifications.default_channel_id";
|
|
52
|
+
const CHANNEL_NAME_KEY = "com.appswissknife.notifications.default_channel_name";
|
|
53
|
+
|
|
54
|
+
/** Normalize plugin props, applying defaults. */
|
|
55
|
+
function normalizeProps(props) {
|
|
56
|
+
const p = props || {};
|
|
57
|
+
const ios = p.ios || {};
|
|
58
|
+
const android = p.android || {};
|
|
59
|
+
return {
|
|
60
|
+
ios: {
|
|
61
|
+
mode: ios.mode === "production" ? "production" : "development",
|
|
62
|
+
notificationServiceExtension: ios.notificationServiceExtension === true,
|
|
63
|
+
},
|
|
64
|
+
android: {
|
|
65
|
+
registerMessagingService:
|
|
66
|
+
typeof android.registerMessagingService === "boolean"
|
|
67
|
+
? android.registerMessagingService
|
|
68
|
+
: undefined,
|
|
69
|
+
googleServicesFile:
|
|
70
|
+
typeof android.googleServicesFile === "string" ? android.googleServicesFile : undefined,
|
|
71
|
+
defaultChannel:
|
|
72
|
+
android.defaultChannel && android.defaultChannel.id
|
|
73
|
+
? {
|
|
74
|
+
id: String(android.defaultChannel.id),
|
|
75
|
+
name: String(android.defaultChannel.name || android.defaultChannel.id),
|
|
76
|
+
}
|
|
77
|
+
: undefined,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** entitlements mod: set `aps-environment`. */
|
|
83
|
+
function applyApsEnvironment(entitlements, mode) {
|
|
84
|
+
entitlements["aps-environment"] = mode;
|
|
85
|
+
return entitlements;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Info.plist mod: ensure `remote-notification` in UIBackgroundModes. */
|
|
89
|
+
function applyBackgroundModes(infoPlist) {
|
|
90
|
+
const modes = Array.isArray(infoPlist.UIBackgroundModes) ? infoPlist.UIBackgroundModes : [];
|
|
91
|
+
if (!modes.includes("remote-notification")) modes.push("remote-notification");
|
|
92
|
+
infoPlist.UIBackgroundModes = modes;
|
|
93
|
+
return infoPlist;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function upsertMetaData(application, name, value) {
|
|
97
|
+
const list = (application["meta-data"] = application["meta-data"] || []);
|
|
98
|
+
const existing = list.find((m) => m.$ && m.$["android:name"] === name);
|
|
99
|
+
if (existing) existing.$["android:value"] = value;
|
|
100
|
+
else list.push({ $: { "android:name": name, "android:value": value } });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** AndroidManifest mod (operates on the parsed manifest object). Idempotent. */
|
|
104
|
+
function applyAndroidManifest(manifestRoot, android) {
|
|
105
|
+
const manifest = manifestRoot.manifest;
|
|
106
|
+
|
|
107
|
+
const perms = (manifest["uses-permission"] = manifest["uses-permission"] || []);
|
|
108
|
+
if (!perms.some((p) => p.$ && p.$["android:name"] === POST_NOTIFICATIONS)) {
|
|
109
|
+
perms.push({ $: { "android:name": POST_NOTIFICATIONS } });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const application = manifest.application && manifest.application[0];
|
|
113
|
+
if (!application) return manifestRoot;
|
|
114
|
+
|
|
115
|
+
const services = (application.service = application.service || []);
|
|
116
|
+
const register = !android || android.registerMessagingService !== false;
|
|
117
|
+
if (register && !services.some((s) => s.$ && s.$["android:name"] === MESSAGING_SERVICE)) {
|
|
118
|
+
services.push({
|
|
119
|
+
$: { "android:name": MESSAGING_SERVICE, "android:exported": "false" },
|
|
120
|
+
"intent-filter": [{ action: [{ $: { "android:name": FCM_ACTION } }] }],
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (android && android.defaultChannel) {
|
|
125
|
+
upsertMetaData(application, CHANNEL_ID_KEY, android.defaultChannel.id);
|
|
126
|
+
upsertMetaData(application, CHANNEL_NAME_KEY, android.defaultChannel.name);
|
|
127
|
+
}
|
|
128
|
+
return manifestRoot;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const CONFLICTING_LIBS = ["expo-notifications", "@react-native-firebase/messaging"];
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Name of a push library in the project that already owns FCM delivery
|
|
135
|
+
* (in the Expo `plugins` list or the project's package.json), else null.
|
|
136
|
+
*/
|
|
137
|
+
function detectMessagingConflict(config, pkgJson) {
|
|
138
|
+
const plugins = (config && config.plugins) || [];
|
|
139
|
+
for (const entry of plugins) {
|
|
140
|
+
const name = Array.isArray(entry) ? entry[0] : entry;
|
|
141
|
+
if (CONFLICTING_LIBS.includes(name)) return name;
|
|
142
|
+
}
|
|
143
|
+
const deps = Object.assign({}, pkgJson && pkgJson.dependencies, pkgJson && pkgJson.devDependencies);
|
|
144
|
+
return CONFLICTING_LIBS.find((n) => n in deps) || null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function readProjectPackageJson() {
|
|
148
|
+
try {
|
|
149
|
+
return JSON.parse(require("fs").readFileSync(require("path").join(process.cwd(), "package.json"), "utf8"));
|
|
150
|
+
} catch {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Forward googleServicesFile to Expo's own field unless the app set one. */
|
|
156
|
+
function applyGoogleServicesFile(config, android) {
|
|
157
|
+
if (android && android.googleServicesFile) {
|
|
158
|
+
config.android = config.android || {};
|
|
159
|
+
if (!config.android.googleServicesFile) {
|
|
160
|
+
config.android.googleServicesFile = android.googleServicesFile;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return config;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** app/build.gradle mod: add firebase-messaging to `dependencies` once. */
|
|
167
|
+
function applyAppBuildGradle(contents) {
|
|
168
|
+
if (contents.includes("com.google.firebase:firebase-messaging")) return contents;
|
|
169
|
+
const line = ` implementation "${FIREBASE_MESSAGING}"\n`;
|
|
170
|
+
const re = /dependencies\s*\{\n/;
|
|
171
|
+
if (re.test(contents)) return contents.replace(re, (m) => m + line);
|
|
172
|
+
return contents + `\ndependencies {\n${line}}\n`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Load `expo/config-plugins` from the APP's dependency tree. This package has
|
|
177
|
+
* no `expo` dependency of its own, so under pnpm (or any symlinked workspace /
|
|
178
|
+
* store layout) a bare `require("expo/config-plugins")` from this file cannot
|
|
179
|
+
* resolve. `expo prebuild` happens to patch resolution, but the Xcode
|
|
180
|
+
* "Generate app.config for prebuilt Constants.manifest" script phase evaluates
|
|
181
|
+
* the config with plain Node and failed with MODULE_NOT_FOUND. Resolve from the
|
|
182
|
+
* project root (cwd) first, then from this file.
|
|
183
|
+
*/
|
|
184
|
+
function loadConfigPlugins() {
|
|
185
|
+
const paths = [process.cwd(), __dirname];
|
|
186
|
+
try {
|
|
187
|
+
return require(require.resolve("expo/config-plugins", { paths }));
|
|
188
|
+
} catch {
|
|
189
|
+
return require("expo/config-plugins");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const ANDROID_STORE_ENV = "SWISS_KNIFE_ANDROID_STORE";
|
|
194
|
+
|
|
195
|
+
/** What is missing or invalid in an `android.rustore` option, by field. */
|
|
196
|
+
function ruStoreConfigProblems(rustore) {
|
|
197
|
+
const r = rustore && typeof rustore === "object" ? rustore : {};
|
|
198
|
+
const problems = [];
|
|
199
|
+
if (!/^\d+$/.test(String(r.consoleAppId ?? ""))) {
|
|
200
|
+
problems.push(r.consoleAppId === undefined ? "consoleAppId (missing)" : "consoleAppId (must be digits)");
|
|
201
|
+
}
|
|
202
|
+
if (!/^[a-z][a-z0-9+.-]*$/.test(r.scheme ?? "")) {
|
|
203
|
+
problems.push(r.scheme === undefined ? "scheme (missing)" : "scheme (not a valid deeplink scheme)");
|
|
204
|
+
}
|
|
205
|
+
return problems;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* The Android store this prebuild targets: `{ store: "play" | "rustore",
|
|
210
|
+
* rustore }`, where `rustore` is the `android.rustore` option for a RuStore
|
|
211
|
+
* build and null for a Play build.
|
|
212
|
+
*
|
|
213
|
+
* `SWISS_KNIFE_ANDROID_STORE` (from `env`, normally `process.env`) chooses it,
|
|
214
|
+
* so one app config can produce both builds (set it per EAS build profile):
|
|
215
|
+
* - unset or empty: as before the variable existed, RuStore when
|
|
216
|
+
* `android.rustore` is configured, else Play;
|
|
217
|
+
* - `play`: Play, ignoring `android.rustore`;
|
|
218
|
+
* - `rustore`: RuStore, which needs `android.rustore`;
|
|
219
|
+
* - anything else: an error.
|
|
220
|
+
* A RuStore build with an incomplete `android.rustore` is an error naming the
|
|
221
|
+
* fields.
|
|
222
|
+
*/
|
|
223
|
+
function resolveAndroidStore(android, env) {
|
|
224
|
+
const rustore = android ? android.rustore : undefined;
|
|
225
|
+
const raw = env && typeof env[ANDROID_STORE_ENV] === "string" ? env[ANDROID_STORE_ENV].trim() : "";
|
|
226
|
+
if (raw !== "" && raw !== "play" && raw !== "rustore") {
|
|
227
|
+
throw new Error(
|
|
228
|
+
`[swiss-knife] ${ANDROID_STORE_ENV} must be "play" or "rustore", got ${JSON.stringify(raw)}. ` +
|
|
229
|
+
"Leave it unset to build for RuStore when android.rustore is configured and for Google Play otherwise."
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
if (raw === "play" || (raw === "" && !rustore)) return { store: "play", rustore: null };
|
|
233
|
+
const problems = ruStoreConfigProblems(rustore);
|
|
234
|
+
if (problems.length > 0) {
|
|
235
|
+
const prefix =
|
|
236
|
+
raw === "rustore"
|
|
237
|
+
? `${ANDROID_STORE_ENV}=rustore needs the plugin's android.rustore option ` +
|
|
238
|
+
'({ "consoleAppId": "<digits>", "scheme": "<deeplink scheme>" })'
|
|
239
|
+
: "android.rustore requires consoleAppId (digits) and a valid deeplink scheme";
|
|
240
|
+
throw new Error(`${prefix}; missing or invalid: ${problems.map((p) => "android.rustore." + p).join(", ")}`);
|
|
241
|
+
}
|
|
242
|
+
return { store: "rustore", rustore };
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function withSwissKnifePush(config, props) {
|
|
246
|
+
const { withEntitlementsPlist, withInfoPlist, withAndroidManifest, withAppBuildGradle, withGradleProperties, withStringsXml } =
|
|
247
|
+
loadConfigPlugins();
|
|
248
|
+
const opts = normalizeProps(props);
|
|
249
|
+
const { store, rustore } = resolveAndroidStore(props && props.android, typeof process === "undefined" ? {} : process.env);
|
|
250
|
+
config = withGradleProperties(config, (c) => {
|
|
251
|
+
c.modResults = c.modResults.filter((entry) => entry.key !== "swissKnifeStore");
|
|
252
|
+
c.modResults.push({ type: "property", key: "swissKnifeStore", value: store });
|
|
253
|
+
return c;
|
|
254
|
+
});
|
|
255
|
+
if (rustore) {
|
|
256
|
+
config = withStringsXml(config, (c) => {
|
|
257
|
+
c.modResults.resources.string = (c.modResults.resources.string || []).filter((entry) => entry.$?.name !== "swissknife_rustore_app_id");
|
|
258
|
+
c.modResults.resources.string.push({ $: { name: "swissknife_rustore_app_id", translatable: "false" }, _: String(rustore.consoleAppId) });
|
|
259
|
+
return c;
|
|
260
|
+
});
|
|
261
|
+
config = withAndroidManifest(config, (c) => {
|
|
262
|
+
applyRuStoreManifest(c.modResults, rustore.scheme);
|
|
263
|
+
return c;
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
config = withEntitlementsPlist(config, (c) => {
|
|
268
|
+
applyApsEnvironment(c.modResults, opts.ios.mode);
|
|
269
|
+
return c;
|
|
270
|
+
});
|
|
271
|
+
config = withInfoPlist(config, (c) => {
|
|
272
|
+
applyBackgroundModes(c.modResults);
|
|
273
|
+
return c;
|
|
274
|
+
});
|
|
275
|
+
if (opts.ios.notificationServiceExtension) {
|
|
276
|
+
console.warn(
|
|
277
|
+
"[swiss-knife] ios.notificationServiceExtension: the extension target is not generated " +
|
|
278
|
+
"automatically. Add a Notification Service Extension target and subclass " +
|
|
279
|
+
"SwissKnifeNotificationServiceExtension — see the README, \"Push notifications\"."
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
let registerService = opts.android.registerMessagingService;
|
|
284
|
+
if (registerService === undefined) {
|
|
285
|
+
const conflict = detectMessagingConflict(config, readProjectPackageJson());
|
|
286
|
+
registerService = !conflict;
|
|
287
|
+
if (conflict) {
|
|
288
|
+
console.warn(
|
|
289
|
+
"[swiss-knife] " + conflict + " detected: NOT registering SwissKnifeMessagingService " +
|
|
290
|
+
"(two FCM services cannot both own delivery). Register tokens with " +
|
|
291
|
+
"Notifications.registerDeviceToken and report events with trackReceived/trackOpened, " +
|
|
292
|
+
"or set android.registerMessagingService: true to override."
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
config = withAndroidManifest(config, (c) => {
|
|
297
|
+
applyAndroidManifest(c.modResults, Object.assign({}, opts.android, { registerMessagingService: registerService }));
|
|
298
|
+
return c;
|
|
299
|
+
});
|
|
300
|
+
config = withAppBuildGradle(config, (c) => {
|
|
301
|
+
if (c.modResults.language === "groovy") {
|
|
302
|
+
c.modResults.contents = applyAppBuildGradle(c.modResults.contents);
|
|
303
|
+
} else {
|
|
304
|
+
console.warn("[swiss-knife] app/build.gradle is not Groovy; add " + FIREBASE_MESSAGING + " to dependencies by hand.");
|
|
305
|
+
}
|
|
306
|
+
return c;
|
|
307
|
+
});
|
|
308
|
+
return applyGoogleServicesFile(config, opts.android);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
module.exports = withSwissKnifePush;
|
|
312
|
+
module.exports.default = withSwissKnifePush;
|
|
313
|
+
module.exports.loadConfigPlugins = loadConfigPlugins;
|
|
314
|
+
module.exports.normalizeProps = normalizeProps;
|
|
315
|
+
module.exports.applyApsEnvironment = applyApsEnvironment;
|
|
316
|
+
module.exports.applyBackgroundModes = applyBackgroundModes;
|
|
317
|
+
module.exports.applyAndroidManifest = applyAndroidManifest;
|
|
318
|
+
module.exports.detectMessagingConflict = detectMessagingConflict;
|
|
319
|
+
module.exports.applyAppBuildGradle = applyAppBuildGradle;
|
|
320
|
+
module.exports.applyGoogleServicesFile = applyGoogleServicesFile;
|
|
321
|
+
module.exports.resolveAndroidStore = resolveAndroidStore;
|
|
322
|
+
module.exports.ANDROID_STORE_ENV = ANDROID_STORE_ENV;
|
|
323
|
+
module.exports.MESSAGING_SERVICE = MESSAGING_SERVICE;
|
|
324
|
+
|
|
325
|
+
function applyRuStoreManifest(manifest, scheme) {
|
|
326
|
+
const app = manifest.manifest.application[0];
|
|
327
|
+
app["meta-data"] = (app["meta-data"] || []).filter((entry) => !["console_app_id_value", "sdk_pay_scheme_value"].includes(entry.$["android:name"]));
|
|
328
|
+
app["meta-data"].push(
|
|
329
|
+
{ $: { "android:name": "console_app_id_value", "android:value": "@string/swissknife_rustore_app_id" } },
|
|
330
|
+
{ $: { "android:name": "sdk_pay_scheme_value", "android:value": scheme } },
|
|
331
|
+
);
|
|
332
|
+
const activity = (app.activity || []).find((a) => (a["intent-filter"] || []).some((f) => (f.action || []).some((v) => v.$["android:name"] === "android.intent.action.MAIN")));
|
|
333
|
+
if (!activity) throw new Error("RuStore requires a launcher Activity for payment return intents");
|
|
334
|
+
activity.$["android:launchMode"] = "singleTask";
|
|
335
|
+
activity["intent-filter"] = (activity["intent-filter"] || []).filter((f) => !(f.data || []).some((d) => d.$["android:scheme"] === scheme));
|
|
336
|
+
activity["intent-filter"].push({
|
|
337
|
+
action: [{ $: { "android:name": "android.intent.action.VIEW" } }],
|
|
338
|
+
category: ["DEFAULT", "BROWSABLE"].map((v) => ({ $: { "android:name": `android.intent.category.${v}` } })),
|
|
339
|
+
data: [{ $: { "android:scheme": scheme } }],
|
|
340
|
+
});
|
|
341
|
+
return manifest;
|
|
342
|
+
}
|
|
343
|
+
module.exports.applyRuStoreManifest = applyRuStoreManifest;
|
package/ios/SwissKnifeJSON.swift
CHANGED
|
@@ -102,8 +102,10 @@ enum SwissKnifeJSON {
|
|
|
102
102
|
"priceString": product.displayPrice,
|
|
103
103
|
"price": NSDecimalNumber(decimal: product.price).doubleValue,
|
|
104
104
|
"currencyCode": product.currencyCode,
|
|
105
|
-
"productCategory":
|
|
106
|
-
"productType":
|
|
105
|
+
"productCategory": productCategoryString(product.productType),
|
|
106
|
+
"productType": productTypeString(product.productType),
|
|
107
|
+
// Both nil unless the product is an auto-renewable subscription (the
|
|
108
|
+
// SDK's OfferingsService sets them only then).
|
|
107
109
|
"subscriptionPeriod": product.subscriptionPeriod.map { periodString($0) } ?? NSNull(),
|
|
108
110
|
"defaultOption": NSNull(),
|
|
109
111
|
"subscriptionOptions": NSNull(),
|
|
@@ -217,6 +219,26 @@ enum SwissKnifeJSON {
|
|
|
217
219
|
}
|
|
218
220
|
}
|
|
219
221
|
|
|
222
|
+
/// `PurchasesStoreProduct.productType` in src/types.ts. No `default:`, so a
|
|
223
|
+
/// new `StoreProductType` case fails the compile instead of mislabelling.
|
|
224
|
+
static func productTypeString(_ t: StoreProductType) -> String {
|
|
225
|
+
switch t {
|
|
226
|
+
case .autoRenewableSubscription: return "AUTO_RENEWABLE_SUBSCRIPTION"
|
|
227
|
+
case .nonRenewableSubscription: return "NON_RENEWABLE_SUBSCRIPTION"
|
|
228
|
+
case .consumable: return "CONSUMABLE"
|
|
229
|
+
case .nonConsumable: return "NON_CONSUMABLE"
|
|
230
|
+
case .unknown: return "UNKNOWN"
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/// `PurchasesStoreProduct.productCategory` in src/types.ts: SUBSCRIPTION only
|
|
235
|
+
/// for an auto-renewable subscription (RevenueCat's convention), so a
|
|
236
|
+
/// non-renewing subscription, a consumable or a lifetime unlock is
|
|
237
|
+
/// NON_SUBSCRIPTION — as the Android bridge reports a one-time product.
|
|
238
|
+
static func productCategoryString(_ t: StoreProductType) -> String {
|
|
239
|
+
t.isSubscription ? "SUBSCRIPTION" : "NON_SUBSCRIPTION"
|
|
240
|
+
}
|
|
241
|
+
|
|
220
242
|
private static func packageTypeString(_ p: PackageType) -> String {
|
|
221
243
|
switch p {
|
|
222
244
|
case .unknown: return "UNKNOWN"
|
|
@@ -136,4 +136,24 @@ RCT_EXTERN_METHOD(removeListeners:(double)count)
|
|
|
136
136
|
return YES;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
// Push notifications (swiss-push) — see src/modules/notifications.ts.
|
|
140
|
+
RCT_EXTERN_METHOD(pushRequestPermission:(BOOL)provisional
|
|
141
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
142
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
143
|
+
|
|
144
|
+
RCT_EXTERN_METHOD(pushPermissionStatus:(RCTPromiseResolveBlock)resolve
|
|
145
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
146
|
+
|
|
147
|
+
RCT_EXTERN_METHOD(pushRegister:(RCTPromiseResolveBlock)resolve
|
|
148
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
149
|
+
|
|
150
|
+
RCT_EXTERN_METHOD(pushUnregister:(RCTPromiseResolveBlock)resolve
|
|
151
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
152
|
+
|
|
153
|
+
RCT_EXTERN_METHOD(pushGetInitialNotification:(RCTPromiseResolveBlock)resolve
|
|
154
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
155
|
+
|
|
156
|
+
RCT_EXTERN_METHOD(pushDeviceInfo:(RCTPromiseResolveBlock)resolve
|
|
157
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
158
|
+
|
|
139
159
|
@end
|
|
@@ -28,6 +28,20 @@ class SwissKnifePurchases: RCTEventEmitter {
|
|
|
28
28
|
// so re-configuring does not leak/stack duplicate stream subscribers.
|
|
29
29
|
private var customerInfoTask: Task<Void, Never>?
|
|
30
30
|
|
|
31
|
+
override init() {
|
|
32
|
+
super.init()
|
|
33
|
+
// Runs before JS: if the app opted into native push on an earlier launch,
|
|
34
|
+
// install the notification delegate proxy NOW so a cold-start tap is
|
|
35
|
+
// captured (and buffered until JS listens / asks for the initial one).
|
|
36
|
+
SwissKnife.Notifications.resumeAutoIntegration()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/// Called from SwissKnifePushBootstrap.m when the app finishes launching (well
|
|
40
|
+
/// before JS), so a cold-start notification tap finds the delegate proxy.
|
|
41
|
+
@objc static func resumePushEarly() {
|
|
42
|
+
SwissKnife.Notifications.resumeAutoIntegration()
|
|
43
|
+
}
|
|
44
|
+
|
|
31
45
|
deinit {
|
|
32
46
|
customerInfoTask?.cancel()
|
|
33
47
|
}
|
|
@@ -37,15 +51,42 @@ class SwissKnifePurchases: RCTEventEmitter {
|
|
|
37
51
|
// Event names this module can emit. Must include the CustomerInfo updated event
|
|
38
52
|
// whose JS constant is CUSTOMER_INFO_UPDATED_EVENT in src/native/spec.ts.
|
|
39
53
|
override func supportedEvents() -> [String]! {
|
|
40
|
-
return ["Purchases-CustomerInfoUpdated"]
|
|
54
|
+
return ["Purchases-CustomerInfoUpdated", "SwissKnife-PushOpened"]
|
|
41
55
|
}
|
|
42
56
|
|
|
43
57
|
override static func requiresMainQueueSetup() -> Bool {
|
|
44
58
|
return true
|
|
45
59
|
}
|
|
46
60
|
|
|
47
|
-
override func startObserving() {
|
|
48
|
-
|
|
61
|
+
override func startObserving() {
|
|
62
|
+
hasListeners = true
|
|
63
|
+
// Push opens: drain anything buffered before JS listened, then stream.
|
|
64
|
+
SwissKnife.Notifications.onOpened = { [weak self] open in
|
|
65
|
+
self?.sendPushOpened(open)
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
override func stopObserving() {
|
|
69
|
+
hasListeners = false
|
|
70
|
+
SwissKnife.Notifications.onOpened = nil
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private static func encodeOpen(_ open: SwissKnife.Notifications.Opened) -> [String: Any] {
|
|
74
|
+
var out: [String: Any] = [
|
|
75
|
+
"messageId": open.payload.messageId,
|
|
76
|
+
"deliveryId": open.payload.deliveryId,
|
|
77
|
+
"data": (JSONSerialization.isValidJSONObject(open.userInfo) ? open.userInfo : [:]) as [AnyHashable: Any],
|
|
78
|
+
]
|
|
79
|
+
if let link = open.payload.link { out["link"] = link.absoluteString }
|
|
80
|
+
if let action = open.actionId { out["actionId"] = action }
|
|
81
|
+
return out
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private func sendPushOpened(_ open: SwissKnife.Notifications.Opened) {
|
|
85
|
+
DispatchQueue.main.async {
|
|
86
|
+
guard self.hasListeners else { return }
|
|
87
|
+
self.sendEvent(withName: "SwissKnife-PushOpened", body: Self.encodeOpen(open))
|
|
88
|
+
}
|
|
89
|
+
}
|
|
49
90
|
|
|
50
91
|
private func sendCustomerInfo(_ customerInfo: [String: Any]) {
|
|
51
92
|
// RCTEventEmitter is not thread-safe; the stream callback runs off-main.
|
|
@@ -497,10 +538,63 @@ class SwissKnifePurchases: RCTEventEmitter {
|
|
|
497
538
|
func setPushToken(_ pushToken: NSString?,
|
|
498
539
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
499
540
|
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
541
|
+
// Legacy attribute-only path, kept for source compatibility. New code
|
|
542
|
+
// uses pushRegister / registerDeviceToken (see src/modules/notifications.ts).
|
|
500
543
|
SwissKnife.setPushToken(pushToken as String?)
|
|
501
544
|
resolve(nil)
|
|
502
545
|
}
|
|
503
546
|
|
|
547
|
+
// MARK: Push notifications (swiss-push)
|
|
548
|
+
|
|
549
|
+
@objc(pushRequestPermission:resolver:rejecter:)
|
|
550
|
+
func pushRequestPermission(_ provisional: Bool,
|
|
551
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
552
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
553
|
+
Task {
|
|
554
|
+
let status = await SwissKnife.Notifications.requestPermission(provisional: provisional)
|
|
555
|
+
resolve(status.rawValue)
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
@objc(pushPermissionStatus:rejecter:)
|
|
560
|
+
func pushPermissionStatus(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
561
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
562
|
+
Task { resolve(await SwissKnife.Notifications.permissionStatus().rawValue) }
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/// Installs the delegate proxy + APNs-token capture, then asks iOS for a token.
|
|
566
|
+
@objc(pushRegister:rejecter:)
|
|
567
|
+
func pushRegister(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
568
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
569
|
+
SwissKnife.Notifications.enableAutoIntegration(captureDeviceToken: true)
|
|
570
|
+
SwissKnife.Notifications.registerForRemoteNotifications()
|
|
571
|
+
resolve(nil)
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
@objc(pushUnregister:rejecter:)
|
|
575
|
+
func pushUnregister(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
576
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
577
|
+
SwissKnife.Notifications.unregister()
|
|
578
|
+
resolve(nil)
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
@objc(pushGetInitialNotification:rejecter:)
|
|
582
|
+
func pushGetInitialNotification(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
583
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
584
|
+
if let open = SwissKnife.Notifications.takeInitialOpen() {
|
|
585
|
+
resolve(Self.encodeOpen(open))
|
|
586
|
+
} else {
|
|
587
|
+
resolve(nil)
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/// Facts the JS-only registration path cannot know.
|
|
592
|
+
@objc(pushDeviceInfo:rejecter:)
|
|
593
|
+
func pushDeviceInfo(_ resolve: @escaping RCTPromiseResolveBlock,
|
|
594
|
+
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
595
|
+
resolve(SwissKnife.Notifications.deviceInfo())
|
|
596
|
+
}
|
|
597
|
+
|
|
504
598
|
@objc(setLogLevel:resolver:rejecter:)
|
|
505
599
|
func setLogLevel(_ level: String,
|
|
506
600
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|