@app-swiss-knife/react-native-sdk 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +165 -2
- package/README.md +75 -19
- package/android/src/main/java/com/swissknife/purchases/SwissKnifeJson.kt +17 -4
- package/android/vendor/GENERATED.md +1 -0
- package/android/vendor/java/com/appswissknife/SwissKnife.kt +4 -0
- package/android/vendor/java/com/appswissknife/context/DeviceContext.kt +1 -1
- package/android/vendor/java/com/appswissknife/net/IngestClient.kt +1 -1
- package/android/vendor/java/com/appswissknife/offerings/OfferingsRepository.kt +47 -2
- package/android/vendor/java/com/appswissknife/purchases/BillingClientGateway.kt +185 -33
- package/android/vendor/java/com/appswissknife/purchases/ProductKindHint.kt +8 -0
- package/android/vendor/java/com/appswissknife/purchases/PurchasesGateway.kt +10 -0
- package/app.plugin.js +61 -5
- package/ios/SwissKnifeJSON.swift +24 -2
- package/ios/SwissKnifePurchases.swift +9 -1
- package/ios/vendor/GENERATED.md +1 -0
- package/ios/vendor/SwissKnifeiOS/Context/DeviceContext.swift +1 -1
- package/ios/vendor/SwissKnifeiOS/Identity/Identity.swift +7 -0
- package/ios/vendor/SwissKnifeiOS/Net/IngestClient.swift +2 -3
- package/ios/vendor/SwissKnifeiOS/Services/EntitlementSync.swift +104 -0
- package/ios/vendor/SwissKnifeiOS/Services/IntroEligibility.swift +137 -0
- package/ios/vendor/SwissKnifeiOS/Services/OfferingsService.swift +37 -5
- package/ios/vendor/SwissKnifeiOS/Services/PurchaseService.swift +368 -52
- package/ios/vendor/SwissKnifeiOS/Services/TransactionEvents.swift +371 -0
- package/ios/vendor/SwissKnifeiOS/SwissKnife.swift +73 -8
- 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/internal/config.js +3 -0
- package/lib/commonjs/internal/config.js.map +1 -1
- package/lib/commonjs/native/spec.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/internal/config.js +3 -0
- package/lib/module/internal/config.js.map +1 -1
- package/lib/module/native/spec.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/commonjs/internal/config.d.ts.map +1 -1
- package/lib/typescript/commonjs/native/spec.d.ts +2 -0
- package/lib/typescript/commonjs/native/spec.d.ts.map +1 -1
- package/lib/typescript/commonjs/types.d.ts +13 -0
- package/lib/typescript/commonjs/types.d.ts.map +1 -1
- package/lib/typescript/module/internal/config.d.ts.map +1 -1
- package/lib/typescript/module/native/spec.d.ts +2 -0
- package/lib/typescript/module/native/spec.d.ts.map +1 -1
- package/lib/typescript/module/types.d.ts +13 -0
- package/lib/typescript/module/types.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/internal/config.ts +3 -0
- package/src/native/spec.ts +4 -0
- package/src/types.ts +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,11 +7,174 @@ this package follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
7
7
|
While the major version is `0`, a minor bump may carry behavioral changes that a
|
|
8
8
|
`1.x` package would treat as breaking; each one is called out under **Changed**.
|
|
9
9
|
|
|
10
|
-
The native iOS and Android SDKs are
|
|
11
|
-
|
|
10
|
+
The native iOS and Android SDKs' sources are vendored into this npm tarball at
|
|
11
|
+
pack time, so a version here covers all three. The iOS SDK is also published as
|
|
12
|
+
a Swift package (https://github.com/Remneys/swiss-knife-ios) under the same
|
|
13
|
+
version.
|
|
12
14
|
|
|
13
15
|
## [Unreleased]
|
|
14
16
|
|
|
17
|
+
## [0.6.0] - 2026-11-26
|
|
18
|
+
|
|
19
|
+
Four StoreKit 2 additions to the native iOS SDK (`SwissKnifeiOS`), asked for
|
|
20
|
+
by a native SwiftUI app, and the same SDK published as a Swift package. The
|
|
21
|
+
additions are in native code, so React Native apps get them only through a new
|
|
22
|
+
store build; of the four, React Native reaches only the two configuration
|
|
23
|
+
switches below from JS so far. Android is unchanged.
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- **iOS: `appAccountToken` on purchases.** `purchasePackage(_:appAccountToken:)`
|
|
28
|
+
and `purchaseStoreProduct(_:appAccountToken:)` take an optional UUID. Without
|
|
29
|
+
one, the SDK sends the signed-in app user id when it is a UUID (StoreKit
|
|
30
|
+
signs it lower-case). The backend reads the token from the verified
|
|
31
|
+
transaction, remembers which user it stands for when it is not the user id
|
|
32
|
+
itself, and resolves App Store Server Notifications and outgoing webhooks
|
|
33
|
+
to that user.
|
|
34
|
+
- **iOS: `syncCurrentEntitlements()`.** Posts the device's current
|
|
35
|
+
entitlements (`Transaction.currentEntitlements`) that the backend has not
|
|
36
|
+
accepted for the current user, without `AppStore.sync()` and so without the
|
|
37
|
+
Apple ID sheet, and returns `CustomerInfo`. Hashed fingerprints of accepted
|
|
38
|
+
transactions on the device mean a launch with nothing new sends nothing.
|
|
39
|
+
A sync never moves a purchase between users: it posts with
|
|
40
|
+
`silent_sync: true`, and the backend records what belongs to the current
|
|
41
|
+
user but leaves a purchase it holds for another user where it is, whatever
|
|
42
|
+
the app's transfer setting, and says so (`owned_elsewhere`). The SDK
|
|
43
|
+
reports it as a `.sync` transaction event with `ownedByAnotherUser: true`.
|
|
44
|
+
`restorePurchases()` still calls `AppStore.sync()` first, posts everything
|
|
45
|
+
and applies the transfer setting.
|
|
46
|
+
- **iOS: `checkTrialOrIntroDiscountEligibility(productIdentifiers:)` and
|
|
47
|
+
`checkTrialOrIntroDiscountEligibility(subscriptionGroupIdentifier:)`.**
|
|
48
|
+
Answer `.eligible`, `.ineligible`, `.noIntroOfferExists` or `.unknown` from
|
|
49
|
+
StoreKit 2. The per-product form asks StoreKit once per subscription group.
|
|
50
|
+
- **iOS: transaction events.** `addTransactionObserver(_:)` /
|
|
51
|
+
`removeTransactionObserver(_:)` and the `transactionEvents` stream report
|
|
52
|
+
each purchase, renewal, restore, sync and refund/revocation the SDK handles.
|
|
53
|
+
An event carries the product, transaction and original transaction ids,
|
|
54
|
+
dates, price and currency, offer type (trial, introductory, promotional,
|
|
55
|
+
offer code, win-back or none), environment, `appAccountToken`, and
|
|
56
|
+
`serverConfirmed`, and `ownedByAnotherUser` on a sync that left another
|
|
57
|
+
user's purchase with them. It fires after the backend answers, or with
|
|
58
|
+
`serverConfirmed: false` when the backend could not be reached or refused
|
|
59
|
+
the transaction. In that case a later event for the same transaction can
|
|
60
|
+
follow, so de-duplicate on `transactionIdentifier`. Observers never delay
|
|
61
|
+
`finish()`.
|
|
62
|
+
- **The native iOS SDK as a Swift package.** Each release is now also published
|
|
63
|
+
to the public repository https://github.com/Remneys/swiss-knife-ios, tagged
|
|
64
|
+
with the SDK version (no `v`), so a native iOS app adds it with
|
|
65
|
+
`.package(url: "https://github.com/Remneys/swiss-knife-ios", from: "<version>")`
|
|
66
|
+
and the `SwissKnifeiOS` product; a Notification Service Extension adds the
|
|
67
|
+
`SwissKnifeNotificationService` product. The package holds the same Swift
|
|
68
|
+
sources this npm package vendors, byte for byte. Nothing changes for React
|
|
69
|
+
Native apps.
|
|
70
|
+
- **React Native: `syncEntitlementsAutomatically` and
|
|
71
|
+
`automaticAppAccountToken` options on `Purchases.configure`** (iOS only,
|
|
72
|
+
both default `true`).
|
|
73
|
+
|
|
74
|
+
### Changed
|
|
75
|
+
|
|
76
|
+
- **iOS: the SDK now syncs entitlements by itself** after `configure` and
|
|
77
|
+
after each `Identity.logIn`. The sync is debounced by a second and runs at
|
|
78
|
+
most once a minute per user. The automatic run does not post a transaction
|
|
79
|
+
whose `appAccountToken` belongs to another account of the app, and nothing
|
|
80
|
+
runs in `configureCore` mode. It never moves a purchase between users:
|
|
81
|
+
a subscription or one-time purchase the backend holds for another app user
|
|
82
|
+
stays with them under every transfer behaviour, `transfer_to_new_user`
|
|
83
|
+
included, until the user taps Restore. Turn the sync off with
|
|
84
|
+
`PurchasesConfiguration(syncEntitlementsAutomatically: false)` natively, or
|
|
85
|
+
with `syncEntitlementsAutomatically: false` in `Purchases.configure`.
|
|
86
|
+
- **iOS: purchases by a signed-in user whose app user id is a UUID now carry
|
|
87
|
+
that id as `appAccountToken`.** Turn this off with
|
|
88
|
+
`automaticAppAccountToken: false`.
|
|
89
|
+
|
|
90
|
+
## [0.5.1] - 2026-11-24
|
|
91
|
+
|
|
92
|
+
Google Play consumables can be bought again, both platforms report each
|
|
93
|
+
product's real type, the iOS Notification Service Extension pod ships in this
|
|
94
|
+
package, and one Expo config can build for Google Play and for RuStore. The
|
|
95
|
+
fixes are in native code, so they reach users only through a new store build.
|
|
96
|
+
|
|
97
|
+
### Upgrading from 0.5.0
|
|
98
|
+
|
|
99
|
+
1. **Bump the dependency, commit the lockfile, rebuild the native app.**
|
|
100
|
+
`npm install @app-swiss-knife/react-native-sdk@0.5.1`, commit
|
|
101
|
+
`package.json` and the lockfile, then `npx expo prebuild --clean` (or let
|
|
102
|
+
EAS Build run prebuild), or `cd ios && pod install` and a Gradle sync on
|
|
103
|
+
bare React Native. Ship it as a new store build: an over-the-air JS update
|
|
104
|
+
does not carry it.
|
|
105
|
+
2. **iOS product labels are now real.** Before, every iOS product reached JS
|
|
106
|
+
as `productCategory: "SUBSCRIPTION"` and
|
|
107
|
+
`productType: "AUTO_RENEWABLE_SUBSCRIPTION"`. A lifetime unlock or a
|
|
108
|
+
consumable is now `NON_SUBSCRIPTION` with its own `productType`. If your
|
|
109
|
+
paywall filters on `productCategory === "SUBSCRIPTION"` and should keep
|
|
110
|
+
one-time products, filter on `productType` instead, or show every package.
|
|
111
|
+
3. **Android (Play): consumables can be sold for repeat purchase.** Type the
|
|
112
|
+
product as a consumable in the dashboard. A consumable a user bought with
|
|
113
|
+
0.5.0 stays owned until `restorePurchases()` runs, or until the app reads
|
|
114
|
+
offerings that name it a consumable (see **Fixed**).
|
|
115
|
+
|
|
116
|
+
### Added
|
|
117
|
+
|
|
118
|
+
- The iOS Notification Service Extension pod is part of this package. In the
|
|
119
|
+
extension target of your Podfile:
|
|
120
|
+
`pod 'SwissKnifeNotificationService', :path => '../node_modules/@app-swiss-knife/react-native-sdk/ios-notification-service'`.
|
|
121
|
+
It compiles only the extension class (Foundation and UserNotifications), and
|
|
122
|
+
the app pod compiles the same files as in 0.5.0. This replaces the 0.5.0
|
|
123
|
+
note that the extension class was not part of the npm package. See README
|
|
124
|
+
"Rich notifications".
|
|
125
|
+
- Expo config plugin: `SWISS_KNIFE_ANDROID_STORE=play|rustore`, read at
|
|
126
|
+
prebuild, so one app config can produce a Google Play build and a RuStore
|
|
127
|
+
build (set it in each EAS build profile's `env`). Unset keeps the old
|
|
128
|
+
behaviour: RuStore when `android.rustore` is configured. `rustore` without a
|
|
129
|
+
complete `android.rustore`, or any other value, fails the prebuild with an
|
|
130
|
+
error naming the fields; the check runs when the config is read, so it fails
|
|
131
|
+
an iOS prebuild too.
|
|
132
|
+
- Native iOS: `StoreProduct.productType` (`StoreProductType`, with
|
|
133
|
+
`isSubscription`).
|
|
134
|
+
- Native Android: `ProductKindHint.productKind`, the server's product type for
|
|
135
|
+
a product, and `PurchasesGateway.onServerProductTypes(types)` (default
|
|
136
|
+
no-op), which receives the server's type for each of the store's products
|
|
137
|
+
that the offerings name.
|
|
138
|
+
|
|
139
|
+
### Changed
|
|
140
|
+
|
|
141
|
+
- iOS: `productType` and `productCategory` report the product's StoreKit type:
|
|
142
|
+
`AUTO_RENEWABLE_SUBSCRIPTION`, `NON_RENEWABLE_SUBSCRIPTION`, `CONSUMABLE` or
|
|
143
|
+
`NON_CONSUMABLE`, and `UNKNOWN` for a dashboard-only one-time product that
|
|
144
|
+
StoreKit did not return. `productCategory` is `SUBSCRIPTION` only for an
|
|
145
|
+
auto-renewable product; non-subscriptions have no `subscriptionPeriod`.
|
|
146
|
+
- Android: a one-time product is `CONSUMABLE` or `NON_CONSUMABLE` when the
|
|
147
|
+
server's catalogue names its type, `UNKNOWN` otherwise (it was always
|
|
148
|
+
`UNKNOWN`).
|
|
149
|
+
- The server's offerings name each product's type (`product_type`), except a
|
|
150
|
+
product with no duration whose type is still the dashboard's default
|
|
151
|
+
subscription type: that one is left out, so the SDKs keep treating it as a
|
|
152
|
+
one-time product.
|
|
153
|
+
|
|
154
|
+
### Fixed
|
|
155
|
+
|
|
156
|
+
- Android (Play): consumables can be bought again. A one-time purchase is
|
|
157
|
+
consumed once the server's validation answer says its product is a
|
|
158
|
+
consumable (the server has recorded the purchase by then); every other
|
|
159
|
+
product is still only acknowledged. A failed consume is retried and never
|
|
160
|
+
fails the purchase. A consumable that 0.5.0 acknowledged and left owned is
|
|
161
|
+
consumed by `restorePurchases()`, and by the purchase check that runs after
|
|
162
|
+
`getOfferings()` reads offerings naming it a consumable; the same check runs
|
|
163
|
+
when Play answers `ITEM_ALREADY_OWNED`, so the next attempt can buy.
|
|
164
|
+
- Expo config plugin: `android.rustore` no longer turns every Android build
|
|
165
|
+
into a RuStore build when `SWISS_KNIFE_ANDROID_STORE=play` is set.
|
|
166
|
+
- The dashboard's native Android install snippet showed version 0.4.0; it now
|
|
167
|
+
follows the SDK version.
|
|
168
|
+
|
|
169
|
+
### Known limitations
|
|
170
|
+
|
|
171
|
+
- Android: Play has no non-renewing subscriptions, so a product the server
|
|
172
|
+
types `non_renewing` is reported as `AUTO_RENEWABLE_SUBSCRIPTION`; iOS
|
|
173
|
+
reports `NON_RENEWABLE_SUBSCRIPTION`.
|
|
174
|
+
- Android (Play): a consumable bought before sign-in with 0.5.0 and validated
|
|
175
|
+
again under the signed-in user is refused by the server as another user's
|
|
176
|
+
purchase, so it stays owned, as in 0.5.0.
|
|
177
|
+
|
|
15
178
|
## [0.5.0] - 2026-11-24
|
|
16
179
|
|
|
17
180
|
Push notifications, Android offerings and one-time products, Google Play
|
package/README.md
CHANGED
|
@@ -12,15 +12,18 @@ This SDK is part of a three-package split:
|
|
|
12
12
|
| Package | Language | Purpose |
|
|
13
13
|
| -------------------------------------------------------------------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------- |
|
|
14
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` (
|
|
15
|
+
| `packages/swiss-knife-ios` (SwiftPM: Remneys/swiss-knife-ios; vendored here) | Swift | Native iOS SDK — StoreKit 2 directly, own typed model layer. Owns `configure`, proxyURL. |
|
|
16
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
17
|
|
|
18
|
-
Only the npm package is published. A native
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
package,
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
Only the npm package is published to a package registry. A native
|
|
19
|
+
(non-React-Native) iOS app adds the iOS SDK as a Swift package from its public
|
|
20
|
+
repository, https://github.com/Remneys/swiss-knife-ios (tagged with this
|
|
21
|
+
package's version), or vendors `ios/vendor/SwissKnifeiOS` out of this package's
|
|
22
|
+
tarball as a local Swift package; there is no CocoaPods pod. A native Android app
|
|
23
|
+
cannot install the Android SDK from Maven; it vendors `android/vendor/java` and
|
|
24
|
+
`android/vendor/res` as Kotlin source in the app module. The `setup-native` skill
|
|
25
|
+
of the Swiss-Knife plugin (github.com/Remneys/swiss-knife-plugin) does that for
|
|
26
|
+
you.
|
|
24
27
|
|
|
25
28
|
### How the bridge gets the native SDKs (vendoring)
|
|
26
29
|
|
|
@@ -31,11 +34,12 @@ has to exist on any registry for a consumer app to build.
|
|
|
31
34
|
`scripts/vendor-native.mjs` runs on `build` and `prepack` and copies the
|
|
32
35
|
native sources into this package:
|
|
33
36
|
|
|
34
|
-
| From
|
|
35
|
-
|
|
|
36
|
-
| `packages/swiss-knife-ios/Sources/SwissKnifeiOS`
|
|
37
|
-
| `packages/swiss-knife-android/src/main/java`
|
|
38
|
-
| `packages/swiss-knife-android/src/main/res`
|
|
37
|
+
| From | To | Compiled by |
|
|
38
|
+
| ---------------------------------------------------------------- | --------------------------------------------------------------- | ---------------------------------------------------------------------------------------- |
|
|
39
|
+
| `packages/swiss-knife-ios/Sources/SwissKnifeiOS` | `ios/vendor/SwissKnifeiOS` | `SwissKnifePurchases.podspec` (`source_files = ios/**`) |
|
|
40
|
+
| `packages/swiss-knife-android/src/main/java` | `android/vendor/java` | `android/build.gradle` (`sourceSets.main.java.srcDirs`) |
|
|
41
|
+
| `packages/swiss-knife-android/src/main/res` | `android/vendor/res` | `android/build.gradle` (`sourceSets.main.res.srcDirs`) |
|
|
42
|
+
| `packages/swiss-knife-ios/Sources/SwissKnifeNotificationService` | `ios-notification-service/vendor/SwissKnifeNotificationService` | `ios-notification-service/SwissKnifeNotificationService.podspec` (extension target only) |
|
|
39
43
|
|
|
40
44
|
The vendored trees are **git-ignored build artifacts** (same status as `lib/`)
|
|
41
45
|
but ARE included in the tarball. The single source of truth stays in
|
|
@@ -125,6 +129,14 @@ const pkg = offerings.current?.availablePackages[0];
|
|
|
125
129
|
if (pkg) await Purchases.purchasePackage(pkg);
|
|
126
130
|
```
|
|
127
131
|
|
|
132
|
+
An email or phone number the app sends (`Attributes.setEmail`,
|
|
133
|
+
`Attributes.setPhoneNumber`, or `$email` / `$phone` in identify properties)
|
|
134
|
+
goes with the public key, so it is recorded as an unverified claim: it never
|
|
135
|
+
links two people and never opens the person's support history to whoever
|
|
136
|
+
writes from that address. Only your server can assert one as the person's
|
|
137
|
+
own, by calling `POST /api/sdk/users/identify` with an agent credential (an
|
|
138
|
+
admin's `sk_mcp_` token with the `write` scope).
|
|
139
|
+
|
|
128
140
|
## The namespaces
|
|
129
141
|
|
|
130
142
|
Everything hangs off `SwissKnife`, the same way it does in the native iOS and
|
|
@@ -411,11 +423,23 @@ The plugin does **not** generate the extension target (it needs an Xcode
|
|
|
411
423
|
project rewrite). Manual steps:
|
|
412
424
|
|
|
413
425
|
1. Xcode → File → New → Target → _Notification Service Extension_.
|
|
414
|
-
2. Add the `SwissKnifeNotificationService`
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
426
|
+
2. Add the `SwissKnifeNotificationService` pod, which ships in this package, to
|
|
427
|
+
**that target only**: in `ios/Podfile`, at the top level, then `pod install`.
|
|
428
|
+
|
|
429
|
+
```ruby
|
|
430
|
+
target 'YourNotificationService' do
|
|
431
|
+
pod 'SwissKnifeNotificationService', :path => '../node_modules/@app-swiss-knife/react-native-sdk/ios-notification-service'
|
|
432
|
+
end
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
The path is relative to `ios/`; in a monorepo that hoists `node_modules`,
|
|
436
|
+
point it at the folder where the package is actually installed.
|
|
437
|
+
|
|
438
|
+
It is deliberately separate from the SDK's pod and imports only Foundation +
|
|
439
|
+
UserNotifications, so the extension stays under its memory cap. (A native
|
|
440
|
+
app without React Native adds the `SwissKnifeNotificationService` product of
|
|
441
|
+
the Swift package https://github.com/Remneys/swiss-knife-ios instead.)
|
|
442
|
+
|
|
419
443
|
3. Replace the generated class:
|
|
420
444
|
|
|
421
445
|
```swift
|
|
@@ -466,8 +490,40 @@ The npm package includes the native RuStore adapter. Enable it in Expo:
|
|
|
466
490
|
```
|
|
467
491
|
|
|
468
492
|
Prebuild configures the payment return deeplink and selects `swissKnifeStore=rustore`.
|
|
469
|
-
Without this option, builds use Play and do not load RuStore dependencies.
|
|
470
|
-
|
|
493
|
+
Without this option, builds use Play and do not load RuStore dependencies.
|
|
494
|
+
|
|
495
|
+
To ship one app config to both stores, choose the store per build with the
|
|
496
|
+
`SWISS_KNIFE_ANDROID_STORE` environment variable, which the config plugin reads
|
|
497
|
+
at prebuild:
|
|
498
|
+
|
|
499
|
+
| `SWISS_KNIFE_ANDROID_STORE` | Build |
|
|
500
|
+
| --------------------------- | ------------------------------------------------------------------------------------------------------------------- |
|
|
501
|
+
| unset or empty | RuStore when `android.rustore` is configured, Google Play otherwise (the behaviour above) |
|
|
502
|
+
| `play` | Google Play: `swissKnifeStore=play`, no RuStore strings or manifest entries, even with `android.rustore` configured |
|
|
503
|
+
| `rustore` | RuStore; prebuild fails, naming the missing fields, unless `android.rustore` has `consoleAppId` and `scheme` |
|
|
504
|
+
|
|
505
|
+
Any other value fails the prebuild, an iOS one included, since the plugin checks
|
|
506
|
+
the variable whenever it reads the app config. With EAS Build, set it in each
|
|
507
|
+
build profile's `env`; EAS runs prebuild with it when `android/` is not
|
|
508
|
+
committed (a bare project sets `swissKnifeStore` itself, see below):
|
|
509
|
+
|
|
510
|
+
```json
|
|
511
|
+
{
|
|
512
|
+
"build": {
|
|
513
|
+
"production-play": {
|
|
514
|
+
"env": { "SWISS_KNIFE_ANDROID_STORE": "play" }
|
|
515
|
+
},
|
|
516
|
+
"production-rustore": {
|
|
517
|
+
"env": { "SWISS_KNIFE_ANDROID_STORE": "rustore" }
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
Locally, `SWISS_KNIFE_ANDROID_STORE=play npx expo prebuild -p android --clean`;
|
|
524
|
+
`--clean` matters when switching stores, since prebuild without it keeps the
|
|
525
|
+
RuStore entries an earlier RuStore prebuild wrote into `android/`. Bare React
|
|
526
|
+
Native apps can set the `swissKnifeStore` Gradle property and provide RuStore's manifest metadata
|
|
471
527
|
(`console_app_id_value`, `sdk_pay_scheme_value`) plus the launcher Activity's
|
|
472
528
|
singleTask payment return intent filter. Backend credentials use `rustore_api_key`;
|
|
473
529
|
products and entitlements must be configured for platform `rustore`.
|
|
@@ -115,11 +115,12 @@ object SwissKnifeJson {
|
|
|
115
115
|
map.putDouble("price", product.price.amountMicros / 1_000_000.0)
|
|
116
116
|
map.putString("currencyCode", product.price.currencyCode)
|
|
117
117
|
// A product the SDK knows is one-time (Play INAPP, or a dashboard product
|
|
118
|
-
// with no duration) is not labelled a subscription.
|
|
119
|
-
//
|
|
120
|
-
val
|
|
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
|
|
121
122
|
map.putString("productCategory", if (oneTime) "NON_SUBSCRIPTION" else "SUBSCRIPTION")
|
|
122
|
-
map.putString("productType",
|
|
123
|
+
map.putString("productType", productTypeLabel(oneTime, hint?.productKind))
|
|
123
124
|
map.putNullableString(
|
|
124
125
|
"subscriptionPeriod",
|
|
125
126
|
product.subscriptionPeriod?.let { periodToISOString(it) },
|
|
@@ -373,4 +374,16 @@ object SwissKnifeJson {
|
|
|
373
374
|
private fun WritableMap.putNullableMap(key: String, value: WritableMap?) {
|
|
374
375
|
if (value == null) putNull(key) else putMap(key, value)
|
|
375
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
|
+
}
|
|
376
389
|
}
|
|
@@ -4,6 +4,7 @@ Copied verbatim by packages/react-native-sdk/scripts/vendor-native.mjs from the
|
|
|
4
4
|
standalone native SDK sources in the monorepo. Edit those instead:
|
|
5
5
|
|
|
6
6
|
packages/swiss-knife-ios/Sources/SwissKnifeiOS/**
|
|
7
|
+
packages/swiss-knife-ios/Sources/SwissKnifeNotificationService/**
|
|
7
8
|
packages/swiss-knife-android/src/main/{java,res}/**
|
|
8
9
|
|
|
9
10
|
This directory is gitignored and regenerated on every `build` / `prepack`.
|
|
@@ -290,6 +290,7 @@ object SwissKnife {
|
|
|
290
290
|
// one wired by an earlier configure in this process must not shadow it.
|
|
291
291
|
// A blank proxyURL means the SDK's default host, as on iOS.
|
|
292
292
|
val priceProvider = gateway.priceEnrichmentProvider()
|
|
293
|
+
val storeGateway = gateway
|
|
293
294
|
offeringsRepository = priceProvider?.let {
|
|
294
295
|
com.appswissknife.offerings.OfferingsRepository(
|
|
295
296
|
httpClient = com.appswissknife.net.BackendHttpClientAdapter(),
|
|
@@ -297,6 +298,9 @@ object SwissKnife {
|
|
|
297
298
|
apiKey = apiKey,
|
|
298
299
|
platformTags = it.platformTags(),
|
|
299
300
|
priceProvider = it,
|
|
301
|
+
// The backend's product types reach the gateway that sells them (the
|
|
302
|
+
// Play gateway finds consumables an older SDK left unconsumed).
|
|
303
|
+
onServerProductTypes = storeGateway::onServerProductTypes,
|
|
300
304
|
)
|
|
301
305
|
}
|
|
302
306
|
// Same store-agnostic gate as the offerings wiring: real store gateways
|
|
@@ -42,7 +42,7 @@ internal object DeviceContextProvider {
|
|
|
42
42
|
* eventually inject this via `BuildConfig`, but for now keep it in
|
|
43
43
|
* source so we don't have to thread build settings through every test.
|
|
44
44
|
*/
|
|
45
|
-
const val SDK_VERSION: String = "0.
|
|
45
|
+
const val SDK_VERSION: String = "0.6.0"
|
|
46
46
|
|
|
47
47
|
private val cacheLock = Any()
|
|
48
48
|
|
|
@@ -59,6 +59,10 @@ class OfferingsRepository(
|
|
|
59
59
|
// Live price enrichment for the active store; null = backend prices only.
|
|
60
60
|
private val priceProvider: PriceEnrichmentProvider?,
|
|
61
61
|
private val clock: () -> Long = System::currentTimeMillis,
|
|
62
|
+
// Told the backend's product type of each of this store's products it reads
|
|
63
|
+
// (only those the backend names a type for). SwissKnife hands it to the
|
|
64
|
+
// gateway (PurchasesGateway.onServerProductTypes).
|
|
65
|
+
private val onServerProductTypes: (Map<String, String>) -> Unit = {},
|
|
62
66
|
) {
|
|
63
67
|
|
|
64
68
|
private data class CacheEntry(val offerings: Offerings, val fetchedAt: Long, val ttlMillis: Long) {
|
|
@@ -169,6 +173,7 @@ class OfferingsRepository(
|
|
|
169
173
|
)
|
|
170
174
|
}
|
|
171
175
|
val storeProducts = parsed.flatMap { o -> o.packages.map { it.product } }
|
|
176
|
+
reportProductTypes(storeProducts)
|
|
172
177
|
val priced = priceByStore(storeProducts)
|
|
173
178
|
val all = LinkedHashMap<String, Offering>()
|
|
174
179
|
for (o in parsed) {
|
|
@@ -180,7 +185,7 @@ class OfferingsRepository(
|
|
|
180
185
|
SimplePackage(
|
|
181
186
|
identifier = p.identifier ?: p.product.productId,
|
|
182
187
|
packageType = p.packageType?.let(::packageTypeOf) ?: p.product.durationDays.toPackageType(),
|
|
183
|
-
product = priced[p.product.productId] ?: StoreProductFromBackend(p.product),
|
|
188
|
+
product = withServerKind(priced[p.product.productId] ?: StoreProductFromBackend(p.product), p.product),
|
|
184
189
|
offeringIdentifier = o.identifier,
|
|
185
190
|
)
|
|
186
191
|
},
|
|
@@ -199,11 +204,12 @@ class OfferingsRepository(
|
|
|
199
204
|
}
|
|
200
205
|
// Filter to the active store's products (Play: play/android; RuStore: rustore).
|
|
201
206
|
val storeProducts = backendProducts.filter { it.isForThisStore() }
|
|
207
|
+
reportProductTypes(storeProducts)
|
|
202
208
|
// Enrich with live store prices; ids the store can't resolve fall back to
|
|
203
209
|
// the backend-priced product.
|
|
204
210
|
val enriched = priceByStore(storeProducts)
|
|
205
211
|
val packages = storeProducts.map { bp ->
|
|
206
|
-
val storeProduct = enriched[bp.productId] ?: StoreProductFromBackend(bp)
|
|
212
|
+
val storeProduct = withServerKind(enriched[bp.productId] ?: StoreProductFromBackend(bp), bp)
|
|
207
213
|
SimplePackage(
|
|
208
214
|
identifier = bp.productId,
|
|
209
215
|
packageType = bp.durationDays.toPackageType(),
|
|
@@ -249,6 +255,24 @@ class OfferingsRepository(
|
|
|
249
255
|
|
|
250
256
|
private fun BackendProduct.isForThisStore(): Boolean = platform.lowercase() in storeTags
|
|
251
257
|
|
|
258
|
+
/**
|
|
259
|
+
* Tell [onServerProductTypes] the types the backend named; a failure there
|
|
260
|
+
* never fails the read. A LinkageError is caught too: a PurchasesGateway
|
|
261
|
+
* compiled separately against an SDK that predates
|
|
262
|
+
* `PurchasesGateway.onServerProductTypes` has no such method.
|
|
263
|
+
*/
|
|
264
|
+
private fun reportProductTypes(products: List<BackendProduct>) {
|
|
265
|
+
val types = products.mapNotNull { p -> p.productType?.let { p.productId to it } }.toMap()
|
|
266
|
+
if (types.isEmpty()) return
|
|
267
|
+
try {
|
|
268
|
+
onServerProductTypes(types)
|
|
269
|
+
} catch (e: RuntimeException) {
|
|
270
|
+
Log.w(TAG, "product type listener failed", e)
|
|
271
|
+
} catch (e: LinkageError) {
|
|
272
|
+
Log.w(TAG, "product type listener failed", e)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
252
276
|
/**
|
|
253
277
|
* Live store prices for [products], keyed by product id. A store failure
|
|
254
278
|
* leaves every product on its dashboard price rather than failing the read.
|
|
@@ -391,6 +415,7 @@ private class StoreProductFromBackend(private val bp: BackendProduct) : StorePro
|
|
|
391
415
|
amountMicros = (bp.backendPrice * 1_000_000).toLong(),
|
|
392
416
|
)
|
|
393
417
|
override val isOneTime: Boolean = bp.isOneTime
|
|
418
|
+
override val productKind: String? = bp.productType
|
|
394
419
|
/** From the dashboard duration, as iOS's backend-priced product; null for a one-time product. */
|
|
395
420
|
override val subscriptionPeriod: SubscriptionPeriod? =
|
|
396
421
|
if (bp.isOneTime) null else subscriptionPeriodFromDays(bp.durationDays)
|
|
@@ -398,6 +423,26 @@ private class StoreProductFromBackend(private val bp: BackendProduct) : StorePro
|
|
|
398
423
|
override val discounts: List<StoreProductDiscount> = emptyList()
|
|
399
424
|
}
|
|
400
425
|
|
|
426
|
+
/**
|
|
427
|
+
* [product] with the server's product type attached ([ProductKindHint.productKind]),
|
|
428
|
+
* so the React Native bridge can label a store-priced one-time product
|
|
429
|
+
* CONSUMABLE or NON_CONSUMABLE. Unchanged when the server names no type. The
|
|
430
|
+
* store's own one-time/subscription answer ([ProductKindHint.isOneTime]) wins
|
|
431
|
+
* over the server's type.
|
|
432
|
+
*/
|
|
433
|
+
private fun withServerKind(product: StoreProduct, bp: BackendProduct): StoreProduct {
|
|
434
|
+
val kind = bp.productType ?: return product
|
|
435
|
+
val hint = product as? ProductKindHint
|
|
436
|
+
if (hint?.productKind == kind) return product
|
|
437
|
+
return KindedStoreProduct(product, kind, hint?.isOneTime ?: bp.isOneTime)
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
private class KindedStoreProduct(
|
|
441
|
+
inner: StoreProduct,
|
|
442
|
+
override val productKind: String,
|
|
443
|
+
override val isOneTime: Boolean,
|
|
444
|
+
) : StoreProduct by inner, ProductKindHint
|
|
445
|
+
|
|
401
446
|
/** iOS `OfferingsService.subscriptionPeriodFromDays`, for the same dashboard durations. */
|
|
402
447
|
private fun subscriptionPeriodFromDays(days: Int): SubscriptionPeriod? = when (days) {
|
|
403
448
|
0 -> null
|