Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: typescript rewrite #41

Merged
merged 34 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e65103f
refactor: initial typescript refactorings
dylancom Dec 14, 2021
cd8ed69
refactor: all ads are ts files now
dylancom Dec 14, 2021
c53f99a
refactor: 137 ts errors to go
dylancom Dec 14, 2021
c54a0e6
refactor: further progress on ts integration
dylancom Dec 14, 2021
0b4a809
feat: remove ts checks on internal
dylancom Dec 14, 2021
e5f89cb
refactor: more ts conversions
dylancom Dec 14, 2021
401bf71
refactor: fix ts errors
dylancom Dec 15, 2021
56f8840
feat: integrate builder bob
dylancom Dec 15, 2021
e072223
chore: remove output files
dylancom Dec 15, 2021
33e3ff2
refactor: prepare task
dylancom Dec 15, 2021
6cfd09e
refactor: use enum for banner size constants
dylancom Dec 15, 2021
85691d0
refactor: default test ids type
dylancom Dec 15, 2021
2338c5e
feat: make use of enum
dylancom Dec 15, 2021
73ccb8b
fix: add missing exports
dylancom Dec 15, 2021
0a6525f
fix: ignore lib
dylancom Dec 15, 2021
ebedeb4
fix types
dylancom Dec 15, 2021
664ec0a
fix: jest config
dylancom Dec 15, 2021
7fe22d1
Update src/types/AdsConsent.interface.ts
dylancom Dec 17, 2021
307b9c5
Update src/types/RequestConfiguration.ts
dylancom Dec 17, 2021
e7986d2
refactor: re-use build task
dylancom Dec 17, 2021
338511f
Merge branch 'feature/ts-rewrite' of https://github.com/dylancom/reac…
dylancom Dec 17, 2021
9527a4b
refactor: use global undefined
dylancom Dec 17, 2021
d147da1
add enum InitializationState
dylancom Dec 19, 2021
cb853a2
use enum and import eventemitter type
dylancom Dec 19, 2021
cbcaf0e
no emit
dylancom Dec 19, 2021
89bdf38
remove explicit any
dylancom Dec 19, 2021
008813e
refactor: use named exports
dylancom Dec 20, 2021
5590a8e
remove unused error methods
dylancom Dec 20, 2021
4aa8bc0
bring back deleted files
dylancom Dec 20, 2021
4491bef
added types to common
dylancom Dec 20, 2021
4e6e2e1
completed ts rewrite
dylancom Dec 20, 2021
eccf803
improved interface naming
dylancom Dec 20, 2021
bc77692
use the same naming as the native class MobileAds
dylancom Dec 20, 2021
44741f2
git track uppercase change
dylancom Dec 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ module.exports = {
'no-empty-description': 'off',
'@typescript-eslint/ban-ts-comment': 'off', // keep it professional when you use them though please
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ google-services.json
GoogleService-Info.plist

# generated files
src/version.ts
RNFBVersion.m
ReactNativeFirebaseVersion.java

Expand All @@ -564,3 +565,6 @@ spelling.json
# Gatsby / Website
website/.cache
website/public

# generated files by bob
lib/
2 changes: 1 addition & 1 deletion __tests__/consent.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AdsConsent } from '../lib';
import { AdsConsent } from '../src';

describe('Google Ads AdsConsent', function () {
describe('requestInfoUpdate', function () {
Expand Down
5 changes: 2 additions & 3 deletions __tests__/googleAds.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import admob, { GoogleAdsTypes } from '../lib';
import admob, { MaxAdContentRating } from '../src';

describe('Admob', function () {
describe('setRequestConfiguration()', function () {
Expand All @@ -13,8 +13,7 @@ describe('Admob', function () {
it('throws if maxAdContentRating is invalid', function () {
expect(() =>
admob().setRequestConfiguration({
maxAdContentRating:
'Y' as GoogleAdsTypes.MaxAdContentRating[keyof GoogleAdsTypes.MaxAdContentRating],
maxAdContentRating: 'Y' as MaxAdContentRating,
}),
).toThrowError(
"setRequestConfiguration(*) 'requestConfiguration.maxAdContentRating' expected on of MaxAdContentRating.G, MaxAdContentRating.PG, MaxAdContentRating.T or MaxAdContentRating.MA",
Expand Down
2 changes: 1 addition & 1 deletion __tests__/interstitial.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InterstitialAd } from '../lib';
import { InterstitialAd } from '../src';

describe('Google Ads Interstitial', function () {
describe('createForAdRequest', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,13 @@ public ReactNativeModule(ReactApplicationContext reactContext, String moduleName
this.executorService = new TaskExecutorService(getName());
}

public static void rejectPromiseWithExceptionMap(Promise promise, Exception exception) {
promise.reject(exception, SharedUtils.getExceptionMap(exception));
}

public static void rejectPromiseWithCodeAndMessage(Promise promise, String code, String message) {
WritableMap userInfoMap = Arguments.createMap();
userInfoMap.putString("code", code);
userInfoMap.putString("message", message);
promise.reject(code, message, userInfoMap);
}

public static void rejectPromiseWithCodeAndMessage(
Promise promise, String code, String message, String nativeErrorMessage) {
WritableMap userInfoMap = Arguments.createMap();
userInfoMap.putString("code", code);
userInfoMap.putString("message", message);
userInfoMap.putString("nativeErrorMessage", nativeErrorMessage);
promise.reject(code, message, userInfoMap);
}

@Override
public void initialize() {
super.initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ public static Uri getUri(String uri) {
return parsed;
}

public static WritableMap getExceptionMap(Exception exception) {
WritableMap exceptionMap = Arguments.createMap();
String code = "unknown";
String message = exception.getMessage();
exceptionMap.putString("code", code);
exceptionMap.putString("nativeErrorCode", code);
exceptionMap.putString("message", message);
exceptionMap.putString("nativeErrorMessage", message);
return exceptionMap;
}

public static String timestampToUTC(long timestamp) {
long millisTimestamp = timestamp * 1000;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Expand Down
8 changes: 4 additions & 4 deletions docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ receive content suitable for children before loading any adverts.
If you need to set a custom request configuration, you must call the `setRequestConfiguration` method before initializing the Google Mobile Ads SDK:

```js
import admob, { MaxAdContentRating } from '@invertase/react-native-google-ads';
import mobileAds, { MaxAdContentRating } from '@invertase/react-native-google-ads';

admob()
mobileAds()
.setRequestConfiguration({
// Update all future requests suitable for parental guidance
maxAdContentRating: MaxAdContentRating.PG,
Expand Down Expand Up @@ -111,9 +111,9 @@ This needs to be done only once, ideally at app launch.
If you need to obtain consent from users in the European Economic Area (EEA), set any request-specific flags (such as tagForChildDirectedTreatment), or otherwise take action before loading ads, ensure you do so before initializing the Mobile Ads SDK.

```js
import admob from '@invertase/react-native-google-ads';
import mobileAds from '@invertase/react-native-google-ads';

admob()
mobileAds()
.initialize()
.then((adapterStatuses) => {
// Initialization complete!
Expand Down
5 changes: 0 additions & 5 deletions ios/RNGoogleAds/common/RNSharedUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@

+ (void)sendJSEvent:name:(NSString *)name body:(NSDictionary *)body;

+ (void)rejectPromiseWithExceptionDict:(RCTPromiseRejectBlock)reject
exception:(NSException *)exception;

+ (void)rejectPromiseWithNSError:(RCTPromiseRejectBlock)reject error:(NSError *)error;

+ (void)rejectPromiseWithUserInfo:(RCTPromiseRejectBlock)reject
userInfo:(NSMutableDictionary *)userInfo;

Expand Down
30 changes: 0 additions & 30 deletions ios/RNGoogleAds/common/RNSharedUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,6 @@ @implementation RNSharedUtils
#pragma mark -
#pragma mark Methods

+ (void)rejectPromiseWithExceptionDict:(RCTPromiseRejectBlock)reject
exception:(NSException *)exception {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];

[userInfo setValue:@(YES) forKey:@"fatal"];
[userInfo setValue:@"unknown" forKey:@"code"];
[userInfo setValue:exception.reason forKey:@"message"];
[userInfo setValue:exception.name forKey:@"nativeErrorCode"];
[userInfo setValue:exception.reason forKey:@"nativeErrorMessage"];

NSError *error = [NSError errorWithDomain:RNErrorDomain code:666 userInfo:userInfo];

reject(exception.name, exception.reason, error);
}

+ (void)rejectPromiseWithNSError:(RCTPromiseRejectBlock)reject error:(NSError *)error {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];

[userInfo setValue:@(NO) forKey:@"fatal"];
[userInfo setValue:@"unknown" forKey:@"code"];
[userInfo setValue:error.localizedDescription forKey:@"message"];
[userInfo setValue:@(error.code) forKey:@"nativeErrorCode"];
[userInfo setValue:error.localizedDescription forKey:@"nativeErrorMessage"];

NSError *newErrorWithUserInfo = [NSError errorWithDomain:RNErrorDomain
code:666
userInfo:userInfo];
reject(@"unknown", error.localizedDescription, newErrorWithUserInfo);
}

+ (void)rejectPromiseWithUserInfo:(RCTPromiseRejectBlock)reject
userInfo:(NSMutableDictionary *)userInfo {
NSError *error = [NSError errorWithDomain:RNErrorDomain code:666 userInfo:userInfo];
Expand Down
11 changes: 2 additions & 9 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
module.exports = {
maxConcurrency: 10,
preset: './node_modules/react-native/jest-preset.js',
transform: {
'^.+\\.(js)$': '<rootDir>/node_modules/babel-jest',
'\\.(ts|tsx)$': 'ts-jest',
},
preset: 'react-native',
modulePathIgnorePatterns: ['<rootDir>/example/node_modules', '<rootDir>/lib/'],
setupFiles: ['./jest.setup.ts'],
testRegex: '(/^__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
modulePaths: ['node_modules'],
moduleDirectories: ['node_modules'],
moduleFileExtensions: ['ts', 'tsx', 'js'],
};
24 changes: 0 additions & 24 deletions lib/AdEventType.js

This file was deleted.

23 changes: 0 additions & 23 deletions lib/MaxAdContentRating.js

This file was deleted.

21 changes: 0 additions & 21 deletions lib/RewardedAdEventType.js

This file was deleted.

77 changes: 0 additions & 77 deletions lib/ads/InterstitialAd.js

This file was deleted.

Loading