react-native-purchases 9.0.0 → 9.2.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/RNPurchases.podspec +1 -1
- package/android/build.gradle +3 -3
- package/android/src/main/java/com/revenuecat/purchases/react/RNPurchasesModule.java +24 -1
- package/dist/{preview → browser}/nativeModule.d.ts +40 -38
- package/dist/{preview → browser}/nativeModule.js +230 -154
- package/dist/browser/typeGuards.d.ts +23 -0
- package/dist/browser/typeGuards.js +61 -0
- package/dist/browser/utils.d.ts +6 -0
- package/dist/browser/utils.js +18 -0
- package/dist/purchases.d.ts +28 -2
- package/dist/purchases.js +70 -75
- package/dist/utils/environment.d.ts +5 -1
- package/dist/utils/environment.js +6 -5
- package/ios/RNPurchases.m +19 -1
- package/package.json +7 -2
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CustomerInfo, MakePurchaseResult, PurchasesOffering, PurchasesOfferings } from '@revenuecat/purchases-typescript-internal';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard function type - returns true if value matches type T
|
|
4
|
+
*/
|
|
5
|
+
type TypeGuard<T> = (value: any) => value is T;
|
|
6
|
+
/**
|
|
7
|
+
* Type-safe transformation function that validates purchases-js output matches expected type
|
|
8
|
+
* @param value - The value from purchases-js
|
|
9
|
+
* @param typeGuard - Runtime type guard function that validates the structure
|
|
10
|
+
* @param typeName - String description of expected type for logging
|
|
11
|
+
* @returns The value cast to expected type T
|
|
12
|
+
* @throws {Error} If type validation fails
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateAndTransform<T>(value: any, typeGuard: TypeGuard<T>, typeName: string): T;
|
|
15
|
+
export declare function isCustomerInfo(value: any): value is CustomerInfo;
|
|
16
|
+
export declare function isPurchasesOfferings(value: any): value is PurchasesOfferings;
|
|
17
|
+
export declare function isPurchasesOffering(value: any): value is PurchasesOffering;
|
|
18
|
+
export declare function isLogInResult(value: any): value is {
|
|
19
|
+
customerInfo: CustomerInfo;
|
|
20
|
+
created: boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare function isMakePurchaseResult(value: any): value is MakePurchaseResult;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMakePurchaseResult = exports.isLogInResult = exports.isPurchasesOffering = exports.isPurchasesOfferings = exports.isCustomerInfo = exports.validateAndTransform = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Type-safe transformation function that validates purchases-js output matches expected type
|
|
6
|
+
* @param value - The value from purchases-js
|
|
7
|
+
* @param typeGuard - Runtime type guard function that validates the structure
|
|
8
|
+
* @param typeName - String description of expected type for logging
|
|
9
|
+
* @returns The value cast to expected type T
|
|
10
|
+
* @throws {Error} If type validation fails
|
|
11
|
+
*/
|
|
12
|
+
function validateAndTransform(value, typeGuard, typeName) {
|
|
13
|
+
if (value === null || value === undefined) {
|
|
14
|
+
if (typeName.includes('null')) {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
console.error("Type validation failed: Expected ".concat(typeName, ", got ").concat(value));
|
|
18
|
+
throw new Error("Type validation failed: Expected ".concat(typeName, ", got ").concat(value));
|
|
19
|
+
}
|
|
20
|
+
if (typeGuard(value)) {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
console.error("Type validation failed: Expected ".concat(typeName, ", got:"), value);
|
|
24
|
+
throw new Error("Type validation failed: Expected ".concat(typeName, ", received invalid structure"));
|
|
25
|
+
}
|
|
26
|
+
exports.validateAndTransform = validateAndTransform;
|
|
27
|
+
// Type guards for the interfaces we use
|
|
28
|
+
function isCustomerInfo(value) {
|
|
29
|
+
return value && typeof value === 'object' &&
|
|
30
|
+
typeof value.originalAppUserId === 'string' &&
|
|
31
|
+
typeof value.entitlements === 'object';
|
|
32
|
+
}
|
|
33
|
+
exports.isCustomerInfo = isCustomerInfo;
|
|
34
|
+
function isPurchasesOfferings(value) {
|
|
35
|
+
return value && typeof value === 'object' &&
|
|
36
|
+
typeof value.all === 'object' &&
|
|
37
|
+
(value.current === null || typeof value.current === 'object');
|
|
38
|
+
}
|
|
39
|
+
exports.isPurchasesOfferings = isPurchasesOfferings;
|
|
40
|
+
function isPurchasesOffering(value) {
|
|
41
|
+
return value && typeof value === 'object' &&
|
|
42
|
+
typeof value.identifier === 'string' &&
|
|
43
|
+
typeof value.serverDescription === 'string' &&
|
|
44
|
+
Array.isArray(value.availablePackages);
|
|
45
|
+
}
|
|
46
|
+
exports.isPurchasesOffering = isPurchasesOffering;
|
|
47
|
+
function isLogInResult(value) {
|
|
48
|
+
return value && typeof value === 'object' &&
|
|
49
|
+
typeof value.customerInfo === 'object' &&
|
|
50
|
+
typeof value.created === 'boolean' &&
|
|
51
|
+
isCustomerInfo(value.customerInfo);
|
|
52
|
+
}
|
|
53
|
+
exports.isLogInResult = isLogInResult;
|
|
54
|
+
function isMakePurchaseResult(value) {
|
|
55
|
+
return value && typeof value === 'object' &&
|
|
56
|
+
typeof value.productIdentifier === 'string' &&
|
|
57
|
+
typeof value.customerInfo === 'object' &&
|
|
58
|
+
isCustomerInfo(value.customerInfo) &&
|
|
59
|
+
typeof value.transaction === 'object';
|
|
60
|
+
}
|
|
61
|
+
exports.isMakePurchaseResult = isMakePurchaseResult;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper function to ensure PurchasesCommon is configured before making API calls
|
|
3
|
+
* @throws {Error} If PurchasesCommon is not configured
|
|
4
|
+
*/
|
|
5
|
+
export declare function ensurePurchasesConfigured(): void;
|
|
6
|
+
export declare function methodNotSupportedOnWeb(methodName: string): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.methodNotSupportedOnWeb = exports.ensurePurchasesConfigured = void 0;
|
|
4
|
+
var purchases_js_hybrid_mappings_1 = require("@revenuecat/purchases-js-hybrid-mappings");
|
|
5
|
+
/**
|
|
6
|
+
* Helper function to ensure PurchasesCommon is configured before making API calls
|
|
7
|
+
* @throws {Error} If PurchasesCommon is not configured
|
|
8
|
+
*/
|
|
9
|
+
function ensurePurchasesConfigured() {
|
|
10
|
+
if (!purchases_js_hybrid_mappings_1.PurchasesCommon.isConfigured()) {
|
|
11
|
+
throw new Error('PurchasesCommon is not configured. Call setupPurchases first.');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ensurePurchasesConfigured = ensurePurchasesConfigured;
|
|
15
|
+
function methodNotSupportedOnWeb(methodName) {
|
|
16
|
+
throw new Error("".concat(methodName, " is not supported on web platform."));
|
|
17
|
+
}
|
|
18
|
+
exports.methodNotSupportedOnWeb = methodNotSupportedOnWeb;
|
package/dist/purchases.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PURCHASES_ERROR_CODE, UninitializedPurchasesError, UnsupportedPlatformError, CustomerInfo, PurchasesEntitlementInfo, PRORATION_MODE, PACKAGE_TYPE, INTRO_ELIGIBILITY_STATUS, PurchasesOfferings, PurchasesStoreProduct, UpgradeInfo, PurchasesPromotionalOffer, PurchasesPackage, IntroEligibility, PurchasesStoreProductDiscount, SubscriptionOption, PRODUCT_CATEGORY, GoogleProductChangeInfo, PURCHASE_TYPE, BILLING_FEATURE, REFUND_REQUEST_STATUS, LOG_LEVEL, PurchasesConfiguration, CustomerInfoUpdateListener, ShouldPurchasePromoProductListener, MakePurchaseResult, LogHandler, LogInResult, IN_APP_MESSAGE_TYPE, ENTITLEMENT_VERIFICATION_MODE, VERIFICATION_RESULT, STOREKIT_VERSION, PurchasesStoreTransaction, PurchasesOffering, PURCHASES_ARE_COMPLETED_BY_TYPE, PurchasesWinBackOffer, WebPurchaseRedemption, WebPurchaseRedemptionResult, Storefront } from "@revenuecat/purchases-typescript-internal";
|
|
1
|
+
import { PURCHASES_ERROR_CODE, UninitializedPurchasesError, UnsupportedPlatformError, CustomerInfo, PurchasesEntitlementInfo, PRORATION_MODE, PACKAGE_TYPE, INTRO_ELIGIBILITY_STATUS, PurchasesOfferings, PurchasesStoreProduct, UpgradeInfo, PurchasesPromotionalOffer, PurchasesPackage, IntroEligibility, PurchasesStoreProductDiscount, SubscriptionOption, PRODUCT_CATEGORY, GoogleProductChangeInfo, PURCHASE_TYPE, BILLING_FEATURE, REFUND_REQUEST_STATUS, LOG_LEVEL, PurchasesConfiguration, CustomerInfoUpdateListener, ShouldPurchasePromoProductListener, MakePurchaseResult, LogHandler, LogInResult, IN_APP_MESSAGE_TYPE, ENTITLEMENT_VERIFICATION_MODE, VERIFICATION_RESULT, STOREKIT_VERSION, PurchasesStoreTransaction, PurchasesOffering, PURCHASES_ARE_COMPLETED_BY_TYPE, PurchasesVirtualCurrencies, PurchasesWinBackOffer, WebPurchaseRedemption, WebPurchaseRedemptionResult, Storefront } from "@revenuecat/purchases-typescript-internal";
|
|
2
2
|
export { PURCHASE_TYPE, PurchasesAreCompletedBy, PurchasesAreCompletedByMyApp, PURCHASES_ARE_COMPLETED_BY_TYPE, BILLING_FEATURE, REFUND_REQUEST_STATUS, LOG_LEVEL, STOREKIT_VERSION, PurchasesConfiguration, CustomerInfoUpdateListener, ShouldPurchasePromoProductListener, MakePurchaseResult, LogHandler, LogInResult, } from "@revenuecat/purchases-typescript-internal";
|
|
3
3
|
export default class Purchases {
|
|
4
4
|
/**
|
|
@@ -780,6 +780,33 @@ export default class Purchases {
|
|
|
780
780
|
* WebPurchaseRedemption parameter is passed or Purchases is not configured.
|
|
781
781
|
*/
|
|
782
782
|
static redeemWebPurchase(webPurchaseRedemption: WebPurchaseRedemption): Promise<WebPurchaseRedemptionResult>;
|
|
783
|
+
/**
|
|
784
|
+
* Fetches the virtual currencies for the current subscriber.
|
|
785
|
+
*
|
|
786
|
+
* @returns {Promise<PurchasesVirtualCurrencies>} A PurchasesVirtualCurrencies object containing the subscriber's virtual currencies.
|
|
787
|
+
* The promise will be rejected if configure has not been called yet or if an error occurs.
|
|
788
|
+
*/
|
|
789
|
+
static getVirtualCurrencies(): Promise<PurchasesVirtualCurrencies>;
|
|
790
|
+
/**
|
|
791
|
+
* Invalidates the cache for virtual currencies.
|
|
792
|
+
*
|
|
793
|
+
* This is useful for cases where a virtual currency's balance might have been updated
|
|
794
|
+
* outside of the app, like if you decreased a user's balance from the user spending a virtual currency,
|
|
795
|
+
* or if you increased the balance from your backend using the server APIs.
|
|
796
|
+
*
|
|
797
|
+
* @returns {Promise<void>} The promise will be rejected if configure has not been called yet or there's an error
|
|
798
|
+
* invalidating the virtual currencies cache.
|
|
799
|
+
*/
|
|
800
|
+
static invalidateVirtualCurrenciesCache(): Promise<void>;
|
|
801
|
+
/**
|
|
802
|
+
* The currently cached [PurchasesVirtualCurrencies] if one is available.
|
|
803
|
+
* This value will remain null until virtual currencies have been fetched at
|
|
804
|
+
* least once with [Purchases.getVirtualCurrencies] or an equivalent function.
|
|
805
|
+
*
|
|
806
|
+
* @returns {Promise<PurchasesVirtualCurrencies | null>} The currently cached virtual currencies for the current subscriber.
|
|
807
|
+
* The promise will be rejected if configure has not been called yet or there's an error.
|
|
808
|
+
*/
|
|
809
|
+
static getCachedVirtualCurrencies(): Promise<PurchasesVirtualCurrencies | null>;
|
|
783
810
|
/**
|
|
784
811
|
* Check if configure has finished and Purchases has been configured.
|
|
785
812
|
*
|
|
@@ -787,7 +814,6 @@ export default class Purchases {
|
|
|
787
814
|
*/
|
|
788
815
|
static isConfigured(): Promise<boolean>;
|
|
789
816
|
private static throwIfNotConfigured;
|
|
790
|
-
private static logWarningIfPreviewAPIMode;
|
|
791
817
|
private static throwIfAndroidPlatform;
|
|
792
818
|
private static throwIfIOSPlatform;
|
|
793
819
|
private static isPurchasesAreCompletedByMyApp;
|