expo-iap 3.3.0-rc.2 → 3.3.0-rc.4

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.
@@ -1,6 +1,12 @@
1
1
  import { ConfigPlugin } from 'expo/config-plugins';
2
2
  import { withIosAlternativeBilling, type IOSAlternativeBillingConfig } from './withIosAlternativeBilling';
3
3
  export interface ExpoIapPluginOptions {
4
+ /**
5
+ * IAPKit API key for server-side receipt verification.
6
+ * Get your API key from https://iapkit.com
7
+ * This will be available via `Constants.expoConfig?.extra?.iapkitApiKey`
8
+ */
9
+ iapkitApiKey?: string;
4
10
  /** Local development path for OpenIAP library */
5
11
  localPath?: string | {
6
12
  ios?: string;
@@ -46,11 +52,8 @@ export interface ExpoIapPluginOptions {
46
52
  */
47
53
  horizonAppId?: string;
48
54
  };
49
- /** @deprecated Use ios.alternativeBilling instead */
50
- iosAlternativeBilling?: IOSAlternativeBillingConfig;
51
- /** @deprecated Use android.horizonAppId instead */
52
- horizonAppId?: string;
53
55
  }
54
- export { withIosAlternativeBilling };
56
+ declare const withIap: ConfigPlugin<ExpoIapPluginOptions | void>;
57
+ export { withIosAlternativeBilling, withIap };
55
58
  declare const _default: ConfigPlugin<void | ExpoIapPluginOptions>;
56
59
  export default _default;
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.withIosAlternativeBilling = void 0;
39
+ exports.withIap = exports.withIosAlternativeBilling = void 0;
40
40
  const config_plugins_1 = require("expo/config-plugins");
41
41
  const fs = __importStar(require("fs"));
42
42
  const path = __importStar(require("path"));
@@ -219,10 +219,18 @@ const withIapIOS = (config, options) => {
219
219
  };
220
220
  const withIap = (config, options) => {
221
221
  try {
222
+ // Add iapkitApiKey to extra if provided
223
+ if (options?.iapkitApiKey) {
224
+ config.extra = {
225
+ ...config.extra,
226
+ iapkitApiKey: options.iapkitApiKey,
227
+ };
228
+ logOnce('🔑 [expo-iap] Added iapkitApiKey to config.extra');
229
+ }
222
230
  // Read Horizon configuration from modules
223
231
  const isHorizonEnabled = options?.modules?.horizon ?? false;
224
- const horizonAppId = options?.android?.horizonAppId ?? options?.horizonAppId;
225
- const iosAlternativeBilling = options?.ios?.alternativeBilling ?? options?.iosAlternativeBilling;
232
+ const horizonAppId = options?.android?.horizonAppId;
233
+ const iosAlternativeBilling = options?.ios?.alternativeBilling;
226
234
  logOnce(`🔍 [expo-iap] Config values: horizonAppId=${horizonAppId}, isHorizonEnabled=${isHorizonEnabled}`);
227
235
  // Respect explicit flag; fall back to presence of localPath only when flag is unset
228
236
  const isLocalDev = options?.enableLocalDev ?? !!options?.localPath;
@@ -270,4 +278,5 @@ const withIap = (config, options) => {
270
278
  return config;
271
279
  }
272
280
  };
281
+ exports.withIap = withIap;
273
282
  exports.default = (0, config_plugins_1.createRunOncePlugin)(withIap, pkg.name, pkg.version);
@@ -289,6 +289,12 @@ const withIapIOS: ConfigPlugin<IOSAlternativeBillingConfig | undefined> = (
289
289
  };
290
290
 
291
291
  export interface ExpoIapPluginOptions {
292
+ /**
293
+ * IAPKit API key for server-side receipt verification.
294
+ * Get your API key from https://iapkit.com
295
+ * This will be available via `Constants.expoConfig?.extra?.iapkitApiKey`
296
+ */
297
+ iapkitApiKey?: string;
292
298
  /** Local development path for OpenIAP library */
293
299
  localPath?:
294
300
  | string
@@ -336,10 +342,6 @@ export interface ExpoIapPluginOptions {
336
342
  */
337
343
  horizonAppId?: string;
338
344
  };
339
- /** @deprecated Use ios.alternativeBilling instead */
340
- iosAlternativeBilling?: IOSAlternativeBillingConfig;
341
- /** @deprecated Use android.horizonAppId instead */
342
- horizonAppId?: string;
343
345
  }
344
346
 
345
347
  const withIap: ConfigPlugin<ExpoIapPluginOptions | void> = (
@@ -347,13 +349,20 @@ const withIap: ConfigPlugin<ExpoIapPluginOptions | void> = (
347
349
  options,
348
350
  ) => {
349
351
  try {
352
+ // Add iapkitApiKey to extra if provided
353
+ if (options?.iapkitApiKey) {
354
+ config.extra = {
355
+ ...config.extra,
356
+ iapkitApiKey: options.iapkitApiKey,
357
+ };
358
+ logOnce('🔑 [expo-iap] Added iapkitApiKey to config.extra');
359
+ }
360
+
350
361
  // Read Horizon configuration from modules
351
362
  const isHorizonEnabled = options?.modules?.horizon ?? false;
352
363
 
353
- const horizonAppId =
354
- options?.android?.horizonAppId ?? options?.horizonAppId;
355
- const iosAlternativeBilling =
356
- options?.ios?.alternativeBilling ?? options?.iosAlternativeBilling;
364
+ const horizonAppId = options?.android?.horizonAppId;
365
+ const iosAlternativeBilling = options?.ios?.alternativeBilling;
357
366
 
358
367
  logOnce(
359
368
  `🔍 [expo-iap] Config values: horizonAppId=${horizonAppId}, isHorizonEnabled=${isHorizonEnabled}`,
@@ -416,5 +425,5 @@ const withIap: ConfigPlugin<ExpoIapPluginOptions | void> = (
416
425
  }
417
426
  };
418
427
 
419
- export {withIosAlternativeBilling};
428
+ export {withIosAlternativeBilling, withIap};
420
429
  export default createRunOncePlugin(withIap, pkg.name, pkg.version);
package/src/index.ts CHANGED
@@ -808,6 +808,33 @@ export const verifyPurchaseWithProvider: MutationField<
808
808
  'verifyPurchaseWithProvider'
809
809
  > = async (options) => {
810
810
  if (Platform.OS === 'ios' || Platform.OS === 'android') {
811
+ // Auto-fill apiKey from config if not provided and provider is iapkit
812
+ if (
813
+ options.provider === 'iapkit' &&
814
+ options.iapkit &&
815
+ !options.iapkit.apiKey
816
+ ) {
817
+ try {
818
+ // Dynamically import expo-constants to avoid hard dependency
819
+ const {default: Constants} = await import('expo-constants');
820
+ const configApiKey = Constants.expoConfig?.extra?.iapkitApiKey;
821
+ if (configApiKey) {
822
+ options = {
823
+ ...options,
824
+ iapkit: {
825
+ ...options.iapkit,
826
+ apiKey: configApiKey,
827
+ },
828
+ };
829
+ }
830
+ } catch {
831
+ throw new Error(
832
+ 'expo-constants is required for auto-filling iapkitApiKey from config. ' +
833
+ 'Please install it: npx expo install expo-constants\n' +
834
+ 'Or provide apiKey directly in verifyPurchaseWithProvider options.',
835
+ );
836
+ }
837
+ }
811
838
  return ExpoIapModule.verifyPurchaseWithProvider(options);
812
839
  }
813
840