There is LuaEntity#get_cargo_bays for relating space platform hub / cargo landing pad to its cargo bays, but no clean way to go in reverse.
Workaround for when connected to platform hub is cargo bay entity's .surface.platform.hub. When it's connected to landing pad, mod has to either keep track of all existing, or do naive full surface searches for all landing pads, to then call LuaEntity#get_cargo_bays until the same bay was found in it.
My use case is for Item Cam 2, which after following a cargo pod to its destination cargo bay, switches to related platform hub/landing pad because next interaction is there
Cargo bay reverse relation to connected platform hub/landing pad
Re: Cargo bay reverse relation to connected platform hub/landing pad
I've added LuaEntity::cargo_bay_connection_owner read for the next release.
If you want to get ahold of me I'm almost always on Discord.