@@ -63,23 +63,38 @@ export class SeamPaginator<
6363 pathname : this . #request. pathname ,
6464 method : 'get' ,
6565 responseKey,
66- params : { ...this . #request. params , next_page_cursor : nextPageCursor } ,
66+ params :
67+ this . #request. params != null
68+ ? { ...this . #request. params , next_page_cursor : nextPageCursor }
69+ : undefined ,
70+ body :
71+ this . #request. body != null
72+ ? { ...this . #request. body , next_page_cursor : nextPageCursor }
73+ : undefined ,
6774 } )
75+
6876 const response = await request . fetchResponse ( )
6977 const data = response [ responseKey ]
70- const pagination : Pagination =
78+
79+ const paginationData =
7180 response != null &&
7281 typeof response === 'object' &&
7382 'pagination' in response
74- ? ( response . pagination as Pagination )
75- : {
76- hasNextPage : false ,
77- nextPageCursor : null ,
78- nextPageUrl : null ,
79- }
83+ ? ( response . pagination as PaginationData )
84+ : null
85+
86+ const pagination : Pagination = {
87+ hasNextPage : paginationData ?. has_next_page ?? false ,
88+ nextPageCursor : paginationData ?. next_page_cursor ?? null ,
89+ nextPageUrl : paginationData ?. next_page_url ?? null ,
90+ }
91+
8092 if ( ! Array . isArray ( data ) ) {
81- throw new Error ( 'Expected an array response' )
93+ throw new Error (
94+ `Expected an array response for ${ String ( responseKey ) } but got ${ String ( typeof data ) } ` ,
95+ )
8296 }
97+
8398 return [
8499 data as EnsureReadonlyArray < TResponse [ TResponseKey ] > ,
85100 pagination ,
@@ -126,3 +141,9 @@ export class SeamPaginator<
126141
127142type EnsureReadonlyArray < T > = T extends readonly any [ ] ? T : never
128143type EnsureMutableArray < T > = T extends any [ ] ? T : never
144+
145+ interface PaginationData {
146+ has_next_page : boolean
147+ next_page_cursor : string | null
148+ next_page_url : string | null
149+ }
0 commit comments