I love Readwise! One of the Readwise apps had a bug where instead of selecting an existing tag, it would create a new tag for a value with a trailing whitespace. This caused me to have duplicates of 50 or so tags. Unfortunately, some Readwise APIs try to be "nice" and silently "trim" the whitespace from the tags so they would show up on the site as if they were totally fine - gaslighting you! This made it very hard to find all of the tags that were broken and rename them using the regular UI. Readwise mirror replaces the trailing spaces with "-" so you get a bunch of duplicate tags ending with "-".
Tags are also maintained within each book record so are not a single value you can rename and fix them everywhere.
This script will iterate through every Readwise entry. When it finds a tag ending with a trailing space, it will add a new tag with the same name but without the space. If that is successful, it will delete the tag containing the trailing space.
Setup
Authentication
Sadly, not all of the Readwise APIs allow you to just use existing browser credentials via CORS. Some require you to use the persistent API key credential. So, you'll need to use the context menu to edit the script settings and paste in the API key for those to work.
That value is ONLY stored in local script configuration so I can't access it. It uses the GM_config library to do this in case you want to verify the supply chain is secure before doing that.