Groups (pages, artboards, layer groups) have a property called
children, which is the recursive list of contained objects - including the object itself (Sketch 49 introduced a new method
childrenIncludingSelf_(bool) which lets you choose whether to include the object itself).
Unfortunately the document itself doesn't have this method, so you need to iterate through the pages individually, calling
So this will give you all items (including pages) in a document