react-native-iap 15.3.5 → 15.4.0-rc.1
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/README.md +1 -1
- package/android/build.gradle +13 -5
- package/android/src/main/java/com/margelo/nitro/iap/HybridRnIap.kt +16 -3
- package/ios/HybridRnIap.swift +12 -0
- package/lib/module/index.js +93 -75
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.kepler.js +170 -0
- package/lib/module/index.kepler.js.map +1 -0
- package/lib/module/types/amazon-devices-kepler/index.d.js +2 -0
- package/lib/module/types/amazon-devices-kepler/index.d.js.map +1 -0
- package/lib/module/types.js +5 -2
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/error.js +98 -15
- package/lib/module/utils/error.js.map +1 -1
- package/lib/module/utils/type-bridge.js +4 -1
- package/lib/module/utils/type-bridge.js.map +1 -1
- package/lib/module/vega-adapter.js +981 -0
- package/lib/module/vega-adapter.js.map +1 -0
- package/lib/module/vega.js +10 -0
- package/lib/module/vega.js.map +1 -0
- package/lib/module/vega.kepler.js +18 -0
- package/lib/module/vega.kepler.js.map +1 -0
- package/lib/typescript/plugin/src/withIAP.d.ts +33 -0
- package/lib/typescript/plugin/src/withIAP.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +9 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/index.kepler.d.ts +55 -0
- package/lib/typescript/src/index.kepler.d.ts.map +1 -0
- package/lib/typescript/src/specs/RnIap.nitro.d.ts +10 -1
- package/lib/typescript/src/specs/RnIap.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +16 -3
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/error.d.ts +1 -1
- package/lib/typescript/src/utils/error.d.ts.map +1 -1
- package/lib/typescript/src/utils/type-bridge.d.ts.map +1 -1
- package/lib/typescript/src/vega-adapter.d.ts +76 -0
- package/lib/typescript/src/vega-adapter.d.ts.map +1 -0
- package/lib/typescript/src/vega.d.ts +4 -0
- package/lib/typescript/src/vega.d.ts.map +1 -0
- package/lib/typescript/src/vega.kepler.d.ts +4 -0
- package/lib/typescript/src/vega.kepler.d.ts.map +1 -0
- package/nitrogen/generated/android/NitroIap+autolinking.cmake +1 -0
- package/nitrogen/generated/android/c++/JHybridRnIapSpec.cpp +5 -0
- package/nitrogen/generated/android/c++/JIapStore.hpp +3 -0
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithIapkitAmazonProps.hpp +71 -0
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithIapkitProps.hpp +9 -1
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithProviderProps.hpp +4 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_NitroVerifyPurchaseWithIapkitAmazonProps.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_NitroVerifyPurchaseWithIapkitAmazonProps.hpp +75 -0
- package/nitrogen/generated/android/c++/JVariant_NullType_NitroVerifyPurchaseWithIapkitProps.hpp +4 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/IapStore.kt +2 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroVerifyPurchaseWithIapkitAmazonProps.kt +44 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroVerifyPurchaseWithIapkitProps.kt +5 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Variant_NullType_NitroVerifyPurchaseWithIapkitAmazonProps.kt +53 -0
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.hpp +47 -0
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.hpp +3 -0
- package/nitrogen/generated/ios/swift/IapStore.swift +4 -0
- package/nitrogen/generated/ios/swift/NitroVerifyPurchaseWithIapkitAmazonProps.swift +103 -0
- package/nitrogen/generated/ios/swift/NitroVerifyPurchaseWithIapkitProps.swift +38 -1
- package/nitrogen/generated/ios/swift/Variant_NullType_NitroVerifyPurchaseWithIapkitAmazonProps.swift +18 -0
- package/nitrogen/generated/shared/c++/IapStore.hpp +4 -0
- package/nitrogen/generated/shared/c++/NitroVerifyPurchaseWithIapkitAmazonProps.hpp +94 -0
- package/nitrogen/generated/shared/c++/NitroVerifyPurchaseWithIapkitProps.hpp +8 -1
- package/openiap-versions.json +2 -2
- package/package.json +17 -4
- package/plugin/build/withIAP.d.ts +33 -0
- package/plugin/build/withIAP.js +109 -42
- package/plugin/src/withIAP.ts +185 -55
- package/src/index.kepler.ts +311 -0
- package/src/index.ts +187 -78
- package/src/specs/RnIap.nitro.ts +13 -2
- package/src/types/amazon-devices-kepler/index.d.ts +14 -0
- package/src/types.ts +17 -3
- package/src/utils/error.ts +127 -14
- package/src/utils/type-bridge.ts +4 -1
- package/src/vega-adapter.ts +1503 -0
- package/src/vega.kepler.ts +21 -0
- package/src/vega.ts +10 -0
- package/android/src/test/java/com/margelo/nitro/iap/ListenerThreadSafetyTest.kt +0 -154
- package/android/src/test/java/com/margelo/nitro/iap/OpenIapExceptionTest.kt +0 -93
- package/android/src/test/java/com/margelo/nitro/iap/ProductQueryHelpersTest.kt +0 -140
- package/plugin/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import {getVegaIapModule} from './vega';
|
|
2
|
+
import type {
|
|
3
|
+
MutationField,
|
|
4
|
+
Product,
|
|
5
|
+
ProductQueryType,
|
|
6
|
+
ProductSubscription,
|
|
7
|
+
Purchase,
|
|
8
|
+
PurchaseError,
|
|
9
|
+
PurchaseUpdatedListenerOptions,
|
|
10
|
+
QueryField,
|
|
11
|
+
RequestPurchasePropsByPlatforms,
|
|
12
|
+
RequestSubscriptionPropsByPlatforms,
|
|
13
|
+
} from './types';
|
|
14
|
+
import type {
|
|
15
|
+
NitroAvailablePurchasesOptions,
|
|
16
|
+
NitroFinishTransactionParams,
|
|
17
|
+
NitroProduct,
|
|
18
|
+
NitroPurchase,
|
|
19
|
+
NitroPurchaseRequest,
|
|
20
|
+
} from './specs/RnIap.nitro';
|
|
21
|
+
import {
|
|
22
|
+
convertNitroProductToProduct,
|
|
23
|
+
convertNitroPurchaseToPurchase,
|
|
24
|
+
convertProductToProductSubscription,
|
|
25
|
+
validateNitroProduct,
|
|
26
|
+
validateNitroPurchase,
|
|
27
|
+
} from './utils/type-bridge';
|
|
28
|
+
|
|
29
|
+
export * from './types';
|
|
30
|
+
export * from './utils/error';
|
|
31
|
+
export * from './vega';
|
|
32
|
+
export {useIAP, type UseIapOptions} from './hooks/useIAP';
|
|
33
|
+
export {connectWebhookStream, parseWebhookEventData} from './webhook-client';
|
|
34
|
+
export {kitApi, KitApiError} from './kit-api';
|
|
35
|
+
|
|
36
|
+
export type ProductTypeInput = 'inapp' | 'in-app' | 'subs';
|
|
37
|
+
|
|
38
|
+
export interface EventSubscription {
|
|
39
|
+
remove(): void;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type VegaModuleExtras = {
|
|
43
|
+
acknowledgePurchaseAndroid(purchaseToken: string): Promise<boolean>;
|
|
44
|
+
consumePurchaseAndroid(purchaseToken: string): Promise<boolean>;
|
|
45
|
+
restorePurchases?: () => Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const unsupported = (feature: string): never => {
|
|
49
|
+
throw new Error(`${feature} is not supported on Amazon Vega.`);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const getModule = () => {
|
|
53
|
+
const module = getVegaIapModule();
|
|
54
|
+
if (!module) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
'Amazon Vega IAP module is unavailable. Install @amazon-devices/keplerscript-appstore-iap-lib in the Vega app target and build with the React Native for Vega kepler platform.',
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return module;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const getVegaModule = () =>
|
|
63
|
+
getModule() as ReturnType<typeof getModule> & VegaModuleExtras;
|
|
64
|
+
|
|
65
|
+
const normalizeProductQueryType = (
|
|
66
|
+
type?: ProductQueryType | ProductTypeInput | null,
|
|
67
|
+
): ProductTypeInput | 'all' => {
|
|
68
|
+
if (type === 'subs') return 'subs';
|
|
69
|
+
if (type === 'all') return 'all';
|
|
70
|
+
return 'inapp';
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const mapProducts = (
|
|
74
|
+
nitroProducts: NitroProduct[],
|
|
75
|
+
type: ProductTypeInput | 'all',
|
|
76
|
+
) => {
|
|
77
|
+
const converted = nitroProducts
|
|
78
|
+
.filter(validateNitroProduct)
|
|
79
|
+
.map(convertNitroProductToProduct);
|
|
80
|
+
|
|
81
|
+
if (type === 'subs') {
|
|
82
|
+
return converted.map(convertProductToProductSubscription);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return converted;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const isNitroReady = (): boolean => false;
|
|
89
|
+
export const isTVOS = (): boolean => false;
|
|
90
|
+
export const isMacOS = (): boolean => false;
|
|
91
|
+
export const isStandardIOS = (): boolean => false;
|
|
92
|
+
|
|
93
|
+
export const initConnection: MutationField<'initConnection'> = async (
|
|
94
|
+
config,
|
|
95
|
+
) => {
|
|
96
|
+
return getModule().initConnection(config ?? null);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const endConnection: MutationField<'endConnection'> = async () => {
|
|
100
|
+
return getModule().endConnection();
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const fetchProducts: QueryField<'fetchProducts'> = async (request) => {
|
|
104
|
+
const {skus, type} = request;
|
|
105
|
+
const normalizedType = normalizeProductQueryType(type);
|
|
106
|
+
const nitroProducts = await getModule().fetchProducts(skus, normalizedType);
|
|
107
|
+
return mapProducts(nitroProducts, normalizedType) as
|
|
108
|
+
| Product[]
|
|
109
|
+
| ProductSubscription[];
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const requestPurchase: MutationField<'requestPurchase'> = async (
|
|
113
|
+
request,
|
|
114
|
+
) => {
|
|
115
|
+
const perPlatformRequest = request.request as
|
|
116
|
+
| RequestPurchasePropsByPlatforms
|
|
117
|
+
| RequestSubscriptionPropsByPlatforms
|
|
118
|
+
| undefined;
|
|
119
|
+
const androidRequest =
|
|
120
|
+
perPlatformRequest?.google ?? perPlatformRequest?.android;
|
|
121
|
+
|
|
122
|
+
if (!androidRequest?.skus?.length) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
'Invalid request for Amazon Vega. The `request.google.skus` or `request.android.skus` property is required and must be a non-empty array.',
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const nitroRequest: NitroPurchaseRequest = {
|
|
129
|
+
google: androidRequest,
|
|
130
|
+
android: androidRequest,
|
|
131
|
+
};
|
|
132
|
+
const result = await getModule().requestPurchase(nitroRequest);
|
|
133
|
+
if (!Array.isArray(result)) return null;
|
|
134
|
+
const purchases = result as unknown as NitroPurchase[];
|
|
135
|
+
return purchases
|
|
136
|
+
.filter(validateNitroPurchase)
|
|
137
|
+
.map((purchase) => convertNitroPurchaseToPurchase(purchase));
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const getAvailablePurchases: QueryField<
|
|
141
|
+
'getAvailablePurchases'
|
|
142
|
+
> = async (options) => {
|
|
143
|
+
const nitroOptions: NitroAvailablePurchasesOptions = {
|
|
144
|
+
android: {
|
|
145
|
+
includeSuspended: options?.includeSuspendedAndroid ?? false,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
return getModule()
|
|
149
|
+
.getAvailablePurchases(nitroOptions)
|
|
150
|
+
.then((purchases) =>
|
|
151
|
+
purchases
|
|
152
|
+
.filter(validateNitroPurchase)
|
|
153
|
+
.map(convertNitroPurchaseToPurchase),
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
export const finishTransaction: MutationField<'finishTransaction'> = async (
|
|
158
|
+
args,
|
|
159
|
+
) => {
|
|
160
|
+
const token = args.purchase.purchaseToken ?? undefined;
|
|
161
|
+
if (!token) {
|
|
162
|
+
throw new Error('purchaseToken required to finish Amazon Vega transaction');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const params: NitroFinishTransactionParams = {
|
|
166
|
+
android: {
|
|
167
|
+
purchaseToken: token,
|
|
168
|
+
isConsumable: args.isConsumable ?? false,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
await getModule().finishTransaction(params);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export const restorePurchases: MutationField<'restorePurchases'> = async () => {
|
|
175
|
+
await getVegaModule().restorePurchases?.();
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
export const getActiveSubscriptions: QueryField<
|
|
179
|
+
'getActiveSubscriptions'
|
|
180
|
+
> = async (args) => {
|
|
181
|
+
return getModule().getActiveSubscriptions(args ?? undefined);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export const hasActiveSubscriptions: QueryField<
|
|
185
|
+
'hasActiveSubscriptions'
|
|
186
|
+
> = async (args) => {
|
|
187
|
+
return getModule().hasActiveSubscriptions(args ?? undefined);
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
export const purchaseUpdatedListener = (
|
|
191
|
+
listener: (purchase: Purchase) => void,
|
|
192
|
+
options?: PurchaseUpdatedListenerOptions | null,
|
|
193
|
+
): EventSubscription => {
|
|
194
|
+
const token = getModule().addPurchaseUpdatedListener((purchase) => {
|
|
195
|
+
if (validateNitroPurchase(purchase)) {
|
|
196
|
+
listener(convertNitroPurchaseToPurchase(purchase));
|
|
197
|
+
}
|
|
198
|
+
}, options ?? undefined);
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
remove: () => {
|
|
202
|
+
if (typeof token === 'number') {
|
|
203
|
+
getModule().removePurchaseUpdatedListener(token);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
export const purchaseErrorListener = (
|
|
210
|
+
listener: (error: PurchaseError) => void,
|
|
211
|
+
): EventSubscription => {
|
|
212
|
+
const nativeListener = (error: {code?: string; message?: string}) => {
|
|
213
|
+
listener({
|
|
214
|
+
code: (error.code ?? 'service-error') as PurchaseError['code'],
|
|
215
|
+
message: error.message ?? 'Amazon Vega purchase failed',
|
|
216
|
+
});
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
getModule().addPurchaseErrorListener(nativeListener);
|
|
220
|
+
return {
|
|
221
|
+
remove: () => getModule().removePurchaseErrorListener(nativeListener),
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export const getStorefront: QueryField<'getStorefront'> = async () => {
|
|
226
|
+
return getModule().getStorefront();
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
export const verifyPurchaseWithProvider: MutationField<
|
|
230
|
+
'verifyPurchaseWithProvider'
|
|
231
|
+
> = async (params) => {
|
|
232
|
+
return getModule().verifyPurchaseWithProvider(params) as ReturnType<
|
|
233
|
+
MutationField<'verifyPurchaseWithProvider'>
|
|
234
|
+
>;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export const validateReceipt: MutationField<'validateReceipt'> = async () => {
|
|
238
|
+
return unsupported('validateReceipt');
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
export const verifyPurchase: MutationField<'verifyPurchase'> = validateReceipt;
|
|
242
|
+
export const validateReceiptIOS: QueryField<'validateReceiptIOS'> = async () =>
|
|
243
|
+
unsupported('validateReceiptIOS');
|
|
244
|
+
export const syncIOS: MutationField<'syncIOS'> = async () =>
|
|
245
|
+
unsupported('syncIOS');
|
|
246
|
+
export const getAppTransactionIOS: QueryField<
|
|
247
|
+
'getAppTransactionIOS'
|
|
248
|
+
> = async () => null;
|
|
249
|
+
export const getPromotedProductIOS: QueryField<
|
|
250
|
+
'getPromotedProductIOS'
|
|
251
|
+
> = async () => null;
|
|
252
|
+
export const requestPromotedProductIOS = getPromotedProductIOS;
|
|
253
|
+
export const requestPurchaseOnPromotedProductIOS = async (): Promise<void> =>
|
|
254
|
+
unsupported('requestPurchaseOnPromotedProductIOS');
|
|
255
|
+
export const showManageSubscriptionsIOS: MutationField<
|
|
256
|
+
'showManageSubscriptionsIOS'
|
|
257
|
+
> = async () => [];
|
|
258
|
+
export const presentCodeRedemptionSheetIOS: MutationField<
|
|
259
|
+
'presentCodeRedemptionSheetIOS'
|
|
260
|
+
> = async () => false;
|
|
261
|
+
export const presentExternalPurchaseLinkIOS: MutationField<
|
|
262
|
+
'presentExternalPurchaseLinkIOS'
|
|
263
|
+
> = async () => unsupported('presentExternalPurchaseLinkIOS');
|
|
264
|
+
export const deepLinkToSubscriptions: MutationField<
|
|
265
|
+
'deepLinkToSubscriptions'
|
|
266
|
+
> = async () => unsupported('deepLinkToSubscriptions');
|
|
267
|
+
export const promotedProductListenerIOS = (): EventSubscription => ({
|
|
268
|
+
remove: () => {},
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
export const acknowledgePurchaseAndroid: MutationField<
|
|
272
|
+
'acknowledgePurchaseAndroid'
|
|
273
|
+
> = async (purchaseToken) => {
|
|
274
|
+
return getVegaModule().acknowledgePurchaseAndroid(purchaseToken);
|
|
275
|
+
};
|
|
276
|
+
export const consumePurchaseAndroid: MutationField<
|
|
277
|
+
'consumePurchaseAndroid'
|
|
278
|
+
> = async (purchaseToken) => {
|
|
279
|
+
return getVegaModule().consumePurchaseAndroid(purchaseToken);
|
|
280
|
+
};
|
|
281
|
+
export const acknowledgePurchase = acknowledgePurchaseAndroid;
|
|
282
|
+
export const consumePurchase = consumePurchaseAndroid;
|
|
283
|
+
|
|
284
|
+
export const checkAlternativeBillingAvailabilityAndroid: MutationField<
|
|
285
|
+
'checkAlternativeBillingAvailabilityAndroid'
|
|
286
|
+
> = async () => unsupported('checkAlternativeBillingAvailabilityAndroid');
|
|
287
|
+
export const showAlternativeBillingDialogAndroid: MutationField<
|
|
288
|
+
'showAlternativeBillingDialogAndroid'
|
|
289
|
+
> = async () => unsupported('showAlternativeBillingDialogAndroid');
|
|
290
|
+
export const createAlternativeBillingTokenAndroid: MutationField<
|
|
291
|
+
'createAlternativeBillingTokenAndroid'
|
|
292
|
+
> = async () => unsupported('createAlternativeBillingTokenAndroid');
|
|
293
|
+
export const isBillingProgramAvailableAndroid: MutationField<
|
|
294
|
+
'isBillingProgramAvailableAndroid'
|
|
295
|
+
> = async () => unsupported('isBillingProgramAvailableAndroid');
|
|
296
|
+
export const launchExternalLinkAndroid: MutationField<
|
|
297
|
+
'launchExternalLinkAndroid'
|
|
298
|
+
> = async () => unsupported('launchExternalLinkAndroid');
|
|
299
|
+
export const createBillingProgramReportingDetailsAndroid: MutationField<
|
|
300
|
+
'createBillingProgramReportingDetailsAndroid'
|
|
301
|
+
> = async () => unsupported('createBillingProgramReportingDetailsAndroid');
|
|
302
|
+
export const userChoiceBillingListenerAndroid = (): EventSubscription => ({
|
|
303
|
+
remove: () => {},
|
|
304
|
+
});
|
|
305
|
+
export const developerProvidedBillingListenerAndroid =
|
|
306
|
+
(): EventSubscription => ({
|
|
307
|
+
remove: () => {},
|
|
308
|
+
});
|
|
309
|
+
export const subscriptionBillingIssueListener = (): EventSubscription => ({
|
|
310
|
+
remove: () => {},
|
|
311
|
+
});
|