expo-iap 3.0.4 → 3.0.5
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/.eslintignore +1 -1
- package/.eslintrc.js +1 -0
- package/.prettierignore +1 -0
- package/CHANGELOG.md +6 -0
- package/CLAUDE.md +1 -1
- package/CONTRIBUTING.md +10 -0
- package/android/build.gradle +1 -1
- package/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +12 -12
- package/android/src/main/java/expo/modules/iap/PromiseUtils.kt +2 -2
- package/build/index.d.ts +28 -14
- package/build/index.d.ts.map +1 -1
- package/build/index.js +36 -15
- package/build/index.js.map +1 -1
- package/build/modules/android.d.ts +3 -4
- package/build/modules/android.d.ts.map +1 -1
- package/build/modules/android.js +2 -4
- package/build/modules/android.js.map +1 -1
- package/build/modules/ios.d.ts +2 -3
- package/build/modules/ios.d.ts.map +1 -1
- package/build/modules/ios.js +1 -3
- package/build/modules/ios.js.map +1 -1
- package/build/purchase-error.d.ts +8 -10
- package/build/purchase-error.d.ts.map +1 -1
- package/build/purchase-error.js +4 -2
- package/build/purchase-error.js.map +1 -1
- package/build/types.d.ts +159 -204
- package/build/types.d.ts.map +1 -1
- package/build/types.js +1 -59
- package/build/types.js.map +1 -1
- package/build/useIAP.d.ts +5 -8
- package/build/useIAP.d.ts.map +1 -1
- package/build/useIAP.js.map +1 -1
- package/ios/ExpoIap.podspec +1 -1
- package/ios/ExpoIapModule.swift +103 -89
- package/package.json +2 -1
- package/plugin/build/withIAP.js +4 -5
- package/plugin/src/withIAP.ts +4 -5
- package/scripts/update-types.mjs +61 -0
- package/src/index.ts +77 -29
- package/src/modules/android.ts +5 -7
- package/src/modules/ios.ts +3 -5
- package/src/purchase-error.ts +13 -16
- package/src/types.ts +183 -216
- package/src/useIAP.ts +10 -10
package/build/modules/android.js
CHANGED
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
import { Linking } from 'react-native';
|
|
3
3
|
// Internal modules
|
|
4
4
|
import ExpoIapModule from '../ExpoIapModule';
|
|
5
|
-
import { Platform as PurchasePlatform } from '../types';
|
|
6
5
|
// Type guards
|
|
7
6
|
export function isProductAndroid(item) {
|
|
8
7
|
return (item != null &&
|
|
9
8
|
typeof item === 'object' &&
|
|
10
9
|
'platform' in item &&
|
|
11
|
-
|
|
12
|
-
item.platform === PurchasePlatform.Android));
|
|
10
|
+
item.platform === 'android');
|
|
13
11
|
}
|
|
14
12
|
/**
|
|
15
13
|
* Deep link to subscriptions screen on Android.
|
|
@@ -51,7 +49,7 @@ export const deepLinkToSubscriptionsAndroid = async ({ sku, packageName, }) => {
|
|
|
51
49
|
* @param {string} params.productId - product id for your in app product.
|
|
52
50
|
* @param {string} params.productToken - token for your purchase (called 'token' in the API documentation).
|
|
53
51
|
* @param {string} params.accessToken - OAuth access token with androidpublisher scope. Required for authentication.
|
|
54
|
-
* @param {boolean} params.isSub - whether this is subscription or
|
|
52
|
+
* @param {boolean} params.isSub - whether this is subscription or in-app. `true` for subscription.
|
|
55
53
|
* @returns {Promise<ReceiptAndroid>}
|
|
56
54
|
*/
|
|
57
55
|
export const validateReceiptAndroid = async ({ packageName, productId, productToken, accessToken, isSub, }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android.js","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAErC,mBAAmB;AACnB,OAAO,aAAa,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"android.js","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AAAA,wBAAwB;AACxB,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAErC,mBAAmB;AACnB,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAK7C,cAAc;AACd,MAAM,UAAU,gBAAgB,CAC9B,IAAa;IAEb,OAAO,CACL,IAAI,IAAI,IAAI;QAC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E,CAAC,CAAC","sourcesContent":["// External dependencies\nimport {Linking} from 'react-native';\n\n// Internal modules\nimport ExpoIapModule from '../ExpoIapModule';\n\n// Types\nimport type {ReceiptValidationResultAndroid, VoidResult} from '../types';\n\n// Type guards\nexport function isProductAndroid<T extends {platform?: string}>(\n item: unknown,\n): item is T & {platform: 'android'} {\n return (\n item != null &&\n typeof item === 'object' &&\n 'platform' in item &&\n (item as any).platform === 'android'\n );\n}\n\n/**\n * Deep link to subscriptions screen on Android.\n * @param {Object} params - The parameters object\n * @param {string} params.sku - The product's SKU (on Android)\n * @param {string} params.packageName - The package name of your Android app (e.g., 'com.example.app')\n * @returns {Promise<void>}\n *\n * @example\n * ```typescript\n * await deepLinkToSubscriptionsAndroid({\n * sku: 'subscription_id',\n * packageName: 'com.example.app'\n * });\n * ```\n */\nexport const deepLinkToSubscriptionsAndroid = async ({\n sku,\n packageName,\n}: {\n sku?: string;\n packageName?: string;\n}): Promise<void> => {\n // Prefer native deep link implementation via OpenIAP module\n if (ExpoIapModule?.deepLinkToSubscriptionsAndroid) {\n return (ExpoIapModule as any).deepLinkToSubscriptionsAndroid({\n skuAndroid: sku,\n packageNameAndroid: packageName,\n });\n }\n\n // Fallback to Linking if native method unavailable\n if (!packageName) {\n throw new Error(\n 'packageName is required for deepLinkToSubscriptionsAndroid',\n );\n }\n const base = `https://play.google.com/store/account/subscriptions?package=${encodeURIComponent(\n packageName,\n )}`;\n const url = sku ? `${base}&sku=${encodeURIComponent(sku)}` : base;\n return Linking.openURL(url);\n};\n\n/**\n * Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including\n * your access token in the binary you ship to users is potentially dangerous.\n * Use server side validation instead for your production builds\n * @param {Object} params - The parameters object\n * @param {string} params.packageName - package name of your app.\n * @param {string} params.productId - product id for your in app product.\n * @param {string} params.productToken - token for your purchase (called 'token' in the API documentation).\n * @param {string} params.accessToken - OAuth access token with androidpublisher scope. Required for authentication.\n * @param {boolean} params.isSub - whether this is subscription or in-app. `true` for subscription.\n * @returns {Promise<ReceiptAndroid>}\n */\nexport const validateReceiptAndroid = async ({\n packageName,\n productId,\n productToken,\n accessToken,\n isSub,\n}: {\n packageName: string;\n productId: string;\n productToken: string;\n accessToken: string;\n isSub?: boolean;\n}): Promise<ReceiptValidationResultAndroid> => {\n const type = isSub ? 'subscriptions' : 'products';\n\n const url =\n 'https://androidpublisher.googleapis.com/androidpublisher/v3/applications' +\n `/${packageName}/purchases/${type}/${productId}` +\n `/tokens/${productToken}`;\n\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${accessToken}`,\n },\n });\n\n if (!response.ok) {\n throw Object.assign(new Error(response.statusText), {\n statusCode: response.status,\n });\n }\n\n return response.json();\n};\n\n/**\n * Acknowledge a product (on Android.) No-op on iOS.\n * @param {Object} params - The parameters object\n * @param {string} params.token - The product's token (on Android)\n * @returns {Promise<VoidResult | void>}\n */\nexport const acknowledgePurchaseAndroid = async ({\n token,\n}: {\n token: string;\n}): Promise<VoidResult | boolean | void> => {\n const result = await ExpoIapModule.acknowledgePurchaseAndroid(token);\n\n if (typeof result === 'boolean' || typeof result === 'undefined') {\n return result;\n }\n\n if (result && typeof result === 'object') {\n const record = result as Record<string, unknown>;\n if (typeof record.success === 'boolean') {\n return {success: record.success};\n }\n if (typeof record.responseCode === 'number') {\n return {success: record.responseCode === 0};\n }\n }\n\n return {success: true};\n};\n\n/**\n * Open the Google Play Store to redeem offer codes (Android only).\n * Note: Google Play does not provide a direct API to redeem codes within the app.\n * This function opens the Play Store where users can manually enter their codes.\n *\n * @returns {Promise<void>}\n */\nexport const openRedeemOfferCodeAndroid = async (): Promise<void> => {\n return Linking.openURL(`https://play.google.com/redeem?code=`);\n};\n"]}
|
package/build/modules/ios.d.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type { Product, Purchase, SubscriptionStatusIOS, AppTransaction, ReceiptValidationResultIOS } from '../types';
|
|
2
2
|
import type { PurchaseError } from '../purchase-error';
|
|
3
|
-
import { Platform as PurchasePlatform } from '../types';
|
|
4
3
|
export type TransactionEvent = {
|
|
5
4
|
transaction?: Purchase;
|
|
6
5
|
error?: PurchaseError;
|
|
7
6
|
};
|
|
8
7
|
export declare function isProductIOS<T extends {
|
|
9
|
-
platform?: string
|
|
8
|
+
platform?: string;
|
|
10
9
|
}>(item: unknown): item is T & {
|
|
11
|
-
platform:
|
|
10
|
+
platform: 'ios';
|
|
12
11
|
};
|
|
13
12
|
/**
|
|
14
13
|
* Sync state with Appstore (iOS only)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/modules/ios.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,OAAO,EACP,QAAQ,EACR,qBAAqB,EACrB,cAAc,EACd,0BAA0B,EAC3B,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/modules/ios.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,OAAO,EACP,QAAQ,EACR,qBAAqB,EACrB,cAAc,EACd,0BAA0B,EAC3B,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAGrD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,CAAC,EAAE,QAAQ,CAAC;IACvB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,CAAC;AAKF,wBAAgB,YAAY,CAAC,CAAC,SAAS;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAC,EACxD,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,CAAC,GAAG;IAAC,QAAQ,EAAE,KAAK,CAAA;CAAC,CAO/B;AAGD;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,QAAO,OAAO,CAAC,IAAI,CAEtC,CAAC;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;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,QAAO,OAAO,CAAC,OAAO,GAAG,IAAI,CAE9D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,mCAAmC,QAAO,OAAO,CAAC,IAAI,CAElE,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,QAAO,OAAO,CAAC,GAAG,EAAE,CAEzD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,QAAO,OAAO,CAAC,IAAI,CAElD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,QAAO,OAAO,CAAC,IAAI,CACO,CAAC"}
|
package/build/modules/ios.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// Internal modules
|
|
3
3
|
// import removed: use purchaseUpdatedListener directly in app code
|
|
4
4
|
import ExpoIapModule from '../ExpoIapModule';
|
|
5
|
-
import { Platform as PurchasePlatform } from '../types';
|
|
6
5
|
import { Linking } from 'react-native';
|
|
7
6
|
// Listeners
|
|
8
7
|
// Type guards
|
|
@@ -10,8 +9,7 @@ export function isProductIOS(item) {
|
|
|
10
9
|
return (item != null &&
|
|
11
10
|
typeof item === 'object' &&
|
|
12
11
|
'platform' in item &&
|
|
13
|
-
|
|
14
|
-
item.platform === PurchasePlatform.Ios));
|
|
12
|
+
item.platform === 'ios');
|
|
15
13
|
}
|
|
16
14
|
// Functions
|
|
17
15
|
/**
|
package/build/modules/ios.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ios.js","sourceRoot":"","sources":["../../src/modules/ios.ts"],"names":[],"mappings":"AAAA,wBAAwB;AAExB,mBAAmB;AACnB,mEAAmE;AACnE,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAW7C,OAAO,EAAC,QAAQ,IAAI,gBAAgB,EAAC,MAAM,UAAU,CAAC;AACtD,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAOrC,YA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aAAa,CAAC,mCAAmC,EAAE,CAAC;AAC7D,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAmB,EAAE;IAC5D,OAAO,aAAa,CAAC,yBAAyB,EAAE,CAAC;AACnD,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAkB,EAAE;IACrD,OAAO,aAAa,CAAC,mBAAmB,EAAE,CAAC;AAC7C,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAkB,EAAE,CAC5D,OAAO,CAAC,OAAO,CAAC,8CAA8C,CAAC,CAAC;AAElE,uEAAuE","sourcesContent":["// External dependencies\n\n// Internal modules\n// import removed: use purchaseUpdatedListener directly in app code\nimport ExpoIapModule from '../ExpoIapModule';\n\n// Types\nimport type {\n Product,\n Purchase,\n SubscriptionStatusIOS,\n AppTransaction,\n ReceiptValidationResultIOS,\n} from '../types';\nimport type {PurchaseError} from '../purchase-error';\nimport {Platform as PurchasePlatform} from '../types';\nimport {Linking} from 'react-native';\n\nexport type TransactionEvent = {\n transaction?: Purchase;\n error?: PurchaseError;\n};\n\n// Listeners\n\n// Type guards\nexport function isProductIOS<T extends {platform?: string | PurchasePlatform}>(\n item: unknown,\n): item is T & {platform: PurchasePlatform.Ios | 'ios'} {\n return (\n item != null &&\n typeof item === 'object' &&\n 'platform' in item &&\n ((item as any).platform === 'ios' ||\n (item as any).platform === PurchasePlatform.Ios)\n );\n}\n\n// Functions\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n *\n * @returns Promise resolving to null on success\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const syncIOS = (): Promise<null> => {\n return ExpoIapModule.syncIOS();\n};\n\n/**\n * Check if user is eligible for introductory offer\n *\n * @param groupId The subscription group ID\n * @returns Promise resolving to true if eligible\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const isEligibleForIntroOfferIOS = (\n groupId: string,\n): Promise<boolean> => {\n return ExpoIapModule.isEligibleForIntroOfferIOS(groupId);\n};\n\n/**\n * Get subscription status for a specific SKU\n *\n * @param sku The product SKU\n * @returns Promise resolving to array of subscription status\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const subscriptionStatusIOS = (\n sku: string,\n): Promise<SubscriptionStatusIOS[]> => {\n return ExpoIapModule.subscriptionStatusIOS(sku);\n};\n\n/**\n * Get current entitlement for a specific SKU\n *\n * @param sku The product SKU\n * @returns Promise resolving to current entitlement\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const currentEntitlementIOS = (sku: string): Promise<Purchase> => {\n return ExpoIapModule.currentEntitlementIOS(sku);\n};\n\n/**\n * Get latest transaction for a specific SKU\n *\n * @param sku The product SKU\n * @returns Promise resolving to latest transaction\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const latestTransactionIOS = (sku: string): Promise<Purchase> => {\n return ExpoIapModule.latestTransactionIOS(sku);\n};\n\n/**\n * Begin refund request for a specific SKU\n *\n * @param sku The product SKU\n * @returns Promise resolving to refund request status\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\ntype RefundRequestStatus = 'success' | 'userCancelled';\nexport const beginRefundRequestIOS = (\n sku: string,\n): Promise<RefundRequestStatus> => {\n return ExpoIapModule.beginRefundRequestIOS(sku);\n};\n\n/**\n * Shows the system UI for managing subscriptions.\n * Returns an array of subscriptions that had status changes after the UI is closed.\n *\n * @returns Promise<Purchase[]> - Array of subscriptions with status changes (e.g., auto-renewal toggled)\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const showManageSubscriptionsIOS = (): Promise<Purchase[]> => {\n return ExpoIapModule.showManageSubscriptionsIOS();\n};\n\n/**\n * Get the receipt data from the iOS device.\n * This returns the base64 encoded receipt data which can be sent to your server\n * for verification with Apple's server.\n *\n * NOTE: For proper security, always verify receipts on your server using\n * Apple's verifyReceipt endpoint, not directly from the app.\n *\n * @returns {Promise<string>} Base64 encoded receipt data\n */\nexport const getReceiptIOS = (): Promise<string> => {\n return ExpoIapModule.getReceiptDataIOS();\n};\n\n/**\n * Check if a transaction is verified through StoreKit 2.\n * StoreKit 2 performs local verification of transaction JWS signatures.\n *\n * @param sku The product's SKU (on iOS)\n * @returns Promise resolving to true if the transaction is verified\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const isTransactionVerifiedIOS = (sku: string): Promise<boolean> => {\n return ExpoIapModule.isTransactionVerifiedIOS(sku);\n};\n\n/**\n * Get the JWS representation of a purchase for server-side verification.\n * The JWS (JSON Web Signature) can be verified on your server using Apple's public keys.\n *\n * @param sku The product's SKU (on iOS)\n * @returns Promise resolving to JWS representation of the transaction\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const getTransactionJwsIOS = (sku: string): Promise<string> => {\n return ExpoIapModule.getTransactionJwsIOS(sku);\n};\n\n/**\n * Validate receipt for iOS using StoreKit 2's built-in verification.\n * Returns receipt data and verification information to help with server-side validation.\n *\n * NOTE: For proper security, Apple recommends verifying receipts on your server using\n * the verifyReceipt endpoint rather than relying solely on client-side verification.\n *\n * @param {string} sku The product's SKU (on iOS)\n * @returns {Promise<{\n * isValid: boolean;\n * receiptData: string;\n * jwsRepresentation: string;\n * latestTransaction?: Purchase;\n * }>}\n */\nexport const validateReceiptIOS = async (\n sku: string,\n): Promise<ReceiptValidationResultIOS> => {\n const result = await ExpoIapModule.validateReceiptIOS(sku);\n return result;\n};\n\n/**\n * Present the code redemption sheet for offer codes (iOS only).\n * This allows users to redeem promotional codes for in-app purchases and subscriptions.\n *\n * Note: This only works on real devices, not simulators.\n *\n * @returns Promise resolving to true if the sheet was presented successfully\n * @throws Error if called on non-iOS platform or tvOS\n *\n * @platform iOS\n */\nexport const presentCodeRedemptionSheetIOS = (): Promise<boolean> => {\n return ExpoIapModule.presentCodeRedemptionSheetIOS();\n};\n\n/**\n * Get app transaction information (iOS 16.0+).\n * AppTransaction represents the initial purchase that unlocked the app.\n *\n * NOTE: This function requires:\n * - iOS 16.0 or later at runtime\n * - Xcode 15.0+ with iOS 16.0 SDK for compilation\n *\n * @returns Promise resolving to the app transaction information or null if not available\n * @throws Error if called on non-iOS platform, iOS version < 16.0, or compiled with older SDK\n *\n * @platform iOS\n * @since iOS 16.0\n */\nexport const getAppTransactionIOS = (): Promise<AppTransaction | null> => {\n return ExpoIapModule.getAppTransactionIOS();\n};\n\n/**\n * Get information about a promoted product if one is available (iOS only).\n * Promoted products are products that the App Store promotes on your behalf.\n * This is called after a promoted product event is received from the App Store.\n *\n * @returns Promise resolving to the promoted product information or null if none available\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const getPromotedProductIOS = (): Promise<Product | null> => {\n return ExpoIapModule.getPromotedProductIOS();\n};\n\n/**\n * Complete the purchase of a promoted product (iOS only).\n * This should be called after showing your purchase UI for a promoted product.\n *\n * @returns Promise resolving when the purchase is initiated\n * @throws Error if called on non-iOS platform or no promoted product is available\n *\n * @platform iOS\n */\nexport const requestPurchaseOnPromotedProductIOS = (): Promise<void> => {\n return ExpoIapModule.requestPurchaseOnPromotedProductIOS();\n};\n\n/**\n * Get pending transactions that haven't been finished yet (iOS only).\n *\n * @returns Promise resolving to array of pending transactions\n * @platform iOS\n */\nexport const getPendingTransactionsIOS = (): Promise<any[]> => {\n return ExpoIapModule.getPendingTransactionsIOS();\n};\n\n/**\n * Clear a specific transaction (iOS only).\n *\n * @returns Promise resolving when transaction is cleared\n * @platform iOS\n */\nexport const clearTransactionIOS = (): Promise<void> => {\n return ExpoIapModule.clearTransactionIOS();\n};\n\n/**\n * Deep link to subscriptions screen on iOS.\n * @returns {Promise<void>}\n *\n * @platform iOS\n */\nexport const deepLinkToSubscriptionsIOS = (): Promise<void> =>\n Linking.openURL('https://apps.apple.com/account/subscriptions');\n\n// iOS-specific APIs only; cross-platform wrappers live in src/index.ts\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A4B,EAAE;IACjE,OAAO,aAAa,CAAC,qBAAqB,EAAE,CAAC;AAC/C,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,GAAkB,EAAE;IACrE,OAAO,aAAa,CAAC,mCAAmC,EAAE,CAAC;AAC7D,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAmB,EAAE;IAC5D,OAAO,aAAa,CAAC,yBAAyB,EAAE,CAAC;AACnD,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAkB,EAAE;IACrD,OAAO,aAAa,CAAC,mBAAmB,EAAE,CAAC;AAC7C,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAkB,EAAE,CAC5D,OAAO,CAAC,OAAO,CAAC,8CAA8C,CAAC,CAAC;AAElE,uEAAuE","sourcesContent":["// External dependencies\n\n// Internal modules\n// import removed: use purchaseUpdatedListener directly in app code\nimport ExpoIapModule from '../ExpoIapModule';\n\n// Types\nimport type {\n Product,\n Purchase,\n SubscriptionStatusIOS,\n AppTransaction,\n ReceiptValidationResultIOS,\n} from '../types';\nimport type {PurchaseError} from '../purchase-error';\nimport {Linking} from 'react-native';\n\nexport type TransactionEvent = {\n transaction?: Purchase;\n error?: PurchaseError;\n};\n\n// Listeners\n\n// Type guards\nexport function isProductIOS<T extends {platform?: string}>(\n item: unknown,\n): item is T & {platform: 'ios'} {\n return (\n item != null &&\n typeof item === 'object' &&\n 'platform' in item &&\n (item as any).platform === 'ios'\n );\n}\n\n// Functions\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n *\n * @returns Promise resolving to null on success\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const syncIOS = (): Promise<null> => {\n return ExpoIapModule.syncIOS();\n};\n\n/**\n * Check if user is eligible for introductory offer\n *\n * @param groupId The subscription group ID\n * @returns Promise resolving to true if eligible\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const isEligibleForIntroOfferIOS = (\n groupId: string,\n): Promise<boolean> => {\n return ExpoIapModule.isEligibleForIntroOfferIOS(groupId);\n};\n\n/**\n * Get subscription status for a specific SKU\n *\n * @param sku The product SKU\n * @returns Promise resolving to array of subscription status\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const subscriptionStatusIOS = (\n sku: string,\n): Promise<SubscriptionStatusIOS[]> => {\n return ExpoIapModule.subscriptionStatusIOS(sku);\n};\n\n/**\n * Get current entitlement for a specific SKU\n *\n * @param sku The product SKU\n * @returns Promise resolving to current entitlement\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const currentEntitlementIOS = (sku: string): Promise<Purchase> => {\n return ExpoIapModule.currentEntitlementIOS(sku);\n};\n\n/**\n * Get latest transaction for a specific SKU\n *\n * @param sku The product SKU\n * @returns Promise resolving to latest transaction\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const latestTransactionIOS = (sku: string): Promise<Purchase> => {\n return ExpoIapModule.latestTransactionIOS(sku);\n};\n\n/**\n * Begin refund request for a specific SKU\n *\n * @param sku The product SKU\n * @returns Promise resolving to refund request status\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\ntype RefundRequestStatus = 'success' | 'userCancelled';\nexport const beginRefundRequestIOS = (\n sku: string,\n): Promise<RefundRequestStatus> => {\n return ExpoIapModule.beginRefundRequestIOS(sku);\n};\n\n/**\n * Shows the system UI for managing subscriptions.\n * Returns an array of subscriptions that had status changes after the UI is closed.\n *\n * @returns Promise<Purchase[]> - Array of subscriptions with status changes (e.g., auto-renewal toggled)\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const showManageSubscriptionsIOS = (): Promise<Purchase[]> => {\n return ExpoIapModule.showManageSubscriptionsIOS();\n};\n\n/**\n * Get the receipt data from the iOS device.\n * This returns the base64 encoded receipt data which can be sent to your server\n * for verification with Apple's server.\n *\n * NOTE: For proper security, always verify receipts on your server using\n * Apple's verifyReceipt endpoint, not directly from the app.\n *\n * @returns {Promise<string>} Base64 encoded receipt data\n */\nexport const getReceiptIOS = (): Promise<string> => {\n return ExpoIapModule.getReceiptDataIOS();\n};\n\n/**\n * Check if a transaction is verified through StoreKit 2.\n * StoreKit 2 performs local verification of transaction JWS signatures.\n *\n * @param sku The product's SKU (on iOS)\n * @returns Promise resolving to true if the transaction is verified\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const isTransactionVerifiedIOS = (sku: string): Promise<boolean> => {\n return ExpoIapModule.isTransactionVerifiedIOS(sku);\n};\n\n/**\n * Get the JWS representation of a purchase for server-side verification.\n * The JWS (JSON Web Signature) can be verified on your server using Apple's public keys.\n *\n * @param sku The product's SKU (on iOS)\n * @returns Promise resolving to JWS representation of the transaction\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const getTransactionJwsIOS = (sku: string): Promise<string> => {\n return ExpoIapModule.getTransactionJwsIOS(sku);\n};\n\n/**\n * Validate receipt for iOS using StoreKit 2's built-in verification.\n * Returns receipt data and verification information to help with server-side validation.\n *\n * NOTE: For proper security, Apple recommends verifying receipts on your server using\n * the verifyReceipt endpoint rather than relying solely on client-side verification.\n *\n * @param {string} sku The product's SKU (on iOS)\n * @returns {Promise<{\n * isValid: boolean;\n * receiptData: string;\n * jwsRepresentation: string;\n * latestTransaction?: Purchase;\n * }>}\n */\nexport const validateReceiptIOS = async (\n sku: string,\n): Promise<ReceiptValidationResultIOS> => {\n const result = await ExpoIapModule.validateReceiptIOS(sku);\n return result;\n};\n\n/**\n * Present the code redemption sheet for offer codes (iOS only).\n * This allows users to redeem promotional codes for in-app purchases and subscriptions.\n *\n * Note: This only works on real devices, not simulators.\n *\n * @returns Promise resolving to true if the sheet was presented successfully\n * @throws Error if called on non-iOS platform or tvOS\n *\n * @platform iOS\n */\nexport const presentCodeRedemptionSheetIOS = (): Promise<boolean> => {\n return ExpoIapModule.presentCodeRedemptionSheetIOS();\n};\n\n/**\n * Get app transaction information (iOS 16.0+).\n * AppTransaction represents the initial purchase that unlocked the app.\n *\n * NOTE: This function requires:\n * - iOS 16.0 or later at runtime\n * - Xcode 15.0+ with iOS 16.0 SDK for compilation\n *\n * @returns Promise resolving to the app transaction information or null if not available\n * @throws Error if called on non-iOS platform, iOS version < 16.0, or compiled with older SDK\n *\n * @platform iOS\n * @since iOS 16.0\n */\nexport const getAppTransactionIOS = (): Promise<AppTransaction | null> => {\n return ExpoIapModule.getAppTransactionIOS();\n};\n\n/**\n * Get information about a promoted product if one is available (iOS only).\n * Promoted products are products that the App Store promotes on your behalf.\n * This is called after a promoted product event is received from the App Store.\n *\n * @returns Promise resolving to the promoted product information or null if none available\n * @throws Error if called on non-iOS platform\n *\n * @platform iOS\n */\nexport const getPromotedProductIOS = (): Promise<Product | null> => {\n return ExpoIapModule.getPromotedProductIOS();\n};\n\n/**\n * Complete the purchase of a promoted product (iOS only).\n * This should be called after showing your purchase UI for a promoted product.\n *\n * @returns Promise resolving when the purchase is initiated\n * @throws Error if called on non-iOS platform or no promoted product is available\n *\n * @platform iOS\n */\nexport const requestPurchaseOnPromotedProductIOS = (): Promise<void> => {\n return ExpoIapModule.requestPurchaseOnPromotedProductIOS();\n};\n\n/**\n * Get pending transactions that haven't been finished yet (iOS only).\n *\n * @returns Promise resolving to array of pending transactions\n * @platform iOS\n */\nexport const getPendingTransactionsIOS = (): Promise<any[]> => {\n return ExpoIapModule.getPendingTransactionsIOS();\n};\n\n/**\n * Clear a specific transaction (iOS only).\n *\n * @returns Promise resolving when transaction is cleared\n * @platform iOS\n */\nexport const clearTransactionIOS = (): Promise<void> => {\n return ExpoIapModule.clearTransactionIOS();\n};\n\n/**\n * Deep link to subscriptions screen on iOS.\n * @returns {Promise<void>}\n *\n * @platform iOS\n */\nexport const deepLinkToSubscriptionsIOS = (): Promise<void> =>\n Linking.openURL('https://apps.apple.com/account/subscriptions');\n\n// iOS-specific APIs only; cross-platform wrappers live in src/index.ts\n"]}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { ErrorCode,
|
|
2
|
-
/** Platform identifiers supported by {@link PurchaseError}. */
|
|
3
|
-
export type PurchaseErrorPlatform = Platform | 'ios' | 'android';
|
|
1
|
+
import { ErrorCode, IapPlatform } from './types';
|
|
4
2
|
/** Properties used to construct a {@link PurchaseError}. */
|
|
5
3
|
export interface PurchaseErrorProps {
|
|
6
4
|
message: string;
|
|
@@ -8,7 +6,7 @@ export interface PurchaseErrorProps {
|
|
|
8
6
|
debugMessage?: string;
|
|
9
7
|
code?: ErrorCode;
|
|
10
8
|
productId?: string;
|
|
11
|
-
platform?:
|
|
9
|
+
platform?: IapPlatform;
|
|
12
10
|
}
|
|
13
11
|
/** Shape of raw platform error objects coming from native modules. */
|
|
14
12
|
type PlatformErrorData = {
|
|
@@ -34,13 +32,13 @@ export declare class PurchaseError extends Error {
|
|
|
34
32
|
debugMessage?: string;
|
|
35
33
|
code?: ErrorCode;
|
|
36
34
|
productId?: string;
|
|
37
|
-
platform?:
|
|
38
|
-
constructor(message: string, responseCode?: number, debugMessage?: string, code?: ErrorCode, productId?: string, platform?:
|
|
35
|
+
platform?: IapPlatform;
|
|
36
|
+
constructor(message: string, responseCode?: number, debugMessage?: string, code?: ErrorCode, productId?: string, platform?: IapPlatform);
|
|
39
37
|
constructor(props: PurchaseErrorProps);
|
|
40
38
|
/**
|
|
41
39
|
* Create a {@link PurchaseError} from raw platform error data.
|
|
42
40
|
*/
|
|
43
|
-
static fromPlatformError(errorData: PlatformErrorData, platform:
|
|
41
|
+
static fromPlatformError(errorData: PlatformErrorData, platform: IapPlatform): PurchaseError;
|
|
44
42
|
/**
|
|
45
43
|
* Returns the platform specific error code for this instance.
|
|
46
44
|
*/
|
|
@@ -55,15 +53,15 @@ export declare const ErrorCodeUtils: {
|
|
|
55
53
|
/**
|
|
56
54
|
* Converts a platform-specific error code into a standardized {@link ErrorCode}.
|
|
57
55
|
*/
|
|
58
|
-
fromPlatformCode: (platformCode: string | number, _platform:
|
|
56
|
+
fromPlatformCode: (platformCode: string | number, _platform: IapPlatform) => ErrorCode;
|
|
59
57
|
/**
|
|
60
58
|
* Converts a standardized {@link ErrorCode} into its platform-specific value.
|
|
61
59
|
*/
|
|
62
|
-
toPlatformCode: (errorCode: ErrorCode, _platform:
|
|
60
|
+
toPlatformCode: (errorCode: ErrorCode, _platform: IapPlatform) => string | number;
|
|
63
61
|
/**
|
|
64
62
|
* Determines whether the error code is supported on the given platform.
|
|
65
63
|
*/
|
|
66
|
-
isValidForPlatform: (errorCode: ErrorCode, platform:
|
|
64
|
+
isValidForPlatform: (errorCode: ErrorCode, platform: IapPlatform) => boolean;
|
|
67
65
|
};
|
|
68
66
|
export {};
|
|
69
67
|
//# sourceMappingURL=purchase-error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"purchase-error.d.ts","sourceRoot":"","sources":["../src/purchase-error.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"purchase-error.d.ts","sourceRoot":"","sources":["../src/purchase-error.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAE,WAAW,EAAC,MAAM,SAAS,CAAC;AAE/C,4DAA4D;AAC5D,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,WAAW,CAAC;CACxB;AAED,sEAAsE;AACtE,KAAK,iBAAiB,GAAG;IACvB,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAiEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;CAGnB,CAAC;AAEX;;GAEG;AACH,qBAAa,aAAc,SAAQ,KAAK;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,WAAW,CAAC;gBAG5B,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,MAAM,EACrB,YAAY,CAAC,EAAE,MAAM,EACrB,IAAI,CAAC,EAAE,SAAS,EAChB,SAAS,CAAC,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,WAAW;gBAEZ,KAAK,EAAE,kBAAkB;IAgCrC;;OAEG;IACH,MAAM,CAAC,iBAAiB,CACtB,SAAS,EAAE,iBAAiB,EAC5B,QAAQ,EAAE,WAAW,GACpB,aAAa;IAiBhB;;OAEG;IACH,eAAe,IAAI,MAAM,GAAG,MAAM,GAAG,SAAS;CAM/C;AAED,qEAAqE;AACrE,eAAO,MAAM,cAAc;IACzB;;OAEG;oCAC6B,SAAS,KAAG,MAAM;IAQlD;;OAEG;qCAEa,MAAM,GAAG,MAAM,aAClB,WAAW,KACrB,SAAS;IAsCZ;;OAEG;gCAEU,SAAS,aACT,WAAW,KACrB,MAAM,GAAG,MAAM;IAOlB;;OAEG;oCAEU,SAAS,YACV,WAAW,KACpB,OAAO;CAUX,CAAC"}
|
package/build/purchase-error.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { NATIVE_ERROR_CODES } from './ExpoIapModule';
|
|
2
|
-
import { ErrorCode
|
|
2
|
+
import { ErrorCode } from './types';
|
|
3
3
|
const toStandardizedCode = (errorCode) => errorCode.startsWith('E_') ? errorCode : `E_${errorCode}`;
|
|
4
|
-
const normalizePlatform = (platform) => platform ===
|
|
4
|
+
const normalizePlatform = (platform) => typeof platform === 'string' && platform.toLowerCase() === 'ios'
|
|
5
|
+
? 'ios'
|
|
6
|
+
: 'android';
|
|
5
7
|
const OPENIAP_ERROR_CODE_SET = new Set(Object.values(ErrorCode).map((code) => toStandardizedCode(code)));
|
|
6
8
|
const COMMON_ERROR_CODE_MAP = {
|
|
7
9
|
[ErrorCode.Unknown]: toStandardizedCode(ErrorCode.Unknown),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"purchase-error.js","sourceRoot":"","sources":["../src/purchase-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,SAAS,CAAC;AAwB5C,MAAM,kBAAkB,GAAG,CAAC,SAAoB,EAAU,EAAE,CAC1D,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;AAE5D,MAAM,iBAAiB,GAAG,CACxB,QAA+B,EACZ,EAAE,CACrB,QAAQ,KAAK,QAAQ,CAAC,GAAG,IAAI,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAEtE,MAAM,sBAAsB,GAAgB,IAAI,GAAG,CACjD,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CACjE,CAAC;AAEF,MAAM,qBAAqB,GAA8B;IACvD,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,SAAS,CAAC,OAAO,CAAC;IAC1D,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,kBAAkB,CAAC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AgC,EACf,EAAE;QACnB,MAAM,YAAY,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACnD,MAAM,MAAM,GAAI,kBAAsD,CACpE,YAAY,CACb,CAAC;QACF,OAAO,MAAM,IAAI,qBAAqB,CAAC,SAAS,CAAC,IAAI,WAAW,CAAC;IACnE,CAAC;IACD;;OAEG;IACH,kBAAkB,EAAE,CAClB,SAAoB,EACpB,QAA+B,EACtB,EAAE;QACX,MAAM,YAAY,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACnD,IACG,kBAA8C,CAAC,YAAY,CAAC;YAC7D,SAAS,EACT,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,YAAY,IAAI,gBAAgB,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvE,CAAC;CACF,CAAC","sourcesContent":["import {NATIVE_ERROR_CODES} from './ExpoIapModule';\nimport {ErrorCode, Platform} from './types';\n\n/** Platform identifiers supported by {@link PurchaseError}. */\nexport type PurchaseErrorPlatform = Platform | 'ios' | 'android';\n\n/** Properties used to construct a {@link PurchaseError}. */\nexport interface PurchaseErrorProps {\n message: string;\n responseCode?: number;\n debugMessage?: string;\n code?: ErrorCode;\n productId?: string;\n platform?: PurchaseErrorPlatform;\n}\n\n/** Shape of raw platform error objects coming from native modules. */\ntype PlatformErrorData = {\n code?: string | number;\n message?: string;\n responseCode?: number;\n debugMessage?: string;\n productId?: string;\n};\n\nconst toStandardizedCode = (errorCode: ErrorCode): string =>\n errorCode.startsWith('E_') ? errorCode : `E_${errorCode}`;\n\nconst normalizePlatform = (\n platform: PurchaseErrorPlatform,\n): 'ios' | 'android' =>\n platform === Platform.Ios || platform === 'ios' ? 'ios' : 'android';\n\nconst OPENIAP_ERROR_CODE_SET: Set<string> = new Set(\n Object.values(ErrorCode).map((code) => toStandardizedCode(code)),\n);\n\nconst COMMON_ERROR_CODE_MAP: Record<ErrorCode, string> = {\n [ErrorCode.Unknown]: toStandardizedCode(ErrorCode.Unknown),\n [ErrorCode.UserCancelled]: toStandardizedCode(ErrorCode.UserCancelled),\n [ErrorCode.UserError]: toStandardizedCode(ErrorCode.UserError),\n [ErrorCode.ItemUnavailable]: toStandardizedCode(ErrorCode.ItemUnavailable),\n [ErrorCode.RemoteError]: toStandardizedCode(ErrorCode.RemoteError),\n [ErrorCode.NetworkError]: toStandardizedCode(ErrorCode.NetworkError),\n [ErrorCode.ServiceError]: toStandardizedCode(ErrorCode.ServiceError),\n [ErrorCode.ReceiptFailed]: toStandardizedCode(ErrorCode.ReceiptFailed),\n [ErrorCode.ReceiptFinished]: toStandardizedCode(ErrorCode.ReceiptFinished),\n [ErrorCode.ReceiptFinishedFailed]: toStandardizedCode(\n ErrorCode.ReceiptFinishedFailed,\n ),\n [ErrorCode.NotPrepared]: toStandardizedCode(ErrorCode.NotPrepared),\n [ErrorCode.NotEnded]: toStandardizedCode(ErrorCode.NotEnded),\n [ErrorCode.AlreadyOwned]: toStandardizedCode(ErrorCode.AlreadyOwned),\n [ErrorCode.DeveloperError]: toStandardizedCode(ErrorCode.DeveloperError),\n [ErrorCode.BillingResponseJsonParseError]: toStandardizedCode(\n ErrorCode.BillingResponseJsonParseError,\n ),\n [ErrorCode.DeferredPayment]: toStandardizedCode(ErrorCode.DeferredPayment),\n [ErrorCode.Interrupted]: toStandardizedCode(ErrorCode.Interrupted),\n [ErrorCode.IapNotAvailable]: toStandardizedCode(ErrorCode.IapNotAvailable),\n [ErrorCode.PurchaseError]: toStandardizedCode(ErrorCode.PurchaseError),\n [ErrorCode.SyncError]: toStandardizedCode(ErrorCode.SyncError),\n [ErrorCode.TransactionValidationFailed]: toStandardizedCode(\n ErrorCode.TransactionValidationFailed,\n ),\n [ErrorCode.ActivityUnavailable]: toStandardizedCode(\n ErrorCode.ActivityUnavailable,\n ),\n [ErrorCode.AlreadyPrepared]: toStandardizedCode(ErrorCode.AlreadyPrepared),\n [ErrorCode.Pending]: toStandardizedCode(ErrorCode.Pending),\n [ErrorCode.ConnectionClosed]: toStandardizedCode(ErrorCode.ConnectionClosed),\n [ErrorCode.InitConnection]: toStandardizedCode(ErrorCode.InitConnection),\n [ErrorCode.ServiceDisconnected]: toStandardizedCode(\n ErrorCode.ServiceDisconnected,\n ),\n [ErrorCode.QueryProduct]: toStandardizedCode(ErrorCode.QueryProduct),\n [ErrorCode.SkuNotFound]: toStandardizedCode(ErrorCode.SkuNotFound),\n [ErrorCode.SkuOfferMismatch]: toStandardizedCode(ErrorCode.SkuOfferMismatch),\n [ErrorCode.ItemNotOwned]: toStandardizedCode(ErrorCode.ItemNotOwned),\n [ErrorCode.BillingUnavailable]: toStandardizedCode(\n ErrorCode.BillingUnavailable,\n ),\n [ErrorCode.FeatureNotSupported]: toStandardizedCode(\n ErrorCode.FeatureNotSupported,\n ),\n [ErrorCode.EmptySkuList]: toStandardizedCode(ErrorCode.EmptySkuList),\n};\n\n/**\n * Mapping between platforms and their canonical error codes.\n * Values are platform-native string identifiers.\n */\nexport const ErrorCodeMapping = {\n ios: COMMON_ERROR_CODE_MAP,\n android: COMMON_ERROR_CODE_MAP,\n} as const;\n\n/**\n * Error thrown by expo-iap when purchases fail.\n */\nexport class PurchaseError extends Error {\n public responseCode?: number;\n public debugMessage?: string;\n public code?: ErrorCode;\n public productId?: string;\n public platform?: PurchaseErrorPlatform;\n\n constructor(\n message: string,\n responseCode?: number,\n debugMessage?: string,\n code?: ErrorCode,\n productId?: string,\n platform?: PurchaseErrorPlatform,\n );\n constructor(props: PurchaseErrorProps);\n constructor(\n messageOrProps: string | PurchaseErrorProps,\n responseCode?: number,\n debugMessage?: string,\n code?: ErrorCode,\n productId?: string,\n platform?: PurchaseErrorPlatform,\n ) {\n super(\n typeof messageOrProps === 'string'\n ? messageOrProps\n : messageOrProps.message,\n );\n this.name = '[expo-iap]: PurchaseError';\n Object.setPrototypeOf(this, new.target.prototype);\n\n if (typeof messageOrProps === 'string') {\n this.responseCode = responseCode;\n this.debugMessage = debugMessage;\n this.code = code;\n this.productId = productId;\n this.platform = platform;\n } else {\n this.responseCode = messageOrProps.responseCode;\n this.debugMessage = messageOrProps.debugMessage;\n this.code = messageOrProps.code;\n this.productId = messageOrProps.productId;\n this.platform = messageOrProps.platform;\n }\n }\n\n /**\n * Create a {@link PurchaseError} from raw platform error data.\n */\n static fromPlatformError(\n errorData: PlatformErrorData,\n platform: PurchaseErrorPlatform,\n ): PurchaseError {\n const normalizedPlatform = normalizePlatform(platform);\n\n const errorCode = errorData.code\n ? ErrorCodeUtils.fromPlatformCode(errorData.code, normalizedPlatform)\n : ErrorCode.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 * Returns the platform specific error code for this instance.\n */\n getPlatformCode(): string | number | undefined {\n if (!this.code || !this.platform) {\n return undefined;\n }\n return ErrorCodeUtils.toPlatformCode(this.code, this.platform);\n }\n}\n\n/** Utility helpers for translating error codes between platforms. */\nexport const ErrorCodeUtils = {\n /**\n * Returns the native error code for the provided {@link ErrorCode}.\n */\n getNativeErrorCode: (errorCode: ErrorCode): string => {\n const standardized = toStandardizedCode(errorCode);\n return (\n (NATIVE_ERROR_CODES as Record<string, string | undefined>)[\n standardized\n ] ?? standardized\n );\n },\n /**\n * Converts a platform-specific error code into a standardized {@link ErrorCode}.\n */\n fromPlatformCode: (\n platformCode: string | number,\n _platform: PurchaseErrorPlatform,\n ): ErrorCode => {\n if (typeof platformCode === 'string' && platformCode.startsWith('E_')) {\n if (OPENIAP_ERROR_CODE_SET.has(platformCode)) {\n const match = Object.entries(COMMON_ERROR_CODE_MAP).find(\n ([, value]) => value === platformCode,\n );\n if (match) {\n return match[0] as ErrorCode;\n }\n }\n }\n\n for (const [standardized, nativeCode] of Object.entries(\n (NATIVE_ERROR_CODES || {}) as Record<string, string | number>,\n )) {\n if (\n nativeCode === platformCode &&\n OPENIAP_ERROR_CODE_SET.has(standardized)\n ) {\n const match = Object.entries(COMMON_ERROR_CODE_MAP).find(\n ([, mappedCode]) => mappedCode === standardized,\n );\n if (match) {\n return match[0] as ErrorCode;\n }\n }\n }\n\n for (const [errorCode, mappedCode] of Object.entries(\n COMMON_ERROR_CODE_MAP,\n )) {\n if (mappedCode === platformCode) {\n return errorCode as ErrorCode;\n }\n }\n\n return ErrorCode.Unknown;\n },\n /**\n * Converts a standardized {@link ErrorCode} into its platform-specific value.\n */\n toPlatformCode: (\n errorCode: ErrorCode,\n _platform: PurchaseErrorPlatform,\n ): string | number => {\n const standardized = toStandardizedCode(errorCode);\n const native = (NATIVE_ERROR_CODES as Record<string, string | number>)[\n standardized\n ];\n return native ?? COMMON_ERROR_CODE_MAP[errorCode] ?? 'E_UNKNOWN';\n },\n /**\n * Determines whether the error code is supported on the given platform.\n */\n isValidForPlatform: (\n errorCode: ErrorCode,\n platform: PurchaseErrorPlatform,\n ): boolean => {\n const standardized = toStandardizedCode(errorCode);\n if (\n (NATIVE_ERROR_CODES as Record<string, unknown>)[standardized] !==\n undefined\n ) {\n return true;\n }\n return standardized in ErrorCodeMapping[normalizePlatform(platform)];\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"purchase-error.js","sourceRoot":"","sources":["../src/purchase-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAC,SAAS,EAAc,MAAM,SAAS,CAAC;AAqB/C,MAAM,kBAAkB,GAAG,CAAC,SAAoB,EAAU,EAAE,CAC1D,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;AAE5D,MAAM,iBAAiB,GAAG,CAAC,QAAqB,EAAqB,EAAE,CACrE,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,WAAW,EAAE,KAAK,KAAK;IAC9D,CAAC,CAA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AAC;oBACV,OAAO,KAAK,CAAC,CAAC,CAAc,CAAC;gBAC/B,CAAC;YACH,CAAC;QACH,CAAC;QAED,KAAK,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAClD,qBAAqB,CACtB,EAAE,CAAC;YACF,IAAI,UAAU,KAAK,YAAY,EAAE,CAAC;gBAChC,OAAO,SAAsB,CAAC;YAChC,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC,OAAO,CAAC;IAC3B,CAAC;IACD;;OAEG;IACH,cAAc,EAAE,CACd,SAAoB,EACpB,SAAsB,EACL,EAAE;QACnB,MAAM,YAAY,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACnD,MAAM,MAAM,GAAI,kBAAsD,CACpE,YAAY,CACb,CAAC;QACF,OAAO,MAAM,IAAI,qBAAqB,CAAC,SAAS,CAAC,IAAI,WAAW,CAAC;IACnE,CAAC;IACD;;OAEG;IACH,kBAAkB,EAAE,CAClB,SAAoB,EACpB,QAAqB,EACZ,EAAE;QACX,MAAM,YAAY,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACnD,IACG,kBAA8C,CAAC,YAAY,CAAC;YAC7D,SAAS,EACT,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,YAAY,IAAI,gBAAgB,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvE,CAAC;CACF,CAAC","sourcesContent":["import {NATIVE_ERROR_CODES} from './ExpoIapModule';\nimport {ErrorCode, IapPlatform} from './types';\n\n/** Properties used to construct a {@link PurchaseError}. */\nexport interface PurchaseErrorProps {\n message: string;\n responseCode?: number;\n debugMessage?: string;\n code?: ErrorCode;\n productId?: string;\n platform?: IapPlatform;\n}\n\n/** Shape of raw platform error objects coming from native modules. */\ntype PlatformErrorData = {\n code?: string | number;\n message?: string;\n responseCode?: number;\n debugMessage?: string;\n productId?: string;\n};\n\nconst toStandardizedCode = (errorCode: ErrorCode): string =>\n errorCode.startsWith('E_') ? errorCode : `E_${errorCode}`;\n\nconst normalizePlatform = (platform: IapPlatform): 'ios' | 'android' =>\n typeof platform === 'string' && platform.toLowerCase() === 'ios'\n ? 'ios'\n : 'android';\n\nconst OPENIAP_ERROR_CODE_SET: Set<string> = new Set(\n Object.values(ErrorCode).map((code) => toStandardizedCode(code)),\n);\n\nconst COMMON_ERROR_CODE_MAP: Record<ErrorCode, string> = {\n [ErrorCode.Unknown]: toStandardizedCode(ErrorCode.Unknown),\n [ErrorCode.UserCancelled]: toStandardizedCode(ErrorCode.UserCancelled),\n [ErrorCode.UserError]: toStandardizedCode(ErrorCode.UserError),\n [ErrorCode.ItemUnavailable]: toStandardizedCode(ErrorCode.ItemUnavailable),\n [ErrorCode.RemoteError]: toStandardizedCode(ErrorCode.RemoteError),\n [ErrorCode.NetworkError]: toStandardizedCode(ErrorCode.NetworkError),\n [ErrorCode.ServiceError]: toStandardizedCode(ErrorCode.ServiceError),\n [ErrorCode.ReceiptFailed]: toStandardizedCode(ErrorCode.ReceiptFailed),\n [ErrorCode.ReceiptFinished]: toStandardizedCode(ErrorCode.ReceiptFinished),\n [ErrorCode.ReceiptFinishedFailed]: toStandardizedCode(\n ErrorCode.ReceiptFinishedFailed,\n ),\n [ErrorCode.NotPrepared]: toStandardizedCode(ErrorCode.NotPrepared),\n [ErrorCode.NotEnded]: toStandardizedCode(ErrorCode.NotEnded),\n [ErrorCode.AlreadyOwned]: toStandardizedCode(ErrorCode.AlreadyOwned),\n [ErrorCode.DeveloperError]: toStandardizedCode(ErrorCode.DeveloperError),\n [ErrorCode.BillingResponseJsonParseError]: toStandardizedCode(\n ErrorCode.BillingResponseJsonParseError,\n ),\n [ErrorCode.DeferredPayment]: toStandardizedCode(ErrorCode.DeferredPayment),\n [ErrorCode.Interrupted]: toStandardizedCode(ErrorCode.Interrupted),\n [ErrorCode.IapNotAvailable]: toStandardizedCode(ErrorCode.IapNotAvailable),\n [ErrorCode.PurchaseError]: toStandardizedCode(ErrorCode.PurchaseError),\n [ErrorCode.SyncError]: toStandardizedCode(ErrorCode.SyncError),\n [ErrorCode.TransactionValidationFailed]: toStandardizedCode(\n ErrorCode.TransactionValidationFailed,\n ),\n [ErrorCode.ActivityUnavailable]: toStandardizedCode(\n ErrorCode.ActivityUnavailable,\n ),\n [ErrorCode.AlreadyPrepared]: toStandardizedCode(ErrorCode.AlreadyPrepared),\n [ErrorCode.Pending]: toStandardizedCode(ErrorCode.Pending),\n [ErrorCode.ConnectionClosed]: toStandardizedCode(ErrorCode.ConnectionClosed),\n [ErrorCode.InitConnection]: toStandardizedCode(ErrorCode.InitConnection),\n [ErrorCode.ServiceDisconnected]: toStandardizedCode(\n ErrorCode.ServiceDisconnected,\n ),\n [ErrorCode.QueryProduct]: toStandardizedCode(ErrorCode.QueryProduct),\n [ErrorCode.SkuNotFound]: toStandardizedCode(ErrorCode.SkuNotFound),\n [ErrorCode.SkuOfferMismatch]: toStandardizedCode(ErrorCode.SkuOfferMismatch),\n [ErrorCode.ItemNotOwned]: toStandardizedCode(ErrorCode.ItemNotOwned),\n [ErrorCode.BillingUnavailable]: toStandardizedCode(\n ErrorCode.BillingUnavailable,\n ),\n [ErrorCode.FeatureNotSupported]: toStandardizedCode(\n ErrorCode.FeatureNotSupported,\n ),\n [ErrorCode.EmptySkuList]: toStandardizedCode(ErrorCode.EmptySkuList),\n};\n\n/**\n * Mapping between platforms and their canonical error codes.\n * Values are platform-native string identifiers.\n */\nexport const ErrorCodeMapping = {\n ios: COMMON_ERROR_CODE_MAP,\n android: COMMON_ERROR_CODE_MAP,\n} as const;\n\n/**\n * Error thrown by expo-iap when purchases fail.\n */\nexport class PurchaseError extends Error {\n public responseCode?: number;\n public debugMessage?: string;\n public code?: ErrorCode;\n public productId?: string;\n public platform?: IapPlatform;\n\n constructor(\n message: string,\n responseCode?: number,\n debugMessage?: string,\n code?: ErrorCode,\n productId?: string,\n platform?: IapPlatform,\n );\n constructor(props: PurchaseErrorProps);\n constructor(\n messageOrProps: string | PurchaseErrorProps,\n responseCode?: number,\n debugMessage?: string,\n code?: ErrorCode,\n productId?: string,\n platform?: IapPlatform,\n ) {\n super(\n typeof messageOrProps === 'string'\n ? messageOrProps\n : messageOrProps.message,\n );\n this.name = '[expo-iap]: PurchaseError';\n Object.setPrototypeOf(this, new.target.prototype);\n\n if (typeof messageOrProps === 'string') {\n this.responseCode = responseCode;\n this.debugMessage = debugMessage;\n this.code = code;\n this.productId = productId;\n this.platform = platform;\n } else {\n this.responseCode = messageOrProps.responseCode;\n this.debugMessage = messageOrProps.debugMessage;\n this.code = messageOrProps.code;\n this.productId = messageOrProps.productId;\n this.platform = messageOrProps.platform;\n }\n }\n\n /**\n * Create a {@link PurchaseError} from raw platform error data.\n */\n static fromPlatformError(\n errorData: PlatformErrorData,\n platform: IapPlatform,\n ): PurchaseError {\n const normalizedPlatform = normalizePlatform(platform);\n\n const errorCode = errorData.code\n ? ErrorCodeUtils.fromPlatformCode(errorData.code, normalizedPlatform)\n : ErrorCode.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 * Returns the platform specific error code for this instance.\n */\n getPlatformCode(): string | number | undefined {\n if (!this.code || !this.platform) {\n return undefined;\n }\n return ErrorCodeUtils.toPlatformCode(this.code, this.platform);\n }\n}\n\n/** Utility helpers for translating error codes between platforms. */\nexport const ErrorCodeUtils = {\n /**\n * Returns the native error code for the provided {@link ErrorCode}.\n */\n getNativeErrorCode: (errorCode: ErrorCode): string => {\n const standardized = toStandardizedCode(errorCode);\n return (\n (NATIVE_ERROR_CODES as Record<string, string | undefined>)[\n standardized\n ] ?? standardized\n );\n },\n /**\n * Converts a platform-specific error code into a standardized {@link ErrorCode}.\n */\n fromPlatformCode: (\n platformCode: string | number,\n _platform: IapPlatform,\n ): ErrorCode => {\n if (typeof platformCode === 'string' && platformCode.startsWith('E_')) {\n if (OPENIAP_ERROR_CODE_SET.has(platformCode)) {\n const match = Object.entries(COMMON_ERROR_CODE_MAP).find(\n ([, value]) => value === platformCode,\n );\n if (match) {\n return match[0] as ErrorCode;\n }\n }\n }\n\n for (const [standardized, nativeCode] of Object.entries(\n (NATIVE_ERROR_CODES || {}) as Record<string, string | number>,\n )) {\n if (\n nativeCode === platformCode &&\n OPENIAP_ERROR_CODE_SET.has(standardized)\n ) {\n const match = Object.entries(COMMON_ERROR_CODE_MAP).find(\n ([, mappedCode]) => mappedCode === standardized,\n );\n if (match) {\n return match[0] as ErrorCode;\n }\n }\n }\n\n for (const [errorCode, mappedCode] of Object.entries(\n COMMON_ERROR_CODE_MAP,\n )) {\n if (mappedCode === platformCode) {\n return errorCode as ErrorCode;\n }\n }\n\n return ErrorCode.Unknown;\n },\n /**\n * Converts a standardized {@link ErrorCode} into its platform-specific value.\n */\n toPlatformCode: (\n errorCode: ErrorCode,\n _platform: IapPlatform,\n ): string | number => {\n const standardized = toStandardizedCode(errorCode);\n const native = (NATIVE_ERROR_CODES as Record<string, string | number>)[\n standardized\n ];\n return native ?? COMMON_ERROR_CODE_MAP[errorCode] ?? 'E_UNKNOWN';\n },\n /**\n * Determines whether the error code is supported on the given platform.\n */\n isValidForPlatform: (\n errorCode: ErrorCode,\n platform: IapPlatform,\n ): boolean => {\n const standardized = toStandardizedCode(errorCode);\n if (\n (NATIVE_ERROR_CODES as Record<string, unknown>)[standardized] !==\n undefined\n ) {\n return true;\n }\n return standardized in ErrorCodeMapping[normalizePlatform(platform)];\n },\n};\n"]}
|