Skip to content

Commit c03c688

Browse files
committed
Add ESLint configuration and fix TypeScript definition issues
1 parent b7ad8f5 commit c03c688

File tree

8 files changed

+112
-29
lines changed

8 files changed

+112
-29
lines changed

.eslintrc.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* ESLint configuration for react-native-appsflyer plugin
3+
* Optimized for TypeScript + React Native library development
4+
*/
5+
6+
module.exports = {
7+
root: true,
8+
parser: '@typescript-eslint/parser',
9+
parserOptions: {
10+
ecmaVersion: 2020,
11+
sourceType: 'module',
12+
ecmaFeatures: { jsx: true },
13+
},
14+
15+
env: {
16+
node: true,
17+
es6: true,
18+
},
19+
20+
plugins: [
21+
'@typescript-eslint',
22+
],
23+
24+
extends: [
25+
'eslint:recommended',
26+
'plugin:@typescript-eslint/recommended',
27+
],
28+
29+
rules: {
30+
// JS/TS hygiene
31+
'no-console': 'off',
32+
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
33+
'@typescript-eslint/no-explicit-any': 'off',
34+
'@typescript-eslint/no-var-requires': 'off', // Allow require() in CommonJS files
35+
36+
// Import/export rules - disabled because TypeScript handles this
37+
// and our index.d.ts properly declares all exports for ESLint compatibility
38+
'import/default': 'off',
39+
'import/named': 'off',
40+
'import/no-unresolved': 'off',
41+
},
42+
overrides: [
43+
{
44+
files: ['expo/**/*.js'],
45+
rules: {
46+
'@typescript-eslint/no-var-requires': 'off', // Expo config plugins use require()
47+
},
48+
},
49+
{
50+
files: ['**/*.ts', '**/*.tsx'],
51+
rules: {
52+
// TypeScript-specific rules
53+
'no-undef': 'off', // TypeScript handles this
54+
},
55+
},
56+
],
57+
58+
ignorePatterns: [
59+
'node_modules/**',
60+
'demos/**',
61+
'android/**',
62+
'ios/**',
63+
'build/**',
64+
'dist/**',
65+
'__tests__/**',
66+
'*.config.js',
67+
'babel.config.js',
68+
'metro.config.js',
69+
'jest.config.js',
70+
'react-native.config.js',
71+
],
72+
};

PurchaseConnector/models/canceled_state_context.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class CanceledStateContext {
5252
class DeveloperInitiatedCancellation {
5353
constructor() {}
5454

55-
static fromJson(json: any): DeveloperInitiatedCancellation {
55+
static fromJson(_json: any): DeveloperInitiatedCancellation {
5656
// Here you would implement the conversion from JSON to DeveloperInitiatedCancellation instance
5757
return new DeveloperInitiatedCancellation();
5858
}
@@ -66,7 +66,7 @@ class DeveloperInitiatedCancellation {
6666
class ReplacementCancellation {
6767
constructor() {}
6868

69-
static fromJson(json: any): ReplacementCancellation {
69+
static fromJson(_json: any): ReplacementCancellation {
7070
// Here you would implement the conversion from JSON to ReplacementCancellation instance
7171
return new ReplacementCancellation();
7272
}
@@ -79,7 +79,7 @@ class ReplacementCancellation {
7979
class SystemInitiatedCancellation {
8080
constructor() {}
8181

82-
static fromJson(json: any): SystemInitiatedCancellation {
82+
static fromJson(_json: any): SystemInitiatedCancellation {
8383
// Here you would implement the conversion from JSON to SystemInitiatedCancellation instance
8484
return new SystemInitiatedCancellation();
8585
}

PurchaseConnector/models/test_purchase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ interface TestPurchaseJson {}
33
export class TestPurchase {
44
constructor() {}
55

6-
static fromJson(json: TestPurchaseJson): TestPurchase {
6+
static fromJson(_json: TestPurchaseJson): TestPurchase {
77
return new TestPurchase();
88
}
99

PurchaseConnector/utils/connector_callbacks.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { IosError, JVMThrowable } from "../models";
1+
import { IosError } from "../models/ios_errors";
2+
import { JVMThrowable } from "../models/jvm_throwable";
23

34
// Type definition for a general-purpose listener.
45
export type PurchaseConnectorListener = (data: any) => void;

expo/withAppsFlyerAndroid.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ function withCustomAndroidManifest(config) {
5151
module.exports = function withAppsFlyerAndroid(config, { shouldUsePurchaseConnector = false } = {}) {
5252
if (shouldUsePurchaseConnector) {
5353
config = addPurchaseConnectorFlag(config);
54-
} else {
55-
console.log('[AppsFlyerPlugin] Purchase Connector disabled, skipping gradle property injection');
56-
}
57-
54+
}
5855
// Always apply Android manifest modifications for secure data handling
5956
config = withCustomAndroidManifest(config);
6057

index.d.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
/**
22
* Typescript Definition Sync with v5.1.1
33
**/
4-
import { InAppPurchaseValidationResult } from "../models/in_app_purchase_validation_result";
5-
import SubscriptionValidationResult from "../models/subscription_validation_result";
4+
import InAppPurchaseValidationResult from "./PurchaseConnector/models/in_app_purchase_validation_result";
5+
import SubscriptionValidationResult from "./PurchaseConnector/models/subscription_validation_result";
66
import {
77
OnResponse,
88
OnFailure,
99
OnReceivePurchaseRevenueValidationInfo,
10-
} from "../utils/connector_callbacks";
10+
} from "./PurchaseConnector/utils/connector_callbacks";
1111

1212
declare module "react-native-appsflyer" {
1313
type Response<T> = void | Promise<T>;
@@ -151,21 +151,17 @@ declare module "react-native-appsflyer" {
151151
hasConsentForDataUsage?: boolean,
152152
hasConsentForAdsPersonalization?: boolean,
153153
hasConsentForAdStorage?: boolean
154-
) {}
154+
);
155155

156156
/**
157157
* @deprecated since version 6.16.2. Use the AppsFlyerConsent constructor instead for more flexibility with optional booleans.
158158
*/
159-
static forGDPRUser(hasConsentForDataUsage: boolean, hasConsentForAdsPersonalization: boolean): AppsFlyerConsent {
160-
return new AppsFlyerConsent(true, hasConsentForDataUsage, hasConsentForAdsPersonalization);
161-
}
159+
static forGDPRUser(hasConsentForDataUsage: boolean, hasConsentForAdsPersonalization: boolean): AppsFlyerConsent;
162160

163161
/**
164162
* @deprecated since version 6.16.2. Use the AppsFlyerConsent constructor instead for more flexibility with optional booleans.
165163
*/
166-
static forNonGDPRUser(): AppsFlyerConsent {
167-
return new AppsFlyerConsent(false);
168-
}
164+
static forNonGDPRUser(): AppsFlyerConsent;
169165
}
170166

171167
/**
@@ -201,15 +197,15 @@ declare module "react-native-appsflyer" {
201197
mediationNetwork: MEDIATION_NETWORK;
202198
currencyIso4217Code: string;
203199
revenue: number;
204-
additionalParameters?: StringMap;
200+
additionalParameters?: { [key: string]: any };
205201
}
206202

207203
/**
208204
* PurchaseConnector
209205
*/
210-
export const StoreKitVersion = {
211-
SK1: "SK1",
212-
SK2: "SK2",
206+
export const StoreKitVersion: {
207+
readonly SK1: "SK1";
208+
readonly SK2: "SK2";
213209
};
214210

215211
export interface PurchaseConnectorConfig {
@@ -264,13 +260,13 @@ declare module "react-native-appsflyer" {
264260
callback: (data:OnResponse<SubscriptionValidationResult>) => any
265261
): () => void;
266262
onSubscriptionValidationResultFailure(
267-
callback: (data:onFailure) => any
263+
callback: (data:OnFailure) => any
268264
): () => void;
269265
onInAppValidationResultSuccess(
270266
callback: (data:OnResponse<InAppPurchaseValidationResult>) => any
271267
): () => void;
272268
onInAppValidationResultFailure(
273-
callback: (data:onFailure) => any
269+
callback: (data:OnFailure) => any
274270
): () => void;
275271

276272
setSubscriptionPurchaseEventDataSource: (dataSource: SubscriptionPurchaseEventDataSource) => void;
@@ -397,7 +393,7 @@ declare module "react-native-appsflyer" {
397393
): void;
398394
startSdk(): void;
399395
enableTCFDataCollection(enabled: boolean): void;
400-
setConsentData(consentData: AppsFlyerConsentType): void;
396+
setConsentData(consentData: AppsFlyerConsent): void;
401397
logAdRevenue(adRevenueData: AFAdRevenueData): void;
402398
/**
403399
* For iOS Only
@@ -420,3 +416,14 @@ declare module "react-native-appsflyer" {
420416

421417
export default appsFlyer;
422418
}
419+
420+
// Explicit ambient declarations for ESLint compatibility
421+
// ESLint's import resolver doesn't recognize exports inside 'declare module' blocks.
422+
// These top-level declarations allow ESLint to detect the exports.
423+
declare const StoreKitVersion: { readonly SK1: "SK1"; readonly SK2: "SK2" };
424+
declare const AppsFlyerPurchaseConnector: any; // Type is defined in declare module above
425+
declare const AppsFlyerPurchaseConnectorConfig: any; // Type is defined in declare module above
426+
declare const appsFlyer: any; // Type is defined in declare module above
427+
428+
export { StoreKitVersion, AppsFlyerPurchaseConnector, AppsFlyerPurchaseConnectorConfig };
429+
export { appsFlyer as default };

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import AppsFlyerConstants from "./PurchaseConnector/constants/constants";
33
import InAppPurchaseValidationResult from "./PurchaseConnector/models/in_app_purchase_validation_result";
44
import ValidationFailureData from "./PurchaseConnector/models/validation_failure_data";
55
import SubscriptionValidationResult from "./PurchaseConnector/models/subscription_validation_result";
6+
import { MissingConfigurationException } from "./PurchaseConnector/models/missing_configuration_exception";
67

78
const { RNAppsFlyer } = NativeModules;
89
const appsFlyer = {};
@@ -186,7 +187,7 @@ AppsFlyerPurchaseConnector.setInAppPurchaseEventDataSource = (dataSource) => {
186187
// Purchase Connector iOS methods
187188
function logConsumableTransaction(transactionId){
188189
PCAppsFlyer.logConsumableTransaction(transactionId);
189-
};
190+
}
190191

191192
AppsFlyerPurchaseConnector.logConsumableTransaction = logConsumableTransaction;
192193

@@ -233,7 +234,7 @@ AppsFlyerPurchaseConnector.setPurchaseRevenueDataSource = (dataSource) => {
233234

234235
AppsFlyerPurchaseConnector.setPurchaseRevenueDataSourceStoreKit2 = (dataSource) => {
235236
if (!dataSource || typeof dataSource !== 'object') {
236-
throw new Error('dataSource must be an object');
237+
throw new Error('dataSource must be an object');
237238
}
238239
PCAppsFlyer.setPurchaseRevenueDataSourceStoreKit2(dataSource);
239240
};
@@ -847,7 +848,7 @@ appsFlyer.setSharingFilterForAllPartners = () => {
847848
* @param errorC Error callback
848849
*/
849850

850-
appsFlyer.setSharingFilter = (partners, successC, errorC) => {
851+
appsFlyer.setSharingFilter = (partners, _successC, _errorC) => {
851852
return appsFlyer.setSharingFilterForPartners(partners);
852853
};
853854

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"types": "index.d.ts",
77
"scripts": {
88
"test": "jest --coverage",
9+
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
10+
"lint:fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
911
"demo.ios": "npm run ios-pod; cd SampleApps/AppsFlyerExample; npm run ios",
1012
"demo.android": "cd SampleApps/AppsFlyerExample; npm run android",
1113
"ios-pod": "cd SampleApps/AppsFlyerExample/ios; pod install; cd ../"
@@ -32,7 +34,10 @@
3234
"devDependencies": {
3335
"@babel/preset-env": "^7.26.9",
3436
"@types/jest": "^29.5.14",
37+
"@typescript-eslint/eslint-plugin": "^6.21.0",
38+
"@typescript-eslint/parser": "^6.21.0",
3539
"babel-jest": "^29.7.0",
40+
"eslint": "^8.57.1",
3641
"jest": "^29.7.0",
3742
"react": "16.11.0",
3843
"react-native": "0.62.3",

0 commit comments

Comments
 (0)