Skip to content

Conversation

@ebefarooqui
Copy link

@ebefarooqui ebefarooqui commented Nov 21, 2025

Summary

Introduces three dedicated cursor pagination methods, one per each relevant entity:

getAssetsWithCursor
getContentTypesWithCursor
getEntriesWithCursor

Description

These changes expose three new dedicated methods in the plain client for cursor based pagination. These methods map to the getMany endpoint per each entity and are wrapped accordingly with the appropriate cursor pagination collection. Relevant unit and integration tests are also included.

Motivation and Context

Previously we tried to provide correct typing for cma.js by checking the cursor parameter to be true. As the type system of cma.js is already quite complex, this introduced a bug we were not able to foresee. As a result, this was rolled back and the decision was taken to introduce dedicated methods for cursor-based pagination.

PR Checklist

  • I have read the CONTRIBUTING.md file
  • All commits follow conventional commits
  • Documentation is updated (if necessary)
  • PR doesn't contain any sensitive information
  • There are no breaking changes

…ods for entry, asset, and content-type [CAPI-2357]

Adds getManyWithCursor as a dedicated cursor based method for entry, asset, and content-type and getPublishedWithCursor for only the asset and entry entities
…response and params and building utilities to do so [CAPI-2357]

* fix: getPublished does not currently support cursor based pagination, removing relevant methods for entities

* fix: normalize pagination params to filter prevPage and prevNext if falsey

* fix: normalize pagination response to parse next, prev tokens if present
… for getManyWithCursor for content-type, asset, and entry entities [CAPI-2357]
@ebefarooqui ebefarooqui requested a review from a team as a code owner November 21, 2025 10:19
@wiz-inc-38d59fb8d7
Copy link

wiz-inc-38d59fb8d7 bot commented Nov 21, 2025

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities -
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings -
Total -

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

…console statements, adding cbp to toc in readme [CAPI-2357]
@ebefarooqui ebefarooqui force-pushed the feature/add-dedicated-methods-for-cursor-based-pagination branch from 2ac557b to 09e8e07 Compare November 21, 2025 15:43
}

export interface BasicCursorPaginationOptions extends Omit<BasicQueryOptions, 'skip'> {
skip?: never
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this skip unnecessary given the Omit above?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this type used in all the non cursor based functions as signature? 🤔

Copy link
Author

@ebefarooqui ebefarooqui Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ethan-ozelius-contentful It's there because unless strictly forbidden, the value can still be passed in at runtime. I wanted to make sure to have a type error there just in case.

@marcolink Could you point to where that is the case? I'm not sure I follow right now, apologies

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'm not sure why, but can investigate. I was using the same type to idiomatically match how we were using it elsewhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, changing that now would likely create a breaking change ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, we can make a point to investigate what's happening here and if need be spin up another ticket?

},

/**
* Gets a collection of Content Types with cursor based pagination
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two URLs listed in this @param should probably point to the follow URL right?

https://www.contentful.com/developers/docs/references/content-management-api/#/introduction/cursor-pagination?

Copy link
Contributor

@ethan-ozelius-contentful ethan-ozelius-contentful left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left 1-2 non-blocking questions, but otherwise looks good.

console.log(response.items); // Array of items
console.log(response.pages?.next); // Cursor for next page
```
Use the value from `response.pages.next` to fetch the next page.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add an example on how to use the pages.next token?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do

}

export interface BasicCursorPaginationOptions extends Omit<BasicQueryOptions, 'skip'> {
skip?: never
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this type used in all the non cursor based functions as signature? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants