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.

// @ts-ignore
endpoints[entityType]?.[action]

console.debug(endpoint)

Choose a reason for hiding this comment

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

Any specific reason for keeping this debug log?

Copy link
Author

Choose a reason for hiding this comment

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

Good catch, not at all

Comment on lines +70 to +74
const queryIndex = url.indexOf('?')
if (queryIndex === -1) return

const queryString = url.slice(queryIndex + 1)
return new URLSearchParams(queryString).get(key) ?? undefined

Choose a reason for hiding this comment

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

Suggested change
const queryIndex = url.indexOf('?')
if (queryIndex === -1) return
const queryString = url.slice(queryIndex + 1)
return new URLSearchParams(queryString).get(key) ?? undefined
const parsedURL = new URL(url)
return parsedURL.searchParams.get(key) ?? undefined

Copy link
Author

@ebefarooqui ebefarooqui Nov 21, 2025

Choose a reason for hiding this comment

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

The url we are parsing from the response is a relative url

pagePrev: "/spaces/segpl12szpe6/environments/master/assets?pageNext=SMK3D8KEZk..."

so we couldn't use URL here unless we mocked an appropriate base domain. Thoughts?

{ entityType, mockToReturn, methodToTest, wrapperSuffix = '' },
) {
const { api, entitiesMock } = setup(Promise.resolve(mockToReturn))
console.debug('HERE', entitiesMock[entityType])

Choose a reason for hiding this comment

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

Extra?

Copy link
Author

Choose a reason for hiding this comment

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

Sorry! Yes, definitely need to remove


return {
...data,
...(Object.keys(pages).length && { pages }),

Choose a reason for hiding this comment

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

I believe API always returns pages object, even if it's empty. Maybe we can do the same here, what do you think?

- The ability to scope CMA client instance to a specific `spaceId`, `environmentId`, and `organizationId` when initializing the client.
- You can pass a concrete values to `defaults` and omit specifying these params in actual CMA methods calls.

## Cursor Based Pagination

Choose a reason for hiding this comment

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

Can we also add the title in TOC?

})

test('returns [limit] number of items', async () => {
const response = await environment.getAssetsWithCursor({ limit: 3 })

Choose a reason for hiding this comment

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

nit: atm we can provide skip param here. Maybe we can disallow this param with TS to help the users avoid validation errors?

Image

…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
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.

5 participants