Skip to content

Commit

Permalink
fix(pagination): handle number cursor (#2886)
Browse files Browse the repository at this point in the history
## Describe your changes

Fixes
https://linear.app/nango/issue/NAN-1953/pagination-cursor-does-not-handle-number-correctly

- Handle cursor that are typeof number
  • Loading branch information
bodinsamuel authored Oct 25, 2024
1 parent f5dcc09 commit a14ad10
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/shared/lib/services/paginate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class PaginationService {
): AsyncGenerator<T[], undefined, void> {
const cursorPagination: CursorPagination = paginationConfig;

let nextCursor: string | undefined;
let nextCursor: string | number | undefined;

while (true) {
if (nextCursor) {
do {
if (typeof nextCursor !== 'undefined') {
updatedBodyOrParams[cursorPagination.cursor_name_in_request] = nextCursor;
}

Expand All @@ -76,11 +76,15 @@ class PaginationService {
yield responseData;

nextCursor = get(response.data, cursorPagination.cursor_path_in_response);

if (!nextCursor || nextCursor.trim().length === 0) {
return;
if (typeof nextCursor === 'string') {
nextCursor = nextCursor.trim();
if (!nextCursor) {
nextCursor = undefined;
}
} else if (typeof nextCursor !== 'number') {
nextCursor = undefined;
}
}
} while (typeof nextCursor !== 'undefined');
}

public async *link<T>(
Expand Down

0 comments on commit a14ad10

Please # to comment.