I know how to loop through pages, select everything on a page, and group them. But I'll need help to figure out how to:
Save the locked states of each visible item on the page to an array so I can unlock all of them in order to be sure to select all visible items on the page before grouping, so I can then be able to return each object to its original state of locked-ness (those little monsters!).
Find the boundary coordinates of the grouped object.
Use the coordinates to send some kind of "resize page corners to these coordinates" kind of command to fit the page to its content.
After ungrouping the objects on the page, restore the lock states of each object.
I'm using Mac OS X El Capitan, Adobe InDesign CC 2018, and Adobe ExtendScript Toolkit CC.