expo-iap 3.0.6 → 3.0.7-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.
Files changed (39) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +35 -0
  3. package/build/index.d.ts +10 -3
  4. package/build/index.d.ts.map +1 -1
  5. package/build/index.js +23 -14
  6. package/build/index.js.map +1 -1
  7. package/coverage/clover.xml +440 -0
  8. package/coverage/coverage-final.json +7 -0
  9. package/coverage/lcov-report/base.css +224 -0
  10. package/coverage/lcov-report/block-navigation.js +87 -0
  11. package/coverage/lcov-report/favicon.png +0 -0
  12. package/coverage/lcov-report/index.html +161 -0
  13. package/coverage/lcov-report/prettify.css +1 -0
  14. package/coverage/lcov-report/prettify.js +2 -0
  15. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  16. package/coverage/lcov-report/sorter.js +196 -0
  17. package/coverage/lcov-report/src/ExpoIap.types.ts.html +1243 -0
  18. package/coverage/lcov-report/src/PurchaseError.ts.html +787 -0
  19. package/coverage/lcov-report/src/helpers/index.html +116 -0
  20. package/coverage/lcov-report/src/helpers/subscription.ts.html +496 -0
  21. package/coverage/lcov-report/src/index.html +131 -0
  22. package/coverage/lcov-report/src/index.ts.html +2236 -0
  23. package/coverage/lcov-report/src/modules/android.ts.html +544 -0
  24. package/coverage/lcov-report/src/modules/index.html +131 -0
  25. package/coverage/lcov-report/src/modules/ios.ts.html +952 -0
  26. package/coverage/lcov-report/src/purchase-error.ts.html +880 -0
  27. package/coverage/lcov-report/src/types/ExpoIapAndroid.types.ts.html +493 -0
  28. package/coverage/lcov-report/src/types/index.html +116 -0
  29. package/coverage/lcov-report/src/useIap.ts.html +1483 -0
  30. package/coverage/lcov-report/src/utils/errorMapping.ts.html +529 -0
  31. package/coverage/lcov-report/src/utils/index.html +116 -0
  32. package/coverage/lcov.info +852 -0
  33. package/ios/expoiap.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  34. package/ios/expoiap.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  35. package/package.json +1 -1
  36. package/plugin/build/withIAP.js +3 -3
  37. package/plugin/src/withIAP.ts +3 -3
  38. package/plugin/tsconfig.tsbuildinfo +1 -1
  39. package/src/index.ts +93 -29
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Workspace
3
+ version = "1.0">
4
+ <FileRef
5
+ location = "self:">
6
+ </FileRef>
7
+ </Workspace>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>IDEDidComputeMac32BitWarning</key>
6
+ <true/>
7
+ </dict>
8
+ </plist>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-iap",
3
- "version": "3.0.6",
3
+ "version": "3.0.7-rc.1",
4
4
  "description": "In App Purchase module in Expo",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -69,7 +69,7 @@ const modifyAppBuildGradle = (gradle, language) => {
69
69
  const impl = (ga, v) => language === 'kotlin'
70
70
  ? ` implementation("${ga}:${v}")`
71
71
  : ` implementation "${ga}:${v}"`;
72
- const openiapDep = impl('io.github.hyochan.openiap:openiap-google', '1.1.10');
72
+ const openiapDep = impl('io.github.hyochan.openiap:openiap-google', '1.1.11');
73
73
  // Remove any existing openiap-google lines (any version, groovy/kotlin, implementation/api)
74
74
  const openiapAnyLine = /^\s*(?:implementation|api)\s*\(?\s*["']io\.github\.hyochan\.openiap:openiap-google:[^"']+["']\s*\)?\s*$/gm;
75
75
  const hadExisting = openiapAnyLine.test(modified);
@@ -81,8 +81,8 @@ const modifyAppBuildGradle = (gradle, language) => {
81
81
  // Insert just after the opening `dependencies {` line
82
82
  modified = addLineToGradle(modified, /dependencies\s*{/, openiapDep, 1);
83
83
  logOnce(hadExisting
84
- ? '🛠️ expo-iap: Replaced OpenIAP dependency with 1.1.10'
85
- : '🛠️ expo-iap: Added OpenIAP dependency (1.1.10) to build.gradle');
84
+ ? '🛠️ expo-iap: Replaced OpenIAP dependency with 1.1.11'
85
+ : '🛠️ expo-iap: Added OpenIAP dependency (1.1.11) to build.gradle');
86
86
  }
87
87
  return modified;
88
88
  };
@@ -54,7 +54,7 @@ const modifyAppBuildGradle = (
54
54
  language === 'kotlin'
55
55
  ? ` implementation("${ga}:${v}")`
56
56
  : ` implementation "${ga}:${v}"`;
57
- const openiapDep = impl('io.github.hyochan.openiap:openiap-google', '1.1.10');
57
+ const openiapDep = impl('io.github.hyochan.openiap:openiap-google', '1.1.11');
58
58
 
59
59
  // Remove any existing openiap-google lines (any version, groovy/kotlin, implementation/api)
60
60
  const openiapAnyLine =
@@ -74,8 +74,8 @@ const modifyAppBuildGradle = (
74
74
  modified = addLineToGradle(modified, /dependencies\s*{/, openiapDep, 1);
75
75
  logOnce(
76
76
  hadExisting
77
- ? '🛠️ expo-iap: Replaced OpenIAP dependency with 1.1.10'
78
- : '🛠️ expo-iap: Added OpenIAP dependency (1.1.10) to build.gradle',
77
+ ? '🛠️ expo-iap: Replaced OpenIAP dependency with 1.1.11'
78
+ : '🛠️ expo-iap: Added OpenIAP dependency (1.1.11) to build.gradle',
79
79
  );
80
80
  }
81
81
 
@@ -1 +1 @@
1
- {"root":["./src/withIAP.ts","./src/withLocalOpenIAP.ts"],"version":"5.9.2"}
1
+ {"root":["./src/withiap.ts","./src/withlocalopeniap.ts"],"version":"5.9.2"}
package/src/index.ts CHANGED
@@ -23,12 +23,17 @@ import {
23
23
  ErrorCode,
24
24
  RequestPurchaseProps,
25
25
  RequestPurchasePropsByPlatforms,
26
+ RequestPurchaseAndroidProps,
27
+ RequestPurchaseIosProps,
26
28
  RequestSubscriptionPropsByPlatforms,
29
+ RequestSubscriptionAndroidProps,
30
+ RequestSubscriptionIosProps,
27
31
  ProductSubscription,
28
32
  PurchaseAndroid,
29
33
  DiscountOfferInputIOS,
30
34
  VoidResult,
31
35
  ReceiptValidationResult,
36
+ AndroidSubscriptionOfferInput,
32
37
  } from './types';
33
38
  import {PurchaseError} from './purchase-error';
34
39
 
@@ -57,18 +62,31 @@ export function setValueAsync(value: string) {
57
62
  return ExpoIapModule.setValueAsync(value);
58
63
  }
59
64
 
60
- // Ensure the emitter has proper EventEmitter interface
61
- export const emitter = (ExpoIapModule || NativeModulesProxy.ExpoIap) as {
62
- addListener: (
63
- eventName: string,
64
- listener: (...args: any[]) => void,
65
- ) => {remove: () => void};
66
- removeListener: (
67
- eventName: string,
68
- listener: (...args: any[]) => void,
69
- ) => void;
65
+ type ExpoIapEventPayloads = {
66
+ [OpenIapEvent.PurchaseUpdated]: Purchase;
67
+ [OpenIapEvent.PurchaseError]: PurchaseError;
68
+ [OpenIapEvent.PromotedProductIOS]: Product;
69
+ };
70
+
71
+ type ExpoIapEventListener<E extends OpenIapEvent> = (
72
+ payload: ExpoIapEventPayloads[E],
73
+ ) => void;
74
+
75
+ type ExpoIapEmitter = {
76
+ addListener<E extends OpenIapEvent>(
77
+ eventName: E,
78
+ listener: ExpoIapEventListener<E>,
79
+ ): {remove: () => void};
80
+ removeListener<E extends OpenIapEvent>(
81
+ eventName: E,
82
+ listener: ExpoIapEventListener<E>,
83
+ ): void;
70
84
  };
71
85
 
86
+ // Ensure the emitter has proper EventEmitter interface
87
+ export const emitter = (ExpoIapModule ||
88
+ NativeModulesProxy.ExpoIap) as ExpoIapEmitter;
89
+
72
90
  /**
73
91
  * TODO(v3.1.0): Remove legacy 'inapp' alias once downstream apps migrate to 'in-app'.
74
92
  */
@@ -342,15 +360,31 @@ const offerToRecordIOS = (
342
360
  /**
343
361
  * Helper to normalize request props to platform-specific format
344
362
  */
345
- const normalizeRequestProps = (
363
+ function normalizeRequestProps(
364
+ request: RequestPurchasePropsByPlatforms,
365
+ platform: 'ios',
366
+ ): RequestPurchaseIosProps | null | undefined;
367
+ function normalizeRequestProps(
368
+ request: RequestPurchasePropsByPlatforms,
369
+ platform: 'android',
370
+ ): RequestPurchaseAndroidProps | null | undefined;
371
+ function normalizeRequestProps(
372
+ request: RequestSubscriptionPropsByPlatforms,
373
+ platform: 'ios',
374
+ ): RequestSubscriptionIosProps | null | undefined;
375
+ function normalizeRequestProps(
376
+ request: RequestSubscriptionPropsByPlatforms,
377
+ platform: 'android',
378
+ ): RequestSubscriptionAndroidProps | null | undefined;
379
+ function normalizeRequestProps(
346
380
  request:
347
381
  | RequestPurchasePropsByPlatforms
348
382
  | RequestSubscriptionPropsByPlatforms,
349
383
  platform: 'ios' | 'android',
350
- ): any => {
384
+ ) {
351
385
  // Platform-specific format - directly return the appropriate platform data
352
386
  return platform === 'ios' ? request.ios : request.android;
353
- };
387
+ }
354
388
 
355
389
  /**
356
390
  * Request a purchase for products or subscriptions.
@@ -408,7 +442,7 @@ export const requestPurchase = (
408
442
  } = normalizedRequest;
409
443
 
410
444
  return (async () => {
411
- const offer = offerToRecordIOS(withOffer);
445
+ const offer = offerToRecordIOS(withOffer ?? undefined);
412
446
  const purchase = await ExpoIapModule.requestPurchase({
413
447
  sku,
414
448
  andDangerouslyFinishTransactionAutomatically,
@@ -422,15 +456,19 @@ export const requestPurchase = (
422
456
  }
423
457
 
424
458
  if (Platform.OS === 'android') {
425
- const normalizedRequest = normalizeRequestProps(request, 'android');
426
-
427
- if (!normalizedRequest?.skus?.length) {
428
- throw new Error(
429
- 'Invalid request for Android. The `skus` property is required and must be a non-empty array.',
430
- );
431
- }
432
-
433
459
  if (isInAppPurchase) {
460
+ const normalizedRequest: RequestPurchaseAndroidProps | null | undefined =
461
+ normalizeRequestProps(
462
+ request as RequestPurchasePropsByPlatforms,
463
+ 'android',
464
+ );
465
+
466
+ if (!normalizedRequest?.skus?.length) {
467
+ throw new Error(
468
+ 'Invalid request for Android. The `skus` property is required and must be a non-empty array.',
469
+ );
470
+ }
471
+
434
472
  const {
435
473
  skus,
436
474
  obfuscatedAccountIdAndroid,
@@ -453,25 +491,51 @@ export const requestPurchase = (
453
491
  }
454
492
 
455
493
  if (canonical === 'subs') {
494
+ const normalizedRequest:
495
+ | RequestSubscriptionAndroidProps
496
+ | null
497
+ | undefined = normalizeRequestProps(
498
+ request as RequestSubscriptionPropsByPlatforms,
499
+ 'android',
500
+ );
501
+
502
+ if (!normalizedRequest?.skus?.length) {
503
+ throw new Error(
504
+ 'Invalid request for Android. The `skus` property is required and must be a non-empty array.',
505
+ );
506
+ }
507
+
456
508
  const {
457
509
  skus,
458
510
  obfuscatedAccountIdAndroid,
459
511
  obfuscatedProfileIdAndroid,
460
512
  isOfferPersonalized,
461
- subscriptionOffers = [],
462
- replacementModeAndroid = -1,
463
- purchaseToken,
513
+ subscriptionOffers,
514
+ replacementModeAndroid,
515
+ purchaseTokenAndroid,
464
516
  } = normalizedRequest;
465
517
 
518
+ const normalizedOffers = subscriptionOffers ?? [];
519
+ const replacementMode = replacementModeAndroid ?? -1;
520
+ const purchaseToken = purchaseTokenAndroid ?? undefined;
521
+
466
522
  return (async () => {
467
523
  return ExpoIapModule.requestPurchase({
468
524
  type: native,
469
525
  skuArr: skus,
470
526
  purchaseToken,
471
- replacementMode: replacementModeAndroid,
527
+ replacementMode,
472
528
  obfuscatedAccountId: obfuscatedAccountIdAndroid,
473
529
  obfuscatedProfileId: obfuscatedProfileIdAndroid,
474
- offerTokenArr: subscriptionOffers.map((so: any) => so.offerToken),
530
+ offerTokenArr: normalizedOffers.map(
531
+ (so: AndroidSubscriptionOfferInput) => so.offerToken,
532
+ ),
533
+ subscriptionOffers: normalizedOffers.map(
534
+ (so: AndroidSubscriptionOfferInput) => ({
535
+ sku: so.sku,
536
+ offerToken: so.offerToken,
537
+ }),
538
+ ),
475
539
  isOfferPersonalized: isOfferPersonalized ?? false,
476
540
  }) as Promise<Purchase[]>;
477
541
  })();
@@ -563,8 +627,8 @@ export const getStorefrontIOS = (): Promise<string> => {
563
627
  export const getStorefront = (): Promise<string> => {
564
628
  // Cross-platform storefront
565
629
  if (Platform.OS === 'android') {
566
- if (typeof (ExpoIapModule as any).getStorefrontAndroid === 'function') {
567
- return (ExpoIapModule as any).getStorefrontAndroid();
630
+ if (typeof ExpoIapModule.getStorefrontAndroid === 'function') {
631
+ return ExpoIapModule.getStorefrontAndroid();
568
632
  }
569
633
  return Promise.resolve('');
570
634
  }