diff --git a/index.js.flow b/index.js.flow new file mode 100644 index 000000000..9e5be1754 --- /dev/null +++ b/index.js.flow @@ -0,0 +1,97 @@ +// @flow + +declare type Common = { + title: string, + description: string, + price: string, + currency: string, + localizedPrice: string, +} + +declare type ID = string + +export type Product = Common & { + type: "inapp" | "iap", + productId: ID, +} + +export type Subscription = Common & { + type: "subs" | "sub", + productId: ID, + + introductoryPrice?: string, + introductoryPricePaymentModeIOS?: string, + introductoryPriceNumberOfPeriods?: number, + introductoryPriceSubscriptionPeriod: {}, + + subscriptionPeriodNumberIOS?: string, + subscriptionPeriodUnitIOS?: number, + + introductoryPriceCyclesAndroid?: number, + introductoryPricePeriodAndroid?: string, + subscriptionPeriodAndroid?: string, + freeTrialPeriodAndroid: string, +} + +export type ProductPurchase = {| + productId: string, + transactionId: string, + transactionDate: string, + transactionReceipt: string, + signatureAndroid?: string, + dataAndroid?: string, + purchaseToken?: string, +|} + +export type SubscriptionPurchase = ProductPurchase & { + autoRenewingAndroid: boolean, + originalTransactionDateIOS: string, + originalTransactionIdentifierIOS: string, +} + +export type Purchase = ProductPurchase | SubscriptionPurchase + +declare module.exports: { + getProducts: (string[]) => Promise[]>, + getSubscriptions(string[]): Promise[]>, + initConnection(): Promise, + buyProduct: string => Promise, + endConnection: () => Promise, + consumeAllItems(): Promise, + getPurchaseHistory(): Promise, + getAvailablePurchases(): Promise, + buySubscription( + sku: string, + oldSku?: string, + prorationMode?: number, + ): Promise, + buyProductWithQuantityIOS( + sku: string, + quantity: number, + ): Promise, + buyProductWithoutFinishTransaction(sku: string): Promise, + clearTransaction(): void, + clearProducts(): void, + finishTransaction(): void, + consumePurchase(token: string): Promise, + validateReceiptIos( + receiptBody: AppleReceiptValidationRequest, + isTest: boolean, + ): Promise, + validateReceiptAndroid( + packageName: string, + productId: string, + productToken: string, + accessToken: string, + isSub: boolean, + ): Promise<{} | false>, + addAdditionalSuccessPurchaseListenerIOS( + fn: (any) => any, + ): EmitterSubscription, +} + +// TODO: the following definitions should be more specific + +export type AppleReceiptValidationResponse = any +export type AppleReceiptValidationRequest = any +export type EmitterSubscription = any