UNPKG

@revenuecat/purchases-ui-js

Version:

Web components for Paywalls. Powered by RevenueCat

53 lines (52 loc) 2.05 kB
export var PackageIdentifier; (function (PackageIdentifier) { PackageIdentifier["weekly"] = "$rc_weekly"; PackageIdentifier["monthly"] = "$rc_monthly"; PackageIdentifier["two_month"] = "$rc_two_month"; PackageIdentifier["three_month"] = "$rc_three_month"; PackageIdentifier["six_month"] = "$rc_six_month"; PackageIdentifier["annual"] = "$rc_annual"; PackageIdentifier["lifetime"] = "$rc_lifetime"; })(PackageIdentifier || (PackageIdentifier = {})); /** * Factory methods for creating CustomVariableValue instances. */ export const CustomVariableValue = { /** * Creates a string custom variable value. * @param value The string value for the custom variable. * @returns A CustomVariableValue containing the string. */ string: (value) => ({ type: "string", value }), /** * Creates a number custom variable value. * @param value The number value for the custom variable. * @returns A CustomVariableValue containing the number. */ number: (value) => ({ type: "number", value }), /** * Creates a boolean custom variable value. * @param value The boolean value for the custom variable. * @returns A CustomVariableValue containing the boolean. */ boolean: (value) => ({ type: "boolean", value, }), }; export function mergeCustomVariables(customVariables, uiConfig) { const normalizedUserProvidedCustomVariables = Object.fromEntries(Object.entries(customVariables).map(([customVariableKey, { value: customVariableValue }]) => [ customVariableKey, String(customVariableValue), ])); if (!uiConfig) return normalizedUserProvidedCustomVariables; const normalizedDefaultCustomVariables = Object.fromEntries(Object.entries(uiConfig.custom_variables ?? {}).map(([customVariableKey, { default_value }]) => [ customVariableKey, String(default_value), ])); return { ...normalizedDefaultCustomVariables, ...normalizedUserProvidedCustomVariables, }; }