xifin logo

[internal] Node.js Automation Suite

At Xifin I was brought on to automate processes where a large amount of users were performing repetitive tasks inside the RPM biling software that was costing the company millions of dollars every quarter.

At that time my boss had already built out the MVP and showcased the usefulness of scripting by automating processes that interacted with the main part of RPM.

When I was brought on I was quickly inundated with requests to execute existing scripts and create new scripts based on existing processes. Without deep knowledge of the nomenclature of the healthcare industry I was frequently lost and made mistakes navigating a library of vanilla js scripts.

So, to tackle these problems and make our process more efficient I elected to make several changes to the existing codebase:

  1. migrate to typescript
  2. move all API logic to a separate directory
  3. break out frequently used logic into their own functions (I like to call them actions)
  4. create a small interface that prompted the script use for all the information necessary to run a script
  5. create a small interface that allowed a user to create a new script out of existing actions easily

Image

Migrating to Typescript

I want to preface this section by saying, I love hacking in vanilla.js. Executing a node program by just typing node start.js is a sublime experience. But, as our codebase was growing and tracking down errors of cannot read property "data" of undefined due to a typo was become more and more tedious by the day.

Our codebase effectively is a 1:1 replication of the client of a behemoth of an application that drives billing for the biggest medicare providers in the United States.

Before we had all the interfaces coded out in javascript I migrated everything over to typescript files and resolved any type issues. I did this by following some basic rules:

  1. do not use the "any" type. If you don't know what something is use "unknown"
  2. resolve types immediately.

The migration immediately caught several typos and logic issues and was a boon to development almost immediately after the lift of correcting all the problems. This took roughly a week.

Actions

The codebase had another flaw that limited process improvement. Most scripts that were created performed very similar actions except for a few small changes that warranted a whole new script to be created OR the script would frequently change on the spot completely mutating the original version.

We needed a way to quickly combine frequently used functions that can be combined in novel ways without writing a lot of bloat. I would say for most use cases, writing a new javascript or typescript file that combines these functions is the best way but, finding the imports across our codebase was becoming monotonous and energy consuming.

I opted to create a CLI that would fetch all exported functions and display them in an organized and filterable fashion so generating a brand new script took a matter of seconds and minimal effort and thought. This CLI would save the structure of the script as a JSON file that could be re-used and modified in the future.

No more would a script user have to dig around in the javascript looking for the column header that needed to be changed to match the CSV file.

These actions are basically components for node.js in the same way that react components are for browsers. I hope to make a drag and drop version of this library in VSCode.