expo-iap 2.9.7 → 3.0.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 +30 -0
- package/README.md +1 -1
- package/android/build.gradle +7 -2
- package/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +195 -650
- package/android/src/main/java/expo/modules/iap/PromiseUtils.kt +85 -0
- package/build/ExpoIap.types.d.ts +0 -6
- package/build/ExpoIap.types.d.ts.map +1 -1
- package/build/ExpoIap.types.js.map +1 -1
- package/build/helpers/subscription.d.ts.map +1 -1
- package/build/helpers/subscription.js +14 -3
- package/build/helpers/subscription.js.map +1 -1
- package/build/index.d.ts +6 -73
- package/build/index.d.ts.map +1 -1
- package/build/index.js +21 -154
- package/build/index.js.map +1 -1
- package/build/modules/android.d.ts +2 -2
- package/build/modules/android.d.ts.map +1 -1
- package/build/modules/android.js +11 -1
- package/build/modules/android.js.map +1 -1
- package/build/modules/ios.d.ts +0 -60
- package/build/modules/ios.d.ts.map +1 -1
- package/build/modules/ios.js +2 -121
- package/build/modules/ios.js.map +1 -1
- package/build/types/ExpoIapAndroid.types.d.ts +0 -8
- package/build/types/ExpoIapAndroid.types.d.ts.map +1 -1
- package/build/types/ExpoIapAndroid.types.js +0 -1
- package/build/types/ExpoIapAndroid.types.js.map +1 -1
- package/build/types/ExpoIapIOS.types.d.ts +0 -5
- package/build/types/ExpoIapIOS.types.d.ts.map +1 -1
- package/build/types/ExpoIapIOS.types.js.map +1 -1
- package/build/useIAP.d.ts +0 -18
- package/build/useIAP.d.ts.map +1 -1
- package/build/useIAP.js +1 -18
- package/build/useIAP.js.map +1 -1
- package/bun.lock +340 -137
- package/codecov.yml +17 -21
- package/ios/ExpoIapModule.swift +10 -3
- package/jest.config.js +5 -9
- package/package.json +5 -3
- package/plugin/build/withIAP.d.ts +4 -1
- package/plugin/build/withIAP.js +38 -24
- package/plugin/build/withLocalOpenIAP.d.ts +6 -2
- package/plugin/build/withLocalOpenIAP.js +175 -20
- package/plugin/src/withIAP.ts +66 -30
- package/plugin/src/withLocalOpenIAP.ts +228 -24
- package/src/ExpoIap.types.ts +0 -8
- package/src/helpers/subscription.ts +14 -3
- package/src/index.ts +22 -230
- package/src/modules/android.ts +16 -6
- package/src/modules/ios.ts +2 -168
- package/src/types/ExpoIapAndroid.types.ts +0 -11
- package/src/types/ExpoIapIOS.types.ts +0 -5
- package/src/useIAP.ts +3 -55
- package/android/src/main/java/expo/modules/iap/PlayUtils.kt +0 -178
- package/android/src/main/java/expo/modules/iap/Types.kt +0 -98
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
package expo.modules.iap
|
|
2
|
+
|
|
3
|
+
import android.util.Log
|
|
4
|
+
import dev.hyo.openiap.OpenIapError
|
|
5
|
+
import expo.modules.kotlin.Promise
|
|
6
|
+
|
|
7
|
+
object PromiseUtils {
|
|
8
|
+
private val promises = java.util.concurrent.ConcurrentHashMap<String, java.util.concurrent.CopyOnWriteArrayList<Promise>>()
|
|
9
|
+
|
|
10
|
+
const val TAG = "PromiseUtils"
|
|
11
|
+
|
|
12
|
+
// React Native specific promise key used by JS bridge
|
|
13
|
+
const val PROMISE_BUY_ITEM = "PROMISE_BUY_ITEM"
|
|
14
|
+
|
|
15
|
+
fun addPromiseForKey(
|
|
16
|
+
key: String,
|
|
17
|
+
promise: Promise,
|
|
18
|
+
) {
|
|
19
|
+
promises.computeIfAbsent(key) { java.util.concurrent.CopyOnWriteArrayList() }.add(promise)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
fun resolvePromisesForKey(
|
|
23
|
+
key: String,
|
|
24
|
+
value: Any?,
|
|
25
|
+
) {
|
|
26
|
+
promises[key]?.forEach { promise ->
|
|
27
|
+
promise.safeResolve(value)
|
|
28
|
+
}
|
|
29
|
+
promises.remove(key)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fun rejectAllPendingPromises() {
|
|
33
|
+
// Snapshot to avoid concurrent modification
|
|
34
|
+
promises.values.flatMap { it.toList() }.forEach { promise ->
|
|
35
|
+
promise.safeReject(OpenIapError.E_CONNECTION_CLOSED, "Connection has been closed", null)
|
|
36
|
+
}
|
|
37
|
+
promises.clear()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fun rejectPromisesForKey(
|
|
41
|
+
key: String,
|
|
42
|
+
code: String,
|
|
43
|
+
message: String?,
|
|
44
|
+
err: Exception?,
|
|
45
|
+
) {
|
|
46
|
+
promises[key]?.forEach { promise ->
|
|
47
|
+
promise.safeReject(code, message, err)
|
|
48
|
+
}
|
|
49
|
+
promises.remove(key)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const val TAG = "IapPromises"
|
|
54
|
+
|
|
55
|
+
fun Promise.safeResolve(value: Any?) {
|
|
56
|
+
try {
|
|
57
|
+
this.resolve(value)
|
|
58
|
+
} catch (e: RuntimeException) {
|
|
59
|
+
Log.d(TAG, "Already consumed ${e.message}")
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fun Promise.safeReject(message: String) = this.safeReject("E_UNKNOWN", message, null)
|
|
64
|
+
|
|
65
|
+
fun Promise.safeReject(
|
|
66
|
+
code: String,
|
|
67
|
+
message: String?,
|
|
68
|
+
) = this.safeReject(code, message, null)
|
|
69
|
+
|
|
70
|
+
fun Promise.safeReject(
|
|
71
|
+
code: String,
|
|
72
|
+
throwable: Throwable?,
|
|
73
|
+
) = this.safeReject(code, null, throwable)
|
|
74
|
+
|
|
75
|
+
fun Promise.safeReject(
|
|
76
|
+
code: String,
|
|
77
|
+
message: String?,
|
|
78
|
+
throwable: Throwable?,
|
|
79
|
+
) {
|
|
80
|
+
try {
|
|
81
|
+
this.reject(code, message, throwable)
|
|
82
|
+
} catch (e: RuntimeException) {
|
|
83
|
+
Log.d(TAG, "Already consumed ${e.message}")
|
|
84
|
+
}
|
|
85
|
+
}
|
package/build/ExpoIap.types.d.ts
CHANGED
|
@@ -20,7 +20,6 @@ export type PurchaseCommon = {
|
|
|
20
20
|
id: string;
|
|
21
21
|
productId: string;
|
|
22
22
|
ids?: string[];
|
|
23
|
-
transactionId?: string;
|
|
24
23
|
transactionDate: number;
|
|
25
24
|
transactionReceipt: string;
|
|
26
25
|
purchaseToken?: string;
|
|
@@ -45,10 +44,6 @@ export type PurchaseResult = {
|
|
|
45
44
|
debugMessage?: string;
|
|
46
45
|
code?: string;
|
|
47
46
|
message?: string;
|
|
48
|
-
/**
|
|
49
|
-
* @deprecated Use `purchaseToken` instead. This field will be removed in a future version.
|
|
50
|
-
*/
|
|
51
|
-
purchaseTokenAndroid?: string;
|
|
52
47
|
purchaseToken?: string;
|
|
53
48
|
};
|
|
54
49
|
/**
|
|
@@ -265,7 +260,6 @@ export interface RequestPurchaseAndroidProps {
|
|
|
265
260
|
* Android-specific subscription request parameters
|
|
266
261
|
*/
|
|
267
262
|
export interface RequestSubscriptionAndroidProps extends RequestPurchaseAndroidProps {
|
|
268
|
-
readonly purchaseTokenAndroid?: string;
|
|
269
263
|
readonly replacementModeAndroid?: number;
|
|
270
264
|
readonly subscriptionOffers: {
|
|
271
265
|
sku: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoIap.types.d.ts","sourceRoot":"","sources":["../src/ExpoIap.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,0BAA0B,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAGlC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;AAM3C,MAAM,MAAM,aAAa,GAAG;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;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AAI,kBAA0B,EAAE,CAAC,SAAS,CAAC,CAAC;YACxD,IAAI,MAAM,KAAK,SAAS;gBAAE,OAAO,MAAM,CAAC;QAC1C,CAAC;QACD,MAAM,OAAO,GAAG,gBAAgB,CAAC,QAAQ,CAGxC,CAAC;QACF,OAAO,OAAO,CAAC,SAAS,CAAC,IAAI,WAAW,CAAC;IAC3C,CAAC;IAED;;;;;OAKG;IACH,kBAAkB,EAAE,CAClB,SAAoB,EACpB,QAA2B,EAClB,EAAE;QACX,OAAO,SAAS,IAAI,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IACjD,CAAC;CACF,CAAC","sourcesContent":["import type {\n ProductAndroid,\n PurchaseAndroid,\n ProductSubscriptionAndroid,\n} from './types/ExpoIapAndroid.types';\nimport type {\n ProductIOS,\n PurchaseIOS,\n ProductSubscriptionIOS,\n} from './types/ExpoIapIOS.types';\nimport {NATIVE_ERROR_CODES} from './ExpoIapModule';\n\nexport type ChangeEventPayload = {\n value: string;\n};\n\nexport type ProductType = 'inapp' | 'subs';\n\n// =============================================================================\n// COMMON TYPES (Base types shared across all platforms)\n// =============================================================================\n\nexport type ProductCommon = {\n id: string;\n title: string;\n description: string;\n type: ProductType;\n displayName?: string;\n displayPrice: string;\n currency: string;\n price?: number;\n debugDescription?: string;\n platform?: string;\n};\n\nexport type PurchaseCommon = {\n id: string; // Transaction identifier - used by finishTransaction\n productId: string; // Product identifier - which product was purchased\n ids?: string[]; // Product identifiers for purchases that include multiple products\n transactionId?: string; // @deprecated - use id instead\n transactionDate: number;\n transactionReceipt: string;\n purchaseToken?: string; // Unified purchase token (jwsRepresentation for iOS, purchaseToken for Android)\n platform?: string;\n};\n\nexport type ProductSubscriptionCommon = ProductCommon & {\n type: 'subs';\n};\n\n// Define literal platform types for better type discrimination\nexport type IosPlatform = {platform: 'ios'};\nexport type AndroidPlatform = {platform: 'android'};\n\n// Platform-agnostic unified product types (public API)\nexport type Product =\n | (ProductAndroid & AndroidPlatform)\n | (ProductIOS & IosPlatform);\n\nexport type SubscriptionProduct =\n | (ProductSubscriptionAndroid & AndroidPlatform)\n | (ProductSubscriptionIOS & IosPlatform);\n\n// Re-export all platform-specific types to avoid deep imports\nexport * from './types/ExpoIapAndroid.types';\nexport * from './types/ExpoIapIOS.types';\n\n// Unified purchase type for both products and subscriptions\nexport type Purchase =\n | (PurchaseAndroid & AndroidPlatform)\n | (PurchaseIOS & IosPlatform);\n\n// Removed legacy type aliases `ProductPurchase` and `SubscriptionPurchase` in v2.9.0\n\nexport type PurchaseResult = {\n responseCode?: number;\n debugMessage?: string;\n code?: string;\n message?: string;\n /**\n * @deprecated Use `purchaseToken` instead. This field will be removed in a future version.\n */\n purchaseTokenAndroid?: string;\n purchaseToken?: string;\n};\n/**\n * Centralized error codes for expo-iap\n * These are mapped to platform-specific error codes and provide consistent error handling\n */\nexport enum ErrorCode {\n E_UNKNOWN = 'E_UNKNOWN',\n E_USER_CANCELLED = 'E_USER_CANCELLED',\n E_USER_ERROR = 'E_USER_ERROR',\n E_ITEM_UNAVAILABLE = 'E_ITEM_UNAVAILABLE',\n E_REMOTE_ERROR = 'E_REMOTE_ERROR',\n E_NETWORK_ERROR = 'E_NETWORK_ERROR',\n E_SERVICE_ERROR = 'E_SERVICE_ERROR',\n E_RECEIPT_FAILED = 'E_RECEIPT_FAILED',\n E_RECEIPT_FINISHED = 'E_RECEIPT_FINISHED',\n E_RECEIPT_FINISHED_FAILED = 'E_RECEIPT_FINISHED_FAILED',\n E_NOT_PREPARED = 'E_NOT_PREPARED',\n E_NOT_ENDED = 'E_NOT_ENDED',\n E_ALREADY_OWNED = 'E_ALREADY_OWNED',\n E_DEVELOPER_ERROR = 'E_DEVELOPER_ERROR',\n E_BILLING_RESPONSE_JSON_PARSE_ERROR = 'E_BILLING_RESPONSE_JSON_PARSE_ERROR',\n E_DEFERRED_PAYMENT = 'E_DEFERRED_PAYMENT',\n E_INTERRUPTED = 'E_INTERRUPTED',\n E_IAP_NOT_AVAILABLE = 'E_IAP_NOT_AVAILABLE',\n E_PURCHASE_ERROR = 'E_PURCHASE_ERROR',\n E_SYNC_ERROR = 'E_SYNC_ERROR',\n E_TRANSACTION_VALIDATION_FAILED = 'E_TRANSACTION_VALIDATION_FAILED',\n E_ACTIVITY_UNAVAILABLE = 'E_ACTIVITY_UNAVAILABLE',\n E_ALREADY_PREPARED = 'E_ALREADY_PREPARED',\n E_PENDING = 'E_PENDING',\n E_CONNECTION_CLOSED = 'E_CONNECTION_CLOSED',\n // Additional detailed errors (Android-focused, kept cross-platform)\n E_INIT_CONNECTION = 'E_INIT_CONNECTION',\n E_SERVICE_DISCONNECTED = 'E_SERVICE_DISCONNECTED',\n E_QUERY_PRODUCT = 'E_QUERY_PRODUCT',\n E_SKU_NOT_FOUND = 'E_SKU_NOT_FOUND',\n E_SKU_OFFER_MISMATCH = 'E_SKU_OFFER_MISMATCH',\n E_ITEM_NOT_OWNED = 'E_ITEM_NOT_OWNED',\n E_BILLING_UNAVAILABLE = 'E_BILLING_UNAVAILABLE',\n E_FEATURE_NOT_SUPPORTED = 'E_FEATURE_NOT_SUPPORTED',\n E_EMPTY_SKU_LIST = 'E_EMPTY_SKU_LIST',\n}\n\n// Fast lookup set for validating standardized error code strings\nconst OPENIAP_ERROR_CODE_SET: Set<string> = new Set(\n Object.values(ErrorCode) as string[],\n);\n\n/**\n * Platform-specific error code mappings\n * Maps ErrorCode enum values to platform-specific integer codes\n */\n// Shared OpenIAP string code mapping for both platforms\nconst COMMON_ERROR_CODE_MAP = {\n [ErrorCode.E_UNKNOWN]: 'E_UNKNOWN',\n [ErrorCode.E_USER_CANCELLED]: 'E_USER_CANCELLED',\n [ErrorCode.E_USER_ERROR]: 'E_USER_ERROR',\n [ErrorCode.E_ITEM_UNAVAILABLE]: 'E_ITEM_UNAVAILABLE',\n [ErrorCode.E_REMOTE_ERROR]: 'E_REMOTE_ERROR',\n [ErrorCode.E_NETWORK_ERROR]: 'E_NETWORK_ERROR',\n [ErrorCode.E_SERVICE_ERROR]: 'E_SERVICE_ERROR',\n [ErrorCode.E_RECEIPT_FAILED]: 'E_RECEIPT_FAILED',\n [ErrorCode.E_RECEIPT_FINISHED]: 'E_RECEIPT_FINISHED',\n [ErrorCode.E_RECEIPT_FINISHED_FAILED]: 'E_RECEIPT_FINISHED_FAILED',\n [ErrorCode.E_NOT_PREPARED]: 'E_NOT_PREPARED',\n [ErrorCode.E_NOT_ENDED]: 'E_NOT_ENDED',\n [ErrorCode.E_ALREADY_OWNED]: 'E_ALREADY_OWNED',\n [ErrorCode.E_DEVELOPER_ERROR]: 'E_DEVELOPER_ERROR',\n [ErrorCode.E_BILLING_RESPONSE_JSON_PARSE_ERROR]:\n 'E_BILLING_RESPONSE_JSON_PARSE_ERROR',\n [ErrorCode.E_DEFERRED_PAYMENT]: 'E_DEFERRED_PAYMENT',\n [ErrorCode.E_INTERRUPTED]: 'E_INTERRUPTED',\n [ErrorCode.E_IAP_NOT_AVAILABLE]: 'E_IAP_NOT_AVAILABLE',\n [ErrorCode.E_PURCHASE_ERROR]: 'E_PURCHASE_ERROR',\n [ErrorCode.E_SYNC_ERROR]: 'E_SYNC_ERROR',\n [ErrorCode.E_TRANSACTION_VALIDATION_FAILED]:\n 'E_TRANSACTION_VALIDATION_FAILED',\n [ErrorCode.E_ACTIVITY_UNAVAILABLE]: 'E_ACTIVITY_UNAVAILABLE',\n [ErrorCode.E_ALREADY_PREPARED]: 'E_ALREADY_PREPARED',\n [ErrorCode.E_PENDING]: 'E_PENDING',\n [ErrorCode.E_CONNECTION_CLOSED]: 'E_CONNECTION_CLOSED',\n [ErrorCode.E_INIT_CONNECTION]: 'E_INIT_CONNECTION',\n [ErrorCode.E_SERVICE_DISCONNECTED]: 'E_SERVICE_DISCONNECTED',\n [ErrorCode.E_QUERY_PRODUCT]: 'E_QUERY_PRODUCT',\n [ErrorCode.E_SKU_NOT_FOUND]: 'E_SKU_NOT_FOUND',\n [ErrorCode.E_SKU_OFFER_MISMATCH]: 'E_SKU_OFFER_MISMATCH',\n [ErrorCode.E_ITEM_NOT_OWNED]: 'E_ITEM_NOT_OWNED',\n [ErrorCode.E_BILLING_UNAVAILABLE]: 'E_BILLING_UNAVAILABLE',\n [ErrorCode.E_FEATURE_NOT_SUPPORTED]: 'E_FEATURE_NOT_SUPPORTED',\n [ErrorCode.E_EMPTY_SKU_LIST]: 'E_EMPTY_SKU_LIST',\n} as const;\n\nexport const ErrorCodeMapping = {\n // iOS: standardized OpenIAP string codes\n ios: COMMON_ERROR_CODE_MAP,\n // Android: standardized OpenIAP string codes\n android: COMMON_ERROR_CODE_MAP,\n} as const;\n\nexport type PurchaseErrorProps = {\n message: string;\n responseCode?: number;\n debugMessage?: string;\n code?: ErrorCode;\n productId?: string;\n platform?: 'ios' | 'android';\n};\n\nexport class PurchaseError implements Error {\n public name: string;\n public message: string;\n public responseCode?: number;\n public debugMessage?: string;\n public code?: ErrorCode;\n public productId?: string;\n public platform?: 'ios' | 'android';\n\n // Backwards-compatible constructor: accepts either props object or legacy positional args\n constructor(messageOrProps: string | PurchaseErrorProps, ...rest: any[]) {\n this.name = '[expo-iap]: PurchaseError';\n\n if (typeof messageOrProps === 'string') {\n // Legacy signature: (name, message, responseCode?, debugMessage?, code?, productId?, platform?)\n // The first legacy argument was a name which we always override, so treat it as message here\n const message = messageOrProps;\n this.message = message;\n this.responseCode = rest[0];\n this.debugMessage = rest[1];\n this.code = rest[2];\n this.productId = rest[3];\n this.platform = rest[4];\n } else {\n const props = messageOrProps;\n this.message = props.message;\n this.responseCode = props.responseCode;\n this.debugMessage = props.debugMessage;\n this.code = props.code;\n this.productId = props.productId;\n this.platform = props.platform;\n }\n }\n\n /**\n * Creates a PurchaseError from platform-specific error data\n * @param errorData Raw error data from native modules\n * @param platform Platform where the error occurred\n * @returns Properly typed PurchaseError instance\n */\n static fromPlatformError(\n errorData: any,\n platform: 'ios' | 'android',\n ): PurchaseError {\n const errorCode = errorData.code\n ? ErrorCodeUtils.fromPlatformCode(errorData.code, platform)\n : ErrorCode.E_UNKNOWN;\n\n return new PurchaseError({\n message: errorData.message || 'Unknown error occurred',\n responseCode: errorData.responseCode,\n debugMessage: errorData.debugMessage,\n code: errorCode,\n productId: errorData.productId,\n platform,\n });\n }\n\n /**\n * Gets the platform-specific error code for this error\n * @returns Platform-specific error code\n */\n getPlatformCode(): string | number | undefined {\n if (!this.code || !this.platform) return undefined;\n return ErrorCodeUtils.toPlatformCode(this.code, this.platform);\n }\n}\n\n/**\n * Utility functions for error code mapping and validation\n */\nexport const ErrorCodeUtils = {\n /**\n * Gets the native error code for the current platform\n * @param errorCode ErrorCode enum value\n * @returns Platform-specific error code from native constants\n */\n getNativeErrorCode: (errorCode: ErrorCode): string => {\n return NATIVE_ERROR_CODES[errorCode] || errorCode;\n },\n\n /**\n * Maps a platform-specific error code back to the standardized ErrorCode enum\n * @param platformCode Platform-specific error code (string for Android, number for iOS)\n * @param platform Target platform\n * @returns Corresponding ErrorCode enum value or E_UNKNOWN if not found\n */\n fromPlatformCode: (\n platformCode: string | number,\n platform: 'ios' | 'android',\n ): ErrorCode => {\n // If native sent standardized string code, accept it directly\n if (typeof platformCode === 'string' && platformCode.startsWith('E_')) {\n if (OPENIAP_ERROR_CODE_SET.has(platformCode)) {\n return platformCode as ErrorCode;\n }\n }\n // Prefer dynamic native mapping for iOS to avoid drift\n if (platform === 'ios') {\n for (const [, value] of Object.entries(NATIVE_ERROR_CODES || {})) {\n if (value === platformCode) {\n // Native maps friendly keys to standardized 'E_*' codes\n if (typeof value === 'string' && OPENIAP_ERROR_CODE_SET.has(value)) {\n return value as ErrorCode;\n }\n }\n }\n }\n\n const mapping = ErrorCodeMapping[platform];\n for (const [errorCode, mappedCode] of Object.entries(mapping)) {\n if (mappedCode === platformCode) {\n return errorCode as ErrorCode;\n }\n }\n\n return ErrorCode.E_UNKNOWN;\n },\n\n /**\n * Maps an ErrorCode enum to platform-specific code\n * @param errorCode ErrorCode enum value\n * @param platform Target platform\n * @returns Platform-specific error code\n */\n toPlatformCode: (\n errorCode: ErrorCode,\n platform: 'ios' | 'android',\n ): string | number => {\n if (platform === 'ios') {\n const native = (NATIVE_ERROR_CODES as any)?.[errorCode];\n if (native !== undefined) return native;\n }\n const mapping = ErrorCodeMapping[platform] as Record<\n ErrorCode,\n string | number\n >;\n return mapping[errorCode] ?? 'E_UNKNOWN';\n },\n\n /**\n * Checks if an error code is valid for the specified platform\n * @param errorCode ErrorCode enum value\n * @param platform Target platform\n * @returns True if the error code is supported on the platform\n */\n isValidForPlatform: (\n errorCode: ErrorCode,\n platform: 'ios' | 'android',\n ): boolean => {\n return errorCode in ErrorCodeMapping[platform];\n },\n};\n\n// ============================================================================\n// Enhanced Unified Request Types\n// ============================================================================\n\n/**\n * Unified request props that work on both iOS and Android platforms\n * iOS will use 'sku', Android will use 'skus' (or convert sku to skus array)\n */\nexport interface UnifiedRequestPurchaseProps {\n // Universal properties - works on both platforms\n readonly sku?: string; // Single SKU (iOS native, Android fallback)\n readonly skus?: string[]; // Multiple SKUs (Android native, iOS uses first item)\n\n // iOS-specific properties (ignored on Android)\n readonly andDangerouslyFinishTransactionAutomatically?: boolean;\n readonly appAccountToken?: string;\n readonly quantity?: number;\n readonly withOffer?: import('./types/ExpoIapIOS.types').PaymentDiscount;\n\n // Android-specific properties (ignored on iOS)\n readonly obfuscatedAccountIdAndroid?: string;\n readonly obfuscatedProfileIdAndroid?: string;\n readonly isOfferPersonalized?: boolean;\n}\n\n// ============================================================================\n// New Platform-Specific Request Types (v2.7.0+)\n// ============================================================================\n\n/**\n * iOS-specific purchase request parameters\n */\nexport interface RequestPurchaseIosProps {\n readonly sku: string;\n readonly andDangerouslyFinishTransactionAutomatically?: boolean;\n readonly appAccountToken?: string;\n readonly quantity?: number;\n readonly withOffer?: import('./types/ExpoIapIOS.types').PaymentDiscount;\n}\n\n/**\n * Android-specific purchase request parameters\n */\nexport interface RequestPurchaseAndroidProps {\n readonly skus: string[];\n readonly obfuscatedAccountIdAndroid?: string;\n readonly obfuscatedProfileIdAndroid?: string;\n readonly isOfferPersonalized?: boolean;\n}\n\n/**\n * Android-specific subscription request parameters\n */\nexport interface RequestSubscriptionAndroidProps\n extends RequestPurchaseAndroidProps {\n readonly purchaseTokenAndroid?: string;\n readonly replacementModeAndroid?: number;\n readonly subscriptionOffers: {\n sku: string;\n offerToken: string;\n }[];\n}\n\n/**\n * Modern platform-specific request structure (v2.7.0+)\n * Allows clear separation of iOS and Android parameters\n */\nexport interface RequestPurchasePropsByPlatforms {\n readonly ios?: RequestPurchaseIosProps;\n readonly android?: RequestPurchaseAndroidProps;\n}\n\n/**\n * Modern platform-specific subscription request structure (v2.7.0+)\n */\nexport interface RequestSubscriptionPropsByPlatforms {\n readonly ios?: RequestPurchaseIosProps;\n readonly android?: RequestSubscriptionAndroidProps;\n}\n\n/**\n * Modern request purchase parameters (v2.7.0+)\n * This is the recommended API moving forward\n */\nexport type RequestPurchaseProps = RequestPurchasePropsByPlatforms;\n\n/**\n * Modern request subscription parameters (v2.7.0+)\n * This is the recommended API moving forward\n */\nexport type RequestSubscriptionProps = RequestSubscriptionPropsByPlatforms;\n"]}
|
|
1
|
+
{"version":3,"file":"ExpoIap.types.js","sourceRoot":"","sources":["../src/ExpoIap.types.ts"],"names":[],"mappings":"AAUA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAoDnD,8DAA8D;AAC9D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AAczC;;;GAGG;AACH,MAAM,CAAN,IAAY,SAoCX;AApCD,WAAY,SAAS;IACnB,oCAAuB,CAAA;IACvB,kDAAqC,CAAA;IACrC,0CAA6B,CAAA;IAC7B,sDAAyC,CAAA;IACzC,8CAAiC,CAAA;IACjC,gDAAmC,CAAA;IACnC,gDAAmC,CAAA;IACnC,kDAAqC,CAAA;IACrC,sDAAyC,CAAA;IACzC,oEAAuD,CAAA;IACvD,8CAAiC,CAAA;IACjC,wCAA2B,CAAA;IAC3B,gDAAmC,CAAA;IACnC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from './types/ExpoIapAndroid.types';\nimport type {\n ProductIOS,\n PurchaseIOS,\n ProductSubscriptionIOS,\n} from './types/ExpoIapIOS.types';\nimport {NATIVE_ERROR_CODES} from './ExpoIapModule';\n\nexport type ChangeEventPayload = {\n value: string;\n};\n\nexport type ProductType = 'inapp' | 'subs';\n\n// =============================================================================\n// COMMON TYPES (Base types shared across all platforms)\n// =============================================================================\n\nexport type ProductCommon = {\n id: string;\n title: string;\n description: string;\n type: ProductType;\n displayName?: string;\n displayPrice: string;\n currency: string;\n price?: number;\n debugDescription?: string;\n platform?: string;\n};\n\nexport type PurchaseCommon = {\n id: string; // Transaction identifier - used by finishTransaction\n productId: string; // Product identifier - which product was purchased\n ids?: string[]; // Product identifiers for purchases that include multiple products\n transactionDate: number;\n transactionReceipt: string;\n purchaseToken?: string; // Unified purchase token (jwsRepresentation for iOS, purchaseToken for Android)\n platform?: string;\n};\n\nexport type ProductSubscriptionCommon = ProductCommon & {\n type: 'subs';\n};\n\n// Define literal platform types for better type discrimination\nexport type IosPlatform = {platform: 'ios'};\nexport type AndroidPlatform = {platform: 'android'};\n\n// Platform-agnostic unified product types (public API)\nexport type Product =\n | (ProductAndroid & AndroidPlatform)\n | (ProductIOS & IosPlatform);\n\nexport type SubscriptionProduct =\n | (ProductSubscriptionAndroid & AndroidPlatform)\n | (ProductSubscriptionIOS & IosPlatform);\n\n// Re-export all platform-specific types to avoid deep imports\nexport * from './types/ExpoIapAndroid.types';\nexport * from './types/ExpoIapIOS.types';\n\n// Unified purchase type for both products and subscriptions\nexport type Purchase =\n | (PurchaseAndroid & AndroidPlatform)\n | (PurchaseIOS & IosPlatform);\n\nexport type PurchaseResult = {\n responseCode?: number;\n debugMessage?: string;\n code?: string;\n message?: string;\n purchaseToken?: string;\n};\n/**\n * Centralized error codes for expo-iap\n * These are mapped to platform-specific error codes and provide consistent error handling\n */\nexport enum ErrorCode {\n E_UNKNOWN = 'E_UNKNOWN',\n E_USER_CANCELLED = 'E_USER_CANCELLED',\n E_USER_ERROR = 'E_USER_ERROR',\n E_ITEM_UNAVAILABLE = 'E_ITEM_UNAVAILABLE',\n E_REMOTE_ERROR = 'E_REMOTE_ERROR',\n E_NETWORK_ERROR = 'E_NETWORK_ERROR',\n E_SERVICE_ERROR = 'E_SERVICE_ERROR',\n E_RECEIPT_FAILED = 'E_RECEIPT_FAILED',\n E_RECEIPT_FINISHED = 'E_RECEIPT_FINISHED',\n E_RECEIPT_FINISHED_FAILED = 'E_RECEIPT_FINISHED_FAILED',\n E_NOT_PREPARED = 'E_NOT_PREPARED',\n E_NOT_ENDED = 'E_NOT_ENDED',\n E_ALREADY_OWNED = 'E_ALREADY_OWNED',\n E_DEVELOPER_ERROR = 'E_DEVELOPER_ERROR',\n E_BILLING_RESPONSE_JSON_PARSE_ERROR = 'E_BILLING_RESPONSE_JSON_PARSE_ERROR',\n E_DEFERRED_PAYMENT = 'E_DEFERRED_PAYMENT',\n E_INTERRUPTED = 'E_INTERRUPTED',\n E_IAP_NOT_AVAILABLE = 'E_IAP_NOT_AVAILABLE',\n E_PURCHASE_ERROR = 'E_PURCHASE_ERROR',\n E_SYNC_ERROR = 'E_SYNC_ERROR',\n E_TRANSACTION_VALIDATION_FAILED = 'E_TRANSACTION_VALIDATION_FAILED',\n E_ACTIVITY_UNAVAILABLE = 'E_ACTIVITY_UNAVAILABLE',\n E_ALREADY_PREPARED = 'E_ALREADY_PREPARED',\n E_PENDING = 'E_PENDING',\n E_CONNECTION_CLOSED = 'E_CONNECTION_CLOSED',\n // Additional detailed errors (Android-focused, kept cross-platform)\n E_INIT_CONNECTION = 'E_INIT_CONNECTION',\n E_SERVICE_DISCONNECTED = 'E_SERVICE_DISCONNECTED',\n E_QUERY_PRODUCT = 'E_QUERY_PRODUCT',\n E_SKU_NOT_FOUND = 'E_SKU_NOT_FOUND',\n E_SKU_OFFER_MISMATCH = 'E_SKU_OFFER_MISMATCH',\n E_ITEM_NOT_OWNED = 'E_ITEM_NOT_OWNED',\n E_BILLING_UNAVAILABLE = 'E_BILLING_UNAVAILABLE',\n E_FEATURE_NOT_SUPPORTED = 'E_FEATURE_NOT_SUPPORTED',\n E_EMPTY_SKU_LIST = 'E_EMPTY_SKU_LIST',\n}\n\n// Fast lookup set for validating standardized error code strings\nconst OPENIAP_ERROR_CODE_SET: Set<string> = new Set(\n Object.values(ErrorCode) as string[],\n);\n\n/**\n * Platform-specific error code mappings\n * Maps ErrorCode enum values to platform-specific integer codes\n */\n// Shared OpenIAP string code mapping for both platforms\nconst COMMON_ERROR_CODE_MAP = {\n [ErrorCode.E_UNKNOWN]: 'E_UNKNOWN',\n [ErrorCode.E_USER_CANCELLED]: 'E_USER_CANCELLED',\n [ErrorCode.E_USER_ERROR]: 'E_USER_ERROR',\n [ErrorCode.E_ITEM_UNAVAILABLE]: 'E_ITEM_UNAVAILABLE',\n [ErrorCode.E_REMOTE_ERROR]: 'E_REMOTE_ERROR',\n [ErrorCode.E_NETWORK_ERROR]: 'E_NETWORK_ERROR',\n [ErrorCode.E_SERVICE_ERROR]: 'E_SERVICE_ERROR',\n [ErrorCode.E_RECEIPT_FAILED]: 'E_RECEIPT_FAILED',\n [ErrorCode.E_RECEIPT_FINISHED]: 'E_RECEIPT_FINISHED',\n [ErrorCode.E_RECEIPT_FINISHED_FAILED]: 'E_RECEIPT_FINISHED_FAILED',\n [ErrorCode.E_NOT_PREPARED]: 'E_NOT_PREPARED',\n [ErrorCode.E_NOT_ENDED]: 'E_NOT_ENDED',\n [ErrorCode.E_ALREADY_OWNED]: 'E_ALREADY_OWNED',\n [ErrorCode.E_DEVELOPER_ERROR]: 'E_DEVELOPER_ERROR',\n [ErrorCode.E_BILLING_RESPONSE_JSON_PARSE_ERROR]:\n 'E_BILLING_RESPONSE_JSON_PARSE_ERROR',\n [ErrorCode.E_DEFERRED_PAYMENT]: 'E_DEFERRED_PAYMENT',\n [ErrorCode.E_INTERRUPTED]: 'E_INTERRUPTED',\n [ErrorCode.E_IAP_NOT_AVAILABLE]: 'E_IAP_NOT_AVAILABLE',\n [ErrorCode.E_PURCHASE_ERROR]: 'E_PURCHASE_ERROR',\n [ErrorCode.E_SYNC_ERROR]: 'E_SYNC_ERROR',\n [ErrorCode.E_TRANSACTION_VALIDATION_FAILED]:\n 'E_TRANSACTION_VALIDATION_FAILED',\n [ErrorCode.E_ACTIVITY_UNAVAILABLE]: 'E_ACTIVITY_UNAVAILABLE',\n [ErrorCode.E_ALREADY_PREPARED]: 'E_ALREADY_PREPARED',\n [ErrorCode.E_PENDING]: 'E_PENDING',\n [ErrorCode.E_CONNECTION_CLOSED]: 'E_CONNECTION_CLOSED',\n [ErrorCode.E_INIT_CONNECTION]: 'E_INIT_CONNECTION',\n [ErrorCode.E_SERVICE_DISCONNECTED]: 'E_SERVICE_DISCONNECTED',\n [ErrorCode.E_QUERY_PRODUCT]: 'E_QUERY_PRODUCT',\n [ErrorCode.E_SKU_NOT_FOUND]: 'E_SKU_NOT_FOUND',\n [ErrorCode.E_SKU_OFFER_MISMATCH]: 'E_SKU_OFFER_MISMATCH',\n [ErrorCode.E_ITEM_NOT_OWNED]: 'E_ITEM_NOT_OWNED',\n [ErrorCode.E_BILLING_UNAVAILABLE]: 'E_BILLING_UNAVAILABLE',\n [ErrorCode.E_FEATURE_NOT_SUPPORTED]: 'E_FEATURE_NOT_SUPPORTED',\n [ErrorCode.E_EMPTY_SKU_LIST]: 'E_EMPTY_SKU_LIST',\n} as const;\n\nexport const ErrorCodeMapping = {\n // iOS: standardized OpenIAP string codes\n ios: COMMON_ERROR_CODE_MAP,\n // Android: standardized OpenIAP string codes\n android: COMMON_ERROR_CODE_MAP,\n} as const;\n\nexport type PurchaseErrorProps = {\n message: string;\n responseCode?: number;\n debugMessage?: string;\n code?: ErrorCode;\n productId?: string;\n platform?: 'ios' | 'android';\n};\n\nexport class PurchaseError implements Error {\n public name: string;\n public message: string;\n public responseCode?: number;\n public debugMessage?: string;\n public code?: ErrorCode;\n public productId?: string;\n public platform?: 'ios' | 'android';\n\n // Backwards-compatible constructor: accepts either props object or legacy positional args\n constructor(messageOrProps: string | PurchaseErrorProps, ...rest: any[]) {\n this.name = '[expo-iap]: PurchaseError';\n\n if (typeof messageOrProps === 'string') {\n // Legacy signature: (name, message, responseCode?, debugMessage?, code?, productId?, platform?)\n // The first legacy argument was a name which we always override, so treat it as message here\n const message = messageOrProps;\n this.message = message;\n this.responseCode = rest[0];\n this.debugMessage = rest[1];\n this.code = rest[2];\n this.productId = rest[3];\n this.platform = rest[4];\n } else {\n const props = messageOrProps;\n this.message = props.message;\n this.responseCode = props.responseCode;\n this.debugMessage = props.debugMessage;\n this.code = props.code;\n this.productId = props.productId;\n this.platform = props.platform;\n }\n }\n\n /**\n * Creates a PurchaseError from platform-specific error data\n * @param errorData Raw error data from native modules\n * @param platform Platform where the error occurred\n * @returns Properly typed PurchaseError instance\n */\n static fromPlatformError(\n errorData: any,\n platform: 'ios' | 'android',\n ): PurchaseError {\n const errorCode = errorData.code\n ? ErrorCodeUtils.fromPlatformCode(errorData.code, platform)\n : ErrorCode.E_UNKNOWN;\n\n return new PurchaseError({\n message: errorData.message || 'Unknown error occurred',\n responseCode: errorData.responseCode,\n debugMessage: errorData.debugMessage,\n code: errorCode,\n productId: errorData.productId,\n platform,\n });\n }\n\n /**\n * Gets the platform-specific error code for this error\n * @returns Platform-specific error code\n */\n getPlatformCode(): string | number | undefined {\n if (!this.code || !this.platform) return undefined;\n return ErrorCodeUtils.toPlatformCode(this.code, this.platform);\n }\n}\n\n/**\n * Utility functions for error code mapping and validation\n */\nexport const ErrorCodeUtils = {\n /**\n * Gets the native error code for the current platform\n * @param errorCode ErrorCode enum value\n * @returns Platform-specific error code from native constants\n */\n getNativeErrorCode: (errorCode: ErrorCode): string => {\n return NATIVE_ERROR_CODES[errorCode] || errorCode;\n },\n\n /**\n * Maps a platform-specific error code back to the standardized ErrorCode enum\n * @param platformCode Platform-specific error code (string for Android, number for iOS)\n * @param platform Target platform\n * @returns Corresponding ErrorCode enum value or E_UNKNOWN if not found\n */\n fromPlatformCode: (\n platformCode: string | number,\n platform: 'ios' | 'android',\n ): ErrorCode => {\n // If native sent standardized string code, accept it directly\n if (typeof platformCode === 'string' && platformCode.startsWith('E_')) {\n if (OPENIAP_ERROR_CODE_SET.has(platformCode)) {\n return platformCode as ErrorCode;\n }\n }\n // Prefer dynamic native mapping for iOS to avoid drift\n if (platform === 'ios') {\n for (const [, value] of Object.entries(NATIVE_ERROR_CODES || {})) {\n if (value === platformCode) {\n // Native maps friendly keys to standardized 'E_*' codes\n if (typeof value === 'string' && OPENIAP_ERROR_CODE_SET.has(value)) {\n return value as ErrorCode;\n }\n }\n }\n }\n\n const mapping = ErrorCodeMapping[platform];\n for (const [errorCode, mappedCode] of Object.entries(mapping)) {\n if (mappedCode === platformCode) {\n return errorCode as ErrorCode;\n }\n }\n\n return ErrorCode.E_UNKNOWN;\n },\n\n /**\n * Maps an ErrorCode enum to platform-specific code\n * @param errorCode ErrorCode enum value\n * @param platform Target platform\n * @returns Platform-specific error code\n */\n toPlatformCode: (\n errorCode: ErrorCode,\n platform: 'ios' | 'android',\n ): string | number => {\n if (platform === 'ios') {\n const native = (NATIVE_ERROR_CODES as any)?.[errorCode];\n if (native !== undefined) return native;\n }\n const mapping = ErrorCodeMapping[platform] as Record<\n ErrorCode,\n string | number\n >;\n return mapping[errorCode] ?? 'E_UNKNOWN';\n },\n\n /**\n * Checks if an error code is valid for the specified platform\n * @param errorCode ErrorCode enum value\n * @param platform Target platform\n * @returns True if the error code is supported on the platform\n */\n isValidForPlatform: (\n errorCode: ErrorCode,\n platform: 'ios' | 'android',\n ): boolean => {\n return errorCode in ErrorCodeMapping[platform];\n },\n};\n\n// ============================================================================\n// Enhanced Unified Request Types\n// ============================================================================\n\n/**\n * Unified request props that work on both iOS and Android platforms\n * iOS will use 'sku', Android will use 'skus' (or convert sku to skus array)\n */\nexport interface UnifiedRequestPurchaseProps {\n // Universal properties - works on both platforms\n readonly sku?: string; // Single SKU (iOS native, Android fallback)\n readonly skus?: string[]; // Multiple SKUs (Android native, iOS uses first item)\n\n // iOS-specific properties (ignored on Android)\n readonly andDangerouslyFinishTransactionAutomatically?: boolean;\n readonly appAccountToken?: string;\n readonly quantity?: number;\n readonly withOffer?: import('./types/ExpoIapIOS.types').PaymentDiscount;\n\n // Android-specific properties (ignored on iOS)\n readonly obfuscatedAccountIdAndroid?: string;\n readonly obfuscatedProfileIdAndroid?: string;\n readonly isOfferPersonalized?: boolean;\n}\n\n// ============================================================================\n// New Platform-Specific Request Types (v2.7.0+)\n// ============================================================================\n\n/**\n * iOS-specific purchase request parameters\n */\nexport interface RequestPurchaseIosProps {\n readonly sku: string;\n readonly andDangerouslyFinishTransactionAutomatically?: boolean;\n readonly appAccountToken?: string;\n readonly quantity?: number;\n readonly withOffer?: import('./types/ExpoIapIOS.types').PaymentDiscount;\n}\n\n/**\n * Android-specific purchase request parameters\n */\nexport interface RequestPurchaseAndroidProps {\n readonly skus: string[];\n readonly obfuscatedAccountIdAndroid?: string;\n readonly obfuscatedProfileIdAndroid?: string;\n readonly isOfferPersonalized?: boolean;\n}\n\n/**\n * Android-specific subscription request parameters\n */\nexport interface RequestSubscriptionAndroidProps\n extends RequestPurchaseAndroidProps {\n readonly replacementModeAndroid?: number;\n readonly subscriptionOffers: {\n sku: string;\n offerToken: string;\n }[];\n}\n\n/**\n * Modern platform-specific request structure (v2.7.0+)\n * Allows clear separation of iOS and Android parameters\n */\nexport interface RequestPurchasePropsByPlatforms {\n readonly ios?: RequestPurchaseIosProps;\n readonly android?: RequestPurchaseAndroidProps;\n}\n\n/**\n * Modern platform-specific subscription request structure (v2.7.0+)\n */\nexport interface RequestSubscriptionPropsByPlatforms {\n readonly ios?: RequestPurchaseIosProps;\n readonly android?: RequestSubscriptionAndroidProps;\n}\n\n/**\n * Modern request purchase parameters (v2.7.0+)\n * This is the recommended API moving forward\n */\nexport type RequestPurchaseProps = RequestPurchasePropsByPlatforms;\n\n/**\n * Modern request subscription parameters (v2.7.0+)\n * This is the recommended API moving forward\n */\nexport type RequestSubscriptionProps = RequestSubscriptionPropsByPlatforms;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../src/helpers/subscription.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,IAAI,CAAC;IACzB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,kBAAkB,MAAM,EAAE,KACzB,OAAO,CAAC,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"subscription.d.ts","sourceRoot":"","sources":["../../src/helpers/subscription.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,IAAI,CAAC;IACzB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,kBAAkB,MAAM,EAAE,KACzB,OAAO,CAAC,kBAAkB,EAAE,CA6G9B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,kBAAkB,MAAM,EAAE,KACzB,OAAO,CAAC,OAAO,CAGjB,CAAC"}
|
|
@@ -20,7 +20,8 @@ export const getActiveSubscriptions = async (subscriptionIds) => {
|
|
|
20
20
|
}
|
|
21
21
|
// Check if this purchase has subscription-specific fields
|
|
22
22
|
const hasSubscriptionFields = ('expirationDateIOS' in purchase && !!purchase.expirationDateIOS) ||
|
|
23
|
-
'autoRenewingAndroid' in purchase
|
|
23
|
+
'autoRenewingAndroid' in purchase ||
|
|
24
|
+
('environmentIOS' in purchase && !!purchase.environmentIOS);
|
|
24
25
|
if (!hasSubscriptionFields) {
|
|
25
26
|
return false;
|
|
26
27
|
}
|
|
@@ -50,12 +51,22 @@ export const getActiveSubscriptions = async (subscriptionIds) => {
|
|
|
50
51
|
}
|
|
51
52
|
return false;
|
|
52
53
|
});
|
|
54
|
+
// Deduplicate by transaction identifier (id)
|
|
55
|
+
const seen = new Set();
|
|
56
|
+
const dedupedPurchases = filteredPurchases.filter((p) => {
|
|
57
|
+
const key = String(p.id);
|
|
58
|
+
if (seen.has(key))
|
|
59
|
+
return false;
|
|
60
|
+
seen.add(key);
|
|
61
|
+
return true;
|
|
62
|
+
});
|
|
53
63
|
// Convert to ActiveSubscription format
|
|
54
|
-
for (const purchase of
|
|
64
|
+
for (const purchase of dedupedPurchases) {
|
|
55
65
|
const subscription = {
|
|
56
66
|
productId: purchase.productId,
|
|
57
67
|
isActive: true,
|
|
58
|
-
|
|
68
|
+
// Use unified id as transaction identifier in v3
|
|
69
|
+
transactionId: purchase.id,
|
|
59
70
|
purchaseToken: purchase.purchaseToken,
|
|
60
71
|
transactionDate: purchase.transactionDate,
|
|
61
72
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../../src/helpers/subscription.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AACtC,OAA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AG,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CACnE,CAAC;oBACF,YAAY,CAAC,sBAAsB,GAAG,mBAAmB,CAAC;oBAC1D,YAAY,CAAC,cAAc,GAAG,mBAAmB,IAAI,CAAC,CAAC;gBACzD,CAAC;gBAED,IAAI,gBAAgB,IAAI,QAAQ,EAAE,CAAC;oBACjC,YAAY,CAAC,cAAc,GAAG,QAAQ,CAAC,cAAc,CAAC;gBACxD,CAAC;YACH,CAAC;iBAAM,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,EAAE,CAAC;gBACrC,IAAI,qBAAqB,IAAI,QAAQ,EAAE,CAAC;oBACtC,YAAY,CAAC,mBAAmB,GAAG,QAAQ,CAAC,mBAAmB,CAAC;oBAChE,2DAA2D;oBAC3D,YAAY,CAAC,cAAc,GAAG,CAAC,QAAQ,CAAC,mBAAmB,CAAC;gBAC9D,CAAC;YACH,CAAC;YAED,mBAAmB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACzC,CAAC;QAED,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;QAC5D,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EACzC,eAA0B,EACR,EAAE;IACpB,MAAM,aAAa,GAAG,MAAM,sBAAsB,CAAC,eAAe,CAAC,CAAC;IACpE,OAAO,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;AAClC,CAAC,CAAC","sourcesContent":["import {Platform} from 'react-native';\nimport {getAvailablePurchases} from '../index';\n\nexport interface ActiveSubscription {\n productId: string;\n isActive: boolean;\n transactionId: string; // Transaction identifier for backend validation\n purchaseToken?: string; // JWT token (iOS) or purchase token (Android) for backend validation\n transactionDate: number; // Transaction timestamp\n expirationDateIOS?: Date;\n autoRenewingAndroid?: boolean;\n environmentIOS?: string;\n willExpireSoon?: boolean;\n daysUntilExpirationIOS?: number;\n}\n\n/**\n * Get all active subscriptions with detailed information\n * @param subscriptionIds - Optional array of subscription product IDs to filter. If not provided, returns all active subscriptions.\n * @returns Promise<ActiveSubscription[]> array of active subscriptions with details\n */\nexport const getActiveSubscriptions = async (\n subscriptionIds?: string[],\n): Promise<ActiveSubscription[]> => {\n try {\n const purchases = await getAvailablePurchases();\n const currentTime = Date.now();\n const activeSubscriptions: ActiveSubscription[] = [];\n\n // Filter purchases to find active subscriptions\n const filteredPurchases = purchases.filter((purchase) => {\n // If specific IDs provided, filter by them\n if (subscriptionIds && subscriptionIds.length > 0) {\n if (!subscriptionIds.includes(purchase.productId)) {\n return false;\n }\n }\n\n // Check if this purchase has subscription-specific fields\n const hasSubscriptionFields =\n ('expirationDateIOS' in purchase && !!purchase.expirationDateIOS) ||\n 'autoRenewingAndroid' in purchase ||\n ('environmentIOS' in purchase && !!(purchase as any).environmentIOS);\n\n if (!hasSubscriptionFields) {\n return false;\n }\n\n // Check if it's actually active\n if (Platform.OS === 'ios') {\n if ('expirationDateIOS' in purchase && purchase.expirationDateIOS) {\n return purchase.expirationDateIOS > currentTime;\n }\n // For iOS purchases without expiration date (like Sandbox), we consider them active\n // if they have the environmentIOS field and were created recently\n if ('environmentIOS' in purchase && purchase.environmentIOS) {\n const dayInMs = 24 * 60 * 60 * 1000;\n // If no expiration date, consider active if transaction is recent (within 24 hours for Sandbox)\n if (\n !('expirationDateIOS' in purchase) ||\n !purchase.expirationDateIOS\n ) {\n if (\n purchase.environmentIOS === 'Sandbox' &&\n purchase.transactionDate &&\n currentTime - purchase.transactionDate < dayInMs\n ) {\n return true;\n }\n }\n }\n } else if (Platform.OS === 'android') {\n // For Android, if it's in the purchases list, it's active\n return true;\n }\n\n return false;\n });\n\n // Deduplicate by transaction identifier (id)\n const seen = new Set<string>();\n const dedupedPurchases = filteredPurchases.filter((p) => {\n const key = String(p.id);\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n });\n\n // Convert to ActiveSubscription format\n for (const purchase of dedupedPurchases) {\n const subscription: ActiveSubscription = {\n productId: purchase.productId,\n isActive: true,\n // Use unified id as transaction identifier in v3\n transactionId: purchase.id,\n purchaseToken: purchase.purchaseToken,\n transactionDate: purchase.transactionDate,\n };\n\n // Add platform-specific details\n if (Platform.OS === 'ios') {\n if ('expirationDateIOS' in purchase && purchase.expirationDateIOS) {\n const expirationDate = new Date(purchase.expirationDateIOS);\n subscription.expirationDateIOS = expirationDate;\n\n // Calculate days until expiration (round to nearest day)\n const daysUntilExpiration = Math.round(\n (purchase.expirationDateIOS - currentTime) / (1000 * 60 * 60 * 24),\n );\n subscription.daysUntilExpirationIOS = daysUntilExpiration;\n subscription.willExpireSoon = daysUntilExpiration <= 7;\n }\n\n if ('environmentIOS' in purchase) {\n subscription.environmentIOS = purchase.environmentIOS;\n }\n } else if (Platform.OS === 'android') {\n if ('autoRenewingAndroid' in purchase) {\n subscription.autoRenewingAndroid = purchase.autoRenewingAndroid;\n // If auto-renewing is false, subscription will expire soon\n subscription.willExpireSoon = !purchase.autoRenewingAndroid;\n }\n }\n\n activeSubscriptions.push(subscription);\n }\n\n return activeSubscriptions;\n } catch (error) {\n console.error('Error getting active subscriptions:', error);\n return [];\n }\n};\n\n/**\n * Check if user has any active subscriptions\n * @param subscriptionIds - Optional array of subscription product IDs to check. If not provided, checks all subscriptions.\n * @returns Promise<boolean> true if user has at least one active subscription\n */\nexport const hasActiveSubscriptions = async (\n subscriptionIds?: string[],\n): Promise<boolean> => {\n const subscriptions = await getActiveSubscriptions(subscriptionIds);\n return subscriptions.length > 0;\n};\n"]}
|
package/build/index.d.ts
CHANGED
|
@@ -7,8 +7,6 @@ export declare const PI: any;
|
|
|
7
7
|
export declare enum OpenIapEvent {
|
|
8
8
|
PurchaseUpdated = "purchase-updated",
|
|
9
9
|
PurchaseError = "purchase-error",
|
|
10
|
-
/** @deprecated Use PurchaseUpdated instead. This will be removed in a future version. */
|
|
11
|
-
TransactionIapUpdated = "iap-transaction-updated",
|
|
12
10
|
PromotedProductIOS = "promoted-product-ios"
|
|
13
11
|
}
|
|
14
12
|
export declare function setValueAsync(value: string): any;
|
|
@@ -48,8 +46,6 @@ export declare const promotedProductListenerIOS: (listener: (product: Product) =
|
|
|
48
46
|
remove: () => void;
|
|
49
47
|
};
|
|
50
48
|
export declare function initConnection(): Promise<boolean>;
|
|
51
|
-
export declare const getProducts: (skus: string[]) => Promise<Product[]>;
|
|
52
|
-
export declare const getSubscriptions: (skus: string[]) => Promise<SubscriptionProduct[]>;
|
|
53
49
|
export declare function endConnection(): Promise<boolean>;
|
|
54
50
|
/**
|
|
55
51
|
* Fetch products with unified API (v2.7.0+)
|
|
@@ -77,48 +73,7 @@ export declare const fetchProducts: ({ skus, type, }: {
|
|
|
77
73
|
skus: string[];
|
|
78
74
|
type?: "inapp" | "subs";
|
|
79
75
|
}) => Promise<Product[] | SubscriptionProduct[]>;
|
|
80
|
-
|
|
81
|
-
* @deprecated Use `fetchProducts` instead. This method will be removed in version 3.0.0.
|
|
82
|
-
*
|
|
83
|
-
* The 'request' prefix should only be used for event-based operations that trigger
|
|
84
|
-
* purchase flows. Since this function simply fetches product information, it has been
|
|
85
|
-
* renamed to `fetchProducts` to follow OpenIAP terminology guidelines.
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```typescript
|
|
89
|
-
* // Old way (deprecated)
|
|
90
|
-
* const products = await requestProducts({
|
|
91
|
-
* skus: ['com.example.product1'],
|
|
92
|
-
* type: 'inapp'
|
|
93
|
-
* });
|
|
94
|
-
*
|
|
95
|
-
* // New way (recommended)
|
|
96
|
-
* const products = await fetchProducts({
|
|
97
|
-
* skus: ['com.example.product1'],
|
|
98
|
-
* type: 'inapp'
|
|
99
|
-
* });
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
export declare const requestProducts: ({ skus, type, }: {
|
|
103
|
-
skus: string[];
|
|
104
|
-
type?: "inapp" | "subs";
|
|
105
|
-
}) => Promise<Product[] | SubscriptionProduct[]>;
|
|
106
|
-
/**
|
|
107
|
-
* @deprecated Use `getPurchaseHistories` instead. This function will be removed in version 3.0.0.
|
|
108
|
-
*/
|
|
109
|
-
export declare const getPurchaseHistory: ({ alsoPublishToEventListener, onlyIncludeActiveItems, alsoPublishToEventListenerIOS, onlyIncludeActiveItemsIOS, }?: {
|
|
110
|
-
/** @deprecated Use alsoPublishToEventListenerIOS instead */
|
|
111
|
-
alsoPublishToEventListener?: boolean;
|
|
112
|
-
/** @deprecated Use onlyIncludeActiveItemsIOS instead */
|
|
113
|
-
onlyIncludeActiveItems?: boolean;
|
|
114
|
-
alsoPublishToEventListenerIOS?: boolean;
|
|
115
|
-
onlyIncludeActiveItemsIOS?: boolean;
|
|
116
|
-
}) => Promise<Purchase[]>;
|
|
117
|
-
export declare const getAvailablePurchases: ({ alsoPublishToEventListener, onlyIncludeActiveItems, alsoPublishToEventListenerIOS, onlyIncludeActiveItemsIOS, }?: {
|
|
118
|
-
/** @deprecated Use alsoPublishToEventListenerIOS instead */
|
|
119
|
-
alsoPublishToEventListener?: boolean;
|
|
120
|
-
/** @deprecated Use onlyIncludeActiveItemsIOS instead */
|
|
121
|
-
onlyIncludeActiveItems?: boolean;
|
|
76
|
+
export declare const getAvailablePurchases: ({ alsoPublishToEventListenerIOS, onlyIncludeActiveItemsIOS, }?: {
|
|
122
77
|
alsoPublishToEventListenerIOS?: boolean;
|
|
123
78
|
onlyIncludeActiveItemsIOS?: boolean;
|
|
124
79
|
}) => Promise<Purchase[]>;
|
|
@@ -178,32 +133,6 @@ type PurchaseRequest = {
|
|
|
178
133
|
* ```
|
|
179
134
|
*/
|
|
180
135
|
export declare const requestPurchase: (requestObj: PurchaseRequest) => Promise<Purchase | Purchase[] | void>;
|
|
181
|
-
/**
|
|
182
|
-
* @deprecated Use `requestPurchase({ request, type: 'subs' })` instead. This method will be removed in version 3.0.0.
|
|
183
|
-
*
|
|
184
|
-
* @example
|
|
185
|
-
* ```typescript
|
|
186
|
-
* // Old way (deprecated)
|
|
187
|
-
* await requestSubscription({
|
|
188
|
-
* sku: subscriptionId,
|
|
189
|
-
* // or for Android
|
|
190
|
-
* skus: [subscriptionId],
|
|
191
|
-
* });
|
|
192
|
-
*
|
|
193
|
-
* // New way (recommended)
|
|
194
|
-
* await requestPurchase({
|
|
195
|
-
* request: {
|
|
196
|
-
* ios: { sku: subscriptionId },
|
|
197
|
-
* android: {
|
|
198
|
-
* skus: [subscriptionId],
|
|
199
|
-
* subscriptionOffers: [{ sku: subscriptionId, offerToken: 'token' }]
|
|
200
|
-
* }
|
|
201
|
-
* },
|
|
202
|
-
* type: 'subs'
|
|
203
|
-
* });
|
|
204
|
-
* ```
|
|
205
|
-
*/
|
|
206
|
-
export declare const requestSubscription: (request: RequestSubscriptionProps) => Promise<Purchase | Purchase[] | null | void>;
|
|
207
136
|
export declare const finishTransaction: ({ purchase, isConsumable, }: {
|
|
208
137
|
purchase: Purchase;
|
|
209
138
|
isConsumable?: boolean;
|
|
@@ -224,7 +153,11 @@ export declare const finishTransaction: ({ purchase, isConsumable, }: {
|
|
|
224
153
|
*/
|
|
225
154
|
export declare const getStorefrontIOS: () => Promise<string>;
|
|
226
155
|
/**
|
|
227
|
-
*
|
|
156
|
+
* Gets the storefront country code from the underlying native store.
|
|
157
|
+
* Returns a two-letter country code such as 'US', 'KR', or empty string on failure.
|
|
158
|
+
*
|
|
159
|
+
* @platform ios
|
|
160
|
+
* @platform android
|
|
228
161
|
*/
|
|
229
162
|
export declare const getStorefront: () => Promise<string>;
|
|
230
163
|
/**
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,OAAO,EACP,QAAQ,EACR,aAAa,EAEb,cAAc,EACd,wBAAwB,EACxB,oBAAo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