diff --git a/types/react-native-appsflyer/index.d.ts b/types/react-native-appsflyer/index.d.ts new file mode 100644 index 0000000000..b57b173607 --- /dev/null +++ b/types/react-native-appsflyer/index.d.ts @@ -0,0 +1,96 @@ +// Type definitions for react-native-appsflyer 5.1 +// Project: https://github.com/AppsFlyerSDK/react-native-appsflyer#readme +// Definitions by: Fabian Lee +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +export interface InitSdkOptions { + devKey: string; + isDebug: boolean; + appId: string; +} + +export interface ConversionData { + status: 'success' | 'failure'; + type: string; + data: { + is_first_launch: boolean; + af_status: 'Organic' | 'Non-organic'; + af_referrer_uid?: string; + af_referrer_customer_id?: string; + media_source: string; + [key: string]: any; + }; +} + +export enum EmailCryptType { + EmailCryptTypeNone = 0, + EmailCryptTypeSHA1 = 1, + EmailCryptTypeMD5 = 2, + EmailCryptTypeSHA256 = 3, +} + +export interface EmailOptions { + emailsCryptType: EmailCryptType; + emails: string[]; +} + +export interface InviteLinkOptions { + channel?: string; + customerID?: string; + campaign?: string; + referrerName?: string; + referrerImageUrl?: string; + deeplinkPath?: string; + baseDeeplink?: string; + userParams?: { + [key: string]: any; + }; +} + +type SuccessCallback = (success: any) => void; + +type ErrorCallback = (error: any) => void; + +interface AdditionalData { + [key: string]: any; +} + +interface EventValues { + [key: string]: any; +} + +declare namespace appsFlyer { + function initSdk(options: InitSdkOptions, success?: SuccessCallback, error?: ErrorCallback): void | Promise; + function trackAppLaunch(): void; + function onInstallConversionData(callback: (data: ConversionData) => void): () => void; + function onAppOpenAttribution(callback: (response: any) => void): () => void; + function sendDeepLinkData(url: string): void; + function stopTracking(isStopTracking: boolean, callback?: SuccessCallback): void; + function generateInviteLink(options: InviteLinkOptions, success?: SuccessCallback, error?: ErrorCallback): void; + function updateServerUninstallToken(token: string, callback?: SuccessCallback): void; + function trackLocation( + longitude: number, + latitude: number, + callback?: (error: any, coordinates: number[]) => void, + ): void; + function trackCrossPromotionImpression(appId: string, campaign: string): void; + function trackAndOpenStore(appId: string, campaign: string, additionalData?: AdditionalData): void; + function trackEvent( + eventName: string, + eventValues: EventValues, + success?: SuccessCallback, + error?: ErrorCallback, + ): void | Promise; + function getAppsFlyerUID(callback: (error: any, appsFlyerUID: string) => void): void; + function setUserEmails(options: EmailOptions, success?: SuccessCallback, error?: ErrorCallback): void; + function setAdditionalData(additionalData: AdditionalData, success?: SuccessCallback): void; + function setCustomerUserId(userId: string, callback?: SuccessCallback): void; + function setCollectIMEI(isCollect: boolean, callback?: SuccessCallback): void; + function setCollectAndroidID(isCollect: boolean, callback?: SuccessCallback): void; + function setAppInviteOneLinkID(oneLinkId: string, callback?: SuccessCallback): void; + function setCurrencyCode(currencyCode: string, callback?: SuccessCallback): void; + function setDeviceTrackingDisabled(isDeviceTrackingDisabled: boolean, success?: SuccessCallback): void; +} + +export default appsFlyer; diff --git a/types/react-native-appsflyer/react-native-appsflyer-tests.ts b/types/react-native-appsflyer/react-native-appsflyer-tests.ts new file mode 100644 index 0000000000..561297cad7 --- /dev/null +++ b/types/react-native-appsflyer/react-native-appsflyer-tests.ts @@ -0,0 +1,64 @@ +import appsFlyer, { EmailCryptType } from 'react-native-appsflyer'; + +// $ExpectType void | Promise +appsFlyer.initSdk({ devKey: '1A2b3C', appId: 'app_id', isDebug: true }); + +// $ExpectType void +appsFlyer.getAppsFlyerUID((error, appsFlyerId) => {}); + +// $ExpectType () => void +appsFlyer.onAppOpenAttribution(res => {}); + +// $ExpectType () => void +appsFlyer.onInstallConversionData(res => {}); + +// $ExpectType void +appsFlyer.sendDeepLinkData('https://reactjs.org'); + +// $ExpectType void +appsFlyer.setAdditionalData({}); + +// $ExpectType void +appsFlyer.setAppInviteOneLinkID('ABCD'); + +// $ExpectType void +appsFlyer.setCollectAndroidID(true); + +// $ExpectType void +appsFlyer.setCollectIMEI(true); + +// $ExpectType void +appsFlyer.setCurrencyCode('USD'); + +// $ExpectType void +appsFlyer.setCustomerUserId('my_user_id'); + +// $ExpectType void +appsFlyer.setUserEmails({ emails: [], emailsCryptType: EmailCryptType.EmailCryptTypeNone }); + +// $ExpectType void +appsFlyer.stopTracking(true); + +// $ExpectType void +appsFlyer.trackAndOpenStore('app_id', 'testing'); + +// $ExpectType void +appsFlyer.trackAppLaunch(); + +// $ExpectType void +appsFlyer.trackCrossPromotionImpression('app_id', 'testing'); + +// $ExpectType void | Promise +appsFlyer.trackEvent('af_testing', {}); + +// $ExpectType void +appsFlyer.trackLocation(100.1, 120.3); + +// $ExpectType void +appsFlyer.updateServerUninstallToken('token'); + +// $ExpectType void +appsFlyer.generateInviteLink({}); + +// $ExpectType void +appsFlyer.setDeviceTrackingDisabled(true); diff --git a/types/react-native-appsflyer/tsconfig.json b/types/react-native-appsflyer/tsconfig.json new file mode 100644 index 0000000000..1d44f3c5e8 --- /dev/null +++ b/types/react-native-appsflyer/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "react-native-appsflyer-tests.ts" + ] +} diff --git a/types/react-native-appsflyer/tslint.json b/types/react-native-appsflyer/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/react-native-appsflyer/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }