Skip to content

Commit 165b0b9

Browse files
Added TypeScript support (#148)
* Added TypeScript support * Fixed linting issue * Fixed eslint config issues * Added yarn.lock file changes * Removed properties from CheckoutParams.ts * Fixed AmountMoney and build issue * Updated podfile
1 parent c0fd893 commit 165b0b9

16 files changed

+2022
-1701
lines changed

.eslintrc.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
module.exports = {
2-
parser: 'babel-eslint',
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
project: './tsconfig.json',
5+
createDefaultProgram: true,
6+
},
37
root: true,
48
extends: [
5-
'airbnb',
9+
'airbnb-typescript',
610
'plugin:react-native/all',
711
],
812
settings: {
913
'import/resolver': {
1014
node: {
11-
extensions: ['.js', '.jsx'],
15+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
1216
},
1317
},
1418
},

babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ['module:metro-react-native-babel-preset'],
3+
};

index.js

+26-20
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,22 @@ const {
2424
RNReaderSDKStoreCustomerCard,
2525
} = NativeModules;
2626

27+
function createReaderSDKError(ex) {
28+
try {
29+
const errorDetails = JSON.parse(ex.message);
30+
ex.message = errorDetails.message; // eslint-disable-line no-param-reassign
31+
ex.debugCode = errorDetails.debugCode; // eslint-disable-line no-param-reassign
32+
ex.debugMessage = errorDetails.debugMessage; // eslint-disable-line no-param-reassign
33+
} catch (parseEx) {
34+
ex.parseEx = parseEx; // eslint-disable-line no-param-reassign
35+
}
36+
return ex;
37+
}
38+
2739
export async function authorizeAsync(authCode) {
2840
try {
29-
return await RNReaderSDKAuthorization.authorize(authCode);
41+
const value = await RNReaderSDKAuthorization.authorize(authCode);
42+
return value;
3043
} catch (ex) {
3144
throw createReaderSDKError(ex);
3245
}
@@ -42,31 +55,35 @@ export async function deauthorizeAsync() {
4255

4356
export async function isAuthorizedAsync() {
4457
try {
45-
return await RNReaderSDKAuthorization.isAuthorized();
58+
const value = await RNReaderSDKAuthorization.isAuthorized();
59+
return value;
4660
} catch (ex) {
4761
throw createReaderSDKError(ex);
4862
}
4963
}
5064

5165
export async function isAuthorizationInProgressAsync() {
5266
try {
53-
return await RNReaderSDKAuthorization.isAuthorizationInProgress();
67+
const value = await RNReaderSDKAuthorization.isAuthorizationInProgress();
68+
return value;
5469
} catch (ex) {
5570
throw createReaderSDKError(ex);
5671
}
5772
}
5873

5974
export async function canDeauthorizeAsync() {
6075
try {
61-
return await RNReaderSDKAuthorization.canDeauthorize();
76+
const value = await RNReaderSDKAuthorization.canDeauthorize();
77+
return value;
6278
} catch (ex) {
6379
throw createReaderSDKError(ex);
6480
}
6581
}
6682

6783
export async function getAuthorizedLocationAsync() {
6884
try {
69-
return await RNReaderSDKAuthorization.authorizedLocation();
85+
const value = await RNReaderSDKAuthorization.authorizedLocation();
86+
return value;
7087
} catch (ex) {
7188
throw createReaderSDKError(ex);
7289
}
@@ -75,7 +92,8 @@ export async function getAuthorizedLocationAsync() {
7592
export async function startCheckoutAsync(checkoutParams) {
7693
try {
7794
ValidateCheckoutParameters(checkoutParams);
78-
return await RNReaderSDKCheckout.startCheckout(checkoutParams);
95+
const value = await RNReaderSDKCheckout.startCheckout(checkoutParams);
96+
return value;
7997
} catch (ex) {
8098
throw createReaderSDKError(ex);
8199
}
@@ -91,7 +109,8 @@ export async function startReaderSettingsAsync() {
91109

92110
export async function startStoreCardAsync(customerId) {
93111
try {
94-
return await RNReaderSDKStoreCustomerCard.startStoreCard(customerId);
112+
const value = await RNReaderSDKStoreCustomerCard.startStoreCard(customerId);
113+
return value;
95114
} catch (ex) {
96115
throw createReaderSDKError(ex);
97116
}
@@ -114,16 +133,3 @@ export const StoreCustomerCardCancelled = 'STORE_CUSTOMER_CARD_CANCELED';
114133
export const StoreCustomerCardInvalidCustomerId = 'STORE_CUSTOMER_CARD_INVALID_CUSTOMER_ID';
115134
export const StoreCustomerCardSdkNotAuthorized = 'STORE_CUSTOMER_CARD_SDK_NOT_AUTHORIZED';
116135
export const StoreCustomerCardNoNetwork = 'STORE_CUSTOMER_CARD_NO_NETWORK';
117-
118-
function createReaderSDKError(ex) {
119-
try {
120-
const errorDetails = JSON.parse(ex.message);
121-
ex.message = errorDetails.message; // eslint-disable-line no-param-reassign
122-
ex.debugCode = errorDetails.debugCode; // eslint-disable-line no-param-reassign
123-
ex.debugMessage = errorDetails.debugMessage; // eslint-disable-line no-param-reassign
124-
} catch (parseEx) {
125-
ex.parseEx = parseEx; // eslint-disable-line no-param-reassign
126-
}
127-
128-
return ex;
129-
}

jest.config.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
preset: 'react-native',
3+
moduleFileExtensions: [
4+
'ts',
5+
'tsx',
6+
'js',
7+
],
8+
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$',
9+
testPathIgnorePatterns: [
10+
'\\.snap$',
11+
'<rootDir>/node_modules/',
12+
],
13+
};

package.json

+9-4
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,22 @@
2424
"react-native": ">= 0.55.4"
2525
},
2626
"devDependencies": {
27+
"@types/jest": "^26.0.24",
28+
"@types/react": "^17.0.15",
29+
"@types/react-native": "^0.64.12",
30+
"@types/react-test-renderer": "^17.0.1",
31+
"@typescript-eslint/eslint-plugin": "^4.29.0",
2732
"babel-eslint": "^10.1.0",
2833
"eslint": "7.28.0",
29-
"eslint-config-airbnb": "^18.2.1",
30-
"eslint-config-airbnb-base": "^14.2.1",
34+
"eslint-config-airbnb-typescript": "^12.3.1",
3135
"eslint-plugin-import": "^2.23.4",
3236
"eslint-plugin-jsx-a11y": "^6.4.1",
3337
"eslint-plugin-react": "^7.24.0",
3438
"eslint-plugin-react-native": "^3.11.0",
35-
"jest": "^24.9.0",
39+
"jest": "^27.0.6",
3640
"react": "17.0.1",
37-
"react-native": "0.64.1"
41+
"react-native": "0.64.1",
42+
"typescript": "^4.3.5"
3843
},
3944
"jest": {
4045
"preset": "react-native",

reader-sdk-react-native-quickstart/android/app/build.gradle

+9-1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ android {
146146
sourceCompatibility JavaVersion.VERSION_1_8
147147
targetCompatibility JavaVersion.VERSION_1_8
148148
}
149+
150+
packagingOptions {
151+
pickFirst 'lib/x86/libc++_shared.so'
152+
pickFirst 'lib/x86_64/libc++_shared.so'
153+
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
154+
pickFirst 'lib/arm64-v8a/libc++_shared.so'
155+
exclude("META-INF/*.kotlin_module")
156+
}
149157

150158
packagingOptions {
151159
exclude("META-INF/*.kotlin_module")
@@ -236,7 +244,7 @@ dependencies {
236244
// Run this once to be able to run the application with BUCK
237245
// puts all compile dependencies into folder libs for BUCK to use
238246
task copyDownloadableDepsToLibs(type: Copy) {
239-
from configurations.compile
247+
from configurations.implementation
240248
into 'libs'
241249
}
242250

reader-sdk-react-native-quickstart/ios/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ SPEC CHECKSUMS:
397397
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
398398
DoubleConversion: cf9b38bf0b2d048436d9a82ad2abe1404f11e7de
399399
FBLazyVector: 7b423f9e248eae65987838148c36eec1dbfe0b53
400-
FBReactNativeSpec: dc38ec0eb7ab2a01124f65615b175cba46b7de05
400+
FBReactNativeSpec: a75f2cfadcc67ae9876c66d6a2e9f622a2605d41
401401
glog: 73c2498ac6884b13ede40eda8228cb1eee9d9d62
402402
RCT-Folly: ec7a233ccc97cc556cf7237f0db1ff65b986f27c
403403
RCTRequired: ec2ebc96b7bfba3ca5c32740f5a0c6a014a274d2
@@ -432,4 +432,4 @@ SPEC CHECKSUMS:
432432

433433
PODFILE CHECKSUM: 84f780e3429c23272b4f6fcdc30d891d936a5723
434434

435-
COCOAPODS: 1.10.1
435+
COCOAPODS: 1.11.2

src/__tests__/utils.test.js

-143
This file was deleted.

0 commit comments

Comments
 (0)