Skip to content

Commit

Permalink
Merge pull request #21 from integration-os/feat/pagination-helper
Browse files Browse the repository at this point in the history
feat: pagination helper enhancements
  • Loading branch information
paulkr authored Oct 17, 2024
2 parents adc0627 + e584c62 commit 004398a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@integrationos/node",
"version": "4.1.11",
"version": "4.1.12",
"description": "Node SDK for the IntegrationOS Unified API",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
7 changes: 2 additions & 5 deletions src/paginate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ export class PaginationHelper<T> {
private isInitialized: boolean = false;

constructor(
private fetchFunction: PaginationHelperFetch<T>,
private listParams: ListFilter = {}
private fetchFunction: PaginationHelperFetch<T>
) { }

async initialize(): Promise<void> {
if (this.isInitialized) return;

const firstResponse = await this.fetchFunction({ ...this.listParams });
const firstResponse = await this.fetchFunction({});
this.currentBatch = firstResponse.unified;
this.currentCursor = firstResponse.pagination.nextCursor;

if (this.currentCursor) {
const secondResponse = await this.fetchFunction({
...this.listParams,
cursor: this.currentCursor
});

Expand All @@ -43,7 +41,6 @@ export class PaginationHelper<T> {

if (this.currentCursor) {
const response = await this.fetchFunction({
...this.listParams,
cursor: this.currentCursor
});

Expand Down

0 comments on commit 004398a

Please sign in to comment.