expo-iap 3.1.2 → 3.1.3
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/android/src/main/java/expo/modules/iap/ExpoIapHelper.kt +171 -0
- package/android/src/main/java/expo/modules/iap/ExpoIapLog.kt +4 -0
- package/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +50 -114
- package/build/types.d.ts +34 -34
- package/build/types.js +34 -34
- package/build/types.js.map +1 -1
- package/build/utils/errorMapping.d.ts +7 -8
- package/build/utils/errorMapping.d.ts.map +1 -1
- package/build/utils/errorMapping.js +83 -53
- package/build/utils/errorMapping.js.map +1 -1
- package/coverage/clover.xml +105 -96
- package/coverage/coverage-final.json +1 -1
- package/coverage/lcov-report/index.html +19 -19
- package/coverage/lcov-report/src/helpers/index.html +1 -1
- package/coverage/lcov-report/src/helpers/subscription.ts.html +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.ts.html +1 -1
- package/coverage/lcov-report/src/modules/android.ts.html +1 -1
- package/coverage/lcov-report/src/modules/index.html +1 -1
- package/coverage/lcov-report/src/modules/ios.ts.html +1 -1
- package/coverage/lcov-report/src/utils/errorMapping.ts.html +191 -134
- package/coverage/lcov-report/src/utils/index.html +19 -19
- package/coverage/lcov.info +215 -185
- package/ios/ExpoIapHelper.swift +101 -6
- package/ios/ExpoIapModule.swift +29 -97
- package/openiap-versions.json +1 -1
- package/package.json +1 -1
- package/src/types.ts +34 -34
- package/src/utils/errorMapping.ts +101 -82
package/build/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,8CAA8C;AAC9C,yEAAyE;AACzE,+EAA+E;AAwF/E,MAAM,CAAN,IAAY,SAmCX;AAnCD,WAAY,SAAS;IACnB,yDAA4C,CAAA;IAC5C,2CAA8B,CAAA;IAC9B,iDAAoC,CAAA;IACpC,gFAAmE,CAAA;IACnE,uDAA0C,CAAA;IAC1C,mDAAsC,CAAA;IACtC,iDAAoC,CAAA;IACpC,+CAAkC,CAAA;IAClC,4CAA+B,CAAA;IAC/B,0DAA6C,CAAA;IAC7C,kDAAqC,CAAA;IACrC,+CAAkC,CAAA;IAClC,wCAA2B,CAAA;IAC3B,4CAA+B,CAAA;IAC/B,iDAAoC,CAAA;IACpC,2CAA8B,CAAA;IAC9B,mCAAsB,CAAA;IACtB,yCAA4B,CAAA;IAC5B,gCAAmB,CAAA;IACnB,6CAAgC,CAAA;IAChC,2CAA8B,CAAA;IAC9B,6CAAgC,CAAA;IAChC,iDAAoC,CAAA;IACpC,8DAAiD,CAAA;IACjD,yCAA4B,CAAA;IAC5B,yDAA4C,CAAA;IAC5C,2CAA8B,CAAA;IAC9B,0CAA6B,CAAA;IAC7B,oDAAuC,CAAA;IACvC,qCAAwB,CAAA;IACxB,0EAA6D,CAAA;IAC7D,gCAAmB,CAAA;IACnB,6CAAgC,CAAA;IAChC,qCAAwB,CAAA;AAC1B,CAAC,EAnCW,SAAS,KAAT,SAAS,QAmCpB;AAknBD,mCAAmC","sourcesContent":["// ============================================================================\n// AUTO-GENERATED TYPES — DO NOT EDIT DIRECTLY\n// Run `bun run generate:types` after updating any *.graphql schema file.\n// ============================================================================\n\nexport interface ActiveSubscription {\n autoRenewingAndroid?: (boolean | null);\n daysUntilExpirationIOS?: (number | null);\n environmentIOS?: (string | null);\n expirationDateIOS?: (number | null);\n isActive: boolean;\n productId: string;\n purchaseToken?: (string | null);\n transactionDate: number;\n transactionId: string;\n willExpireSoon?: (boolean | null);\n}\n\nexport interface AndroidSubscriptionOfferInput {\n /** Offer token */\n offerToken: string;\n /** Product SKU */\n sku: string;\n}\n\nexport interface AppTransaction {\n appId: number;\n appTransactionId?: (string | null);\n appVersion: string;\n appVersionId: number;\n bundleId: string;\n deviceVerification: string;\n deviceVerificationNonce: string;\n environment: string;\n originalAppVersion: string;\n originalPlatform?: (string | null);\n originalPurchaseDate: number;\n preorderDate?: (number | null);\n signedDate: number;\n}\n\nexport interface DeepLinkOptions {\n /** Android package name to target (required on Android) */\n packageNameAndroid?: (string | null);\n /** Android SKU to open (required on Android) */\n skuAndroid?: (string | null);\n}\n\nexport interface DiscountIOS {\n identifier: string;\n localizedPrice?: (string | null);\n numberOfPeriods: number;\n paymentMode: PaymentModeIOS;\n price: string;\n priceAmount: number;\n subscriptionPeriod: string;\n type: string;\n}\n\nexport interface DiscountOfferIOS {\n /** Discount identifier */\n identifier: string;\n /** Key identifier for validation */\n keyIdentifier: string;\n /** Cryptographic nonce */\n nonce: string;\n /** Signature for validation */\n signature: string;\n /** Timestamp of discount offer */\n timestamp: number;\n}\n\nexport interface DiscountOfferInputIOS {\n /** Discount identifier */\n identifier: string;\n /** Key identifier for validation */\n keyIdentifier: string;\n /** Cryptographic nonce */\n nonce: string;\n /** Signature for validation */\n signature: string;\n /** Timestamp of discount offer */\n timestamp: number;\n}\n\nexport interface EntitlementIOS {\n jsonRepresentation: string;\n sku: string;\n transactionId: string;\n}\n\nexport enum ErrorCode {\n ActivityUnavailable = 'ACTIVITY_UNAVAILABLE',\n AlreadyOwned = 'ALREADY_OWNED',\n AlreadyPrepared = 'ALREADY_PREPARED',\n BillingResponseJsonParseError = 'BILLING_RESPONSE_JSON_PARSE_ERROR',\n BillingUnavailable = 'BILLING_UNAVAILABLE',\n ConnectionClosed = 'CONNECTION_CLOSED',\n DeferredPayment = 'DEFERRED_PAYMENT',\n DeveloperError = 'DEVELOPER_ERROR',\n EmptySkuList = 'EMPTY_SKU_LIST',\n FeatureNotSupported = 'FEATURE_NOT_SUPPORTED',\n IapNotAvailable = 'IAP_NOT_AVAILABLE',\n InitConnection = 'INIT_CONNECTION',\n Interrupted = 'INTERRUPTED',\n ItemNotOwned = 'ITEM_NOT_OWNED',\n ItemUnavailable = 'ITEM_UNAVAILABLE',\n NetworkError = 'NETWORK_ERROR',\n NotEnded = 'NOT_ENDED',\n NotPrepared = 'NOT_PREPARED',\n Pending = 'PENDING',\n PurchaseError = 'PURCHASE_ERROR',\n QueryProduct = 'QUERY_PRODUCT',\n ReceiptFailed = 'RECEIPT_FAILED',\n ReceiptFinished = 'RECEIPT_FINISHED',\n ReceiptFinishedFailed = 'RECEIPT_FINISHED_FAILED',\n RemoteError = 'REMOTE_ERROR',\n ServiceDisconnected = 'SERVICE_DISCONNECTED',\n ServiceError = 'SERVICE_ERROR',\n SkuNotFound = 'SKU_NOT_FOUND',\n SkuOfferMismatch = 'SKU_OFFER_MISMATCH',\n SyncError = 'SYNC_ERROR',\n TransactionValidationFailed = 'TRANSACTION_VALIDATION_FAILED',\n Unknown = 'UNKNOWN',\n UserCancelled = 'USER_CANCELLED',\n UserError = 'USER_ERROR'\n}\n\nexport type FetchProductsResult = Product[] | ProductSubscription[] | null;\n\nexport type IapEvent = 'purchase-updated' | 'purchase-error' | 'promoted-product-ios';\n\nexport type IapPlatform = 'ios' | 'android';\n\nexport interface Mutation {\n /** Acknowledge a non-consumable purchase or subscription */\n acknowledgePurchaseAndroid: Promise<boolean>;\n /** Initiate a refund request for a product (iOS 15+) */\n beginRefundRequestIOS?: Promise<(string | null)>;\n /** Clear pending transactions from the StoreKit payment queue */\n clearTransactionIOS: Promise<boolean>;\n /** Consume a purchase token so it can be repurchased */\n consumePurchaseAndroid: Promise<boolean>;\n /** Open the native subscription management surface */\n deepLinkToSubscriptions: Promise<void>;\n /** Close the platform billing connection */\n endConnection: Promise<boolean>;\n /** Finish a transaction after validating receipts */\n finishTransaction: Promise<void>;\n /** Establish the platform billing connection */\n initConnection: Promise<boolean>;\n /** Present the App Store code redemption sheet */\n presentCodeRedemptionSheetIOS: Promise<boolean>;\n /** Initiate a purchase flow; rely on events for final state */\n requestPurchase?: Promise<(Purchase | Purchase[] | null)>;\n /** Purchase the promoted product surfaced by the App Store */\n requestPurchaseOnPromotedProductIOS: Promise<boolean>;\n /** Restore completed purchases across platforms */\n restorePurchases: Promise<void>;\n /** Open subscription management UI and return changed purchases (iOS 15+) */\n showManageSubscriptionsIOS: Promise<PurchaseIOS[]>;\n /** Force a StoreKit sync for transactions (iOS 15+) */\n syncIOS: Promise<boolean>;\n /** Validate purchase receipts with the configured providers */\n validateReceipt: Promise<ReceiptValidationResult>;\n}\n\n\n\nexport type MutationAcknowledgePurchaseAndroidArgs = string;\n\nexport type MutationBeginRefundRequestIosArgs = string;\n\nexport type MutationConsumePurchaseAndroidArgs = string;\n\nexport type MutationDeepLinkToSubscriptionsArgs = (DeepLinkOptions | null) | undefined;\n\nexport interface MutationFinishTransactionArgs {\n isConsumable?: (boolean | null);\n purchase: PurchaseInput;\n}\n\n\nexport type MutationRequestPurchaseArgs =\n | {\n /** Per-platform purchase request props */\n request: RequestPurchasePropsByPlatforms;\n type: 'in-app';\n }\n | {\n /** Per-platform subscription request props */\n request: RequestSubscriptionPropsByPlatforms;\n type: 'subs';\n };\n\n\nexport type MutationValidateReceiptArgs = ReceiptValidationProps;\n\nexport type PaymentModeIOS = 'empty' | 'free-trial' | 'pay-as-you-go' | 'pay-up-front';\n\nexport interface PricingPhaseAndroid {\n billingCycleCount: number;\n billingPeriod: string;\n formattedPrice: string;\n priceAmountMicros: string;\n priceCurrencyCode: string;\n recurrenceMode: number;\n}\n\nexport interface PricingPhasesAndroid {\n pricingPhaseList: PricingPhaseAndroid[];\n}\n\nexport type Product = ProductAndroid | ProductIOS;\n\nexport interface ProductAndroid extends ProductCommon {\n currency: string;\n debugDescription?: (string | null);\n description: string;\n displayName?: (string | null);\n displayPrice: string;\n id: string;\n nameAndroid: string;\n oneTimePurchaseOfferDetailsAndroid?: (ProductAndroidOneTimePurchaseOfferDetail | null);\n platform: IapPlatform;\n price?: (number | null);\n subscriptionOfferDetailsAndroid?: (ProductSubscriptionAndroidOfferDetails[] | null);\n title: string;\n type: ProductType;\n}\n\nexport interface ProductAndroidOneTimePurchaseOfferDetail {\n formattedPrice: string;\n priceAmountMicros: string;\n priceCurrencyCode: string;\n}\n\nexport interface ProductCommon {\n currency: string;\n debugDescription?: (string | null);\n description: string;\n displayName?: (string | null);\n displayPrice: string;\n id: string;\n platform: IapPlatform;\n price?: (number | null);\n title: string;\n type: ProductType;\n}\n\nexport interface ProductIOS extends ProductCommon {\n currency: string;\n debugDescription?: (string | null);\n description: string;\n displayName?: (string | null);\n displayNameIOS: string;\n displayPrice: string;\n id: string;\n isFamilyShareableIOS: boolean;\n jsonRepresentationIOS: string;\n platform: IapPlatform;\n price?: (number | null);\n subscriptionInfoIOS?: (SubscriptionInfoIOS | null);\n title: string;\n type: ProductType;\n typeIOS: ProductTypeIOS;\n}\n\nexport type ProductQueryType = 'in-app' | 'subs' | 'all';\n\nexport interface ProductRequest {\n skus: string[];\n type?: (ProductQueryType | null);\n}\n\nexport type ProductSubscription = ProductSubscriptionAndroid | ProductSubscriptionIOS;\n\nexport interface ProductSubscriptionAndroid extends ProductCommon {\n currency: string;\n debugDescription?: (string | null);\n description: string;\n displayName?: (string | null);\n displayPrice: string;\n id: string;\n nameAndroid: string;\n oneTimePurchaseOfferDetailsAndroid?: (ProductAndroidOneTimePurchaseOfferDetail | null);\n platform: IapPlatform;\n price?: (number | null);\n subscriptionOfferDetailsAndroid: ProductSubscriptionAndroidOfferDetails[];\n title: string;\n type: ProductType;\n}\n\nexport interface ProductSubscriptionAndroidOfferDetails {\n basePlanId: string;\n offerId?: (string | null);\n offerTags: string[];\n offerToken: string;\n pricingPhases: PricingPhasesAndroid;\n}\n\nexport interface ProductSubscriptionIOS extends ProductCommon {\n currency: string;\n debugDescription?: (string | null);\n description: string;\n discountsIOS?: (DiscountIOS[] | null);\n displayName?: (string | null);\n displayNameIOS: string;\n displayPrice: string;\n id: string;\n introductoryPriceAsAmountIOS?: (string | null);\n introductoryPriceIOS?: (string | null);\n introductoryPriceNumberOfPeriodsIOS?: (string | null);\n introductoryPricePaymentModeIOS?: (PaymentModeIOS | null);\n introductoryPriceSubscriptionPeriodIOS?: (SubscriptionPeriodIOS | null);\n isFamilyShareableIOS: boolean;\n jsonRepresentationIOS: string;\n platform: IapPlatform;\n price?: (number | null);\n subscriptionInfoIOS?: (SubscriptionInfoIOS | null);\n subscriptionPeriodNumberIOS?: (string | null);\n subscriptionPeriodUnitIOS?: (SubscriptionPeriodIOS | null);\n title: string;\n type: ProductType;\n typeIOS: ProductTypeIOS;\n}\n\nexport type ProductType = 'in-app' | 'subs';\n\nexport type ProductTypeIOS = 'consumable' | 'non-consumable' | 'auto-renewable-subscription' | 'non-renewing-subscription';\n\nexport type Purchase = PurchaseAndroid | PurchaseIOS;\n\nexport interface PurchaseAndroid extends PurchaseCommon {\n autoRenewingAndroid?: (boolean | null);\n dataAndroid?: (string | null);\n developerPayloadAndroid?: (string | null);\n id: string;\n ids?: (string[] | null);\n isAcknowledgedAndroid?: (boolean | null);\n isAutoRenewing: boolean;\n obfuscatedAccountIdAndroid?: (string | null);\n obfuscatedProfileIdAndroid?: (string | null);\n packageNameAndroid?: (string | null);\n platform: IapPlatform;\n productId: string;\n purchaseState: PurchaseState;\n purchaseToken?: (string | null);\n quantity: number;\n signatureAndroid?: (string | null);\n transactionDate: number;\n transactionId?: (string | null);\n}\n\nexport interface PurchaseCommon {\n id: string;\n ids?: (string[] | null);\n isAutoRenewing: boolean;\n platform: IapPlatform;\n productId: string;\n purchaseState: PurchaseState;\n /** Unified purchase token (iOS JWS, Android purchaseToken) */\n purchaseToken?: (string | null);\n quantity: number;\n transactionDate: number;\n}\n\nexport interface PurchaseError {\n code: ErrorCode;\n message: string;\n productId?: (string | null);\n}\n\nexport interface PurchaseIOS extends PurchaseCommon {\n appAccountToken?: (string | null);\n appBundleIdIOS?: (string | null);\n countryCodeIOS?: (string | null);\n currencyCodeIOS?: (string | null);\n currencySymbolIOS?: (string | null);\n environmentIOS?: (string | null);\n expirationDateIOS?: (number | null);\n id: string;\n ids?: (string[] | null);\n isAutoRenewing: boolean;\n isUpgradedIOS?: (boolean | null);\n offerIOS?: (PurchaseOfferIOS | null);\n originalTransactionDateIOS?: (number | null);\n originalTransactionIdentifierIOS?: (string | null);\n ownershipTypeIOS?: (string | null);\n platform: IapPlatform;\n productId: string;\n purchaseState: PurchaseState;\n purchaseToken?: (string | null);\n quantity: number;\n quantityIOS?: (number | null);\n reasonIOS?: (string | null);\n reasonStringRepresentationIOS?: (string | null);\n revocationDateIOS?: (number | null);\n revocationReasonIOS?: (string | null);\n storefrontCountryCodeIOS?: (string | null);\n subscriptionGroupIdIOS?: (string | null);\n transactionDate: number;\n transactionId: string;\n transactionReasonIOS?: (string | null);\n webOrderLineItemIdIOS?: (string | null);\n}\n\nexport interface PurchaseInput {\n id: string;\n ids?: (string[] | null);\n isAutoRenewing: boolean;\n platform: IapPlatform;\n productId: string;\n purchaseState: PurchaseState;\n purchaseToken?: (string | null);\n quantity: number;\n transactionDate: number;\n}\n\nexport interface PurchaseOfferIOS {\n id: string;\n paymentMode: string;\n type: string;\n}\n\nexport interface PurchaseOptions {\n /** Also emit results through the iOS event listeners */\n alsoPublishToEventListenerIOS?: (boolean | null);\n /** Limit to currently active items on iOS */\n onlyIncludeActiveItemsIOS?: (boolean | null);\n}\n\nexport type PurchaseState = 'pending' | 'purchased' | 'failed' | 'restored' | 'deferred' | 'unknown';\n\nexport interface Query {\n /** Get current StoreKit 2 entitlements (iOS 15+) */\n currentEntitlementIOS?: Promise<(PurchaseIOS | null)>;\n /** Retrieve products or subscriptions from the store */\n fetchProducts: Promise<(Product[] | ProductSubscription[] | null)>;\n /** Get active subscriptions (filters by subscriptionIds when provided) */\n getActiveSubscriptions: Promise<ActiveSubscription[]>;\n /** Fetch the current app transaction (iOS 16+) */\n getAppTransactionIOS?: Promise<(AppTransaction | null)>;\n /** Get all available purchases for the current user */\n getAvailablePurchases: Promise<Purchase[]>;\n /** Retrieve all pending transactions in the StoreKit queue */\n getPendingTransactionsIOS: Promise<PurchaseIOS[]>;\n /** Get the currently promoted product (iOS 11+) */\n getPromotedProductIOS?: Promise<(ProductIOS | null)>;\n /** Get base64-encoded receipt data for validation */\n getReceiptDataIOS?: Promise<(string | null)>;\n /** Get the current App Store storefront country code */\n getStorefrontIOS: Promise<string>;\n /** Get the transaction JWS (StoreKit 2) */\n getTransactionJwsIOS?: Promise<(string | null)>;\n /** Check whether the user has active subscriptions */\n hasActiveSubscriptions: Promise<boolean>;\n /** Check introductory offer eligibility for a subscription group */\n isEligibleForIntroOfferIOS: Promise<boolean>;\n /** Verify a StoreKit 2 transaction signature */\n isTransactionVerifiedIOS: Promise<boolean>;\n /** Get the latest transaction for a product using StoreKit 2 */\n latestTransactionIOS?: Promise<(PurchaseIOS | null)>;\n /** Get StoreKit 2 subscription status details (iOS 15+) */\n subscriptionStatusIOS: Promise<SubscriptionStatusIOS[]>;\n /** Validate a receipt for a specific product */\n validateReceiptIOS: Promise<ReceiptValidationResultIOS>;\n}\n\n\n\nexport type QueryCurrentEntitlementIosArgs = string;\n\nexport type QueryFetchProductsArgs = ProductRequest;\n\nexport type QueryGetActiveSubscriptionsArgs = (string[] | null) | undefined;\n\nexport type QueryGetAvailablePurchasesArgs = (PurchaseOptions | null) | undefined;\n\nexport type QueryGetTransactionJwsIosArgs = string;\n\nexport type QueryHasActiveSubscriptionsArgs = (string[] | null) | undefined;\n\nexport type QueryIsEligibleForIntroOfferIosArgs = string;\n\nexport type QueryIsTransactionVerifiedIosArgs = string;\n\nexport type QueryLatestTransactionIosArgs = string;\n\nexport type QuerySubscriptionStatusIosArgs = string;\n\nexport type QueryValidateReceiptIosArgs = ReceiptValidationProps;\n\nexport interface ReceiptValidationAndroidOptions {\n accessToken: string;\n isSub?: (boolean | null);\n packageName: string;\n productToken: string;\n}\n\nexport interface ReceiptValidationProps {\n /** Android-specific validation options */\n androidOptions?: (ReceiptValidationAndroidOptions | null);\n /** Product SKU to validate */\n sku: string;\n}\n\nexport type ReceiptValidationResult = ReceiptValidationResultAndroid | ReceiptValidationResultIOS;\n\nexport interface ReceiptValidationResultAndroid {\n autoRenewing: boolean;\n betaProduct: boolean;\n cancelDate?: (number | null);\n cancelReason?: (string | null);\n deferredDate?: (number | null);\n deferredSku?: (string | null);\n freeTrialEndDate: number;\n gracePeriodEndDate: number;\n parentProductId: string;\n productId: string;\n productType: string;\n purchaseDate: number;\n quantity: number;\n receiptId: string;\n renewalDate: number;\n term: string;\n termSku: string;\n testTransaction: boolean;\n}\n\nexport interface ReceiptValidationResultIOS {\n /** Whether the receipt is valid */\n isValid: boolean;\n /** JWS representation */\n jwsRepresentation: string;\n /** Latest transaction if available */\n latestTransaction?: (Purchase | null);\n /** Receipt data string */\n receiptData: string;\n}\n\nexport interface RefundResultIOS {\n message?: (string | null);\n status: string;\n}\n\nexport interface RenewalInfoIOS {\n autoRenewPreference?: (string | null);\n jsonRepresentation?: (string | null);\n willAutoRenew: boolean;\n}\n\nexport interface RequestPurchaseAndroidProps {\n /** Personalized offer flag */\n isOfferPersonalized?: (boolean | null);\n /** Obfuscated account ID */\n obfuscatedAccountIdAndroid?: (string | null);\n /** Obfuscated profile ID */\n obfuscatedProfileIdAndroid?: (string | null);\n /** List of product SKUs */\n skus: string[];\n}\n\nexport interface RequestPurchaseIosProps {\n /** Auto-finish transaction (dangerous) */\n andDangerouslyFinishTransactionAutomatically?: (boolean | null);\n /** App account token for user tracking */\n appAccountToken?: (string | null);\n /** Purchase quantity */\n quantity?: (number | null);\n /** Product SKU */\n sku: string;\n /** Discount offer to apply */\n withOffer?: (DiscountOfferInputIOS | null);\n}\n\nexport type RequestPurchaseProps =\n | {\n /** Per-platform purchase request props */\n request: RequestPurchasePropsByPlatforms;\n type: 'in-app';\n }\n | {\n /** Per-platform subscription request props */\n request: RequestSubscriptionPropsByPlatforms;\n type: 'subs';\n };\n\nexport interface RequestPurchasePropsByPlatforms {\n /** Android-specific purchase parameters */\n android?: (RequestPurchaseAndroidProps | null);\n /** iOS-specific purchase parameters */\n ios?: (RequestPurchaseIosProps | null);\n}\n\nexport type RequestPurchaseResult = Purchase | Purchase[] | null;\n\nexport interface RequestSubscriptionAndroidProps {\n /** Personalized offer flag */\n isOfferPersonalized?: (boolean | null);\n /** Obfuscated account ID */\n obfuscatedAccountIdAndroid?: (string | null);\n /** Obfuscated profile ID */\n obfuscatedProfileIdAndroid?: (string | null);\n /** Purchase token for upgrades/downgrades */\n purchaseTokenAndroid?: (string | null);\n /** Replacement mode for subscription changes */\n replacementModeAndroid?: (number | null);\n /** List of subscription SKUs */\n skus: string[];\n /** Subscription offers */\n subscriptionOffers?: (AndroidSubscriptionOfferInput[] | null);\n}\n\nexport interface RequestSubscriptionIosProps {\n andDangerouslyFinishTransactionAutomatically?: (boolean | null);\n appAccountToken?: (string | null);\n quantity?: (number | null);\n sku: string;\n withOffer?: (DiscountOfferInputIOS | null);\n}\n\nexport interface RequestSubscriptionPropsByPlatforms {\n /** Android-specific subscription parameters */\n android?: (RequestSubscriptionAndroidProps | null);\n /** iOS-specific subscription parameters */\n ios?: (RequestSubscriptionIosProps | null);\n}\n\nexport interface Subscription {\n /** Fires when the App Store surfaces a promoted product (iOS only) */\n promotedProductIOS: string;\n /** Fires when a purchase fails or is cancelled */\n purchaseError: PurchaseError;\n /** Fires when a purchase completes successfully or a pending purchase resolves */\n purchaseUpdated: Purchase;\n}\n\n\nexport interface SubscriptionInfoIOS {\n introductoryOffer?: (SubscriptionOfferIOS | null);\n promotionalOffers?: (SubscriptionOfferIOS[] | null);\n subscriptionGroupId: string;\n subscriptionPeriod: SubscriptionPeriodValueIOS;\n}\n\nexport interface SubscriptionOfferIOS {\n displayPrice: string;\n id: string;\n paymentMode: PaymentModeIOS;\n period: SubscriptionPeriodValueIOS;\n periodCount: number;\n price: number;\n type: SubscriptionOfferTypeIOS;\n}\n\nexport type SubscriptionOfferTypeIOS = 'introductory' | 'promotional';\n\nexport type SubscriptionPeriodIOS = 'day' | 'week' | 'month' | 'year' | 'empty';\n\nexport interface SubscriptionPeriodValueIOS {\n unit: SubscriptionPeriodIOS;\n value: number;\n}\n\nexport interface SubscriptionStatusIOS {\n renewalInfo?: (RenewalInfoIOS | null);\n state: string;\n}\n\nexport type VoidResult = void;\n\n// -- Query helper types (auto-generated)\nexport type QueryArgsMap = {\n currentEntitlementIOS: QueryCurrentEntitlementIosArgs;\n fetchProducts: QueryFetchProductsArgs;\n getActiveSubscriptions: QueryGetActiveSubscriptionsArgs;\n getAppTransactionIOS: never;\n getAvailablePurchases: QueryGetAvailablePurchasesArgs;\n getPendingTransactionsIOS: never;\n getPromotedProductIOS: never;\n getReceiptDataIOS: never;\n getStorefrontIOS: never;\n getTransactionJwsIOS: QueryGetTransactionJwsIosArgs;\n hasActiveSubscriptions: QueryHasActiveSubscriptionsArgs;\n isEligibleForIntroOfferIOS: QueryIsEligibleForIntroOfferIosArgs;\n isTransactionVerifiedIOS: QueryIsTransactionVerifiedIosArgs;\n latestTransactionIOS: QueryLatestTransactionIosArgs;\n subscriptionStatusIOS: QuerySubscriptionStatusIosArgs;\n validateReceiptIOS: QueryValidateReceiptIosArgs;\n};\n\nexport type QueryField<K extends keyof Query> =\n QueryArgsMap[K] extends never\n ? () => NonNullable<Query[K]>\n : undefined extends QueryArgsMap[K]\n ? (args?: QueryArgsMap[K]) => NonNullable<Query[K]>\n : (args: QueryArgsMap[K]) => NonNullable<Query[K]>;\n\nexport type QueryFieldMap = {\n [K in keyof Query]?: QueryField<K>;\n};\n// -- End query helper types\n\n// -- Mutation helper types (auto-generated)\nexport type MutationArgsMap = {\n acknowledgePurchaseAndroid: MutationAcknowledgePurchaseAndroidArgs;\n beginRefundRequestIOS: MutationBeginRefundRequestIosArgs;\n clearTransactionIOS: never;\n consumePurchaseAndroid: MutationConsumePurchaseAndroidArgs;\n deepLinkToSubscriptions: MutationDeepLinkToSubscriptionsArgs;\n endConnection: never;\n finishTransaction: MutationFinishTransactionArgs;\n initConnection: never;\n presentCodeRedemptionSheetIOS: never;\n requestPurchase: MutationRequestPurchaseArgs;\n requestPurchaseOnPromotedProductIOS: never;\n restorePurchases: never;\n showManageSubscriptionsIOS: never;\n syncIOS: never;\n validateReceipt: MutationValidateReceiptArgs;\n};\n\nexport type MutationField<K extends keyof Mutation> =\n MutationArgsMap[K] extends never\n ? () => NonNullable<Mutation[K]>\n : undefined extends MutationArgsMap[K]\n ? (args?: MutationArgsMap[K]) => NonNullable<Mutation[K]>\n : (args: MutationArgsMap[K]) => NonNullable<Mutation[K]>;\n\nexport type MutationFieldMap = {\n [K in keyof Mutation]?: MutationField<K>;\n};\n// -- End mutation helper types\n\n// -- Subscription helper types (auto-generated)\nexport type SubscriptionArgsMap = {\n promotedProductIOS: never;\n purchaseError: never;\n purchaseUpdated: never;\n};\n\nexport type SubscriptionField<K extends keyof Subscription> =\n SubscriptionArgsMap[K] extends never\n ? () => NonNullable<Subscription[K]>\n : undefined extends SubscriptionArgsMap[K]\n ? (args?: SubscriptionArgsMap[K]) => NonNullable<Subscription[K]>\n : (args: SubscriptionArgsMap[K]) => NonNullable<Subscription[K]>;\n\nexport type SubscriptionFieldMap = {\n [K in keyof Subscription]?: SubscriptionField<K>;\n};\n// -- End subscription helper types\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,8CAA8C;AAC9C,yEAAyE;AACzE,+EAA+E;AAwF/E,MAAM,CAAN,IAAY,SAmCX;AAnCD,WAAY,SAAS;IACnB,yDAA4C,CAAA;IAC5C,2CAA8B,CAAA;IAC9B,iDAAoC,CAAA;IACpC,gFAAmE,CAAA;IACnE,uDAA0C,CAAA;IAC1C,mDAAsC,CAAA;IACtC,iDAAoC,CAAA;IACpC,+CAAkC,CAAA;IAClC,4CAA+B,CAAA;IAC/B,0DAA6C,CAAA;IAC7C,kDAAqC,CAAA;IACrC,+CAAkC,CAAA;IAClC,wCAA2B,CAAA;IAC3B,4CAA+B,CAAA;IAC/B,iDAAoC,CAAA;IACpC,2CAA8B,CAAA;IAC9B,mCAAsB,CAAA;IACtB,yCAA4B,CAAA;IAC5B,gCAAmB,CAAA;IACnB,6CAAgC,CAAA;IAChC,2CAA8B,CAAA;IAC9B,6CAAgC,CAAA;IAChC,iDAAoC,CAAA;IACpC,8DAAiD,CAAA;IACjD,yCAA4B,CAAA;IAC5B,yDAA4C,CAAA;IAC5C,2CAA8B,CAAA;IAC9B,0CAA6B,CAAA;IAC7B,oDAAuC,CAAA;IACvC,qCAAwB,CAAA;IACxB,0EAA6D,CAAA;IAC7D,gCAAmB,CAAA;IACnB,6CAAgC,CAAA;IAChC,qCAAwB,CAAA;AAC1B,CAAC,EAnCW,SAAS,KAAT,SAAS,QAmCpB;AAknBD,mCAAmC","sourcesContent":["// ============================================================================\n// AUTO-GENERATED TYPES — DO NOT EDIT DIRECTLY\n// Run `bun run generate:types` after updating any *.graphql schema file.\n// ============================================================================\n\nexport interface ActiveSubscription {\n autoRenewingAndroid?: (boolean | null);\n daysUntilExpirationIOS?: (number | null);\n environmentIOS?: (string | null);\n expirationDateIOS?: (number | null);\n isActive: boolean;\n productId: string;\n purchaseToken?: (string | null);\n transactionDate: number;\n transactionId: string;\n willExpireSoon?: (boolean | null);\n}\n\nexport interface AndroidSubscriptionOfferInput {\n /** Offer token */\n offerToken: string;\n /** Product SKU */\n sku: string;\n}\n\nexport interface AppTransaction {\n appId: number;\n appTransactionId?: (string | null);\n appVersion: string;\n appVersionId: number;\n bundleId: string;\n deviceVerification: string;\n deviceVerificationNonce: string;\n environment: string;\n originalAppVersion: string;\n originalPlatform?: (string | null);\n originalPurchaseDate: number;\n preorderDate?: (number | null);\n signedDate: number;\n}\n\nexport interface DeepLinkOptions {\n /** Android package name to target (required on Android) */\n packageNameAndroid?: (string | null);\n /** Android SKU to open (required on Android) */\n skuAndroid?: (string | null);\n}\n\nexport interface DiscountIOS {\n identifier: string;\n localizedPrice?: (string | null);\n numberOfPeriods: number;\n paymentMode: PaymentModeIOS;\n price: string;\n priceAmount: number;\n subscriptionPeriod: string;\n type: string;\n}\n\nexport interface DiscountOfferIOS {\n /** Discount identifier */\n identifier: string;\n /** Key identifier for validation */\n keyIdentifier: string;\n /** Cryptographic nonce */\n nonce: string;\n /** Signature for validation */\n signature: string;\n /** Timestamp of discount offer */\n timestamp: number;\n}\n\nexport interface DiscountOfferInputIOS {\n /** Discount identifier */\n identifier: string;\n /** Key identifier for validation */\n keyIdentifier: string;\n /** Cryptographic nonce */\n nonce: string;\n /** Signature for validation */\n signature: string;\n /** Timestamp of discount offer */\n timestamp: number;\n}\n\nexport interface EntitlementIOS {\n jsonRepresentation: string;\n sku: string;\n transactionId: string;\n}\n\nexport enum ErrorCode {\n ActivityUnavailable = 'activity-unavailable',\n AlreadyOwned = 'already-owned',\n AlreadyPrepared = 'already-prepared',\n BillingResponseJsonParseError = 'billing-response-json-parse-error',\n BillingUnavailable = 'billing-unavailable',\n ConnectionClosed = 'connection-closed',\n DeferredPayment = 'deferred-payment',\n DeveloperError = 'developer-error',\n EmptySkuList = 'empty-sku-list',\n FeatureNotSupported = 'feature-not-supported',\n IapNotAvailable = 'iap-not-available',\n InitConnection = 'init-connection',\n Interrupted = 'interrupted',\n ItemNotOwned = 'item-not-owned',\n ItemUnavailable = 'item-unavailable',\n NetworkError = 'network-error',\n NotEnded = 'not-ended',\n NotPrepared = 'not-prepared',\n Pending = 'pending',\n PurchaseError = 'purchase-error',\n QueryProduct = 'query-product',\n ReceiptFailed = 'receipt-failed',\n ReceiptFinished = 'receipt-finished',\n ReceiptFinishedFailed = 'receipt-finished-failed',\n RemoteError = 'remote-error',\n ServiceDisconnected = 'service-disconnected',\n ServiceError = 'service-error',\n SkuNotFound = 'sku-not-found',\n SkuOfferMismatch = 'sku-offer-mismatch',\n SyncError = 'sync-error',\n TransactionValidationFailed = 'transaction-validation-failed',\n Unknown = 'unknown',\n UserCancelled = 'user-cancelled',\n UserError = 'user-error'\n}\n\nexport type FetchProductsResult = Product[] | ProductSubscription[] | null;\n\nexport type IapEvent = 'purchase-updated' | 'purchase-error' | 'promoted-product-ios';\n\nexport type IapPlatform = 'ios' | 'android';\n\nexport interface Mutation {\n /** Acknowledge a non-consumable purchase or subscription */\n acknowledgePurchaseAndroid: Promise<boolean>;\n /** Initiate a refund request for a product (iOS 15+) */\n beginRefundRequestIOS?: Promise<(string | null)>;\n /** Clear pending transactions from the StoreKit payment queue */\n clearTransactionIOS: Promise<boolean>;\n /** Consume a purchase token so it can be repurchased */\n consumePurchaseAndroid: Promise<boolean>;\n /** Open the native subscription management surface */\n deepLinkToSubscriptions: Promise<void>;\n /** Close the platform billing connection */\n endConnection: Promise<boolean>;\n /** Finish a transaction after validating receipts */\n finishTransaction: Promise<void>;\n /** Establish the platform billing connection */\n initConnection: Promise<boolean>;\n /** Present the App Store code redemption sheet */\n presentCodeRedemptionSheetIOS: Promise<boolean>;\n /** Initiate a purchase flow; rely on events for final state */\n requestPurchase?: Promise<(Purchase | Purchase[] | null)>;\n /** Purchase the promoted product surfaced by the App Store */\n requestPurchaseOnPromotedProductIOS: Promise<boolean>;\n /** Restore completed purchases across platforms */\n restorePurchases: Promise<void>;\n /** Open subscription management UI and return changed purchases (iOS 15+) */\n showManageSubscriptionsIOS: Promise<PurchaseIOS[]>;\n /** Force a StoreKit sync for transactions (iOS 15+) */\n syncIOS: Promise<boolean>;\n /** Validate purchase receipts with the configured providers */\n validateReceipt: Promise<ReceiptValidationResult>;\n}\n\n\n\nexport type MutationAcknowledgePurchaseAndroidArgs = string;\n\nexport type MutationBeginRefundRequestIosArgs = string;\n\nexport type MutationConsumePurchaseAndroidArgs = string;\n\nexport type MutationDeepLinkToSubscriptionsArgs = (DeepLinkOptions | null) | undefined;\n\nexport interface MutationFinishTransactionArgs {\n isConsumable?: (boolean | null);\n purchase: PurchaseInput;\n}\n\n\nexport type MutationRequestPurchaseArgs =\n | {\n /** Per-platform purchase request props */\n request: RequestPurchasePropsByPlatforms;\n type: 'in-app';\n }\n | {\n /** Per-platform subscription request props */\n request: RequestSubscriptionPropsByPlatforms;\n type: 'subs';\n };\n\n\nexport type MutationValidateReceiptArgs = ReceiptValidationProps;\n\nexport type PaymentModeIOS = 'empty' | 'free-trial' | 'pay-as-you-go' | 'pay-up-front';\n\nexport interface PricingPhaseAndroid {\n billingCycleCount: number;\n billingPeriod: string;\n formattedPrice: string;\n priceAmountMicros: string;\n priceCurrencyCode: string;\n recurrenceMode: number;\n}\n\nexport interface PricingPhasesAndroid {\n pricingPhaseList: PricingPhaseAndroid[];\n}\n\nexport type Product = ProductAndroid | ProductIOS;\n\nexport interface ProductAndroid extends ProductCommon {\n currency: string;\n debugDescription?: (string | null);\n description: string;\n displayName?: (string | null);\n displayPrice: string;\n id: string;\n nameAndroid: string;\n oneTimePurchaseOfferDetailsAndroid?: (ProductAndroidOneTimePurchaseOfferDetail | null);\n platform: IapPlatform;\n price?: (number | null);\n subscriptionOfferDetailsAndroid?: (ProductSubscriptionAndroidOfferDetails[] | null);\n title: string;\n type: ProductType;\n}\n\nexport interface ProductAndroidOneTimePurchaseOfferDetail {\n formattedPrice: string;\n priceAmountMicros: string;\n priceCurrencyCode: string;\n}\n\nexport interface ProductCommon {\n currency: string;\n debugDescription?: (string | null);\n description: string;\n displayName?: (string | null);\n displayPrice: string;\n id: string;\n platform: IapPlatform;\n price?: (number | null);\n title: string;\n type: ProductType;\n}\n\nexport interface ProductIOS extends ProductCommon {\n currency: string;\n debugDescription?: (string | null);\n description: string;\n displayName?: (string | null);\n displayNameIOS: string;\n displayPrice: string;\n id: string;\n isFamilyShareableIOS: boolean;\n jsonRepresentationIOS: string;\n platform: IapPlatform;\n price?: (number | null);\n subscriptionInfoIOS?: (SubscriptionInfoIOS | null);\n title: string;\n type: ProductType;\n typeIOS: ProductTypeIOS;\n}\n\nexport type ProductQueryType = 'in-app' | 'subs' | 'all';\n\nexport interface ProductRequest {\n skus: string[];\n type?: (ProductQueryType | null);\n}\n\nexport type ProductSubscription = ProductSubscriptionAndroid | ProductSubscriptionIOS;\n\nexport interface ProductSubscriptionAndroid extends ProductCommon {\n currency: string;\n debugDescription?: (string | null);\n description: string;\n displayName?: (string | null);\n displayPrice: string;\n id: string;\n nameAndroid: string;\n oneTimePurchaseOfferDetailsAndroid?: (ProductAndroidOneTimePurchaseOfferDetail | null);\n platform: IapPlatform;\n price?: (number | null);\n subscriptionOfferDetailsAndroid: ProductSubscriptionAndroidOfferDetails[];\n title: string;\n type: ProductType;\n}\n\nexport interface ProductSubscriptionAndroidOfferDetails {\n basePlanId: string;\n offerId?: (string | null);\n offerTags: string[];\n offerToken: string;\n pricingPhases: PricingPhasesAndroid;\n}\n\nexport interface ProductSubscriptionIOS extends ProductCommon {\n currency: string;\n debugDescription?: (string | null);\n description: string;\n discountsIOS?: (DiscountIOS[] | null);\n displayName?: (string | null);\n displayNameIOS: string;\n displayPrice: string;\n id: string;\n introductoryPriceAsAmountIOS?: (string | null);\n introductoryPriceIOS?: (string | null);\n introductoryPriceNumberOfPeriodsIOS?: (string | null);\n introductoryPricePaymentModeIOS?: (PaymentModeIOS | null);\n introductoryPriceSubscriptionPeriodIOS?: (SubscriptionPeriodIOS | null);\n isFamilyShareableIOS: boolean;\n jsonRepresentationIOS: string;\n platform: IapPlatform;\n price?: (number | null);\n subscriptionInfoIOS?: (SubscriptionInfoIOS | null);\n subscriptionPeriodNumberIOS?: (string | null);\n subscriptionPeriodUnitIOS?: (SubscriptionPeriodIOS | null);\n title: string;\n type: ProductType;\n typeIOS: ProductTypeIOS;\n}\n\nexport type ProductType = 'in-app' | 'subs';\n\nexport type ProductTypeIOS = 'consumable' | 'non-consumable' | 'auto-renewable-subscription' | 'non-renewing-subscription';\n\nexport type Purchase = PurchaseAndroid | PurchaseIOS;\n\nexport interface PurchaseAndroid extends PurchaseCommon {\n autoRenewingAndroid?: (boolean | null);\n dataAndroid?: (string | null);\n developerPayloadAndroid?: (string | null);\n id: string;\n ids?: (string[] | null);\n isAcknowledgedAndroid?: (boolean | null);\n isAutoRenewing: boolean;\n obfuscatedAccountIdAndroid?: (string | null);\n obfuscatedProfileIdAndroid?: (string | null);\n packageNameAndroid?: (string | null);\n platform: IapPlatform;\n productId: string;\n purchaseState: PurchaseState;\n purchaseToken?: (string | null);\n quantity: number;\n signatureAndroid?: (string | null);\n transactionDate: number;\n transactionId?: (string | null);\n}\n\nexport interface PurchaseCommon {\n id: string;\n ids?: (string[] | null);\n isAutoRenewing: boolean;\n platform: IapPlatform;\n productId: string;\n purchaseState: PurchaseState;\n /** Unified purchase token (iOS JWS, Android purchaseToken) */\n purchaseToken?: (string | null);\n quantity: number;\n transactionDate: number;\n}\n\nexport interface PurchaseError {\n code: ErrorCode;\n message: string;\n productId?: (string | null);\n}\n\nexport interface PurchaseIOS extends PurchaseCommon {\n appAccountToken?: (string | null);\n appBundleIdIOS?: (string | null);\n countryCodeIOS?: (string | null);\n currencyCodeIOS?: (string | null);\n currencySymbolIOS?: (string | null);\n environmentIOS?: (string | null);\n expirationDateIOS?: (number | null);\n id: string;\n ids?: (string[] | null);\n isAutoRenewing: boolean;\n isUpgradedIOS?: (boolean | null);\n offerIOS?: (PurchaseOfferIOS | null);\n originalTransactionDateIOS?: (number | null);\n originalTransactionIdentifierIOS?: (string | null);\n ownershipTypeIOS?: (string | null);\n platform: IapPlatform;\n productId: string;\n purchaseState: PurchaseState;\n purchaseToken?: (string | null);\n quantity: number;\n quantityIOS?: (number | null);\n reasonIOS?: (string | null);\n reasonStringRepresentationIOS?: (string | null);\n revocationDateIOS?: (number | null);\n revocationReasonIOS?: (string | null);\n storefrontCountryCodeIOS?: (string | null);\n subscriptionGroupIdIOS?: (string | null);\n transactionDate: number;\n transactionId: string;\n transactionReasonIOS?: (string | null);\n webOrderLineItemIdIOS?: (string | null);\n}\n\nexport interface PurchaseInput {\n id: string;\n ids?: (string[] | null);\n isAutoRenewing: boolean;\n platform: IapPlatform;\n productId: string;\n purchaseState: PurchaseState;\n purchaseToken?: (string | null);\n quantity: number;\n transactionDate: number;\n}\n\nexport interface PurchaseOfferIOS {\n id: string;\n paymentMode: string;\n type: string;\n}\n\nexport interface PurchaseOptions {\n /** Also emit results through the iOS event listeners */\n alsoPublishToEventListenerIOS?: (boolean | null);\n /** Limit to currently active items on iOS */\n onlyIncludeActiveItemsIOS?: (boolean | null);\n}\n\nexport type PurchaseState = 'pending' | 'purchased' | 'failed' | 'restored' | 'deferred' | 'unknown';\n\nexport interface Query {\n /** Get current StoreKit 2 entitlements (iOS 15+) */\n currentEntitlementIOS?: Promise<(PurchaseIOS | null)>;\n /** Retrieve products or subscriptions from the store */\n fetchProducts: Promise<(Product[] | ProductSubscription[] | null)>;\n /** Get active subscriptions (filters by subscriptionIds when provided) */\n getActiveSubscriptions: Promise<ActiveSubscription[]>;\n /** Fetch the current app transaction (iOS 16+) */\n getAppTransactionIOS?: Promise<(AppTransaction | null)>;\n /** Get all available purchases for the current user */\n getAvailablePurchases: Promise<Purchase[]>;\n /** Retrieve all pending transactions in the StoreKit queue */\n getPendingTransactionsIOS: Promise<PurchaseIOS[]>;\n /** Get the currently promoted product (iOS 11+) */\n getPromotedProductIOS?: Promise<(ProductIOS | null)>;\n /** Get base64-encoded receipt data for validation */\n getReceiptDataIOS?: Promise<(string | null)>;\n /** Get the current App Store storefront country code */\n getStorefrontIOS: Promise<string>;\n /** Get the transaction JWS (StoreKit 2) */\n getTransactionJwsIOS?: Promise<(string | null)>;\n /** Check whether the user has active subscriptions */\n hasActiveSubscriptions: Promise<boolean>;\n /** Check introductory offer eligibility for a subscription group */\n isEligibleForIntroOfferIOS: Promise<boolean>;\n /** Verify a StoreKit 2 transaction signature */\n isTransactionVerifiedIOS: Promise<boolean>;\n /** Get the latest transaction for a product using StoreKit 2 */\n latestTransactionIOS?: Promise<(PurchaseIOS | null)>;\n /** Get StoreKit 2 subscription status details (iOS 15+) */\n subscriptionStatusIOS: Promise<SubscriptionStatusIOS[]>;\n /** Validate a receipt for a specific product */\n validateReceiptIOS: Promise<ReceiptValidationResultIOS>;\n}\n\n\n\nexport type QueryCurrentEntitlementIosArgs = string;\n\nexport type QueryFetchProductsArgs = ProductRequest;\n\nexport type QueryGetActiveSubscriptionsArgs = (string[] | null) | undefined;\n\nexport type QueryGetAvailablePurchasesArgs = (PurchaseOptions | null) | undefined;\n\nexport type QueryGetTransactionJwsIosArgs = string;\n\nexport type QueryHasActiveSubscriptionsArgs = (string[] | null) | undefined;\n\nexport type QueryIsEligibleForIntroOfferIosArgs = string;\n\nexport type QueryIsTransactionVerifiedIosArgs = string;\n\nexport type QueryLatestTransactionIosArgs = string;\n\nexport type QuerySubscriptionStatusIosArgs = string;\n\nexport type QueryValidateReceiptIosArgs = ReceiptValidationProps;\n\nexport interface ReceiptValidationAndroidOptions {\n accessToken: string;\n isSub?: (boolean | null);\n packageName: string;\n productToken: string;\n}\n\nexport interface ReceiptValidationProps {\n /** Android-specific validation options */\n androidOptions?: (ReceiptValidationAndroidOptions | null);\n /** Product SKU to validate */\n sku: string;\n}\n\nexport type ReceiptValidationResult = ReceiptValidationResultAndroid | ReceiptValidationResultIOS;\n\nexport interface ReceiptValidationResultAndroid {\n autoRenewing: boolean;\n betaProduct: boolean;\n cancelDate?: (number | null);\n cancelReason?: (string | null);\n deferredDate?: (number | null);\n deferredSku?: (string | null);\n freeTrialEndDate: number;\n gracePeriodEndDate: number;\n parentProductId: string;\n productId: string;\n productType: string;\n purchaseDate: number;\n quantity: number;\n receiptId: string;\n renewalDate: number;\n term: string;\n termSku: string;\n testTransaction: boolean;\n}\n\nexport interface ReceiptValidationResultIOS {\n /** Whether the receipt is valid */\n isValid: boolean;\n /** JWS representation */\n jwsRepresentation: string;\n /** Latest transaction if available */\n latestTransaction?: (Purchase | null);\n /** Receipt data string */\n receiptData: string;\n}\n\nexport interface RefundResultIOS {\n message?: (string | null);\n status: string;\n}\n\nexport interface RenewalInfoIOS {\n autoRenewPreference?: (string | null);\n jsonRepresentation?: (string | null);\n willAutoRenew: boolean;\n}\n\nexport interface RequestPurchaseAndroidProps {\n /** Personalized offer flag */\n isOfferPersonalized?: (boolean | null);\n /** Obfuscated account ID */\n obfuscatedAccountIdAndroid?: (string | null);\n /** Obfuscated profile ID */\n obfuscatedProfileIdAndroid?: (string | null);\n /** List of product SKUs */\n skus: string[];\n}\n\nexport interface RequestPurchaseIosProps {\n /** Auto-finish transaction (dangerous) */\n andDangerouslyFinishTransactionAutomatically?: (boolean | null);\n /** App account token for user tracking */\n appAccountToken?: (string | null);\n /** Purchase quantity */\n quantity?: (number | null);\n /** Product SKU */\n sku: string;\n /** Discount offer to apply */\n withOffer?: (DiscountOfferInputIOS | null);\n}\n\nexport type RequestPurchaseProps =\n | {\n /** Per-platform purchase request props */\n request: RequestPurchasePropsByPlatforms;\n type: 'in-app';\n }\n | {\n /** Per-platform subscription request props */\n request: RequestSubscriptionPropsByPlatforms;\n type: 'subs';\n };\n\nexport interface RequestPurchasePropsByPlatforms {\n /** Android-specific purchase parameters */\n android?: (RequestPurchaseAndroidProps | null);\n /** iOS-specific purchase parameters */\n ios?: (RequestPurchaseIosProps | null);\n}\n\nexport type RequestPurchaseResult = Purchase | Purchase[] | null;\n\nexport interface RequestSubscriptionAndroidProps {\n /** Personalized offer flag */\n isOfferPersonalized?: (boolean | null);\n /** Obfuscated account ID */\n obfuscatedAccountIdAndroid?: (string | null);\n /** Obfuscated profile ID */\n obfuscatedProfileIdAndroid?: (string | null);\n /** Purchase token for upgrades/downgrades */\n purchaseTokenAndroid?: (string | null);\n /** Replacement mode for subscription changes */\n replacementModeAndroid?: (number | null);\n /** List of subscription SKUs */\n skus: string[];\n /** Subscription offers */\n subscriptionOffers?: (AndroidSubscriptionOfferInput[] | null);\n}\n\nexport interface RequestSubscriptionIosProps {\n andDangerouslyFinishTransactionAutomatically?: (boolean | null);\n appAccountToken?: (string | null);\n quantity?: (number | null);\n sku: string;\n withOffer?: (DiscountOfferInputIOS | null);\n}\n\nexport interface RequestSubscriptionPropsByPlatforms {\n /** Android-specific subscription parameters */\n android?: (RequestSubscriptionAndroidProps | null);\n /** iOS-specific subscription parameters */\n ios?: (RequestSubscriptionIosProps | null);\n}\n\nexport interface Subscription {\n /** Fires when the App Store surfaces a promoted product (iOS only) */\n promotedProductIOS: string;\n /** Fires when a purchase fails or is cancelled */\n purchaseError: PurchaseError;\n /** Fires when a purchase completes successfully or a pending purchase resolves */\n purchaseUpdated: Purchase;\n}\n\n\nexport interface SubscriptionInfoIOS {\n introductoryOffer?: (SubscriptionOfferIOS | null);\n promotionalOffers?: (SubscriptionOfferIOS[] | null);\n subscriptionGroupId: string;\n subscriptionPeriod: SubscriptionPeriodValueIOS;\n}\n\nexport interface SubscriptionOfferIOS {\n displayPrice: string;\n id: string;\n paymentMode: PaymentModeIOS;\n period: SubscriptionPeriodValueIOS;\n periodCount: number;\n price: number;\n type: SubscriptionOfferTypeIOS;\n}\n\nexport type SubscriptionOfferTypeIOS = 'introductory' | 'promotional';\n\nexport type SubscriptionPeriodIOS = 'day' | 'week' | 'month' | 'year' | 'empty';\n\nexport interface SubscriptionPeriodValueIOS {\n unit: SubscriptionPeriodIOS;\n value: number;\n}\n\nexport interface SubscriptionStatusIOS {\n renewalInfo?: (RenewalInfoIOS | null);\n state: string;\n}\n\nexport type VoidResult = void;\n\n// -- Query helper types (auto-generated)\nexport type QueryArgsMap = {\n currentEntitlementIOS: QueryCurrentEntitlementIosArgs;\n fetchProducts: QueryFetchProductsArgs;\n getActiveSubscriptions: QueryGetActiveSubscriptionsArgs;\n getAppTransactionIOS: never;\n getAvailablePurchases: QueryGetAvailablePurchasesArgs;\n getPendingTransactionsIOS: never;\n getPromotedProductIOS: never;\n getReceiptDataIOS: never;\n getStorefrontIOS: never;\n getTransactionJwsIOS: QueryGetTransactionJwsIosArgs;\n hasActiveSubscriptions: QueryHasActiveSubscriptionsArgs;\n isEligibleForIntroOfferIOS: QueryIsEligibleForIntroOfferIosArgs;\n isTransactionVerifiedIOS: QueryIsTransactionVerifiedIosArgs;\n latestTransactionIOS: QueryLatestTransactionIosArgs;\n subscriptionStatusIOS: QuerySubscriptionStatusIosArgs;\n validateReceiptIOS: QueryValidateReceiptIosArgs;\n};\n\nexport type QueryField<K extends keyof Query> =\n QueryArgsMap[K] extends never\n ? () => NonNullable<Query[K]>\n : undefined extends QueryArgsMap[K]\n ? (args?: QueryArgsMap[K]) => NonNullable<Query[K]>\n : (args: QueryArgsMap[K]) => NonNullable<Query[K]>;\n\nexport type QueryFieldMap = {\n [K in keyof Query]?: QueryField<K>;\n};\n// -- End query helper types\n\n// -- Mutation helper types (auto-generated)\nexport type MutationArgsMap = {\n acknowledgePurchaseAndroid: MutationAcknowledgePurchaseAndroidArgs;\n beginRefundRequestIOS: MutationBeginRefundRequestIosArgs;\n clearTransactionIOS: never;\n consumePurchaseAndroid: MutationConsumePurchaseAndroidArgs;\n deepLinkToSubscriptions: MutationDeepLinkToSubscriptionsArgs;\n endConnection: never;\n finishTransaction: MutationFinishTransactionArgs;\n initConnection: never;\n presentCodeRedemptionSheetIOS: never;\n requestPurchase: MutationRequestPurchaseArgs;\n requestPurchaseOnPromotedProductIOS: never;\n restorePurchases: never;\n showManageSubscriptionsIOS: never;\n syncIOS: never;\n validateReceipt: MutationValidateReceiptArgs;\n};\n\nexport type MutationField<K extends keyof Mutation> =\n MutationArgsMap[K] extends never\n ? () => NonNullable<Mutation[K]>\n : undefined extends MutationArgsMap[K]\n ? (args?: MutationArgsMap[K]) => NonNullable<Mutation[K]>\n : (args: MutationArgsMap[K]) => NonNullable<Mutation[K]>;\n\nexport type MutationFieldMap = {\n [K in keyof Mutation]?: MutationField<K>;\n};\n// -- End mutation helper types\n\n// -- Subscription helper types (auto-generated)\nexport type SubscriptionArgsMap = {\n promotedProductIOS: never;\n purchaseError: never;\n purchaseUpdated: never;\n};\n\nexport type SubscriptionField<K extends keyof Subscription> =\n SubscriptionArgsMap[K] extends never\n ? () => NonNullable<Subscription[K]>\n : undefined extends SubscriptionArgsMap[K]\n ? (args?: SubscriptionArgsMap[K]) => NonNullable<Subscription[K]>\n : (args: SubscriptionArgsMap[K]) => NonNullable<Subscription[K]>;\n\nexport type SubscriptionFieldMap = {\n [K in keyof Subscription]?: SubscriptionField<K>;\n};\n// -- End subscription helper types\n"]}
|
|
@@ -5,27 +5,26 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { ErrorCode, IapPlatform } from '../types';
|
|
7
7
|
export interface PurchaseErrorProps {
|
|
8
|
-
message
|
|
8
|
+
message?: string;
|
|
9
9
|
responseCode?: number;
|
|
10
10
|
debugMessage?: string;
|
|
11
|
-
code?: ErrorCode;
|
|
11
|
+
code?: ErrorCode | string | number;
|
|
12
12
|
productId?: string;
|
|
13
13
|
platform?: IapPlatform;
|
|
14
14
|
}
|
|
15
|
-
|
|
16
|
-
code?: string | number;
|
|
17
|
-
message?: string;
|
|
15
|
+
export interface PurchaseError extends Error {
|
|
18
16
|
responseCode?: number;
|
|
19
17
|
debugMessage?: string;
|
|
18
|
+
code?: ErrorCode;
|
|
20
19
|
productId?: string;
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
platform?: IapPlatform;
|
|
21
|
+
}
|
|
23
22
|
export declare const ErrorCodeMapping: {
|
|
24
23
|
readonly ios: Record<ErrorCode, string>;
|
|
25
24
|
readonly android: Record<ErrorCode, string>;
|
|
26
25
|
};
|
|
27
26
|
export declare const createPurchaseError: (props: PurchaseErrorProps) => PurchaseError;
|
|
28
|
-
export declare const createPurchaseErrorFromPlatform: (errorData:
|
|
27
|
+
export declare const createPurchaseErrorFromPlatform: (errorData: PurchaseErrorProps, platform: IapPlatform) => PurchaseError;
|
|
29
28
|
export declare const ErrorCodeUtils: {
|
|
30
29
|
getNativeErrorCode: (errorCode: ErrorCode) => string;
|
|
31
30
|
fromPlatformCode: (platformCode: string | number, _platform: IapPlatform) => ErrorCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorMapping.d.ts","sourceRoot":"","sources":["../../src/utils/errorMapping.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAC,SAAS,EAAE,WAAW,EAAC,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"errorMapping.d.ts","sourceRoot":"","sources":["../../src/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EAAE,OAAO,GAAG,OAAO,CAWtD;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAc1D;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAoDpE"}
|
|
@@ -5,57 +5,75 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { NATIVE_ERROR_CODES } from '../ExpoIapModule';
|
|
7
7
|
import { ErrorCode } from '../types';
|
|
8
|
-
const
|
|
8
|
+
const toKebabCase = (str) => {
|
|
9
|
+
if (str.includes('_')) {
|
|
10
|
+
return str
|
|
11
|
+
.split('_')
|
|
12
|
+
.map((word) => word.toLowerCase())
|
|
13
|
+
.join('-');
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
return str
|
|
17
|
+
.replace(/([A-Z])/g, '-$1')
|
|
18
|
+
.toLowerCase()
|
|
19
|
+
.replace(/^-/, '');
|
|
20
|
+
}
|
|
21
|
+
};
|
|
9
22
|
const normalizePlatform = (platform) => typeof platform === 'string' && platform.toLowerCase() === 'ios'
|
|
10
23
|
? 'ios'
|
|
11
24
|
: 'android';
|
|
12
25
|
const COMMON_ERROR_CODE_MAP = {
|
|
13
|
-
[ErrorCode.Unknown]:
|
|
14
|
-
[ErrorCode.UserCancelled]:
|
|
15
|
-
[ErrorCode.UserError]:
|
|
16
|
-
[ErrorCode.ItemUnavailable]:
|
|
17
|
-
[ErrorCode.RemoteError]:
|
|
18
|
-
[ErrorCode.NetworkError]:
|
|
19
|
-
[ErrorCode.ServiceError]:
|
|
20
|
-
[ErrorCode.ReceiptFailed]:
|
|
21
|
-
[ErrorCode.ReceiptFinished]:
|
|
22
|
-
[ErrorCode.ReceiptFinishedFailed]:
|
|
23
|
-
[ErrorCode.NotPrepared]:
|
|
24
|
-
[ErrorCode.NotEnded]:
|
|
25
|
-
[ErrorCode.AlreadyOwned]:
|
|
26
|
-
[ErrorCode.DeveloperError]:
|
|
27
|
-
[ErrorCode.BillingResponseJsonParseError]:
|
|
28
|
-
[ErrorCode.DeferredPayment]:
|
|
29
|
-
[ErrorCode.Interrupted]:
|
|
30
|
-
[ErrorCode.IapNotAvailable]:
|
|
31
|
-
[ErrorCode.PurchaseError]:
|
|
32
|
-
[ErrorCode.SyncError]:
|
|
33
|
-
[ErrorCode.TransactionValidationFailed]:
|
|
34
|
-
[ErrorCode.ActivityUnavailable]:
|
|
35
|
-
[ErrorCode.AlreadyPrepared]:
|
|
36
|
-
[ErrorCode.Pending]:
|
|
37
|
-
[ErrorCode.ConnectionClosed]:
|
|
38
|
-
[ErrorCode.InitConnection]:
|
|
39
|
-
[ErrorCode.ServiceDisconnected]:
|
|
40
|
-
[ErrorCode.QueryProduct]:
|
|
41
|
-
[ErrorCode.SkuNotFound]:
|
|
42
|
-
[ErrorCode.SkuOfferMismatch]:
|
|
43
|
-
[ErrorCode.ItemNotOwned]:
|
|
44
|
-
[ErrorCode.BillingUnavailable]:
|
|
45
|
-
[ErrorCode.FeatureNotSupported]:
|
|
46
|
-
[ErrorCode.EmptySkuList]:
|
|
26
|
+
[ErrorCode.Unknown]: ErrorCode.Unknown,
|
|
27
|
+
[ErrorCode.UserCancelled]: ErrorCode.UserCancelled,
|
|
28
|
+
[ErrorCode.UserError]: ErrorCode.UserError,
|
|
29
|
+
[ErrorCode.ItemUnavailable]: ErrorCode.ItemUnavailable,
|
|
30
|
+
[ErrorCode.RemoteError]: ErrorCode.RemoteError,
|
|
31
|
+
[ErrorCode.NetworkError]: ErrorCode.NetworkError,
|
|
32
|
+
[ErrorCode.ServiceError]: ErrorCode.ServiceError,
|
|
33
|
+
[ErrorCode.ReceiptFailed]: ErrorCode.ReceiptFailed,
|
|
34
|
+
[ErrorCode.ReceiptFinished]: ErrorCode.ReceiptFinished,
|
|
35
|
+
[ErrorCode.ReceiptFinishedFailed]: ErrorCode.ReceiptFinishedFailed,
|
|
36
|
+
[ErrorCode.NotPrepared]: ErrorCode.NotPrepared,
|
|
37
|
+
[ErrorCode.NotEnded]: ErrorCode.NotEnded,
|
|
38
|
+
[ErrorCode.AlreadyOwned]: ErrorCode.AlreadyOwned,
|
|
39
|
+
[ErrorCode.DeveloperError]: ErrorCode.DeveloperError,
|
|
40
|
+
[ErrorCode.BillingResponseJsonParseError]: ErrorCode.BillingResponseJsonParseError,
|
|
41
|
+
[ErrorCode.DeferredPayment]: ErrorCode.DeferredPayment,
|
|
42
|
+
[ErrorCode.Interrupted]: ErrorCode.Interrupted,
|
|
43
|
+
[ErrorCode.IapNotAvailable]: ErrorCode.IapNotAvailable,
|
|
44
|
+
[ErrorCode.PurchaseError]: ErrorCode.PurchaseError,
|
|
45
|
+
[ErrorCode.SyncError]: ErrorCode.SyncError,
|
|
46
|
+
[ErrorCode.TransactionValidationFailed]: ErrorCode.TransactionValidationFailed,
|
|
47
|
+
[ErrorCode.ActivityUnavailable]: ErrorCode.ActivityUnavailable,
|
|
48
|
+
[ErrorCode.AlreadyPrepared]: ErrorCode.AlreadyPrepared,
|
|
49
|
+
[ErrorCode.Pending]: ErrorCode.Pending,
|
|
50
|
+
[ErrorCode.ConnectionClosed]: ErrorCode.ConnectionClosed,
|
|
51
|
+
[ErrorCode.InitConnection]: ErrorCode.InitConnection,
|
|
52
|
+
[ErrorCode.ServiceDisconnected]: ErrorCode.ServiceDisconnected,
|
|
53
|
+
[ErrorCode.QueryProduct]: ErrorCode.QueryProduct,
|
|
54
|
+
[ErrorCode.SkuNotFound]: ErrorCode.SkuNotFound,
|
|
55
|
+
[ErrorCode.SkuOfferMismatch]: ErrorCode.SkuOfferMismatch,
|
|
56
|
+
[ErrorCode.ItemNotOwned]: ErrorCode.ItemNotOwned,
|
|
57
|
+
[ErrorCode.BillingUnavailable]: ErrorCode.BillingUnavailable,
|
|
58
|
+
[ErrorCode.FeatureNotSupported]: ErrorCode.FeatureNotSupported,
|
|
59
|
+
[ErrorCode.EmptySkuList]: ErrorCode.EmptySkuList,
|
|
47
60
|
};
|
|
48
61
|
export const ErrorCodeMapping = {
|
|
49
62
|
ios: COMMON_ERROR_CODE_MAP,
|
|
50
63
|
android: COMMON_ERROR_CODE_MAP,
|
|
51
64
|
};
|
|
52
|
-
const OPENIAP_ERROR_CODE_SET = new Set(Object.values(ErrorCode)
|
|
65
|
+
const OPENIAP_ERROR_CODE_SET = new Set(Object.values(ErrorCode));
|
|
53
66
|
export const createPurchaseError = (props) => {
|
|
54
|
-
const
|
|
67
|
+
const errorCode = props.code
|
|
68
|
+
? typeof props.code === 'string' || typeof props.code === 'number'
|
|
69
|
+
? ErrorCodeUtils.fromPlatformCode(props.code, props.platform || 'ios')
|
|
70
|
+
: props.code
|
|
71
|
+
: undefined;
|
|
72
|
+
const error = new Error(props.message ?? 'Unknown error occurred');
|
|
55
73
|
error.name = '[expo-iap]: PurchaseError';
|
|
56
74
|
error.responseCode = props.responseCode;
|
|
57
75
|
error.debugMessage = props.debugMessage;
|
|
58
|
-
error.code =
|
|
76
|
+
error.code = errorCode;
|
|
59
77
|
error.productId = props.productId;
|
|
60
78
|
error.platform = props.platform;
|
|
61
79
|
return error;
|
|
@@ -63,7 +81,9 @@ export const createPurchaseError = (props) => {
|
|
|
63
81
|
export const createPurchaseErrorFromPlatform = (errorData, platform) => {
|
|
64
82
|
const normalizedPlatform = normalizePlatform(platform);
|
|
65
83
|
const errorCode = errorData.code
|
|
66
|
-
?
|
|
84
|
+
? typeof errorData.code === 'string' || typeof errorData.code === 'number'
|
|
85
|
+
? ErrorCodeUtils.fromPlatformCode(errorData.code, normalizedPlatform)
|
|
86
|
+
: errorData.code
|
|
67
87
|
: ErrorCode.Unknown;
|
|
68
88
|
return createPurchaseError({
|
|
69
89
|
message: errorData.message ?? 'Unknown error occurred',
|
|
@@ -76,20 +96,27 @@ export const createPurchaseErrorFromPlatform = (errorData, platform) => {
|
|
|
76
96
|
};
|
|
77
97
|
export const ErrorCodeUtils = {
|
|
78
98
|
getNativeErrorCode: (errorCode) => {
|
|
79
|
-
|
|
80
|
-
|
|
99
|
+
return (NATIVE_ERROR_CODES[errorCode] ??
|
|
100
|
+
errorCode);
|
|
81
101
|
},
|
|
82
102
|
fromPlatformCode: (platformCode, _platform) => {
|
|
83
103
|
if (typeof platformCode === 'string' && platformCode.startsWith('E_')) {
|
|
84
|
-
|
|
85
|
-
|
|
104
|
+
const withoutE = platformCode.substring(2);
|
|
105
|
+
const camelCased = toKebabCase(withoutE);
|
|
106
|
+
const withE = `E_${camelCased}`;
|
|
107
|
+
if (OPENIAP_ERROR_CODE_SET.has(withE)) {
|
|
108
|
+
const match = Object.entries(COMMON_ERROR_CODE_MAP).find(([, value]) => value === withE);
|
|
86
109
|
if (match) {
|
|
87
110
|
return match[0];
|
|
88
111
|
}
|
|
89
112
|
}
|
|
90
113
|
}
|
|
114
|
+
const normalizedCode = typeof platformCode === 'string'
|
|
115
|
+
? toKebabCase(platformCode)
|
|
116
|
+
: platformCode;
|
|
91
117
|
for (const [standardized, nativeCode] of Object.entries((NATIVE_ERROR_CODES || {}))) {
|
|
92
|
-
|
|
118
|
+
const normalizedNative = typeof nativeCode === 'string' ? toKebabCase(nativeCode) : nativeCode;
|
|
119
|
+
if (normalizedNative === normalizedCode &&
|
|
93
120
|
OPENIAP_ERROR_CODE_SET.has(standardized)) {
|
|
94
121
|
const match = Object.entries(COMMON_ERROR_CODE_MAP).find(([, mappedCode]) => mappedCode === standardized);
|
|
95
122
|
if (match) {
|
|
@@ -98,24 +125,19 @@ export const ErrorCodeUtils = {
|
|
|
98
125
|
}
|
|
99
126
|
}
|
|
100
127
|
for (const [errorCode, mappedCode] of Object.entries(COMMON_ERROR_CODE_MAP)) {
|
|
101
|
-
if (mappedCode ===
|
|
128
|
+
if (mappedCode === normalizedCode ||
|
|
129
|
+
mappedCode === `E_${normalizedCode}`) {
|
|
102
130
|
return errorCode;
|
|
103
131
|
}
|
|
104
132
|
}
|
|
105
133
|
return ErrorCode.Unknown;
|
|
106
134
|
},
|
|
107
135
|
toPlatformCode: (errorCode, _platform) => {
|
|
108
|
-
const
|
|
109
|
-
const native = NATIVE_ERROR_CODES[standardized];
|
|
136
|
+
const native = NATIVE_ERROR_CODES[errorCode];
|
|
110
137
|
return native ?? COMMON_ERROR_CODE_MAP[errorCode] ?? 'E_UNKNOWN';
|
|
111
138
|
},
|
|
112
139
|
isValidForPlatform: (errorCode, platform) => {
|
|
113
|
-
|
|
114
|
-
if (NATIVE_ERROR_CODES[standardized] !==
|
|
115
|
-
undefined) {
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
return standardized in ErrorCodeMapping[normalizePlatform(platform)];
|
|
140
|
+
return (NATIVE_ERROR_CODES[errorCode] !== undefined);
|
|
119
141
|
},
|
|
120
142
|
};
|
|
121
143
|
const ERROR_CODES = new Set(Object.values(ErrorCode));
|
|
@@ -126,11 +148,19 @@ const normalizeErrorCode = (code) => {
|
|
|
126
148
|
if (ERROR_CODES.has(code)) {
|
|
127
149
|
return code;
|
|
128
150
|
}
|
|
151
|
+
const camelCased = toKebabCase(code);
|
|
152
|
+
if (ERROR_CODES.has(camelCased)) {
|
|
153
|
+
return camelCased;
|
|
154
|
+
}
|
|
129
155
|
if (code.startsWith('E_')) {
|
|
130
156
|
const trimmed = code.substring(2);
|
|
131
157
|
if (ERROR_CODES.has(trimmed)) {
|
|
132
158
|
return trimmed;
|
|
133
159
|
}
|
|
160
|
+
const camelTrimmed = toKebabCase(trimmed);
|
|
161
|
+
if (ERROR_CODES.has(camelTrimmed)) {
|
|
162
|
+
return camelTrimmed;
|
|
163
|
+
}
|
|
134
164
|
}
|
|
135
165
|
return code;
|
|
136
166
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorMapping.js","sourceRoot":"","sources":["../../src/utils/errorMapping.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,kBAAkB,EAAC,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAC,SAAS,EAAc,MAAM,UAAU,CAAC;AAqBhD,MAAM,kBAAkB,GAAG,CAAC,SAAo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;QAC3D,KAAK,SAAS,CAAC,kBAAkB;YAC/B,OAAO,mDAAmD,CAAC;QAC7D,KAAK,SAAS,CAAC,eAAe;YAC5B,OAAO,yCAAyC,CAAC;QACnD,KAAK,SAAS,CAAC,YAAY;YACzB,OAAO,yBAAyB,CAAC;QACnC,KAAK,SAAS,CAAC,YAAY;YACzB,OAAO,2BAA2B,CAAC;QACrC,KAAK,SAAS,CAAC,WAAW;YACxB,OAAO,sCAAsC,CAAC;QAChD,KAAK,SAAS,CAAC,gBAAgB;YAC7B,OAAO,uCAAuC,CAAC;QACjD,KAAK,SAAS,CAAC,eAAe;YAC5B,OAAO,6BAA6B,CAAC;QACvC,KAAK,SAAS,CAAC,WAAW;YACxB,OAAO,uDAAuD,CAAC;QACjE,KAAK,SAAS,CAAC,YAAY;YACzB,OAAO,8CAA8C,CAAC;QACxD,KAAK,SAAS,CAAC,mBAAmB;YAChC,OAAO,+CAA+C,CAAC;QACzD,KAAK,SAAS,CAAC,2BAA2B;YACxC,OAAO,mCAAmC,CAAC;QAC7C,KAAK,SAAS,CAAC,aAAa;YAC1B,OAAO,2BAA2B,CAAC;QACrC,KAAK,SAAS,CAAC,YAAY;YACzB,OAAO,yBAAyB,CAAC;QACnC,KAAK,SAAS,CAAC,cAAc;YAC3B,OAAO,yCAAyC,CAAC;QACnD,KAAK,SAAS,CAAC,YAAY;YACzB,OAAO,mDAAmD,CAAC;QAC7D,OAAO,CAAC,CAAC,CAAC;YACR,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;gBAC7D,OAAO,CACJ,KAA4B,CAAC,OAAO;oBACrC,8BAA8B,CAC/B,CAAC;YACJ,CAAC;YACD,OAAO,8BAA8B,CAAC;QACxC,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/**\n * Error mapping utilities for expo-iap.\n * Provides helpers for working with platform-specific error codes\n * and constructing structured purchase errors.\n */\n\nimport {NATIVE_ERROR_CODES} from '../ExpoIapModule';\nimport {ErrorCode, IapPlatform} from '../types';\n\nexport interface PurchaseErrorProps {\n message: string;\n responseCode?: number;\n debugMessage?: string;\n code?: ErrorCode;\n productId?: string;\n platform?: IapPlatform;\n}\n\ntype PlatformErrorData = {\n code?: string | number;\n message?: string;\n responseCode?: number;\n debugMessage?: string;\n productId?: string;\n};\n\nexport type PurchaseError = Error & PurchaseErrorProps;\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 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\nexport const ErrorCodeMapping = {\n ios: COMMON_ERROR_CODE_MAP,\n android: COMMON_ERROR_CODE_MAP,\n} as const;\n\nconst OPENIAP_ERROR_CODE_SET: Set<string> = new Set(\n Object.values(ErrorCode).map((code) => toStandardizedCode(code)),\n);\n\nexport const createPurchaseError = (\n props: PurchaseErrorProps,\n): PurchaseError => {\n const error = new Error(props.message) as PurchaseError;\n error.name = '[expo-iap]: PurchaseError';\n error.responseCode = props.responseCode;\n error.debugMessage = props.debugMessage;\n error.code = props.code;\n error.productId = props.productId;\n error.platform = props.platform;\n return error;\n};\n\nexport const createPurchaseErrorFromPlatform = (\n errorData: PlatformErrorData,\n platform: IapPlatform,\n): PurchaseError => {\n const normalizedPlatform = normalizePlatform(platform);\n const errorCode = errorData.code\n ? ErrorCodeUtils.fromPlatformCode(errorData.code, normalizedPlatform)\n : ErrorCode.Unknown;\n\n return createPurchaseError({\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\nexport const ErrorCodeUtils = {\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 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 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 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\n// ---------------------------------------------------------------------------\n// Convenience helpers for interpreting error objects\n// ---------------------------------------------------------------------------\n\ntype ErrorLike = string | {code?: ErrorCode | string; message?: string};\n\nconst ERROR_CODES = new Set<string>(Object.values(ErrorCode));\n\nconst normalizeErrorCode = (code?: string | null): string | undefined => {\n if (!code) {\n return undefined;\n }\n\n if (ERROR_CODES.has(code)) {\n return code;\n }\n\n if (code.startsWith('E_')) {\n const trimmed = code.substring(2);\n if (ERROR_CODES.has(trimmed)) {\n return trimmed;\n }\n }\n\n return code;\n};\n\nfunction extractCode(error: unknown): string | undefined {\n if (typeof error === 'string') {\n return normalizeErrorCode(error);\n }\n\n if (error && typeof error === 'object' && 'code' in error) {\n return normalizeErrorCode((error as {code?: string}).code);\n }\n\n return undefined;\n}\n\nexport function isUserCancelledError(error: unknown): boolean {\n return extractCode(error) === ErrorCode.UserCancelled;\n}\n\nexport function isNetworkError(error: unknown): boolean {\n const networkErrors: ErrorCode[] = [\n ErrorCode.NetworkError,\n ErrorCode.RemoteError,\n ErrorCode.ServiceError,\n ErrorCode.ServiceDisconnected,\n ErrorCode.BillingUnavailable,\n ];\n\n const code = extractCode(error);\n return !!code && (networkErrors as string[]).includes(code);\n}\n\nexport function isRecoverableError(error: unknown): boolean {\n const recoverableErrors: ErrorCode[] = [\n ErrorCode.NetworkError,\n ErrorCode.RemoteError,\n ErrorCode.ServiceError,\n ErrorCode.Interrupted,\n ErrorCode.ServiceDisconnected,\n ErrorCode.BillingUnavailable,\n ErrorCode.QueryProduct,\n ErrorCode.InitConnection,\n ];\n\n const code = extractCode(error);\n return !!code && (recoverableErrors as string[]).includes(code);\n}\n\nexport function getUserFriendlyErrorMessage(error: ErrorLike): string {\n const errorCode = extractCode(error);\n\n switch (errorCode) {\n case ErrorCode.UserCancelled:\n return 'Purchase was cancelled by user';\n case ErrorCode.NetworkError:\n return 'Network connection error. Please check your internet connection and try again.';\n case ErrorCode.ReceiptFinished:\n return 'Receipt already finished';\n case ErrorCode.ServiceDisconnected:\n return 'Billing service disconnected. Please try again.';\n case ErrorCode.BillingUnavailable:\n return 'Billing is unavailable on this device or account.';\n case ErrorCode.ItemUnavailable:\n return 'This item is not available for purchase';\n case ErrorCode.ItemNotOwned:\n return \"You don't own this item\";\n case ErrorCode.AlreadyOwned:\n return 'You already own this item';\n case ErrorCode.SkuNotFound:\n return 'Requested product could not be found';\n case ErrorCode.SkuOfferMismatch:\n return 'Selected offer does not match the SKU';\n case ErrorCode.DeferredPayment:\n return 'Payment is pending approval';\n case ErrorCode.NotPrepared:\n return 'In-app purchase is not ready. Please try again later.';\n case ErrorCode.ServiceError:\n return 'Store service error. Please try again later.';\n case ErrorCode.FeatureNotSupported:\n return 'This feature is not supported on this device.';\n case ErrorCode.TransactionValidationFailed:\n return 'Transaction could not be verified';\n case ErrorCode.ReceiptFailed:\n return 'Receipt processing failed';\n case ErrorCode.EmptySkuList:\n return 'No product IDs provided';\n case ErrorCode.InitConnection:\n return 'Failed to initialize billing connection';\n case ErrorCode.QueryProduct:\n return 'Failed to query products. Please try again later.';\n default: {\n if (error && typeof error === 'object' && 'message' in error) {\n return (\n (error as {message?: string}).message ??\n 'An unexpected error occurred'\n );\n }\n return 'An unexpected error occurred';\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"errorMapping.js","sourceRoot":"","sources":["../../src/utils/errorMapping.ts"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,OAAO,mCAAmC,CAAC;QAC7C,KAAK,SAAS,CAAC,aAAa;YAC1B,OAAO,2BAA2B,CAAC;QACrC,KAAK,SAAS,CAAC,YAAY;YACzB,OAAO,yBAAyB,CAAC;QACnC,KAAK,SAAS,CAAC,cAAc;YAC3B,OAAO,yCAAyC,CAAC;QACnD,KAAK,SAAS,CAAC,YAAY;YACzB,OAAO,mDAAmD,CAAC;QAC7D,OAAO,CAAC,CAAC,CAAC;YACR,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,IAAI,KAAK,EAAE,CAAC;gBAC7D,OAAO,CACJ,KAA4B,CAAC,OAAO;oBACrC,8BAA8B,CAC/B,CAAC;YACJ,CAAC;YACD,OAAO,8BAA8B,CAAC;QACxC,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["/**\n * Error mapping utilities for expo-iap.\n * Provides helpers for working with platform-specific error codes\n * and constructing structured purchase errors.\n */\n\nimport {NATIVE_ERROR_CODES} from '../ExpoIapModule';\nimport {ErrorCode, IapPlatform} from '../types';\n\nconst toKebabCase = (str: string): string => {\n if (str.includes('_')) {\n return str\n .split('_')\n .map((word) => word.toLowerCase())\n .join('-');\n } else {\n return str\n .replace(/([A-Z])/g, '-$1')\n .toLowerCase()\n .replace(/^-/, '');\n }\n};\n\nexport interface PurchaseErrorProps {\n message?: string;\n responseCode?: number;\n debugMessage?: string;\n code?: ErrorCode | string | number;\n productId?: string;\n platform?: IapPlatform;\n}\n\nexport interface PurchaseError extends Error {\n responseCode?: number;\n debugMessage?: string;\n code?: ErrorCode;\n productId?: string;\n platform?: IapPlatform;\n}\n\nconst normalizePlatform = (platform: IapPlatform): 'ios' | 'android' =>\n typeof platform === 'string' && platform.toLowerCase() === 'ios'\n ? 'ios'\n : 'android';\n\nconst COMMON_ERROR_CODE_MAP: Record<ErrorCode, string> = {\n [ErrorCode.Unknown]: ErrorCode.Unknown,\n [ErrorCode.UserCancelled]: ErrorCode.UserCancelled,\n [ErrorCode.UserError]: ErrorCode.UserError,\n [ErrorCode.ItemUnavailable]: ErrorCode.ItemUnavailable,\n [ErrorCode.RemoteError]: ErrorCode.RemoteError,\n [ErrorCode.NetworkError]: ErrorCode.NetworkError,\n [ErrorCode.ServiceError]: ErrorCode.ServiceError,\n [ErrorCode.ReceiptFailed]: ErrorCode.ReceiptFailed,\n [ErrorCode.ReceiptFinished]: ErrorCode.ReceiptFinished,\n [ErrorCode.ReceiptFinishedFailed]: ErrorCode.ReceiptFinishedFailed,\n [ErrorCode.NotPrepared]: ErrorCode.NotPrepared,\n [ErrorCode.NotEnded]: ErrorCode.NotEnded,\n [ErrorCode.AlreadyOwned]: ErrorCode.AlreadyOwned,\n [ErrorCode.DeveloperError]: ErrorCode.DeveloperError,\n [ErrorCode.BillingResponseJsonParseError]:\n ErrorCode.BillingResponseJsonParseError,\n [ErrorCode.DeferredPayment]: ErrorCode.DeferredPayment,\n [ErrorCode.Interrupted]: ErrorCode.Interrupted,\n [ErrorCode.IapNotAvailable]: ErrorCode.IapNotAvailable,\n [ErrorCode.PurchaseError]: ErrorCode.PurchaseError,\n [ErrorCode.SyncError]: ErrorCode.SyncError,\n [ErrorCode.TransactionValidationFailed]:\n ErrorCode.TransactionValidationFailed,\n [ErrorCode.ActivityUnavailable]: ErrorCode.ActivityUnavailable,\n [ErrorCode.AlreadyPrepared]: ErrorCode.AlreadyPrepared,\n [ErrorCode.Pending]: ErrorCode.Pending,\n [ErrorCode.ConnectionClosed]: ErrorCode.ConnectionClosed,\n [ErrorCode.InitConnection]: ErrorCode.InitConnection,\n [ErrorCode.ServiceDisconnected]: ErrorCode.ServiceDisconnected,\n [ErrorCode.QueryProduct]: ErrorCode.QueryProduct,\n [ErrorCode.SkuNotFound]: ErrorCode.SkuNotFound,\n [ErrorCode.SkuOfferMismatch]: ErrorCode.SkuOfferMismatch,\n [ErrorCode.ItemNotOwned]: ErrorCode.ItemNotOwned,\n [ErrorCode.BillingUnavailable]: ErrorCode.BillingUnavailable,\n [ErrorCode.FeatureNotSupported]: ErrorCode.FeatureNotSupported,\n [ErrorCode.EmptySkuList]: ErrorCode.EmptySkuList,\n};\n\nexport const ErrorCodeMapping = {\n ios: COMMON_ERROR_CODE_MAP,\n android: COMMON_ERROR_CODE_MAP,\n} as const;\n\nconst OPENIAP_ERROR_CODE_SET: Set<string> = new Set(Object.values(ErrorCode));\n\nexport const createPurchaseError = (\n props: PurchaseErrorProps,\n): PurchaseError => {\n const errorCode = props.code\n ? typeof props.code === 'string' || typeof props.code === 'number'\n ? ErrorCodeUtils.fromPlatformCode(props.code, props.platform || 'ios')\n : props.code\n : undefined;\n\n const error = new Error(\n props.message ?? 'Unknown error occurred',\n ) as PurchaseError;\n error.name = '[expo-iap]: PurchaseError';\n error.responseCode = props.responseCode;\n error.debugMessage = props.debugMessage;\n error.code = errorCode;\n error.productId = props.productId;\n error.platform = props.platform;\n return error;\n};\n\nexport const createPurchaseErrorFromPlatform = (\n errorData: PurchaseErrorProps,\n platform: IapPlatform,\n): PurchaseError => {\n const normalizedPlatform = normalizePlatform(platform);\n const errorCode = errorData.code\n ? typeof errorData.code === 'string' || typeof errorData.code === 'number'\n ? ErrorCodeUtils.fromPlatformCode(errorData.code, normalizedPlatform)\n : errorData.code\n : ErrorCode.Unknown;\n\n return createPurchaseError({\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\nexport const ErrorCodeUtils = {\n getNativeErrorCode: (errorCode: ErrorCode): string => {\n return (\n (NATIVE_ERROR_CODES as Record<string, string | undefined>)[errorCode] ??\n errorCode\n );\n },\n fromPlatformCode: (\n platformCode: string | number,\n _platform: IapPlatform,\n ): ErrorCode => {\n if (typeof platformCode === 'string' && platformCode.startsWith('E_')) {\n const withoutE = platformCode.substring(2);\n const camelCased = toKebabCase(withoutE);\n const withE = `E_${camelCased}`;\n if (OPENIAP_ERROR_CODE_SET.has(withE)) {\n const match = Object.entries(COMMON_ERROR_CODE_MAP).find(\n ([, value]) => value === withE,\n );\n if (match) {\n return match[0] as ErrorCode;\n }\n }\n }\n\n const normalizedCode =\n typeof platformCode === 'string'\n ? toKebabCase(platformCode)\n : platformCode;\n\n for (const [standardized, nativeCode] of Object.entries(\n (NATIVE_ERROR_CODES || {}) as Record<string, string | number>,\n )) {\n const normalizedNative =\n typeof nativeCode === 'string' ? toKebabCase(nativeCode) : nativeCode;\n if (\n normalizedNative === normalizedCode &&\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 (\n mappedCode === normalizedCode ||\n mappedCode === `E_${normalizedCode}`\n ) {\n return errorCode as ErrorCode;\n }\n }\n\n return ErrorCode.Unknown;\n },\n toPlatformCode: (\n errorCode: ErrorCode,\n _platform: IapPlatform,\n ): string | number => {\n const native = (NATIVE_ERROR_CODES as Record<string, string | number>)[\n errorCode\n ];\n return native ?? COMMON_ERROR_CODE_MAP[errorCode] ?? 'E_UNKNOWN';\n },\n isValidForPlatform: (\n errorCode: ErrorCode,\n platform: IapPlatform,\n ): boolean => {\n return (\n (NATIVE_ERROR_CODES as Record<string, unknown>)[errorCode] !== undefined\n );\n },\n};\n\n// ---------------------------------------------------------------------------\n// Convenience helpers for interpreting error objects\n// ---------------------------------------------------------------------------\n\ntype ErrorLike = string | {code?: ErrorCode | string; message?: string};\n\nconst ERROR_CODES = new Set<string>(Object.values(ErrorCode));\n\nconst normalizeErrorCode = (code?: string | null): string | undefined => {\n if (!code) {\n return undefined;\n }\n\n if (ERROR_CODES.has(code)) {\n return code;\n }\n\n const camelCased = toKebabCase(code);\n if (ERROR_CODES.has(camelCased)) {\n return camelCased;\n }\n\n if (code.startsWith('E_')) {\n const trimmed = code.substring(2);\n if (ERROR_CODES.has(trimmed)) {\n return trimmed;\n }\n const camelTrimmed = toKebabCase(trimmed);\n if (ERROR_CODES.has(camelTrimmed)) {\n return camelTrimmed;\n }\n }\n\n return code;\n};\n\nfunction extractCode(error: unknown): string | undefined {\n if (typeof error === 'string') {\n return normalizeErrorCode(error);\n }\n\n if (error && typeof error === 'object' && 'code' in error) {\n return normalizeErrorCode((error as {code?: string}).code);\n }\n\n return undefined;\n}\n\nexport function isUserCancelledError(error: unknown): boolean {\n return extractCode(error) === ErrorCode.UserCancelled;\n}\n\nexport function isNetworkError(error: unknown): boolean {\n const networkErrors: ErrorCode[] = [\n ErrorCode.NetworkError,\n ErrorCode.RemoteError,\n ErrorCode.ServiceError,\n ErrorCode.ServiceDisconnected,\n ErrorCode.BillingUnavailable,\n ];\n\n const code = extractCode(error);\n return !!code && (networkErrors as string[]).includes(code);\n}\n\nexport function isRecoverableError(error: unknown): boolean {\n const recoverableErrors: ErrorCode[] = [\n ErrorCode.NetworkError,\n ErrorCode.RemoteError,\n ErrorCode.ServiceError,\n ErrorCode.Interrupted,\n ErrorCode.ServiceDisconnected,\n ErrorCode.BillingUnavailable,\n ErrorCode.QueryProduct,\n ErrorCode.InitConnection,\n ];\n\n const code = extractCode(error);\n return !!code && (recoverableErrors as string[]).includes(code);\n}\n\nexport function getUserFriendlyErrorMessage(error: ErrorLike): string {\n const errorCode = extractCode(error);\n\n switch (errorCode) {\n case ErrorCode.UserCancelled:\n return 'Purchase was cancelled by user';\n case ErrorCode.NetworkError:\n return 'Network connection error. Please check your internet connection and try again.';\n case ErrorCode.ReceiptFinished:\n return 'Receipt already finished';\n case ErrorCode.ServiceDisconnected:\n return 'Billing service disconnected. Please try again.';\n case ErrorCode.BillingUnavailable:\n return 'Billing is unavailable on this device or account.';\n case ErrorCode.ItemUnavailable:\n return 'This item is not available for purchase';\n case ErrorCode.ItemNotOwned:\n return \"You don't own this item\";\n case ErrorCode.AlreadyOwned:\n return 'You already own this item';\n case ErrorCode.SkuNotFound:\n return 'Requested product could not be found';\n case ErrorCode.SkuOfferMismatch:\n return 'Selected offer does not match the SKU';\n case ErrorCode.DeferredPayment:\n return 'Payment is pending approval';\n case ErrorCode.NotPrepared:\n return 'In-app purchase is not ready. Please try again later.';\n case ErrorCode.ServiceError:\n return 'Store service error. Please try again later.';\n case ErrorCode.FeatureNotSupported:\n return 'This feature is not supported on this device.';\n case ErrorCode.TransactionValidationFailed:\n return 'Transaction could not be verified';\n case ErrorCode.ReceiptFailed:\n return 'Receipt processing failed';\n case ErrorCode.EmptySkuList:\n return 'No product IDs provided';\n case ErrorCode.InitConnection:\n return 'Failed to initialize billing connection';\n case ErrorCode.QueryProduct:\n return 'Failed to query products. Please try again later.';\n default: {\n if (error && typeof error === 'object' && 'message' in error) {\n return (\n (error as {message?: string}).message ??\n 'An unexpected error occurred'\n );\n }\n return 'An unexpected error occurred';\n }\n }\n}\n"]}
|