react-native-iap 16.3.0 → 16.3.2

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 (57) hide show
  1. package/README.md +3 -3
  2. package/android/src/main/java/com/margelo/nitro/iap/HybridRnIap.kt +111 -15
  3. package/android/src/main/java/com/margelo/nitro/iap/RnIapLog.kt +5 -1
  4. package/ios/HybridRnIap.swift +1 -1
  5. package/ios/RnIapLog.swift +6 -6
  6. package/lib/module/index.js +51 -6
  7. package/lib/module/index.js.map +1 -1
  8. package/lib/module/index.kepler.js +9 -0
  9. package/lib/module/index.kepler.js.map +1 -1
  10. package/lib/module/kit-api.js +3 -1
  11. package/lib/module/kit-api.js.map +1 -1
  12. package/lib/module/types.js +2 -0
  13. package/lib/module/types.js.map +1 -1
  14. package/lib/module/vega-adapter.js +3 -4
  15. package/lib/module/vega-adapter.js.map +1 -1
  16. package/lib/typescript/src/index.d.ts.map +1 -1
  17. package/lib/typescript/src/index.kepler.d.ts.map +1 -1
  18. package/lib/typescript/src/kit-api.d.ts +119 -2
  19. package/lib/typescript/src/kit-api.d.ts.map +1 -1
  20. package/lib/typescript/src/specs/RnIap.nitro.d.ts +9 -3
  21. package/lib/typescript/src/specs/RnIap.nitro.d.ts.map +1 -1
  22. package/lib/typescript/src/types.d.ts +33 -9
  23. package/lib/typescript/src/types.d.ts.map +1 -1
  24. package/lib/typescript/src/vega-adapter.d.ts.map +1 -1
  25. package/nitrogen/generated/android/NitroIap+autolinking.cmake +1 -1
  26. package/nitrogen/generated/android/c++/JHybridRnIapSpec.cpp +8 -4
  27. package/nitrogen/generated/android/c++/JHybridRnIapSpec.hpp +1 -1
  28. package/nitrogen/generated/android/c++/JNitroPurchaseVerificationResultAndroid.hpp +5 -1
  29. package/nitrogen/generated/android/c++/JNitroPurchaseVerificationResultHorizon.hpp +69 -0
  30. package/nitrogen/generated/android/c++/JVariant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid_NitroPurchaseVerificationResultHorizon.cpp +30 -0
  31. package/nitrogen/generated/android/c++/{JVariant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid.hpp → JVariant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid_NitroPurchaseVerificationResultHorizon.hpp} +33 -16
  32. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/HybridRnIapSpec.kt +1 -1
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchaseVerificationResultAndroid.kt +8 -3
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchaseVerificationResultHorizon.kt +61 -0
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/{Variant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid.kt → Variant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid_NitroPurchaseVerificationResultHorizon.kt} +21 -8
  36. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.cpp +4 -4
  37. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.hpp +43 -34
  38. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Umbrella.hpp +3 -0
  39. package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.hpp +4 -1
  40. package/nitrogen/generated/ios/swift/{Func_void_std__variant_NitroPurchaseVerificationResultIOS__NitroPurchaseVerificationResultAndroid_.swift → Func_void_std__variant_NitroPurchaseVerificationResultIOS__NitroPurchaseVerificationResultAndroid__NitroPurchaseVerificationResultHorizon_.swift} +14 -11
  41. package/nitrogen/generated/ios/swift/HybridRnIapSpec.swift +1 -1
  42. package/nitrogen/generated/ios/swift/HybridRnIapSpec_cxx.swift +11 -9
  43. package/nitrogen/generated/ios/swift/NitroPurchaseVerificationResultAndroid.swift +7 -2
  44. package/nitrogen/generated/ios/swift/NitroPurchaseVerificationResultHorizon.swift +71 -0
  45. package/nitrogen/generated/ios/swift/{Variant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid.swift → Variant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid_NitroPurchaseVerificationResultHorizon.swift} +6 -4
  46. package/nitrogen/generated/shared/c++/HybridRnIapSpec.hpp +4 -1
  47. package/nitrogen/generated/shared/c++/NitroPurchaseVerificationResultAndroid.hpp +5 -1
  48. package/nitrogen/generated/shared/c++/NitroPurchaseVerificationResultHorizon.hpp +93 -0
  49. package/openiap-versions.json +3 -3
  50. package/package.json +3 -2
  51. package/src/index.kepler.ts +10 -2
  52. package/src/index.ts +88 -18
  53. package/src/kit-api.ts +125 -4
  54. package/src/specs/RnIap.nitro.ts +12 -2
  55. package/src/types.ts +34 -9
  56. package/src/vega-adapter.ts +6 -11
  57. package/nitrogen/generated/android/c++/JVariant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid.cpp +0 -26
package/src/types.ts CHANGED
@@ -885,11 +885,11 @@ export interface Mutation {
885
885
  */
886
886
  syncIOS: Promise<boolean>;
887
887
  /**
888
- * Verify a purchase against your own backend. Returns a platform-specific
889
- * variant of VerifyPurchaseResult VerifyPurchaseResultIOS exposes isValid
890
- * + receipt/JWS metadata, VerifyPurchaseResultAndroid carries Play Store
891
- * receipt fields (no isValid), and VerifyPurchaseResultHorizon uses success.
892
- * Inspect the concrete variant before reading fields.
888
+ * Verify a purchase against your own backend. Every VerifyPurchaseResult
889
+ * variant exposes isValid, so entitlement can be gated without inspecting the
890
+ * concrete type. Variants add their own metadata on top: IOS carries
891
+ * receipt/JWS fields, Android carries Play Store receipt fields, and Horizon
892
+ * carries grantTime.
893
893
  * See: https://openiap.dev/docs/features/validation#verify-purchase
894
894
  */
895
895
  verifyPurchase: Promise<VerifyPurchaseResult>;
@@ -1857,6 +1857,12 @@ export interface RequestVerifyPurchaseWithIapkitResult {
1857
1857
  * Available in OpenIAP Spec 3.2.0 / openiap-apple 3.2.0 / openiap-google 3.3.0.
1858
1858
  * Amazon RVS environment selected by IAPKit. Present as `Sandbox` or
1859
1859
  * `Production` on handled Amazon verification results.
1860
+ *
1861
+ * Deliberately String, not an enum: the value space belongs to IAPKit and the
1862
+ * stores behind it, and Apple's App Store Server alone also names `Xcode` and
1863
+ * `LocalTesting`. SDKs must forward this value opaquely. Never reject a
1864
+ * verification because the environment is unrecognised — that fails a purchase
1865
+ * the store already confirmed.
1860
1866
  */
1861
1867
  environment?: (string | null);
1862
1868
  /**
@@ -2187,7 +2193,7 @@ export interface VerifyPurchaseProps {
2187
2193
 
2188
2194
  export type VerifyPurchaseResult = VerifyPurchaseResultAndroid | VerifyPurchaseResultHorizon | VerifyPurchaseResultIOS;
2189
2195
 
2190
- export interface VerifyPurchaseResultAndroid {
2196
+ export interface VerifyPurchaseResultAndroid extends VerifyPurchaseResultCommon {
2191
2197
  autoRenewing: boolean;
2192
2198
  betaProduct: boolean;
2193
2199
  cancelDate?: (number | null);
@@ -2196,6 +2202,11 @@ export interface VerifyPurchaseResultAndroid {
2196
2202
  deferredSku?: (string | null);
2197
2203
  freeTrialEndDate: number;
2198
2204
  gracePeriodEndDate: number;
2205
+ /**
2206
+ * Whether the purchase is valid. Uniform across every VerifyPurchaseResult
2207
+ * variant so callers can gate entitlement without inspecting the concrete type.
2208
+ */
2209
+ isValid: boolean;
2199
2210
  parentProductId: string;
2200
2211
  productId: string;
2201
2212
  productType: string;
@@ -2208,18 +2219,32 @@ export interface VerifyPurchaseResultAndroid {
2208
2219
  testTransaction: boolean;
2209
2220
  }
2210
2221
 
2222
+ /** Validity shared by every store-specific purchase verification result. */
2223
+ export interface VerifyPurchaseResultCommon {
2224
+ /** Whether the purchase is valid, without inspecting the concrete result variant. */
2225
+ isValid: boolean;
2226
+ }
2227
+
2211
2228
  /**
2212
2229
  * Result from Meta Horizon verify_entitlement API.
2213
2230
  * Returns verification status and grant time for the entitlement.
2214
2231
  */
2215
- export interface VerifyPurchaseResultHorizon {
2232
+ export interface VerifyPurchaseResultHorizon extends VerifyPurchaseResultCommon {
2216
2233
  /** Unix timestamp (seconds) when the entitlement was granted. */
2217
2234
  grantTime?: (number | null);
2218
- /** Whether the entitlement verification succeeded. */
2235
+ /**
2236
+ * Whether the purchase is valid. Uniform across every VerifyPurchaseResult
2237
+ * variant so callers can gate entitlement without inspecting the concrete type.
2238
+ */
2239
+ isValid: boolean;
2240
+ /**
2241
+ * Whether the entitlement verification succeeded.
2242
+ * @deprecated Renamed to isValid so every VerifyPurchaseResult variant answers validity the same way. Scheduled for removal in OpenIAP 4.0.
2243
+ */
2219
2244
  success: boolean;
2220
2245
  }
2221
2246
 
2222
- export interface VerifyPurchaseResultIOS {
2247
+ export interface VerifyPurchaseResultIOS extends VerifyPurchaseResultCommon {
2223
2248
  /** Whether the receipt is valid */
2224
2249
  isValid: boolean;
2225
2250
  /** JWS representation */
@@ -1271,17 +1271,12 @@ export function createVegaIapModule(service: VegaPurchasingService): RnIap {
1271
1271
  `IAPKit returned malformed response (HTTP ${status}).`,
1272
1272
  );
1273
1273
  }
1274
- const environment = json.environment;
1275
- if (
1276
- environment != null &&
1277
- (typeof environment !== 'string' ||
1278
- (environment !== 'Sandbox' && environment !== 'Production'))
1279
- ) {
1280
- throw createVegaError(
1281
- ErrorCode.PurchaseVerificationFailed,
1282
- `IAPKit returned malformed response (HTTP ${status}).`,
1283
- );
1284
- }
1274
+ // Forwarded opaquely: `environment` is String in the spec.
1275
+ const rawEnvironment = json.environment;
1276
+ const environment =
1277
+ typeof rawEnvironment === 'string' && rawEnvironment.length > 0
1278
+ ? rawEnvironment
1279
+ : undefined;
1285
1280
 
1286
1281
  return {
1287
1282
  ...(environment == null ? {} : {environment}),
@@ -1,26 +0,0 @@
1
- ///
2
- /// JVariant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid.cpp
3
- /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
- /// https://github.com/mrousavy/nitro
5
- /// Copyright © Marc Rousavy @ Margelo
6
- ///
7
-
8
- #include "JVariant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid.hpp"
9
-
10
- namespace margelo::nitro::iap {
11
- /**
12
- * Converts JVariant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid to std::variant<NitroPurchaseVerificationResultIOS, NitroPurchaseVerificationResultAndroid>
13
- */
14
- std::variant<NitroPurchaseVerificationResultIOS, NitroPurchaseVerificationResultAndroid> JVariant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid::toCpp() const {
15
- if (isInstanceOf(JVariant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid_impl::First::javaClassStatic())) {
16
- // It's a `NitroPurchaseVerificationResultIOS`
17
- auto jniValue = static_cast<const JVariant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid_impl::First*>(this)->getValue();
18
- return jniValue->toCpp();
19
- } else if (isInstanceOf(JVariant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid_impl::Second::javaClassStatic())) {
20
- // It's a `NitroPurchaseVerificationResultAndroid`
21
- auto jniValue = static_cast<const JVariant_NitroPurchaseVerificationResultIOS_NitroPurchaseVerificationResultAndroid_impl::Second*>(this)->getValue();
22
- return jniValue->toCpp();
23
- }
24
- throw std::invalid_argument("Variant is unknown Kotlin instance!");
25
- }
26
- } // namespace margelo::nitro::iap