@revenuecat/purchases-ui-js
Version:
Web components for Paywalls. Powered by RevenueCat
54 lines (53 loc) • 2.3 kB
TypeScript
import type { WorkflowData, WorkflowScreen, WorkflowStep } from "./workflow";
export interface WorkflowStepChangeEvent {
workflowId: string;
stepId: string;
fromStepId: string | undefined;
toStepId: string | undefined;
isFirstStep: boolean;
isLastStep: boolean;
/**
* Why this event was emitted:
* - `"start"` / `"forward"` / `"back"` — step is being entered (fire step_started)
* - `"completed"` — step is being left (fire step_completed); toStepId is set
* for forward nav, undefined when the workflow is dismissed/closed.
*/
reason: "start" | "forward" | "back" | "completed";
}
/**
* A self-contained multi-page workflow payload for use with the Workflow
* component. This mirrors the shape of rc-workflows' WorkflowData but only
* includes the fields needed for client-side page navigation.
*/
export interface WorkflowNavData {
/** The workflow's unique identifier. */
workflowId: string;
/** ID of the first page to display. Must be a key in `pages`. */
initial_page_id: string;
/**
* All pages in this workflow keyed by screen ID.
* Workflow step actions resolve to these IDs via `steps[stepId].screen_id`.
*/
pages: Record<string, WorkflowScreen>;
/**
* All steps in this workflow keyed by step ID.
* Used to resolve `workflow`-type button actions: the button's component ID
* is looked up in the current step's `triggers` array to get an action_id,
* which maps to a `trigger_actions` entry pointing to the next step_id,
* whose screen_id is then used to navigate to the correct page.
*/
steps: Record<string, WorkflowStep>;
/** The step ID of the first step, corresponding to `initial_page_id`. */
initial_step_id: string;
}
/**
* Map a full `WorkflowData` SDK response to the `WorkflowNavData` shape
* consumed by the `Workflow` component.
*
* - `pages` is taken directly from `WorkflowData.screens`, keyed by screen ID.
* - `initial_page_id` is resolved by looking up the screen_id of the initial
* step, since `initial_step_id` is a step ID, not a screen ID.
*
* Returns `null` if the initial step or its screen cannot be resolved.
*/
export declare function workflowDataToNavData(data: WorkflowData): WorkflowNavData | null;