Skip to content

Commit

Permalink
fix: type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dylancom committed Dec 4, 2024
1 parent e16bb7b commit e546cf5
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 447 deletions.
21 changes: 14 additions & 7 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ - (NSDictionary *)getConsentInformation {
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];

debugSettings.geography = (UMPDebugGeography)([options[@"debugGeography"] integerValue] ?: UMPDebugGeographyDisabled);
debugSettings.geography =
(UMPDebugGeography)([options[@"debugGeography"] integerValue] ?: UMPDebugGeographyDisabled);
debugSettings.testDeviceIdentifiers =
[options valueForKeyPath:@"testDeviceIdentifiers"] ?: [[NSMutableArray alloc] init];

Expand All @@ -118,7 +119,7 @@ - (NSDictionary *)getConsentInformation {
#endif
}

RCT_EXPORT_METHOD(showForm: (RCTPromiseResolveBlock)resolve : (RCTPromiseRejectBlock)reject) {
RCT_EXPORT_METHOD(showForm : (RCTPromiseResolveBlock)resolve : (RCTPromiseRejectBlock)reject) {
[self showForm:resolve reject:reject];
}

Expand Down Expand Up @@ -176,12 +177,15 @@ - (NSDictionary *)getConsentInformation {
#endif

#ifdef RCT_NEW_ARCH_ENABLED
- (void)requestInfoUpdate:(JS::NativeConsentModule::AdsConsentInfoOptions &)options resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
- (void)requestInfoUpdate:(JS::NativeConsentModule::AdsConsentInfoOptions &)options
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject {
#if !TARGET_OS_MACCATALYST
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];

debugSettings.geography = static_cast<UMPDebugGeography>(options.debugGeography().value_or(UMPDebugGeographyDisabled));
debugSettings.geography =
static_cast<UMPDebugGeography>(options.debugGeography().value_or(UMPDebugGeographyDisabled));
debugSettings.testDeviceIdentifiers = options.testDeviceIdentifiers().has_value()
? ^{
NSMutableArray *array = [[NSMutableArray alloc] init];
Expand Down Expand Up @@ -243,7 +247,8 @@ - (void)showForm:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)r
#endif
}

- (void)showPrivacyOptionsForm:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
- (void)showPrivacyOptionsForm:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject {
#if !TARGET_OS_MACCATALYST
[UMPConsentForm
presentPrivacyOptionsFormFromViewController:[UIApplication sharedApplication]
Expand All @@ -264,7 +269,8 @@ - (void)showPrivacyOptionsForm:(RCTPromiseResolveBlock)resolve reject:(RCTPromis
#endif
}

- (void)loadAndShowConsentFormIfRequired:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
- (void)loadAndShowConsentFormIfRequired:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject {
#if !TARGET_OS_MACCATALYST
[UMPConsentForm
loadAndPresentIfRequiredFromViewController:[UIApplication sharedApplication]
Expand Down Expand Up @@ -332,7 +338,8 @@ - (void)getPurposeConsents:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRej
}
}

- (void)getPurposeLegitimateInterests:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
- (void)getPurposeLegitimateInterests:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject {
@try {
NSString *purposeLegitimateInterests =
[[NSUserDefaults standardUserDefaults] stringForKey:@"IABTCF_PurposeLegitimateInterests"];
Expand Down
3 changes: 2 additions & 1 deletion src/AdsConsent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import { AdsConsentPurposes } from './AdsConsentPurposes';
import { AdsConsentSpecialFeatures } from './AdsConsentSpecialFeatures';
import { isPropertySet, isArray, isBoolean, isObject, isString } from './common';
import {
AdsConsentInterface,
AdsConsentDebugGeography,
AdsConsentInfoOptions,
} from './specs/modules/NativeConsentModule';
import native from './specs/modules/NativeConsentModule';

export const AdsConsent = {
export const AdsConsent: AdsConsentInterface = {
requestInfoUpdate(options: AdsConsentInfoOptions = {}) {
if (!isObject(options)) {
throw new Error("AdsConsent.requestInfoUpdate(*) 'options' expected an object value.");
Expand Down
12 changes: 9 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ import { version } from './version';
export const SDK_VERSION = version;

export { default, MobileAds } from './MobileAds';
export { AdsConsentDebugGeography } from './specs/modules/NativeConsentModule';
export {
AdsConsentDebugGeography,
AdsConsentInfo,
AdsConsentInfoOptions,
AdsConsentInterface,
AdsConsentPrivacyOptionsRequirementStatus,
AdsConsentStatus,
AdsConsentUserChoices,
} from './specs/modules/NativeConsentModule';
export { AdsConsentPurposes } from './AdsConsentPurposes';
export { AdsConsentSpecialFeatures } from './AdsConsentSpecialFeatures';
export { AdsConsentStatus } from './specs/modules/NativeConsentModule';
export { AdsConsentPrivacyOptionsRequirementStatus } from './specs/modules/NativeConsentModule';
export { MaxAdContentRating } from './MaxAdContentRating';
export { TestIds } from './TestIds';
export { AdEventType } from './AdEventType';
Expand Down
194 changes: 194 additions & 0 deletions src/specs/modules/NativeConsentModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,200 @@ export interface AdsConsentUserChoices {
usePreciseGeolocationData: boolean;
}

export interface AdsConsentInterface {
/**
* Requests user consent information.
*
* The response from this method provides information about consent form availability and consent status.
*
* #### Example
*
* ```js
* import { AdsConsent } from 'react-native-google-mobile-ads';
*
* const consentInfo = await AdsConsent.requestInfoUpdate();
* console.log('A consent form is available:', consentInfo.isConsentFormAvailable);
* console.log('User consent status:', consentInfo.status);
* ```
* @param options An AdsConsentInfoOptions interface.
*/
requestInfoUpdate(options?: AdsConsentInfoOptions): Promise<AdsConsentInfo>;

/**
* Shows a Google-rendered user consent form.
*
* #### Example
*
* ```js
* import { AdsConsent, AdsConsentStatus } from 'react-native-google-mobile-ads';
*
* async function requestConsent() {
* const consentInfo = await AdsConsent.requestInfoUpdate();
*
* // Check if user requires consent
* if (
* consentInfo.isConsentFormAvailable &&
* (consentInfo.status === AdsConsentStatus.UNKNOWN ||
* consentInfo.status === AdsConsentStatus.REQUIRED)) {
* // Show a Google-rendered form
* const formResult = await AdsConsent.showForm();
*
* console.log('User consent obtained: ', formResult.status === AdsConsentStatus.OBTAINED);
* }
* }
*
* ```
*/
showForm(): Promise<AdsConsentInfo>;

/**
* Presents a privacy options form if privacyOptionsRequirementStatus is required.
*/
showPrivacyOptionsForm(): Promise<AdsConsentInfo>;

/**
* Loads a consent form and immediately presents it if consentStatus is required.
*
* This method is intended for the use case of showing a form if needed when the app starts.
*/
loadAndShowConsentFormIfRequired(): Promise<AdsConsentInfo>;

/**
* Returns the UMP Consent Information from the last known session.
*
* #### Example
*
* ```js
* import { AdsConsent } from '@invertase/react-native-google-ads';
*
* const consentInfo = await AdsConsent.getConsentInfo();
* ```
*/
getConsentInfo(): Promise<AdsConsentInfo>;

/**
* Helper method to call the UMP SDK methods to request consent information and load/present a
* consent form if necessary.
*/
gatherConsent(): Promise<AdsConsentInfo>;

/**
* Returns the value stored under the `IABTCF_TCString` key
* in NSUserDefaults (iOS) / SharedPreferences (Android) as
* defined by the IAB Europe Transparency & Consent Framework.
*
* More information available here:
* https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md#in-app-details

Check warning on line 396 in src/specs/modules/NativeConsentModule.ts

View check run for this annotation

In Solidarity / Inclusive Language

Match Found

Please consider an alternative to `master`. Possibilities include: `primary`, `main`, `leader`, `active`, `writer`
Raw output
/master/gi
*
* #### Example
*
* ```js
* import { AdsConsent } from '@invertase/react-native-google-ads';
*
* const tcString = await AdsConsent.getTCString();
* ```
*/
getTCString(): Promise<string>;

/**
* Returns the TC Model of the saved IAB TCF 2.0 String.
*
* #### Example
*
* ```js
* import { AdsConsent } from '@invertase/react-native-google-ads';
*
* const tcModel = await AdsConsent.getTCModel();
* ```
*/
getTCModel(): Promise<TCModel>;

/**
* Returns the value stored under the `IABTCF_gdprApplies` key
* in NSUserDefaults (iOS) / SharedPreferences (Android) as
* defined by the IAB Europe Transparency & Consent Framework.
*
* More information available here:
* https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md#in-app-details

Check warning on line 427 in src/specs/modules/NativeConsentModule.ts

View check run for this annotation

In Solidarity / Inclusive Language

Match Found

Please consider an alternative to `master`. Possibilities include: `primary`, `main`, `leader`, `active`, `writer`
Raw output
/master/gi
*
* #### Example
*
* ```js
* import { AdsConsent } from '@invertase/react-native-google-ads';
*
* await AdsConsent.requestInfoUpdate();
* const gdprApplies = await AdsConsent.getGdprApplies();
* ```
*/
getGdprApplies(): Promise<boolean>;

/**
* Returns the value stored under the `IABTCF_PurposeConsents` key
* in NSUserDefaults (iOS) / SharedPreferences (Android) as
* defined by the IAB Europe Transparency & Consent Framework.
*
* More information available here:
* https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md#in-app-details

Check warning on line 446 in src/specs/modules/NativeConsentModule.ts

View check run for this annotation

In Solidarity / Inclusive Language

Match Found

Please consider an alternative to `master`. Possibilities include: `primary`, `main`, `leader`, `active`, `writer`
Raw output
/master/gi
*
* #### Example
*
* ```js
* import { AdsConsent } from '@invertase/react-native-google-ads';
*
* await AdsConsent.requestInfoUpdate();
* const purposeConsents = await AdsConsent.getPurposeConsents();
* const hasConsentForPurposeOne = purposeConsents.startsWith("1");
* ```
*/
getPurposeConsents(): Promise<string>;

/**
* Returns the value stored under the `IABTCF_PurposeLegitimateInterests` key
* in NSUserDefaults (iOS) / SharedPreferences (Android) as
* defined by the IAB Europe Transparency & Consent Framework.
*
* More information available here:
* https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/TCFv2/IAB%20Tech%20Lab%20-%20CMP%20API%20v2.md#in-app-details

Check warning on line 466 in src/specs/modules/NativeConsentModule.ts

View check run for this annotation

In Solidarity / Inclusive Language

Match Found

Please consider an alternative to `master`. Possibilities include: `primary`, `main`, `leader`, `active`, `writer`
Raw output
/master/gi
*
* #### Example
*
* ```js
* import { AdsConsent } from '@invertase/react-native-google-ads';
*
* await AdsConsent.requestInfoUpdate();
* const purposeLegitimateInterests = await AdsConsent.getPurposeLegitimateInterests();
* const hasLegitimateInterestForPurposeTwo = purposeLegitimateInterests.split("")[1] === "1";
* ```
*/
getPurposeLegitimateInterests(): Promise<string>;

/**
* Provides information about a user's consent choices.
*
* #### Example
*
* ```js
* import { AdsConsent } from '@invertase/react-native-google-ads';
*
* const { storeAndAccessInformationOnDevice } = await AdsConsent.getUserChoices();
* ```
*/
getUserChoices(): Promise<AdsConsentUserChoices>;

/**
* Resets the UMP SDK state.
*
* #### Example
*
* ```js
* import { AdsConsent } from '@invertase/react-native-google-ads';
*
* AdsConsent.reset();
* ```
*/
reset(): void;
}

export interface Spec extends TurboModule {
requestInfoUpdate(options?: AdsConsentInfoOptions): Promise<AdsConsentInfo>;
showForm(): Promise<AdsConsentInfo>;
Expand Down
Loading

0 comments on commit e546cf5

Please sign in to comment.