react-native-iap 16.4.1 → 16.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/README.md +2 -0
- package/android/build.gradle +19 -21
- package/android/fix-prefab.gradle +11 -24
- package/android/src/main/java/com/margelo/nitro/iap/HybridRnIap.kt +200 -142
- package/android/src/main/java/com/margelo/nitro/iap/TokenizedListenerRegistry.kt +0 -1
- package/ios/HybridRnIap.swift +832 -165
- package/ios/RnIapHelper.swift +1 -1
- package/lib/module/hooks/useIAP.js +48 -32
- package/lib/module/hooks/useIAP.js.map +1 -1
- package/lib/module/index.js +207 -153
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.kepler.js +1 -0
- package/lib/module/index.kepler.js.map +1 -1
- package/lib/module/kit-api.js +9 -5
- package/lib/module/kit-api.js.map +1 -1
- package/lib/module/types.js +1 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/error.js +5 -4
- package/lib/module/utils/error.js.map +1 -1
- package/lib/module/vega-adapter.js +4 -1
- package/lib/module/vega-adapter.js.map +1 -1
- package/lib/typescript/src/hooks/useIAP.d.ts +31 -15
- package/lib/typescript/src/hooks/useIAP.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +28 -14
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.kepler.d.ts.map +1 -1
- package/lib/typescript/src/kit-api.d.ts +9 -5
- package/lib/typescript/src/kit-api.d.ts.map +1 -1
- package/lib/typescript/src/specs/RnIap.nitro.d.ts +10 -0
- package/lib/typescript/src/specs/RnIap.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +12 -2
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/error.d.ts.map +1 -1
- package/lib/typescript/src/vega-adapter.d.ts.map +1 -1
- package/nitrogen/generated/android/NitroIap+autolinking.cmake +1 -0
- package/nitrogen/generated/android/c++/JHybridRnIapSpec.cpp +9 -0
- package/nitrogen/generated/android/c++/JNitroPurchaseRequest.hpp +7 -1
- package/nitrogen/generated/android/c++/JNitroPurchaseRequestType.hpp +58 -0
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithIapkitHorizonProps.hpp +66 -0
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithIapkitProps.hpp +8 -1
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithProviderProps.hpp +3 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_NitroVerifyPurchaseWithIapkitHorizonProps.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_NitroVerifyPurchaseWithIapkitHorizonProps.hpp +74 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_NitroVerifyPurchaseWithIapkitProps.hpp +3 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchaseRequest.kt +8 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchaseRequestType.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroVerifyPurchaseWithIapkitHorizonProps.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroVerifyPurchaseWithIapkitProps.kt +7 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Variant_NullType_NitroVerifyPurchaseWithIapkitHorizonProps.kt +62 -0
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.hpp +65 -0
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Umbrella.hpp +6 -0
- package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.hpp +6 -0
- package/nitrogen/generated/ios/swift/NitroPurchaseRequest.swift +13 -2
- package/nitrogen/generated/ios/swift/NitroPurchaseRequestType.swift +40 -0
- package/nitrogen/generated/ios/swift/NitroVerifyPurchaseWithIapkitHorizonProps.swift +66 -0
- package/nitrogen/generated/ios/swift/NitroVerifyPurchaseWithIapkitProps.swift +38 -1
- package/nitrogen/generated/ios/swift/Variant_NullType_NitroVerifyPurchaseWithIapkitHorizonProps.swift +30 -0
- package/nitrogen/generated/shared/c++/NitroPurchaseRequest.hpp +9 -2
- package/nitrogen/generated/shared/c++/NitroPurchaseRequestType.hpp +76 -0
- package/nitrogen/generated/shared/c++/NitroVerifyPurchaseWithIapkitHorizonProps.hpp +90 -0
- package/nitrogen/generated/shared/c++/NitroVerifyPurchaseWithIapkitProps.hpp +8 -1
- package/openiap-versions.json +3 -3
- package/package.json +1 -1
- package/src/hooks/useIAP.ts +96 -58
- package/src/index.kepler.ts +1 -0
- package/src/index.ts +249 -196
- package/src/kit-api.ts +10 -6
- package/src/specs/RnIap.nitro.ts +12 -0
- package/src/types.ts +13 -2
- package/src/utils/error.ts +7 -3
- package/src/vega-adapter.ts +9 -5
package/src/kit-api.ts
CHANGED
|
@@ -254,7 +254,7 @@ const DEFAULT_BASE_URL = "https://kit.openiap.dev";
|
|
|
254
254
|
function mergeHeaders(
|
|
255
255
|
callerHeaders: Record<string, string> | undefined,
|
|
256
256
|
hasBody: boolean,
|
|
257
|
-
): RequestInit["headers"] {
|
|
257
|
+
): NonNullable<RequestInit["headers"]> {
|
|
258
258
|
if (typeof Headers === "function") {
|
|
259
259
|
const merged = new Headers(callerHeaders);
|
|
260
260
|
if (!merged.has("accept")) merged.set("accept", "application/json");
|
|
@@ -449,16 +449,20 @@ export function kitApi(options: KitApiOptions) {
|
|
|
449
449
|
apiKey: options.apiKey,
|
|
450
450
|
baseUrl,
|
|
451
451
|
|
|
452
|
-
/** GET /v1/subscriptions/status
|
|
453
|
-
*
|
|
452
|
+
/** GET /v1/subscriptions/status compatibility read.
|
|
453
|
+
* @deprecated New account reads must authenticate the user on a developer
|
|
454
|
+
* backend and call the secret-only, tokenless `/v2/subscriptions/status`.
|
|
455
|
+
*/
|
|
454
456
|
status: (userId: string) =>
|
|
455
457
|
call<StatusResponse>(
|
|
456
458
|
`/v1/subscriptions/status/${encodeURIComponent(options.apiKey)}?userId=${encodeURIComponent(userId)}`,
|
|
457
459
|
),
|
|
458
460
|
|
|
459
|
-
/** GET /v1/subscriptions/entitlements
|
|
460
|
-
*
|
|
461
|
-
*
|
|
461
|
+
/** GET /v1/subscriptions/entitlements compatibility read.
|
|
462
|
+
* @deprecated New account reads must authenticate the user on a developer
|
|
463
|
+
* backend and call the secret-only, tokenless
|
|
464
|
+
* `/v2/subscriptions/entitlements`.
|
|
465
|
+
*/
|
|
462
466
|
entitlements: (userId: string) =>
|
|
463
467
|
call<EntitlementsResponse>(
|
|
464
468
|
`/v1/subscriptions/entitlements/${encodeURIComponent(options.apiKey)}?userId=${encodeURIComponent(userId)}`,
|
package/src/specs/RnIap.nitro.ts
CHANGED
|
@@ -260,7 +260,11 @@ export interface NitroRequestPurchaseAndroid {
|
|
|
260
260
|
subscriptionProductReplacementParams?: SubscriptionProductReplacementParamsAndroid | null;
|
|
261
261
|
}
|
|
262
262
|
|
|
263
|
+
export type NitroPurchaseRequestType = 'in-app' | 'subs';
|
|
264
|
+
|
|
263
265
|
export interface NitroPurchaseRequest {
|
|
266
|
+
/** Canonical product type selected by the public request. */
|
|
267
|
+
type?: NitroPurchaseRequestType | null;
|
|
264
268
|
/** Apple-specific purchase parameters */
|
|
265
269
|
apple?: NitroRequestPurchaseIos | null;
|
|
266
270
|
/** Google-specific purchase parameters */
|
|
@@ -448,6 +452,13 @@ export interface NitroVerifyPurchaseWithIapkitGoogleProps {
|
|
|
448
452
|
purchaseToken: string;
|
|
449
453
|
}
|
|
450
454
|
|
|
455
|
+
export interface NitroVerifyPurchaseWithIapkitHorizonProps {
|
|
456
|
+
/** Meta Horizon product or subscription SKU. */
|
|
457
|
+
sku: string;
|
|
458
|
+
/** Meta app-scoped user ID. The openiap-google Horizon module resolves the logged-in user when omitted. */
|
|
459
|
+
userId?: string | null;
|
|
460
|
+
}
|
|
461
|
+
|
|
451
462
|
export interface NitroVerifyPurchaseWithIapkitAmazonProps {
|
|
452
463
|
/** Available in OpenIAP Spec 3.2.0 / openiap-apple 3.2.0 / openiap-google 3.3.0. Optional Amazon product id that must match the product id verified by RVS. */
|
|
453
464
|
expectedProductId?: string | null;
|
|
@@ -470,6 +481,7 @@ export interface NitroVerifyPurchaseWithIapkitProps {
|
|
|
470
481
|
*/
|
|
471
482
|
baseUrl?: string | null;
|
|
472
483
|
google?: NitroVerifyPurchaseWithIapkitGoogleProps | null;
|
|
484
|
+
horizon?: NitroVerifyPurchaseWithIapkitHorizonProps | null;
|
|
473
485
|
/**
|
|
474
486
|
* Available in OpenIAP Spec 2.4.0 / openiap-apple 2.4.1 / openiap-google 2.4.1.
|
|
475
487
|
* Include the product's public IAPKit client payload when available.
|
package/src/types.ts
CHANGED
|
@@ -1828,11 +1828,19 @@ export interface RequestVerifyPurchaseWithIapkitGoogleProps {
|
|
|
1828
1828
|
purchaseToken: string;
|
|
1829
1829
|
}
|
|
1830
1830
|
|
|
1831
|
+
export interface RequestVerifyPurchaseWithIapkitHorizonProps {
|
|
1832
|
+
/** Meta Horizon product or subscription SKU. */
|
|
1833
|
+
sku: string;
|
|
1834
|
+
/** Meta app-scoped user ID. The openiap-google Horizon module resolves the logged-in user when omitted. */
|
|
1835
|
+
userId?: (string | null);
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1831
1838
|
/**
|
|
1832
1839
|
* Platform-specific verification parameters for IAPKit.
|
|
1833
1840
|
*
|
|
1834
1841
|
* - apple: Verifies via App Store (JWS token)
|
|
1835
1842
|
* - google: Verifies via Play Store (purchase token)
|
|
1843
|
+
* - horizon: Verifies via Meta Horizon (app-scoped user ID + SKU)
|
|
1836
1844
|
* - amazon: Verifies via Amazon Appstore RVS (userId + receiptId)
|
|
1837
1845
|
*/
|
|
1838
1846
|
export interface RequestVerifyPurchaseWithIapkitProps {
|
|
@@ -1851,11 +1859,14 @@ export interface RequestVerifyPurchaseWithIapkitProps {
|
|
|
1851
1859
|
baseUrl?: (string | null);
|
|
1852
1860
|
/** Google Play Store verification parameters. */
|
|
1853
1861
|
google?: (RequestVerifyPurchaseWithIapkitGoogleProps | null);
|
|
1862
|
+
/** Meta Horizon verification parameters. */
|
|
1863
|
+
horizon?: (RequestVerifyPurchaseWithIapkitHorizonProps | null);
|
|
1854
1864
|
/**
|
|
1855
1865
|
* Available in OpenIAP Spec 2.4.0 / openiap-apple 2.4.1 / openiap-google 2.4.1.
|
|
1856
1866
|
* Include the product's public IAPKit client payload in a valid Apple or
|
|
1857
|
-
* Google verification response.
|
|
1858
|
-
*
|
|
1867
|
+
* Google verification response. Horizon and Amazon accept this option for
|
|
1868
|
+
* cross-platform request compatibility but omit the payload. Defaults to
|
|
1869
|
+
* false so existing response shapes and bandwidth remain unchanged.
|
|
1859
1870
|
*/
|
|
1860
1871
|
includeClientPayload?: (boolean | null);
|
|
1861
1872
|
}
|
package/src/utils/error.ts
CHANGED
|
@@ -33,9 +33,9 @@ const parseJsonPayload = (
|
|
|
33
33
|
if (typeof parsed === 'object' && parsed !== null) {
|
|
34
34
|
const parsedError = parsed as Partial<IapError>;
|
|
35
35
|
return {
|
|
36
|
+
...parsedError,
|
|
36
37
|
code: parsedError.code || ErrorCode.Unknown,
|
|
37
38
|
message: parsedError.message || fallbackMessage,
|
|
38
|
-
...parsedError,
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
} catch {
|
|
@@ -118,11 +118,15 @@ const parseStructuredError = (error: object): IapError | null => {
|
|
|
118
118
|
|
|
119
119
|
if (errorWithCode.code != null) {
|
|
120
120
|
const {code, message, ...extraFields} = errorWithCode;
|
|
121
|
+
const normalizedCode = String(code);
|
|
121
122
|
|
|
122
123
|
return {
|
|
123
124
|
...extraFields,
|
|
124
|
-
code:
|
|
125
|
-
message:
|
|
125
|
+
code: normalizedCode || ErrorCode.Unknown,
|
|
126
|
+
message:
|
|
127
|
+
typeof message === 'string' && message
|
|
128
|
+
? message
|
|
129
|
+
: 'Unknown error occurred',
|
|
126
130
|
};
|
|
127
131
|
}
|
|
128
132
|
|
package/src/vega-adapter.ts
CHANGED
|
@@ -1420,6 +1420,8 @@ export function createVegaIapModule(service: VegaPurchasingService): RnIap {
|
|
|
1420
1420
|
productTypesBySku.clear();
|
|
1421
1421
|
subscriptionBasesBySku.clear();
|
|
1422
1422
|
subscriptionParentsBySku.clear();
|
|
1423
|
+
purchaseUpdateListeners.clear();
|
|
1424
|
+
purchaseErrorListeners.clear();
|
|
1423
1425
|
cachedUserData = null;
|
|
1424
1426
|
return true;
|
|
1425
1427
|
},
|
|
@@ -1450,11 +1452,13 @@ export function createVegaIapModule(service: VegaPurchasingService): RnIap {
|
|
|
1450
1452
|
try {
|
|
1451
1453
|
const androidRequest = selectGooglePurchaseRequest(request);
|
|
1452
1454
|
sku = getSkuFromRequest(androidRequest);
|
|
1453
|
-
const
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1455
|
+
const explicitProductType =
|
|
1456
|
+
request.type === 'subs' ? PRODUCT_TYPE_SUBSCRIPTION : request.type;
|
|
1457
|
+
const fallbackProductType =
|
|
1458
|
+
explicitProductType ??
|
|
1459
|
+
(hasSubscriptionRequestContext(androidRequest?.subscriptionOffers)
|
|
1460
|
+
? PRODUCT_TYPE_SUBSCRIPTION
|
|
1461
|
+
: productTypesBySku.get(sku));
|
|
1458
1462
|
if (fallbackProductType != null) {
|
|
1459
1463
|
productTypesBySku.set(sku, fallbackProductType);
|
|
1460
1464
|
}
|