expo-iap 2.8.1 → 2.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/build/ExpoIap.types.d.ts +13 -9
- package/build/ExpoIap.types.d.ts.map +1 -1
- package/build/ExpoIap.types.js.map +1 -1
- package/build/index.d.ts +6 -6
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -3
- package/build/index.js.map +1 -1
- package/build/modules/ios.d.ts +8 -8
- package/build/modules/ios.d.ts.map +1 -1
- package/build/modules/ios.js +3 -3
- package/build/modules/ios.js.map +1 -1
- package/build/useIAP.d.ts +6 -6
- package/build/useIAP.d.ts.map +1 -1
- package/build/useIAP.js.map +1 -1
- package/bun.lock +122 -456
- package/package.json +1 -1
- package/src/ExpoIap.types.ts +15 -16
- package/src/index.ts +12 -22
- package/src/modules/ios.ts +13 -20
- package/src/useIAP.ts +11 -19
package/package.json
CHANGED
package/src/ExpoIap.types.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ProductAndroid,
|
|
3
|
-
|
|
3
|
+
PurchaseAndroid,
|
|
4
4
|
ProductSubscriptionAndroid,
|
|
5
5
|
} from './types/ExpoIapAndroid.types';
|
|
6
6
|
import {
|
|
7
7
|
ProductIOS,
|
|
8
|
-
|
|
8
|
+
PurchaseIOS,
|
|
9
9
|
ProductSubscriptionIOS,
|
|
10
10
|
} from './types/ExpoIapIOS.types';
|
|
11
11
|
import {NATIVE_ERROR_CODES} from './ExpoIapModule';
|
|
@@ -63,29 +63,28 @@ export type SubscriptionProduct =
|
|
|
63
63
|
|
|
64
64
|
// Re-export platform-specific types
|
|
65
65
|
export type {
|
|
66
|
-
ProductPurchaseAndroid,
|
|
67
66
|
PurchaseAndroid,
|
|
68
67
|
ProductSubscriptionAndroid,
|
|
69
|
-
SubscriptionProductAndroid, // Legacy
|
|
70
68
|
} from './types/ExpoIapAndroid.types';
|
|
71
69
|
export type {
|
|
72
|
-
ProductPurchaseIOS,
|
|
73
70
|
PurchaseIOS,
|
|
74
71
|
ProductSubscriptionIOS,
|
|
75
|
-
SubscriptionProductIOS, // Legacy
|
|
76
72
|
} from './types/ExpoIapIOS.types';
|
|
77
73
|
|
|
78
|
-
//
|
|
79
|
-
export type
|
|
80
|
-
| (
|
|
81
|
-
| (
|
|
74
|
+
// Unified purchase type for both products and subscriptions
|
|
75
|
+
export type Purchase =
|
|
76
|
+
| (PurchaseAndroid & AndroidPlatform)
|
|
77
|
+
| (PurchaseIOS & IosPlatform);
|
|
82
78
|
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
79
|
+
// Legacy type aliases - deprecated, use Purchase instead
|
|
80
|
+
/**
|
|
81
|
+
* @deprecated Use `Purchase` instead. This type alias will be removed in v2.9.0.
|
|
82
|
+
*/
|
|
83
|
+
export type ProductPurchase = Purchase;
|
|
84
|
+
/**
|
|
85
|
+
* @deprecated Use `Purchase` instead. This type alias will be removed in v2.9.0.
|
|
86
|
+
*/
|
|
87
|
+
export type SubscriptionPurchase = Purchase;
|
|
89
88
|
|
|
90
89
|
export type PurchaseResult = {
|
|
91
90
|
responseCode?: number;
|
package/src/index.ts
CHANGED
|
@@ -18,16 +18,14 @@ import {
|
|
|
18
18
|
// Types
|
|
19
19
|
import {
|
|
20
20
|
Product,
|
|
21
|
-
ProductPurchase,
|
|
22
21
|
Purchase,
|
|
23
22
|
PurchaseError,
|
|
24
23
|
PurchaseResult,
|
|
25
24
|
RequestSubscriptionProps,
|
|
26
25
|
RequestPurchaseProps,
|
|
27
26
|
SubscriptionProduct,
|
|
28
|
-
SubscriptionPurchase,
|
|
29
27
|
} from './ExpoIap.types';
|
|
30
|
-
import {
|
|
28
|
+
import {PurchaseAndroid} from './types/ExpoIapAndroid.types';
|
|
31
29
|
import {PaymentDiscount} from './types/ExpoIapIOS.types';
|
|
32
30
|
|
|
33
31
|
// Export all types
|
|
@@ -281,7 +279,7 @@ export const getPurchaseHistory = ({
|
|
|
281
279
|
}: {
|
|
282
280
|
alsoPublishToEventListener?: boolean;
|
|
283
281
|
onlyIncludeActiveItems?: boolean;
|
|
284
|
-
} = {}): Promise<
|
|
282
|
+
} = {}): Promise<Purchase[]> => {
|
|
285
283
|
console.warn(
|
|
286
284
|
'`getPurchaseHistory` is deprecated. Use `getPurchaseHistories` instead. This function will be removed in version 3.0.0.',
|
|
287
285
|
);
|
|
@@ -297,7 +295,7 @@ export const getPurchaseHistories = ({
|
|
|
297
295
|
}: {
|
|
298
296
|
alsoPublishToEventListener?: boolean;
|
|
299
297
|
onlyIncludeActiveItems?: boolean;
|
|
300
|
-
} = {}): Promise<
|
|
298
|
+
} = {}): Promise<Purchase[]> =>
|
|
301
299
|
(
|
|
302
300
|
Platform.select({
|
|
303
301
|
ios: async () => {
|
|
@@ -323,7 +321,7 @@ export const getAvailablePurchases = ({
|
|
|
323
321
|
}: {
|
|
324
322
|
alsoPublishToEventListener?: boolean;
|
|
325
323
|
onlyIncludeActiveItems?: boolean;
|
|
326
|
-
} = {}): Promise<
|
|
324
|
+
} = {}): Promise<Purchase[]> =>
|
|
327
325
|
(
|
|
328
326
|
Platform.select({
|
|
329
327
|
ios: () =>
|
|
@@ -409,13 +407,7 @@ const normalizeRequestProps = (
|
|
|
409
407
|
*/
|
|
410
408
|
export const requestPurchase = (
|
|
411
409
|
requestObj: PurchaseRequest,
|
|
412
|
-
): Promise<
|
|
413
|
-
| ProductPurchase
|
|
414
|
-
| SubscriptionPurchase
|
|
415
|
-
| ProductPurchase[]
|
|
416
|
-
| SubscriptionPurchase[]
|
|
417
|
-
| void
|
|
418
|
-
> => {
|
|
410
|
+
): Promise<Purchase | Purchase[] | void> => {
|
|
419
411
|
const {request, type = 'inapp'} = requestObj;
|
|
420
412
|
|
|
421
413
|
if (Platform.OS === 'ios') {
|
|
@@ -445,9 +437,7 @@ export const requestPurchase = (
|
|
|
445
437
|
offer,
|
|
446
438
|
);
|
|
447
439
|
|
|
448
|
-
return type === 'inapp'
|
|
449
|
-
? (purchase as ProductPurchase)
|
|
450
|
-
: (purchase as SubscriptionPurchase);
|
|
440
|
+
return type === 'inapp' ? (purchase as Purchase) : (purchase as Purchase);
|
|
451
441
|
})();
|
|
452
442
|
}
|
|
453
443
|
|
|
@@ -478,7 +468,7 @@ export const requestPurchase = (
|
|
|
478
468
|
obfuscatedProfileId: obfuscatedProfileIdAndroid,
|
|
479
469
|
offerTokenArr: [],
|
|
480
470
|
isOfferPersonalized: isOfferPersonalized ?? false,
|
|
481
|
-
}) as Promise<
|
|
471
|
+
}) as Promise<Purchase[]>;
|
|
482
472
|
})();
|
|
483
473
|
}
|
|
484
474
|
|
|
@@ -504,7 +494,7 @@ export const requestPurchase = (
|
|
|
504
494
|
obfuscatedProfileId: obfuscatedProfileIdAndroid,
|
|
505
495
|
offerTokenArr: subscriptionOffers.map((so: any) => so.offerToken),
|
|
506
496
|
isOfferPersonalized: isOfferPersonalized ?? false,
|
|
507
|
-
}) as Promise<
|
|
497
|
+
}) as Promise<Purchase[]>;
|
|
508
498
|
})();
|
|
509
499
|
}
|
|
510
500
|
|
|
@@ -543,13 +533,13 @@ export const requestPurchase = (
|
|
|
543
533
|
*/
|
|
544
534
|
export const requestSubscription = async (
|
|
545
535
|
request: RequestSubscriptionProps,
|
|
546
|
-
): Promise<
|
|
536
|
+
): Promise<Purchase | Purchase[] | null | void> => {
|
|
547
537
|
console.warn(
|
|
548
538
|
"`requestSubscription` is deprecated and will be removed in version 3.0.0. Use `requestPurchase({ request, type: 'subs' })` instead.",
|
|
549
539
|
);
|
|
550
540
|
return (await requestPurchase({request, type: 'subs'})) as
|
|
551
|
-
|
|
|
552
|
-
|
|
|
541
|
+
| Purchase
|
|
542
|
+
| Purchase[]
|
|
553
543
|
| null
|
|
554
544
|
| void;
|
|
555
545
|
};
|
|
@@ -574,7 +564,7 @@ export const finishTransaction = ({
|
|
|
574
564
|
return Promise.resolve(true);
|
|
575
565
|
},
|
|
576
566
|
android: async () => {
|
|
577
|
-
const androidPurchase = purchase as
|
|
567
|
+
const androidPurchase = purchase as PurchaseAndroid;
|
|
578
568
|
|
|
579
569
|
if (isConsumable) {
|
|
580
570
|
return ExpoIapModule.consumeProduct(androidPurchase.purchaseToken);
|
package/src/modules/ios.ts
CHANGED
|
@@ -5,12 +5,7 @@ import {purchaseUpdatedListener} from '..';
|
|
|
5
5
|
import ExpoIapModule from '../ExpoIapModule';
|
|
6
6
|
|
|
7
7
|
// Types
|
|
8
|
-
import {
|
|
9
|
-
ProductPurchase,
|
|
10
|
-
PurchaseError,
|
|
11
|
-
Purchase,
|
|
12
|
-
SubscriptionPurchase,
|
|
13
|
-
} from '../ExpoIap.types';
|
|
8
|
+
import {Purchase, PurchaseError} from '../ExpoIap.types';
|
|
14
9
|
import type {
|
|
15
10
|
ProductStatusIOS,
|
|
16
11
|
AppTransactionIOS,
|
|
@@ -18,7 +13,7 @@ import type {
|
|
|
18
13
|
import {Linking} from 'react-native';
|
|
19
14
|
|
|
20
15
|
export type TransactionEvent = {
|
|
21
|
-
transaction?:
|
|
16
|
+
transaction?: Purchase;
|
|
22
17
|
error?: PurchaseError;
|
|
23
18
|
};
|
|
24
19
|
|
|
@@ -39,7 +34,7 @@ export type TransactionEvent = {
|
|
|
39
34
|
export const transactionUpdatedIOS = (
|
|
40
35
|
listener: (event: TransactionEvent) => void,
|
|
41
36
|
) => {
|
|
42
|
-
const
|
|
37
|
+
const isPurchase = (item: unknown): item is Purchase => {
|
|
43
38
|
return (
|
|
44
39
|
item != null &&
|
|
45
40
|
typeof item === 'object' &&
|
|
@@ -51,18 +46,18 @@ export const transactionUpdatedIOS = (
|
|
|
51
46
|
|
|
52
47
|
// Helper function to safely convert Purchase to TransactionEvent
|
|
53
48
|
const mapPurchaseToTransactionEvent = (
|
|
54
|
-
purchase: Purchase
|
|
49
|
+
purchase: Purchase,
|
|
55
50
|
): TransactionEvent => {
|
|
56
51
|
// Validate the purchase object before casting
|
|
57
|
-
if (
|
|
52
|
+
if (isPurchase(purchase)) {
|
|
58
53
|
return {
|
|
59
|
-
transaction: purchase as
|
|
54
|
+
transaction: purchase as Purchase,
|
|
60
55
|
};
|
|
61
56
|
}
|
|
62
57
|
|
|
63
58
|
// Fallback: create a basic TransactionEvent structure
|
|
64
59
|
return {
|
|
65
|
-
transaction: purchase as
|
|
60
|
+
transaction: purchase as Purchase,
|
|
66
61
|
};
|
|
67
62
|
};
|
|
68
63
|
|
|
@@ -138,9 +133,7 @@ export const subscriptionStatusIOS = (
|
|
|
138
133
|
*
|
|
139
134
|
* @platform iOS
|
|
140
135
|
*/
|
|
141
|
-
export const currentEntitlementIOS = (
|
|
142
|
-
sku: string,
|
|
143
|
-
): Promise<ProductPurchase> => {
|
|
136
|
+
export const currentEntitlementIOS = (sku: string): Promise<Purchase> => {
|
|
144
137
|
return ExpoIapModule.currentEntitlement(sku);
|
|
145
138
|
};
|
|
146
139
|
|
|
@@ -153,7 +146,7 @@ export const currentEntitlementIOS = (
|
|
|
153
146
|
*
|
|
154
147
|
* @platform iOS
|
|
155
148
|
*/
|
|
156
|
-
export const latestTransactionIOS = (sku: string): Promise<
|
|
149
|
+
export const latestTransactionIOS = (sku: string): Promise<Purchase> => {
|
|
157
150
|
return ExpoIapModule.latestTransaction(sku);
|
|
158
151
|
};
|
|
159
152
|
|
|
@@ -241,7 +234,7 @@ export const getTransactionJwsIOS = (sku: string): Promise<string> => {
|
|
|
241
234
|
* isValid: boolean;
|
|
242
235
|
* receiptData: string;
|
|
243
236
|
* jwsRepresentation: string;
|
|
244
|
-
* latestTransaction?:
|
|
237
|
+
* latestTransaction?: Purchase;
|
|
245
238
|
* }>}
|
|
246
239
|
*/
|
|
247
240
|
export const validateReceiptIOS = async (
|
|
@@ -250,7 +243,7 @@ export const validateReceiptIOS = async (
|
|
|
250
243
|
isValid: boolean;
|
|
251
244
|
receiptData: string;
|
|
252
245
|
jwsRepresentation: string;
|
|
253
|
-
latestTransaction?:
|
|
246
|
+
latestTransaction?: Purchase;
|
|
254
247
|
}> => {
|
|
255
248
|
const result = await ExpoIapModule.validateReceiptIOS(sku);
|
|
256
249
|
return result;
|
|
@@ -362,7 +355,7 @@ export const subscriptionStatus = (
|
|
|
362
355
|
/**
|
|
363
356
|
* @deprecated Use `currentEntitlementIOS` instead. This function will be removed in version 3.0.0.
|
|
364
357
|
*/
|
|
365
|
-
export const currentEntitlement = (sku: string): Promise<
|
|
358
|
+
export const currentEntitlement = (sku: string): Promise<Purchase> => {
|
|
366
359
|
console.warn(
|
|
367
360
|
'`currentEntitlement` is deprecated. Use `currentEntitlementIOS` instead. This function will be removed in version 3.0.0.',
|
|
368
361
|
);
|
|
@@ -372,7 +365,7 @@ export const currentEntitlement = (sku: string): Promise<ProductPurchase> => {
|
|
|
372
365
|
/**
|
|
373
366
|
* @deprecated Use `latestTransactionIOS` instead. This function will be removed in version 3.0.0.
|
|
374
367
|
*/
|
|
375
|
-
export const latestTransaction = (sku: string): Promise<
|
|
368
|
+
export const latestTransaction = (sku: string): Promise<Purchase> => {
|
|
376
369
|
console.warn(
|
|
377
370
|
'`latestTransaction` is deprecated. Use `latestTransactionIOS` instead. This function will be removed in version 3.0.0.',
|
|
378
371
|
);
|
package/src/useIAP.ts
CHANGED
|
@@ -29,12 +29,10 @@ import {
|
|
|
29
29
|
// Types
|
|
30
30
|
import {
|
|
31
31
|
Product,
|
|
32
|
-
ProductPurchase,
|
|
33
32
|
Purchase,
|
|
34
33
|
PurchaseError,
|
|
35
34
|
PurchaseResult,
|
|
36
35
|
SubscriptionProduct,
|
|
37
|
-
SubscriptionPurchase,
|
|
38
36
|
RequestPurchaseProps,
|
|
39
37
|
RequestSubscriptionProps,
|
|
40
38
|
} from './ExpoIap.types';
|
|
@@ -42,12 +40,12 @@ import {
|
|
|
42
40
|
type UseIap = {
|
|
43
41
|
connected: boolean;
|
|
44
42
|
products: Product[];
|
|
45
|
-
promotedProductsIOS:
|
|
43
|
+
promotedProductsIOS: Purchase[];
|
|
46
44
|
promotedProductIdIOS?: string;
|
|
47
45
|
subscriptions: SubscriptionProduct[];
|
|
48
|
-
purchaseHistories:
|
|
49
|
-
availablePurchases:
|
|
50
|
-
currentPurchase?:
|
|
46
|
+
purchaseHistories: Purchase[];
|
|
47
|
+
availablePurchases: Purchase[];
|
|
48
|
+
currentPurchase?: Purchase;
|
|
51
49
|
currentPurchaseError?: PurchaseError;
|
|
52
50
|
promotedProductIOS?: Product;
|
|
53
51
|
activeSubscriptions: ActiveSubscription[];
|
|
@@ -99,9 +97,7 @@ type UseIap = {
|
|
|
99
97
|
};
|
|
100
98
|
|
|
101
99
|
export interface UseIAPOptions {
|
|
102
|
-
onPurchaseSuccess?: (
|
|
103
|
-
purchase: ProductPurchase | SubscriptionPurchase,
|
|
104
|
-
) => void;
|
|
100
|
+
onPurchaseSuccess?: (purchase: Purchase) => void;
|
|
105
101
|
onPurchaseError?: (error: PurchaseError) => void;
|
|
106
102
|
onSyncError?: (error: Error) => void;
|
|
107
103
|
shouldAutoSyncPurchases?: boolean; // New option to control auto-syncing
|
|
@@ -111,15 +107,11 @@ export interface UseIAPOptions {
|
|
|
111
107
|
export function useIAP(options?: UseIAPOptions): UseIap {
|
|
112
108
|
const [connected, setConnected] = useState<boolean>(false);
|
|
113
109
|
const [products, setProducts] = useState<Product[]>([]);
|
|
114
|
-
const [promotedProductsIOS] = useState<
|
|
110
|
+
const [promotedProductsIOS] = useState<Purchase[]>([]);
|
|
115
111
|
const [subscriptions, setSubscriptions] = useState<SubscriptionProduct[]>([]);
|
|
116
|
-
const [purchaseHistories, setPurchaseHistories] = useState<
|
|
117
|
-
|
|
118
|
-
);
|
|
119
|
-
const [availablePurchases, setAvailablePurchases] = useState<
|
|
120
|
-
ProductPurchase[]
|
|
121
|
-
>([]);
|
|
122
|
-
const [currentPurchase, setCurrentPurchase] = useState<ProductPurchase>();
|
|
112
|
+
const [purchaseHistories, setPurchaseHistories] = useState<Purchase[]>([]);
|
|
113
|
+
const [availablePurchases, setAvailablePurchases] = useState<Purchase[]>([]);
|
|
114
|
+
const [currentPurchase, setCurrentPurchase] = useState<Purchase>();
|
|
123
115
|
const [promotedProductIOS, setPromotedProductIOS] = useState<Product>();
|
|
124
116
|
const [currentPurchaseError, setCurrentPurchaseError] =
|
|
125
117
|
useState<PurchaseError>();
|
|
@@ -289,7 +281,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
289
281
|
purchase,
|
|
290
282
|
isConsumable,
|
|
291
283
|
}: {
|
|
292
|
-
purchase:
|
|
284
|
+
purchase: Purchase;
|
|
293
285
|
isConsumable?: boolean;
|
|
294
286
|
}): Promise<PurchaseResult | boolean> => {
|
|
295
287
|
try {
|
|
@@ -382,7 +374,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
382
374
|
|
|
383
375
|
if (result) {
|
|
384
376
|
subscriptionsRef.current.purchaseUpdate = purchaseUpdatedListener(
|
|
385
|
-
async (purchase: Purchase
|
|
377
|
+
async (purchase: Purchase) => {
|
|
386
378
|
setCurrentPurchaseError(undefined);
|
|
387
379
|
setCurrentPurchase(purchase);
|
|
388
380
|
|