UNPKG

@revenuecat/purchases-ui-js

Version:

Web components for Paywalls. Powered by RevenueCat

35 lines (34 loc) 1.42 kB
/** * 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 function workflowDataToNavData(data) { const initialStep = data.steps[data.initial_step_id]; if (!initialStep) { console.warn(`[workflowDataToNavData] initial_step_id "${data.initial_step_id}" not found in steps`); return null; } const initialPageId = initialStep.screen_id; if (!initialPageId) { console.warn(`[workflowDataToNavData] initial step "${data.initial_step_id}" has no screen_id (logic/experiment step?)`); return null; } if (!data.screens[initialPageId]) { console.warn(`[workflowDataToNavData] screen_id "${initialPageId}" not found in screens`); return null; } return { initial_page_id: initialPageId, initial_step_id: data.initial_step_id, // Shared by reference intentionally — screens/steps are never mutated after // WorkflowData is received from the SDK, so a copy would be wasteful. pages: data.screens, steps: data.steps, }; }