You’ll need to inspect the parent node of the cursor, and find the range that the current link covers in that. You could do something like this (untested):
function linkAround(doc, pos) {
let $pos = doc.resolve(pos), parent = $pos.parent
let start = parent.childAfter($pos.parentOffset)
if (!start.node) return null
let link = start.node.marks.find(mark => mark.type.name == "link")
if (!link) return null
let startIndex = $pos.index(), startPos = $pos.start() + start.offset
while (startIndex > 0 && link.isInSet($pos.child(startIndex - 1).marks))
startPos -= $pos.child(--startIndex).nodeSize
let endIndex = $pos.indexAfter(), endPos = startPos + start.node.nodeSize
while (end < parent.childCount && link.isInSet($pos.child(endIndex).marks))
endPos += $pos.child(endIndex++).nodeSize
return {from: startPos, to: endPos}
}