react-native-google-mobile-ads 4.1.0
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/LICENSE +32 -0
- package/README.md +65 -0
- package/RNGoogleMobileAds.podspec +42 -0
- package/__tests__/consent.test.ts +25 -0
- package/__tests__/googleMobileAds.test.ts +63 -0
- package/__tests__/interstitial.test.ts +53 -0
- package/__tests__/requestOptions.test.tsx +4 -0
- package/__tests__/rewarded.test.tsx +4 -0
- package/__tests__/showOptions.test.tsx +4 -0
- package/android/.editorconfig +10 -0
- package/android/app-json.gradle +69 -0
- package/android/build.gradle +98 -0
- package/android/lint.xml +5 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +17 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeAppModule.java +169 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAppOpenModule.java +161 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsBannerAdViewManager.java +209 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsCommon.java +256 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsConsentModule.java +226 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsEvent.java +72 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsInterstitialModule.java +159 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.java +143 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsPackage.java +48 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedModule.java +177 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/RCTConvert.java +111 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeApp.java +34 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeEvent.java +41 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeEventEmitter.java +150 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeInitProvider.java +77 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeJSON.java +107 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeMeta.java +92 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeModule.java +96 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativePreferences.java +86 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/SharedUtils.java +427 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/TaskExecutorService.java +124 -0
- package/android/src/main/java/io/invertase/googlemobileads/interfaces/ContextProvider.java +30 -0
- package/android/src/main/java/io/invertase/googlemobileads/interfaces/NativeError.java +28 -0
- package/android/src/main/java/io/invertase/googlemobileads/interfaces/NativeEvent.java +26 -0
- package/babel.config.js +18 -0
- package/docs/displaying-ads.mdx +319 -0
- package/docs/european-user-consent.mdx +258 -0
- package/docs/img/logo_admob_192px.svg +19 -0
- package/docs/index.mdx +168 -0
- package/docs.json +9 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.h +29 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.m +98 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.h +23 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.m +153 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h +60 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.m +201 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.h +26 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.m +179 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.h +32 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.m +57 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.h +25 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.m +124 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.h +24 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.m +104 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.h +25 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.m +173 -0
- package/ios/RNGoogleMobileAds/common/RNAppModule.h +24 -0
- package/ios/RNGoogleMobileAds/common/RNAppModule.m +158 -0
- package/ios/RNGoogleMobileAds/common/RNJSON.h +34 -0
- package/ios/RNGoogleMobileAds/common/RNJSON.m +93 -0
- package/ios/RNGoogleMobileAds/common/RNMeta.h +30 -0
- package/ios/RNGoogleMobileAds/common/RNMeta.m +61 -0
- package/ios/RNGoogleMobileAds/common/RNPreferences.h +44 -0
- package/ios/RNGoogleMobileAds/common/RNPreferences.m +94 -0
- package/ios/RNGoogleMobileAds/common/RNRCTEventEmitter.h +73 -0
- package/ios/RNGoogleMobileAds/common/RNRCTEventEmitter.m +150 -0
- package/ios/RNGoogleMobileAds/common/RNSharedUtils.h +48 -0
- package/ios/RNGoogleMobileAds/common/RNSharedUtils.m +56 -0
- package/ios/RNGoogleMobileAds.xcodeproj/project.pbxproj +377 -0
- package/ios/RNGoogleMobileAds.xcodeproj/xcshareddata/IDETemplateMacros.plist +24 -0
- package/ios_config.sh +140 -0
- package/jest.config.js +6 -0
- package/jest.setup.ts +29 -0
- package/lib/commonjs/AdEventType.js +34 -0
- package/lib/commonjs/AdEventType.js.map +1 -0
- package/lib/commonjs/AdsConsent.js +160 -0
- package/lib/commonjs/AdsConsent.js.map +1 -0
- package/lib/commonjs/AdsConsentDebugGeography.js +38 -0
- package/lib/commonjs/AdsConsentDebugGeography.js.map +1 -0
- package/lib/commonjs/AdsConsentStatus.js +36 -0
- package/lib/commonjs/AdsConsentStatus.js.map +1 -0
- package/lib/commonjs/BannerAdSize.js +38 -0
- package/lib/commonjs/BannerAdSize.js.map +1 -0
- package/lib/commonjs/MaxAdContentRating.js +33 -0
- package/lib/commonjs/MaxAdContentRating.js.map +1 -0
- package/lib/commonjs/MobileAds.js +67 -0
- package/lib/commonjs/MobileAds.js.map +1 -0
- package/lib/commonjs/RewardedAdEventType.js +31 -0
- package/lib/commonjs/RewardedAdEventType.js.map +1 -0
- package/lib/commonjs/TestIds.js +47 -0
- package/lib/commonjs/TestIds.js.map +1 -0
- package/lib/commonjs/ads/AppOpenAd.js +96 -0
- package/lib/commonjs/ads/AppOpenAd.js.map +1 -0
- package/lib/commonjs/ads/BannerAd.js +128 -0
- package/lib/commonjs/ads/BannerAd.js.map +1 -0
- package/lib/commonjs/ads/InterstitialAd.js +163 -0
- package/lib/commonjs/ads/InterstitialAd.js.map +1 -0
- package/lib/commonjs/ads/MobileAd.js +90 -0
- package/lib/commonjs/ads/MobileAd.js.map +1 -0
- package/lib/commonjs/ads/RewardedAd.js +169 -0
- package/lib/commonjs/ads/RewardedAd.js.map +1 -0
- package/lib/commonjs/common/Base64.js +121 -0
- package/lib/commonjs/common/Base64.js.map +1 -0
- package/lib/commonjs/common/MutatableParams.js +46 -0
- package/lib/commonjs/common/MutatableParams.js.map +1 -0
- package/lib/commonjs/common/ReferenceBase.js +59 -0
- package/lib/commonjs/common/ReferenceBase.js.map +1 -0
- package/lib/commonjs/common/deeps.js +101 -0
- package/lib/commonjs/common/deeps.js.map +1 -0
- package/lib/commonjs/common/id.js +82 -0
- package/lib/commonjs/common/id.js.map +1 -0
- package/lib/commonjs/common/index.js +212 -0
- package/lib/commonjs/common/index.js.map +1 -0
- package/lib/commonjs/common/path.js +144 -0
- package/lib/commonjs/common/path.js.map +1 -0
- package/lib/commonjs/common/promise.js +70 -0
- package/lib/commonjs/common/promise.js.map +1 -0
- package/lib/commonjs/common/serialize.js +52 -0
- package/lib/commonjs/common/serialize.js.map +1 -0
- package/lib/commonjs/common/validate.js +239 -0
- package/lib/commonjs/common/validate.js.map +1 -0
- package/lib/commonjs/declarations.d.js +2 -0
- package/lib/commonjs/declarations.d.js.map +1 -0
- package/lib/commonjs/index.js +143 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/internal/GoogleMobileAdsNativeEventEmitter.js +76 -0
- package/lib/commonjs/internal/GoogleMobileAdsNativeEventEmitter.js.map +1 -0
- package/lib/commonjs/internal/Module.js +60 -0
- package/lib/commonjs/internal/Module.js.map +1 -0
- package/lib/commonjs/internal/NativeError.js +70 -0
- package/lib/commonjs/internal/NativeError.js.map +1 -0
- package/lib/commonjs/internal/SharedEventEmitter.js +31 -0
- package/lib/commonjs/internal/SharedEventEmitter.js.map +1 -0
- package/lib/commonjs/internal/constants.js +30 -0
- package/lib/commonjs/internal/constants.js.map +1 -0
- package/lib/commonjs/internal/index.js +49 -0
- package/lib/commonjs/internal/index.js.map +1 -0
- package/lib/commonjs/internal/registry/nativeModule.js +231 -0
- package/lib/commonjs/internal/registry/nativeModule.js.map +1 -0
- package/lib/commonjs/types/AdEventListener.js +6 -0
- package/lib/commonjs/types/AdEventListener.js.map +1 -0
- package/lib/commonjs/types/AdShowOptions.js +2 -0
- package/lib/commonjs/types/AdShowOptions.js.map +1 -0
- package/lib/commonjs/types/AdapterStatus.js +18 -0
- package/lib/commonjs/types/AdapterStatus.js.map +1 -0
- package/lib/commonjs/types/AdsConsent.interface.js +6 -0
- package/lib/commonjs/types/AdsConsent.interface.js.map +1 -0
- package/lib/commonjs/types/BannerAdProps.js +6 -0
- package/lib/commonjs/types/BannerAdProps.js.map +1 -0
- package/lib/commonjs/types/GoogleMobileAdsNativeModule.js +6 -0
- package/lib/commonjs/types/GoogleMobileAdsNativeModule.js.map +1 -0
- package/lib/commonjs/types/MobileAd.interface.js +6 -0
- package/lib/commonjs/types/MobileAd.interface.js.map +1 -0
- package/lib/commonjs/types/MobileAdsModule.interface.js +6 -0
- package/lib/commonjs/types/MobileAdsModule.interface.js.map +1 -0
- package/lib/commonjs/types/Module.interface.js +2 -0
- package/lib/commonjs/types/Module.interface.js.map +1 -0
- package/lib/commonjs/types/RequestConfiguration.js +6 -0
- package/lib/commonjs/types/RequestConfiguration.js.map +1 -0
- package/lib/commonjs/types/RequestOptions.js +2 -0
- package/lib/commonjs/types/RequestOptions.js.map +1 -0
- package/lib/commonjs/types/RewardedAdReward.js +2 -0
- package/lib/commonjs/types/RewardedAdReward.js.map +1 -0
- package/lib/commonjs/validateAdRequestConfiguration.js +69 -0
- package/lib/commonjs/validateAdRequestConfiguration.js.map +1 -0
- package/lib/commonjs/validateAdRequestOptions.js +158 -0
- package/lib/commonjs/validateAdRequestOptions.js.map +1 -0
- package/lib/commonjs/validateAdShowOptions.js +47 -0
- package/lib/commonjs/validateAdShowOptions.js.map +1 -0
- package/lib/commonjs/version.js +10 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/AdEventType.js +26 -0
- package/lib/module/AdEventType.js.map +1 -0
- package/lib/module/AdsConsent.js +148 -0
- package/lib/module/AdsConsent.js.map +1 -0
- package/lib/module/AdsConsentDebugGeography.js +30 -0
- package/lib/module/AdsConsentDebugGeography.js.map +1 -0
- package/lib/module/AdsConsentStatus.js +28 -0
- package/lib/module/AdsConsentStatus.js.map +1 -0
- package/lib/module/BannerAdSize.js +30 -0
- package/lib/module/BannerAdSize.js.map +1 -0
- package/lib/module/MaxAdContentRating.js +25 -0
- package/lib/module/MaxAdContentRating.js.map +1 -0
- package/lib/module/MobileAds.js +53 -0
- package/lib/module/MobileAds.js.map +1 -0
- package/lib/module/RewardedAdEventType.js +23 -0
- package/lib/module/RewardedAdEventType.js.map +1 -0
- package/lib/module/TestIds.js +38 -0
- package/lib/module/TestIds.js.map +1 -0
- package/lib/module/ads/AppOpenAd.js +81 -0
- package/lib/module/ads/AppOpenAd.js.map +1 -0
- package/lib/module/ads/BannerAd.js +108 -0
- package/lib/module/ads/BannerAd.js.map +1 -0
- package/lib/module/ads/InterstitialAd.js +149 -0
- package/lib/module/ads/InterstitialAd.js.map +1 -0
- package/lib/module/ads/MobileAd.js +94 -0
- package/lib/module/ads/MobileAd.js.map +1 -0
- package/lib/module/ads/RewardedAd.js +155 -0
- package/lib/module/ads/RewardedAd.js.map +1 -0
- package/lib/module/common/Base64.js +106 -0
- package/lib/module/common/Base64.js.map +1 -0
- package/lib/module/common/MutatableParams.js +52 -0
- package/lib/module/common/MutatableParams.js.map +1 -0
- package/lib/module/common/ReferenceBase.js +50 -0
- package/lib/module/common/ReferenceBase.js.map +1 -0
- package/lib/module/common/deeps.js +91 -0
- package/lib/module/common/deeps.js.map +1 -0
- package/lib/module/common/id.js +74 -0
- package/lib/module/common/id.js.map +1 -0
- package/lib/module/common/index.js +109 -0
- package/lib/module/common/index.js.map +1 -0
- package/lib/module/common/path.js +120 -0
- package/lib/module/common/path.js.map +1 -0
- package/lib/module/common/promise.js +60 -0
- package/lib/module/common/promise.js.map +1 -0
- package/lib/module/common/serialize.js +41 -0
- package/lib/module/common/serialize.js.map +1 -0
- package/lib/module/common/validate.js +197 -0
- package/lib/module/common/validate.js.map +1 -0
- package/lib/module/declarations.d.js +2 -0
- package/lib/module/declarations.d.js.map +1 -0
- package/lib/module/index.js +33 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/internal/GoogleMobileAdsNativeEventEmitter.js +83 -0
- package/lib/module/internal/GoogleMobileAdsNativeEventEmitter.js.map +1 -0
- package/lib/module/internal/Module.js +64 -0
- package/lib/module/internal/Module.js.map +1 -0
- package/lib/module/internal/NativeError.js +61 -0
- package/lib/module/internal/NativeError.js.map +1 -0
- package/lib/module/internal/SharedEventEmitter.js +20 -0
- package/lib/module/internal/SharedEventEmitter.js.map +1 -0
- package/lib/module/internal/constants.js +20 -0
- package/lib/module/internal/constants.js.map +1 -0
- package/lib/module/internal/index.js +21 -0
- package/lib/module/internal/index.js.map +1 -0
- package/lib/module/internal/registry/nativeModule.js +215 -0
- package/lib/module/internal/registry/nativeModule.js.map +1 -0
- package/lib/module/types/AdEventListener.js +2 -0
- package/lib/module/types/AdEventListener.js.map +1 -0
- package/lib/module/types/AdShowOptions.js +2 -0
- package/lib/module/types/AdShowOptions.js.map +1 -0
- package/lib/module/types/AdapterStatus.js +10 -0
- package/lib/module/types/AdapterStatus.js.map +1 -0
- package/lib/module/types/AdsConsent.interface.js +2 -0
- package/lib/module/types/AdsConsent.interface.js.map +1 -0
- package/lib/module/types/BannerAdProps.js +2 -0
- package/lib/module/types/BannerAdProps.js.map +1 -0
- package/lib/module/types/GoogleMobileAdsNativeModule.js +2 -0
- package/lib/module/types/GoogleMobileAdsNativeModule.js.map +1 -0
- package/lib/module/types/MobileAd.interface.js +2 -0
- package/lib/module/types/MobileAd.interface.js.map +1 -0
- package/lib/module/types/MobileAdsModule.interface.js +2 -0
- package/lib/module/types/MobileAdsModule.interface.js.map +1 -0
- package/lib/module/types/Module.interface.js +2 -0
- package/lib/module/types/Module.interface.js.map +1 -0
- package/lib/module/types/RequestConfiguration.js +2 -0
- package/lib/module/types/RequestConfiguration.js.map +1 -0
- package/lib/module/types/RequestOptions.js +2 -0
- package/lib/module/types/RequestOptions.js.map +1 -0
- package/lib/module/types/RewardedAdReward.js +2 -0
- package/lib/module/types/RewardedAdReward.js.map +1 -0
- package/lib/module/validateAdRequestConfiguration.js +60 -0
- package/lib/module/validateAdRequestConfiguration.js.map +1 -0
- package/lib/module/validateAdRequestOptions.js +150 -0
- package/lib/module/validateAdRequestOptions.js.map +1 -0
- package/lib/module/validateAdShowOptions.js +39 -0
- package/lib/module/validateAdShowOptions.js.map +1 -0
- package/lib/module/version.js +3 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/AdEventType.d.ts +47 -0
- package/lib/typescript/AdsConsent.d.ts +2 -0
- package/lib/typescript/AdsConsentDebugGeography.d.ts +19 -0
- package/lib/typescript/AdsConsentStatus.d.ts +17 -0
- package/lib/typescript/BannerAdSize.d.ts +34 -0
- package/lib/typescript/MaxAdContentRating.d.ts +18 -0
- package/lib/typescript/MobileAds.d.ts +11 -0
- package/lib/typescript/RewardedAdEventType.d.ts +46 -0
- package/lib/typescript/TestIds.d.ts +6 -0
- package/lib/typescript/ads/AppOpenAd.d.ts +11 -0
- package/lib/typescript/ads/BannerAd.d.ts +3 -0
- package/lib/typescript/ads/InterstitialAd.d.ts +78 -0
- package/lib/typescript/ads/MobileAd.d.ts +32 -0
- package/lib/typescript/ads/RewardedAd.d.ts +84 -0
- package/lib/typescript/common/Base64.d.ts +14 -0
- package/lib/typescript/common/MutatableParams.d.ts +9 -0
- package/lib/typescript/common/ReferenceBase.d.ts +11 -0
- package/lib/typescript/common/deeps.d.ts +18 -0
- package/lib/typescript/common/id.d.ts +11 -0
- package/lib/typescript/common/index.d.ts +28 -0
- package/lib/typescript/common/path.d.ts +43 -0
- package/lib/typescript/common/promise.d.ts +13 -0
- package/lib/typescript/common/serialize.d.ts +5 -0
- package/lib/typescript/common/validate.d.ts +90 -0
- package/lib/typescript/index.d.ts +14 -0
- package/lib/typescript/internal/GoogleMobileAdsNativeEventEmitter.d.ts +12 -0
- package/lib/typescript/internal/Module.d.ts +13 -0
- package/lib/typescript/internal/NativeError.d.ts +26 -0
- package/lib/typescript/internal/SharedEventEmitter.d.ts +2 -0
- package/lib/typescript/internal/constants.d.ts +3 -0
- package/lib/typescript/internal/index.d.ts +4 -0
- package/lib/typescript/internal/registry/nativeModule.d.ts +15 -0
- package/lib/typescript/types/AdEventListener.d.ts +11 -0
- package/lib/typescript/types/AdShowOptions.d.ts +12 -0
- package/lib/typescript/types/AdapterStatus.d.ts +18 -0
- package/lib/typescript/types/AdsConsent.interface.d.ts +286 -0
- package/lib/typescript/types/BannerAdProps.d.ts +66 -0
- package/lib/typescript/types/GoogleMobileAdsNativeModule.d.ts +14 -0
- package/lib/typescript/types/MobileAd.interface.d.ts +64 -0
- package/lib/typescript/types/MobileAdsModule.interface.d.ts +38 -0
- package/lib/typescript/types/Module.interface.d.ts +14 -0
- package/lib/typescript/types/RequestConfiguration.d.ts +36 -0
- package/lib/typescript/types/RequestOptions.d.ts +106 -0
- package/lib/typescript/types/RewardedAdReward.d.ts +13 -0
- package/lib/typescript/validateAdRequestConfiguration.d.ts +2 -0
- package/lib/typescript/validateAdRequestOptions.d.ts +2 -0
- package/lib/typescript/validateAdShowOptions.d.ts +2 -0
- package/lib/typescript/version.d.ts +1 -0
- package/package.json +143 -0
- package/react-native.config.js +19 -0
- package/src/AdEventType.ts +68 -0
- package/src/AdsConsent.ts +191 -0
- package/src/AdsConsentDebugGeography.ts +38 -0
- package/src/AdsConsentStatus.ts +36 -0
- package/src/BannerAdSize.ts +59 -0
- package/src/MaxAdContentRating.ts +38 -0
- package/src/MobileAds.ts +84 -0
- package/src/RewardedAdEventType.ts +64 -0
- package/src/TestIds.ts +39 -0
- package/src/ads/AppOpenAd.ts +85 -0
- package/src/ads/BannerAd.tsx +126 -0
- package/src/ads/InterstitialAd.ts +156 -0
- package/src/ads/MobileAd.ts +101 -0
- package/src/ads/RewardedAd.ts +161 -0
- package/src/common/Base64.ts +114 -0
- package/src/common/MutatableParams.ts +50 -0
- package/src/common/ReferenceBase.ts +45 -0
- package/src/common/deeps.ts +88 -0
- package/src/common/id.ts +74 -0
- package/src/common/index.ts +103 -0
- package/src/common/path.ts +114 -0
- package/src/common/promise.ts +66 -0
- package/src/common/serialize.ts +43 -0
- package/src/common/validate.ts +205 -0
- package/src/declarations.d.ts +3 -0
- package/src/index.ts +35 -0
- package/src/internal/GoogleMobileAdsNativeEventEmitter.ts +81 -0
- package/src/internal/Module.ts +58 -0
- package/src/internal/NativeError.ts +56 -0
- package/src/internal/SharedEventEmitter.ts +22 -0
- package/src/internal/constants.ts +43 -0
- package/src/internal/index.ts +21 -0
- package/src/internal/registry/nativeModule.ts +226 -0
- package/src/types/AdEventListener.ts +16 -0
- package/src/types/AdShowOptions.ts +12 -0
- package/src/types/AdapterStatus.ts +20 -0
- package/src/types/AdsConsent.interface.ts +306 -0
- package/src/types/BannerAdProps.ts +73 -0
- package/src/types/GoogleMobileAdsNativeModule.ts +15 -0
- package/src/types/MobileAd.interface.ts +69 -0
- package/src/types/MobileAdsModule.interface.ts +43 -0
- package/src/types/Module.interface.ts +16 -0
- package/src/types/RequestConfiguration.ts +40 -0
- package/src/types/RequestOptions.ts +113 -0
- package/src/types/RewardedAdReward.ts +14 -0
- package/src/validateAdRequestConfiguration.ts +71 -0
- package/src/validateAdRequestOptions.ts +168 -0
- package/src/validateAdShowOptions.ts +41 -0
- package/src/version.ts +2 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { BannerAdSize } from '../BannerAdSize';
|
|
2
|
+
import { RequestOptions } from './RequestOptions';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* An interface for a Banner advert component.
|
|
6
|
+
*
|
|
7
|
+
* #### Example
|
|
8
|
+
*
|
|
9
|
+
* The `BannerAd` interface is exposed as a React component, allowing you to integrate ads within your existing React
|
|
10
|
+
* Native code base. The component itself is isolated, meaning any standard `View` props (e.g. `style`) are not
|
|
11
|
+
* forwarded on. It is recommended you wrap the `BannerAd` within your own `View` if you wish to apply custom props for use-cases
|
|
12
|
+
* such as positioning.
|
|
13
|
+
*
|
|
14
|
+
* ```js
|
|
15
|
+
* import { BannerAd, BannerAdSize, TestIds } from 'react-native-google-mobile-ads';
|
|
16
|
+
*
|
|
17
|
+
* function HomeScreen() {
|
|
18
|
+
* return (
|
|
19
|
+
* <BannerAd
|
|
20
|
+
* unitId={TestIds.BANNER}
|
|
21
|
+
* size={BannerAdSize.FULL_BANNER}
|
|
22
|
+
* requestOptions={{
|
|
23
|
+
* requestNonPersonalizedAdsOnly: true,
|
|
24
|
+
* }}
|
|
25
|
+
* onAdLoaded={() => {
|
|
26
|
+
* console.log('Advert loaded');
|
|
27
|
+
* }}
|
|
28
|
+
* onAdFailedToLoad={(error) => {
|
|
29
|
+
* console.error('Advert failed to load: ', error);
|
|
30
|
+
* }}
|
|
31
|
+
* />
|
|
32
|
+
* );
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export type BannerAdProps = {
|
|
37
|
+
/**
|
|
38
|
+
* The Google Mobile Ads unit ID for the banner.
|
|
39
|
+
*/
|
|
40
|
+
unitId: string;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The size of the banner. Can be a predefined size via `BannerAdSize` or custom dimensions, e.g. `300x200`.
|
|
44
|
+
*
|
|
45
|
+
* Inventory must be available for the banner size specified, otherwise a no-fill error will be sent to `onAdFailedToLoad`.
|
|
46
|
+
*/
|
|
47
|
+
size: BannerAdSize;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The request options for this banner.
|
|
51
|
+
*/
|
|
52
|
+
requestOptions?: RequestOptions;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* When an ad has finished loading.
|
|
56
|
+
*/
|
|
57
|
+
onAdLoaded?: () => void;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* When an ad has failed to load. Callback contains an Error.
|
|
61
|
+
*/
|
|
62
|
+
onAdFailedToLoad?: (error: Error) => void;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The ad is now visible to the user.
|
|
66
|
+
*/
|
|
67
|
+
onAdOpened?: () => void;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Called when the user is about to return to the app after tapping on an ad.
|
|
71
|
+
*/
|
|
72
|
+
onAdClosed?: () => void;
|
|
73
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AdapterStatus } from './AdapterStatus';
|
|
2
|
+
import { RequestConfiguration } from './RequestConfiguration';
|
|
3
|
+
import { RequestOptions } from './RequestOptions';
|
|
4
|
+
import { AdShowOptions } from './AdShowOptions';
|
|
5
|
+
|
|
6
|
+
export interface GoogleMobileAdsNativeModule {
|
|
7
|
+
initialize(): Promise<AdapterStatus[]>;
|
|
8
|
+
setRequestConfiguration(requestConfiguration?: RequestConfiguration): Promise<void>;
|
|
9
|
+
appOpenLoad(requestId: number, adUnitId: string, requestOptions: RequestOptions): void;
|
|
10
|
+
appOpenShow(requestId: number, showOptions?: AdShowOptions): Promise<void>;
|
|
11
|
+
interstitialLoad(requestId: number, adUnitId: string, requestOptions: RequestOptions): void;
|
|
12
|
+
interstitialShow(requestId: number, showOptions?: AdShowOptions): Promise<void>;
|
|
13
|
+
rewardedLoad(requestId: number, adUnitId: string, requestOptions: RequestOptions): void;
|
|
14
|
+
rewardedShow(requestId: number, adUnitId: string, showOptions?: AdShowOptions): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { AdEventListener } from './AdEventListener';
|
|
2
|
+
import { AdShowOptions } from './AdShowOptions';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Base class for InterstitialAd, RewardedAd, NativeAd and BannerAd.
|
|
6
|
+
*/
|
|
7
|
+
export interface MobileAdInterface {
|
|
8
|
+
/**
|
|
9
|
+
* The Ad Unit ID for this Gogole Mobile Ads ad.
|
|
10
|
+
*/
|
|
11
|
+
adUnitId: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Whether the advert is loaded and can be shown.
|
|
15
|
+
*/
|
|
16
|
+
loaded: boolean;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Start loading the advert with the provided RequestOptions.
|
|
20
|
+
*
|
|
21
|
+
* It is recommended you setup ad event handlers before calling this method.
|
|
22
|
+
*/
|
|
23
|
+
load(): void;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Listen to ad events. See AdEventTypes for more information.
|
|
27
|
+
*
|
|
28
|
+
* Returns an unsubscriber function to stop listening to further events.
|
|
29
|
+
*
|
|
30
|
+
* #### Example
|
|
31
|
+
*
|
|
32
|
+
* ```js
|
|
33
|
+
* // Create InterstitialAd/RewardedAd
|
|
34
|
+
* const advert = InterstitialAd.createForAdRequest('...');
|
|
35
|
+
*
|
|
36
|
+
* const unsubscribe = advert.onAdEvent((type) => {
|
|
37
|
+
*
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Sometime later...
|
|
41
|
+
* unsubscribe();
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @param listener A listener callback containing a event type, error and data.
|
|
45
|
+
*/
|
|
46
|
+
onAdEvent(listener: AdEventListener): () => void;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Show the loaded advert to the user.
|
|
50
|
+
*
|
|
51
|
+
* #### Example
|
|
52
|
+
*
|
|
53
|
+
* ```js
|
|
54
|
+
* // Create InterstitialAd/RewardedAd
|
|
55
|
+
* const advert = InterstitialAd.createForAdRequest('...');
|
|
56
|
+
*
|
|
57
|
+
* advert.onAdEvent((type) => {
|
|
58
|
+
* if (type === AdEventType.LOADED) {
|
|
59
|
+
* advert.show({
|
|
60
|
+
* immersiveModeEnabled: true,
|
|
61
|
+
* });
|
|
62
|
+
* }
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @param showOptions An optional `AdShowOptions` interface.
|
|
67
|
+
*/
|
|
68
|
+
show(showOptions?: AdShowOptions): Promise<void>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { EventEmitter } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import { AdapterStatus } from './AdapterStatus';
|
|
4
|
+
import { GoogleMobileAdsNativeModule } from './GoogleMobileAdsNativeModule';
|
|
5
|
+
import { RequestConfiguration } from './RequestConfiguration';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The Google Mobile Ads service interface.
|
|
9
|
+
*/
|
|
10
|
+
export interface MobileAdsModuleInterface {
|
|
11
|
+
/**
|
|
12
|
+
* Initialize the SDK.
|
|
13
|
+
*/
|
|
14
|
+
initialize(): Promise<AdapterStatus[]>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Sets request options for all future ad requests.
|
|
18
|
+
*
|
|
19
|
+
* #### Example
|
|
20
|
+
*
|
|
21
|
+
* ```js
|
|
22
|
+
* import mobileAds, { MaxAdContentRating } from 'react-native-google-mobile-ads';
|
|
23
|
+
*
|
|
24
|
+
* await mobileAds().setRequestConfiguration({
|
|
25
|
+
* // Update all future requests suitable for parental guidance
|
|
26
|
+
* maxAdContentRating: MaxAdContentRating.PG,
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @param requestConfiguration An RequestConfiguration interface used on all future Google Mobile Ads ad requests.
|
|
31
|
+
*/
|
|
32
|
+
setRequestConfiguration(requestConfiguration: RequestConfiguration): Promise<void>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The native module instance for the Google Mobile Ads service.
|
|
36
|
+
*/
|
|
37
|
+
native: GoogleMobileAdsNativeModule;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Returns the shared event emitter instance used for all JS event routing.
|
|
41
|
+
*/
|
|
42
|
+
emitter: EventEmitter;
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface App {
|
|
2
|
+
name: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface Config {
|
|
6
|
+
version: string;
|
|
7
|
+
namespace: string;
|
|
8
|
+
nativeModuleName: string[];
|
|
9
|
+
nativeEvents: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ModuleInterface {
|
|
13
|
+
app: App;
|
|
14
|
+
_config: Config;
|
|
15
|
+
_customUrlOrRegion?: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { MaxAdContentRating } from '../MaxAdContentRating';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `RequestConfiguration` used when setting global ad settings via `setRequestConfiguration`.
|
|
5
|
+
*/
|
|
6
|
+
export interface RequestConfiguration {
|
|
7
|
+
/**
|
|
8
|
+
* The maximum ad content rating for all ads. Google Mobile Ads returns ads at or below the specified level.
|
|
9
|
+
*
|
|
10
|
+
* Ratings are based on the [digital content label classifications](https://support.google.com/admob/answer/7562142).
|
|
11
|
+
*/
|
|
12
|
+
maxAdContentRating?: MaxAdContentRating;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* If `true`, indicates that you want your content treated as child-directed for purposes of COPPA.
|
|
16
|
+
*
|
|
17
|
+
* For purposes of the [Children's Online Privacy Protection Act (COPPA)](http://business.ftc.gov/privacy-and-security/children%27s-privacy),
|
|
18
|
+
* there is a setting called "tag for child-directed treatment". By setting this tag, you certify that this notification
|
|
19
|
+
* is accurate and you are authorized to act on behalf of the owner of the app. You understand that abuse of this
|
|
20
|
+
* setting may result in termination of your Google account.
|
|
21
|
+
*/
|
|
22
|
+
tagForChildDirectedTreatment?: boolean;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* If `true`, indicates that you want the ad request to be handled in a manner suitable for users under the age of consent.
|
|
26
|
+
*
|
|
27
|
+
* You can mark your ad requests to receive treatment for users in the European Economic Area (EEA) under the age of consent.
|
|
28
|
+
* This feature is designed to help facilitate compliance with the [General Data Protection Regulation (GDPR)](https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX:32016R0679).
|
|
29
|
+
*
|
|
30
|
+
* See the [Google Mobile SDK docs](https://developers.google.com/admob/android/targeting#ad_content_filtering) for more information.
|
|
31
|
+
*/
|
|
32
|
+
tagForUnderAgeOfConsent?: boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* An array of test device IDs to add to the allowlist.
|
|
36
|
+
*
|
|
37
|
+
* If using an emulator, set the device ID to `EMULATOR`.
|
|
38
|
+
*/
|
|
39
|
+
testDeviceIdentifiers?: string[];
|
|
40
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export interface ServerSideVerificationOptions {
|
|
2
|
+
/**
|
|
3
|
+
* User identifier.
|
|
4
|
+
* If no user identifier is provided by the app, this query parameter will not be present in the SSV callback.
|
|
5
|
+
*/
|
|
6
|
+
userId?: string;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Custom data string.
|
|
10
|
+
* If no custom data string is provided by the app, this query parameter value will not be present in the SSV callback.
|
|
11
|
+
*/
|
|
12
|
+
customData?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The `RequestOptions` interface. Used when passing additional request options before an advert is loaded.
|
|
17
|
+
*/
|
|
18
|
+
export interface RequestOptions {
|
|
19
|
+
/**
|
|
20
|
+
* If `true` only non-personalized ads will be loaded.
|
|
21
|
+
*
|
|
22
|
+
* Google serves personalized ads by default. This option must be `true` if users who are within the EEA have only
|
|
23
|
+
* given consent to non-personalized ads.
|
|
24
|
+
*/
|
|
25
|
+
requestNonPersonalizedAdsOnly?: boolean;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Attaches additional properties to an ad request for direct campaign delivery.
|
|
29
|
+
*
|
|
30
|
+
* Takes an array of string key/value pairs.
|
|
31
|
+
*
|
|
32
|
+
* #### Example
|
|
33
|
+
*
|
|
34
|
+
* Attaches `?campaign=abc&user=123` to the ad request:
|
|
35
|
+
*
|
|
36
|
+
* ```js
|
|
37
|
+
* await Interstitial.createForAdRequest('ca-app-pub-3940256099942544/1033173712', {
|
|
38
|
+
* networkExtras: {
|
|
39
|
+
* campaign: 'abc',
|
|
40
|
+
* user: '123',
|
|
41
|
+
* },
|
|
42
|
+
* });
|
|
43
|
+
*/
|
|
44
|
+
networkExtras?: { [key: string]: string };
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* An array of keywords to be sent when loading the ad.
|
|
48
|
+
*
|
|
49
|
+
* Setting keywords helps deliver more specific ads to a user based on the keywords.
|
|
50
|
+
*
|
|
51
|
+
* #### Example
|
|
52
|
+
*
|
|
53
|
+
* ```js
|
|
54
|
+
* await Interstitial.createForAdRequest('ca-app-pub-3940256099942544/1033173712', {
|
|
55
|
+
* keywords: ['fashion', 'clothing'],
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
keywords?: string[];
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Sets a content URL for targeting purposes.
|
|
63
|
+
*
|
|
64
|
+
* Max length of 512.
|
|
65
|
+
*/
|
|
66
|
+
contentUrl?: string;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The latitude and longitude location of the user.
|
|
70
|
+
*
|
|
71
|
+
* Ensure your app requests location permissions from the user.
|
|
72
|
+
*
|
|
73
|
+
* #### Example
|
|
74
|
+
*
|
|
75
|
+
* ```js
|
|
76
|
+
* await Interstitial.createForAdRequest('ca-app-pub-3940256099942544/1033173712', {
|
|
77
|
+
* location: [53.481073, -2.237074],
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
location?: [number, number];
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Sets the location accuracy if the location is set, in meters.
|
|
85
|
+
*
|
|
86
|
+
* This option is only applied to iOS devices. On Android, this option has no effect.
|
|
87
|
+
*
|
|
88
|
+
* @ios
|
|
89
|
+
*/
|
|
90
|
+
locationAccuracy?: number;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Sets the request agent string to identify the ad request's origin. Third party libraries that reference the Mobile
|
|
94
|
+
* Ads SDK should call this method to denote the platform from which the ad request originated. For example, if a
|
|
95
|
+
* third party ad network called "CoolAds network" mediates requests to the Mobile Ads SDK, it should call this
|
|
96
|
+
* method with "CoolAds".
|
|
97
|
+
*
|
|
98
|
+
* #### Example
|
|
99
|
+
*
|
|
100
|
+
* ```js
|
|
101
|
+
* await Interstitial.createForAdRequest('ca-app-pub-3940256099942544/1033173712', {
|
|
102
|
+
* requestAgent: 'CoolAds',
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
requestAgent?: string;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Server Side Verification(SSV) Options
|
|
110
|
+
* See [Google Mobile SDK Docs](https://developers.google.com/admob/android/ssv) for more information.
|
|
111
|
+
*/
|
|
112
|
+
serverSideVerificationOptions?: ServerSideVerificationOptions;
|
|
113
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `RewardedAdReward` returned from rewarded ads.
|
|
3
|
+
*/
|
|
4
|
+
export interface RewardedAdReward {
|
|
5
|
+
/**
|
|
6
|
+
* The reward name, e.g. 'coins', 'diamonds'.
|
|
7
|
+
*/
|
|
8
|
+
type: string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The number value of the reward, e.g. 10
|
|
12
|
+
*/
|
|
13
|
+
amount: number;
|
|
14
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { hasOwnProperty, isArray, isBoolean, isObject } from './common';
|
|
19
|
+
import { MaxAdContentRating } from './MaxAdContentRating';
|
|
20
|
+
import { RequestConfiguration } from './types/RequestConfiguration';
|
|
21
|
+
|
|
22
|
+
export function validateAdRequestConfiguration(requestConfiguration: RequestConfiguration) {
|
|
23
|
+
const out: RequestConfiguration = {};
|
|
24
|
+
|
|
25
|
+
if (!isObject(requestConfiguration)) {
|
|
26
|
+
throw new Error("'requestConfiguration' expected an object value");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (requestConfiguration.maxAdContentRating) {
|
|
30
|
+
if (
|
|
31
|
+
requestConfiguration.maxAdContentRating !== MaxAdContentRating.G &&
|
|
32
|
+
requestConfiguration.maxAdContentRating !== MaxAdContentRating.PG &&
|
|
33
|
+
requestConfiguration.maxAdContentRating !== MaxAdContentRating.T &&
|
|
34
|
+
requestConfiguration.maxAdContentRating !== MaxAdContentRating.MA
|
|
35
|
+
) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
"'requestConfiguration.maxAdContentRating' expected on of MaxAdContentRating.G, MaxAdContentRating.PG, MaxAdContentRating.T or MaxAdContentRating.MA",
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
out.maxAdContentRating = requestConfiguration.maxAdContentRating;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (hasOwnProperty(requestConfiguration, 'tagForChildDirectedTreatment')) {
|
|
45
|
+
if (!isBoolean(requestConfiguration.tagForChildDirectedTreatment)) {
|
|
46
|
+
throw new Error(
|
|
47
|
+
"'requestConfiguration.tagForChildDirectedTreatment' expected a boolean value",
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
out.tagForChildDirectedTreatment = requestConfiguration.tagForChildDirectedTreatment;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (hasOwnProperty(requestConfiguration, 'tagForUnderAgeOfConsent')) {
|
|
55
|
+
if (!isBoolean(requestConfiguration.tagForUnderAgeOfConsent)) {
|
|
56
|
+
throw new Error("'requestConfiguration.tagForUnderAgeOfConsent' expected a boolean value");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
out.tagForUnderAgeOfConsent = requestConfiguration.tagForUnderAgeOfConsent;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (hasOwnProperty(requestConfiguration, 'testDeviceIdentifiers')) {
|
|
63
|
+
if (!isArray(requestConfiguration.testDeviceIdentifiers)) {
|
|
64
|
+
throw new Error("'requestConfiguration.testDeviceIdentifiers' expected an array value");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
out.testDeviceIdentifiers = requestConfiguration.testDeviceIdentifiers;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
hasOwnProperty,
|
|
20
|
+
isArray,
|
|
21
|
+
isBoolean,
|
|
22
|
+
isNumber,
|
|
23
|
+
isObject,
|
|
24
|
+
isString,
|
|
25
|
+
isUndefined,
|
|
26
|
+
isValidUrl,
|
|
27
|
+
} from './common';
|
|
28
|
+
import { RequestOptions } from './types/RequestOptions';
|
|
29
|
+
|
|
30
|
+
export function validateAdRequestOptions(options?: RequestOptions) {
|
|
31
|
+
const out: RequestOptions = {};
|
|
32
|
+
|
|
33
|
+
if (isUndefined(options)) {
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!isObject(options)) {
|
|
38
|
+
throw new Error("'options' expected an object value");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (hasOwnProperty(options, 'requestNonPersonalizedAdsOnly')) {
|
|
42
|
+
if (!isBoolean(options.requestNonPersonalizedAdsOnly)) {
|
|
43
|
+
throw new Error("'options.requestNonPersonalizedAdsOnly' expected a boolean value");
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
out.requestNonPersonalizedAdsOnly = options.requestNonPersonalizedAdsOnly;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (options.networkExtras) {
|
|
50
|
+
if (!isObject(options.networkExtras)) {
|
|
51
|
+
throw new Error("'options.networkExtras' expected an object of key/value pairs");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Object.entries(options.networkExtras).forEach(([key, value]) => {
|
|
55
|
+
if (!isString(value)) {
|
|
56
|
+
throw new Error(`'options.networkExtras' expected a string value for object key "${key}"`);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
out.networkExtras = options.networkExtras;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (options.keywords) {
|
|
64
|
+
if (!isArray(options.keywords)) {
|
|
65
|
+
throw new Error("'options.keywords' expected an array containing string values");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (let i = 0; i < options.keywords.length; i++) {
|
|
69
|
+
const keyword = options.keywords[i];
|
|
70
|
+
|
|
71
|
+
if (!isString(keyword)) {
|
|
72
|
+
throw new Error("'options.keywords' expected an array containing string values");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
out.keywords = options.keywords;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (options.contentUrl) {
|
|
80
|
+
if (!isString(options.contentUrl)) {
|
|
81
|
+
throw new Error("'options.contentUrl' expected a string value");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (!isValidUrl(options.contentUrl)) {
|
|
85
|
+
throw new Error("'options.contentUrl' expected a valid HTTP or HTTPS url.");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (options.contentUrl.length > 512) {
|
|
89
|
+
throw new Error("'options.contentUrl' maximum length of a content URL is 512 characters.");
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
out.contentUrl = options.contentUrl;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (options.location) {
|
|
96
|
+
const error = new Error(
|
|
97
|
+
"'options.location' expected an array value containing a latitude & longitude number value.",
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if (!isArray(options.location)) {
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const [latitude, longitude] = options.location;
|
|
105
|
+
|
|
106
|
+
if (!isNumber(latitude) || !isNumber(longitude)) {
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (latitude < -90 || latitude > 90) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
`'options.location' latitude value must be a number between -90 and 90, but was: ${latitude}`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (longitude < -180 || longitude > 180) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
`'options.location' longitude value must be a number between -180 and 180, but was: ${latitude}`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
out.location = [latitude, longitude];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (hasOwnProperty(options, 'locationAccuracy')) {
|
|
126
|
+
if (!isNumber(options.locationAccuracy)) {
|
|
127
|
+
throw new Error("'options.locationAccuracy' expected a number value.");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (isNumber(options.locationAccuracy) && options.locationAccuracy < 0) {
|
|
131
|
+
throw new Error("'options.locationAccuracy' expected a number greater than 0.");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
out.locationAccuracy = options.locationAccuracy;
|
|
135
|
+
} else {
|
|
136
|
+
out.locationAccuracy = 5;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (options.requestAgent) {
|
|
140
|
+
if (!isString(options.requestAgent)) {
|
|
141
|
+
throw new Error("'options.requestAgent' expected a string value");
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
out.requestAgent = options.requestAgent;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (options.serverSideVerificationOptions) {
|
|
148
|
+
if (!isObject(options.serverSideVerificationOptions)) {
|
|
149
|
+
throw new Error(
|
|
150
|
+
"'options.serverSideVerificationOptions' expected an object of key/value pairs",
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const ssvOptions = options.serverSideVerificationOptions;
|
|
155
|
+
|
|
156
|
+
if (ssvOptions.userId && !isString(ssvOptions.userId)) {
|
|
157
|
+
throw new Error("'options.serverSideVerificationOptions.userId' expected a string value");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (ssvOptions.customData && !isString(ssvOptions.customData)) {
|
|
161
|
+
throw new Error("'options.serverSideVerificationOptions.customData' expected a string value");
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
out.serverSideVerificationOptions = options.serverSideVerificationOptions;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return out;
|
|
168
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { hasOwnProperty, isBoolean, isObject, isUndefined } from './common';
|
|
19
|
+
import { AdShowOptions } from './types/AdShowOptions';
|
|
20
|
+
|
|
21
|
+
export function validateAdShowOptions(options?: AdShowOptions) {
|
|
22
|
+
const out: AdShowOptions = {};
|
|
23
|
+
|
|
24
|
+
if (isUndefined(options)) {
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!isObject(options)) {
|
|
29
|
+
throw new Error("'options' expected an object value");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (hasOwnProperty(options, 'immersiveModeEnabled')) {
|
|
33
|
+
if (!isBoolean(options.immersiveModeEnabled)) {
|
|
34
|
+
throw new Error("'options.immersiveModeEnabled' expected a boolean value");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
out.immersiveModeEnabled = options.immersiveModeEnabled;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return out;
|
|
41
|
+
}
|
package/src/version.ts
ADDED