@revenuecat/purchases-ui-js
Version:
Web components for Paywalls. Powered by RevenueCat
97 lines (96 loc) • 4.65 kB
TypeScript
import type { UIConfig } from "./ui-config";
export declare enum PackageIdentifier {
weekly = "$rc_weekly",
monthly = "$rc_monthly",
two_month = "$rc_two_month",
three_month = "$rc_three_month",
six_month = "$rc_six_month",
annual = "$rc_annual",
lifetime = "$rc_lifetime"
}
/**
* A value type for custom paywall variables that can be passed to paywalls at runtime.
*
* Custom variables allow developers to personalize paywall text with dynamic values.
* Variables are defined in the RevenueCat dashboard and can be overridden at runtime.
*
* @example
* ```typescript
* presentPaywall({
* customVariables: {
* 'player_name': CustomVariableValue.string('John'),
* 'level': CustomVariableValue.number(42),
* 'is_premium': CustomVariableValue.boolean(true),
* },
* });
* ```
*
* In the paywall text (configured in the dashboard), use the `custom.` prefix:
* ```
* Hello {{ custom.player_name }}!
* ```
*/
export type CustomVariableValue = {
readonly type: "string";
readonly value: string;
} | {
readonly type: "number";
readonly value: number;
} | {
readonly type: "boolean";
readonly value: boolean;
};
/**
* Factory methods for creating CustomVariableValue instances.
*/
export declare const CustomVariableValue: {
/**
* Creates a string custom variable value.
* @param value The string value for the custom variable.
* @returns A CustomVariableValue containing the string.
*/
readonly string: (value: string) => CustomVariableValue;
/**
* Creates a number custom variable value.
* @param value The number value for the custom variable.
* @returns A CustomVariableValue containing the number.
*/
readonly number: (value: number) => CustomVariableValue;
/**
* Creates a boolean custom variable value.
* @param value The boolean value for the custom variable.
* @returns A CustomVariableValue containing the boolean.
*/
readonly boolean: (value: boolean) => CustomVariableValue;
};
/**
* A map of custom variable names to their values.
*/
export type CustomVariables = {
[key: CustomVariableName]: CustomVariableValue;
};
type CustomVariableName = string & {};
/**
* Variables that carry values entered by the end user in input components on
* earlier funnel screens. The funnel runtime captures each input's value and
* injects it into the paywall's variables (via `globalVariables`) keyed by the
* input component's `field_id`. Reference them in paywall text as:
* ```
* Welcome back, {{ input.first_name }}!
* ```
* No prefix stripping is applied — the dictionary is keyed by the full
* `input.<field_id>` token, so substitution works the same as built-in
* variables.
*/
export type InputVariableName = `input.${string}`;
export declare function mergeCustomVariables(customVariables: CustomVariables, uiConfig: UIConfig | undefined): VariableDictionary;
type BuiltinVariableName = "product.price" | "product.price_per_period" | "product.price_per_period_abbreviated" | "product.price_per_day" | "product.price_per_week" | "product.price_per_month" | "product.price_per_year" | "product.period" | "product.period_abbreviated" | "product.periodly" | "product.period_in_days" | "product.period_in_weeks" | "product.period_in_months" | "product.period_in_years" | "product.period_with_unit" | "product.currency_code" | "product.currency_symbol" | "product.offer_price" | "product.offer_price_per_day" | "product.offer_price_per_week" | "product.offer_price_per_month" | "product.offer_price_per_year" | "product.offer_period" | "product.offer_period_abbreviated" | "product.offer_period_in_days" | "product.offer_period_in_weeks" | "product.offer_period_in_months" | "product.offer_period_in_years" | "product.offer_period_with_unit" | "product.offer_end_date" | "product.secondary_offer_price" | "product.secondary_offer_period" | "product.secondary_offer_period_abbreviated" | "product.relative_discount" | "product.store_product_name" | "success.redemption_url" | "success.package_identifier" | "success.product_identifier" | "success.product_title" | "success.product_description" | "success.price" | "success.currency_code" | "success.customer_email" | "success.is_subscription" | "success.is_trial";
export type VariableDictionary = Partial<Record<BuiltinVariableName | InputVariableName | CustomVariableName, string>>;
export type VariablesDictionary = Record<PackageIdentifier, VariableDictionary>;
export interface PackageInfo {
hasIntroOffer?: boolean;
hasTrial?: boolean;
hasPromoOffer?: boolean;
webCheckoutURL?: string;
}
export {};