react-native-iap 12.7.0 → 12.7.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/app.plugin.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./plugin/build/withIAP');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-iap",
3
- "version": "12.7.0",
3
+ "version": "12.7.2",
4
4
  "description": "React Native In App Purchase Module.",
5
5
  "repository": "https://github.com/dooboolab/react-native-iap",
6
6
  "author": "dooboolab <support@dooboolab.com> (https://github.com/dooboolab)",
@@ -36,7 +36,7 @@
36
36
  ],
37
37
  "main": "lib/commonjs/index",
38
38
  "module": "lib/module/index",
39
- "types": "lib/typescript/index.d.ts",
39
+ "types": "lib/typescript/src/index.d.ts",
40
40
  "react-native": "src/index",
41
41
  "source": "src/index",
42
42
  "files": [
@@ -45,6 +45,8 @@
45
45
  "android",
46
46
  "ios",
47
47
  "RNIap.podspec",
48
+ "plugin/build",
49
+ "app.plugin.js",
48
50
  "!android/.gradle",
49
51
  "!android/.idea",
50
52
  "!android/build",
@@ -0,0 +1,9 @@
1
+ import { ConfigPlugin } from '@expo/config-plugins';
2
+ declare type PaymentProvider = 'Amazon AppStore' | 'both' | 'Play Store';
3
+ export declare const modifyAppBuildGradle: (buildGradle: string, paymentProvider: PaymentProvider) => string;
4
+ export declare const modifyProjectBuildGradle: (buildGradle: string) => string;
5
+ interface Props {
6
+ paymentProvider?: PaymentProvider;
7
+ }
8
+ declare const _default: ConfigPlugin<Props | undefined>;
9
+ export default _default;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modifyProjectBuildGradle = exports.modifyAppBuildGradle = void 0;
4
+ const config_plugins_1 = require("@expo/config-plugins");
5
+ const config_plugins_2 = require("@expo/config-plugins");
6
+ const pkg = require('../../package.json');
7
+ const hasPaymentProviderProperValue = (paymentProvider) => {
8
+ return ['Amazon AppStore', 'Play Store', 'both'].includes(paymentProvider);
9
+ };
10
+ const linesToAdd = {
11
+ ['Amazon AppStore']: `missingDimensionStrategy "store", "amazon"`,
12
+ ['Play Store']: `missingDimensionStrategy "store", "play"`,
13
+ ['both']: `flavorDimensions "appstore"
14
+
15
+ productFlavors {
16
+ googlePlay {
17
+ dimension "appstore"
18
+ missingDimensionStrategy "store", "play"
19
+ }
20
+
21
+ amazon {
22
+ dimension "appstore"
23
+ missingDimensionStrategy "store", "amazon"
24
+ }
25
+ }`,
26
+ };
27
+ const addToBuildGradle = (newLine, anchor, offset, buildGradle) => {
28
+ const lines = buildGradle.split('\n');
29
+ const lineIndex = lines.findIndex((line) => line.match(anchor));
30
+ // add after given line
31
+ lines.splice(lineIndex + offset, 0, newLine);
32
+ return lines.join('\n');
33
+ };
34
+ const modifyAppBuildGradle = (buildGradle, paymentProvider) => {
35
+ if (paymentProvider === 'both') {
36
+ if (buildGradle.includes(`flavorDimensions "appstore"`)) {
37
+ return buildGradle;
38
+ }
39
+ return addToBuildGradle(linesToAdd[paymentProvider], 'defaultConfig', -1, buildGradle);
40
+ }
41
+ const missingDimensionStrategy = linesToAdd[paymentProvider];
42
+ if (buildGradle.includes(missingDimensionStrategy)) {
43
+ return buildGradle;
44
+ }
45
+ return addToBuildGradle(missingDimensionStrategy, 'defaultConfig', 1, buildGradle);
46
+ };
47
+ exports.modifyAppBuildGradle = modifyAppBuildGradle;
48
+ const modifyProjectBuildGradle = (buildGradle) => {
49
+ const supportLibVersion = `supportLibVersion = "28.0.0"`;
50
+ if (buildGradle.includes(supportLibVersion)) {
51
+ return buildGradle;
52
+ }
53
+ return addToBuildGradle(supportLibVersion, 'ext', 1, buildGradle);
54
+ };
55
+ exports.modifyProjectBuildGradle = modifyProjectBuildGradle;
56
+ const withIAPAndroid = (config, { paymentProvider }) => {
57
+ // eslint-disable-next-line @typescript-eslint/no-shadow
58
+ config = (0, config_plugins_2.withAppBuildGradle)(config, (config) => {
59
+ config.modResults.contents = (0, exports.modifyAppBuildGradle)(config.modResults.contents, paymentProvider);
60
+ return config;
61
+ });
62
+ // eslint-disable-next-line @typescript-eslint/no-shadow
63
+ config = (0, config_plugins_2.withProjectBuildGradle)(config, (config) => {
64
+ config.modResults.contents = (0, exports.modifyProjectBuildGradle)(config.modResults.contents);
65
+ return config;
66
+ });
67
+ return config;
68
+ };
69
+ const withIAP = (config, props) => {
70
+ const paymentProvider = props?.paymentProvider ?? 'Play Store';
71
+ if (!hasPaymentProviderProperValue(paymentProvider)) {
72
+ config_plugins_2.WarningAggregator.addWarningAndroid('react-native-iap', `The payment provider '${paymentProvider}' is not supported. Please update your app.json file with one of the following supported values: 'Play Store', 'Amazon AppStore', or 'both'.`);
73
+ return config;
74
+ }
75
+ try {
76
+ config = withIAPAndroid(config, { paymentProvider });
77
+ }
78
+ catch (error) {
79
+ config_plugins_2.WarningAggregator.addWarningAndroid('react-native-iap', `There was a problem configuring react-native-iap in your native Android project: ${error}`);
80
+ }
81
+ return config;
82
+ };
83
+ exports.default = (0, config_plugins_1.createRunOncePlugin)(withIAP, pkg.name, pkg.version);