diff --git a/package.json b/package.json index 295f7b5..7c7bf5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "median-js-bridge", - "version": "2.16.0", + "version": "2.17.0", "description": "Median bridge and utilities for JS web frameworks", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index 66ffb8b..6680bd7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -182,4 +182,5 @@ export { Clerk } from './types/clerk.js'; export { HealthBridge } from './types/healthBridge.js'; export { JWPlayer } from './types/jwplayer.js'; export { MasterLock } from './types/masterlock.js'; +export { RevenueCat } from './types/revenueCat.js'; export { SalesforceCloud } from './types/salesforceCloud.js'; diff --git a/src/plugins/revenueCat.ts b/src/plugins/revenueCat.ts index 2724b0f..e3d5e0f 100644 --- a/src/plugins/revenueCat.ts +++ b/src/plugins/revenueCat.ts @@ -1,27 +1,34 @@ -import { CallbackData, CallbackParams } from '../types/index.js'; -import { addCommandCallback } from '../utils/index.js'; - -type RevenueCatConfigureParams = CallbackParams & { - apiKey: string; - appUserID: string; -}; - -type RevenueCatOfferings = CallbackData & { - identifiers?: string[]; -}; +import { RevenueCat } from '../types/revenueCat.js'; +import { addCallbackFunction, addCommandCallback } from '../utils/index.js'; const revenueCat = { - configure: function (params: RevenueCatConfigureParams) { - return addCommandCallback('gonative://revenueCat/configure', params); + configure: function (params: RevenueCat.ConfigureParams) { + return addCommandCallback('median://revenueCat/configure', params); + }, + isInitialized: function () { + return addCommandCallback('median://revenueCat/isInitialized'); + }, + getOfferings: function () { + return addCommandCallback('median://revenueCat/getOfferings'); + }, + purchase: function (params: RevenueCat.PurchaseParams) { + return addCommandCallback('median://revenueCat/purchase', params); + }, + restorePurchases: function () { + return addCommandCallback('median://revenueCat/restorePurchases'); }, - getOfferings: function (params: CallbackParams) { - return addCommandCallback('gonative://revenueCat/getOfferings', params); + presentPaywall: function (params?: RevenueCat.PresentPaywallParams) { + const parameters: Record = {}; + if (params?.onCancelPurchase) { + parameters.onCancelPurchase = addCallbackFunction(params.onCancelPurchase, true); + } + return addCommandCallback('median://revenueCat/presentPaywall', parameters); }, - purchase: function (params: CallbackParams & { identifier: string }) { - return addCommandCallback('gonative://revenueCat/purchase', params); + login: function (params: RevenueCat.LoginParams) { + return addCommandCallback('median://revenueCat/login', params); }, - restorePurchases: function (params: CallbackParams) { - return addCommandCallback('gonative://revenueCat/restorePurchases', params); + logout: function () { + return addCommandCallback('median://revenueCat/logout'); }, }; diff --git a/src/types/revenueCat.ts b/src/types/revenueCat.ts new file mode 100644 index 0000000..fa84744 --- /dev/null +++ b/src/types/revenueCat.ts @@ -0,0 +1,88 @@ +export namespace RevenueCat { + export type ConfigureParams = { + apiKey: string; + appUserID?: string; + }; + + export type ConfigureResponse = { + error?: { + code: string; + message: string; + underlyingErrorMessage?: string; + }; + success: boolean; + }; + + export type IsInitializedResponse = { + apiKey?: string; + initialized: boolean; + } + + export type GetOfferingsResponse = { + error?: { + code: string; + message: string; + underlyingErrorMessage?: string; + }; + identifiers?: string[]; + success: boolean; + }; + + export type PurchaseParams = { + identifier: string; + }; + + export type PurchaseResponse = { + error?: { + code: string; + message: string; + underlyingErrorMessage?: string; + }; + success: boolean; + }; + + export type RestorePurchasesResponse = { + error?: { + code: string; + message: string; + underlyingErrorMessage?: string; + }; + success: boolean; + }; + + export type PresentPaywallParams = { + onCancelPurchase?: () => void; + }; + + export type PresentPaywallResponse = { + error?: { + code: string; + message: string; + underlyingErrorMessage?: string; + }; + success: boolean; + }; + + export type LoginParams = { + appUserID: string; + }; + + export type LoginResponse = { + created?: boolean; + error?: { + code: string; + message: string; + underlyingErrorMessage?: string; + }; + success: boolean; + }; + + export type LogoutResponse = { + error?: { + code: string; + message: string; + underlyingErrorMessage?: string; + }; + success: boolean; + }; +}