Write a program that uses IntelliJ's refactoring tools


I'd like to write a program that can use IntelliJ "as a library or service" to perform refactorings, such as renaming some variables in a Typescript source base.  Is there a convenient way to do this / are there some examples?  I'm not sure where to start - I see a bunch of documentation about building plugins for IntelliJ, but that's not quite what I'm looking to do.