export function isEligibleForStep()

in src/app/functions/server/getRelevantGuidedSteps.ts [140:209]


export function isEligibleForStep(
  data: StepDeterminationData,
  stepId: StepLink["id"],
  enabledFeatureFlags?: FeatureFlagName[],
): boolean {
  // Only premium users can see the manual data broker removal flow, once they have run a scan
  /* c8 ignore start */
  if (
    // TODO: MNTOR-3886 - Remove EnableRemovalUnderMaintenanceStep feature flag
    enabledFeatureFlags?.includes("EnableRemovalUnderMaintenanceStep") &&
    stepId === "DataBrokerManualRemoval"
  ) {
    return (
      data.latestScanData?.results?.some((result) => {
        return (
          result.broker_status === "removal_under_maintenance" &&
          result.status !== "removed" &&
          !result.manually_resolved
        );
        // MNTOR-3892
        // Already covered by unit test
      }) ?? false
    );
  }
  /* c8 ignore stop */

  if (stepId === "Scan") {
    return data.countryCode === "us";
  }

  if (stepId === "HighRiskSsn") {
    // Our social security number-related mitigations aren't possible outside of the US:
    return data.countryCode === "us";
  }

  if (
    ["HighRiskCreditCard", "HighRiskBankAccount", "HighRiskPin"].includes(
      stepId,
    )
  ) {
    // Anyone can view/resolve their high risk data breaches
    return true;
  }

  if (
    ["LeakedPasswordsPassword", "LeakedPasswordsSecurityQuestion"].includes(
      stepId,
    )
  ) {
    // Anyone can view/resolve their leaked passwords
    return true;
  }

  if (
    ["SecurityTipsPhone", "SecurityTipsEmail", "SecurityTipsIp"].includes(
      stepId,
    )
  ) {
    // Anyone can view security tips
    return true;
  }

  if (stepId === "Done") {
    return true;
    // All steps should have been covered by the above conditions:
    /* c8 ignore next 4 */
  }

  return false as never;
}