Skip to content

Add V2SearchResultPromise and V2SearchResult - #2792

Open
etienneshi-hub wants to merge 3 commits into
masterfrom
etienneshi/v2-search-result
Open

Add V2SearchResultPromise and V2SearchResult#2792
etienneshi-hub wants to merge 3 commits into
masterfrom
etienneshi/v2-search-result

Conversation

@etienneshi-hub

Copy link
Copy Markdown

Why?

V2 search api responses have a different shape than v1 search. We are adding the first v2 search api and will need to update sdk generation to return the right fields for the new search endpoint.

What?

  • Adds V2SearchResult interface with object: 'v2.search_result', data, next_page_url, previous_page_url, and total_count fields
      - Adds V2SearchResultPromise interface extending Promise<Response<V2SearchResult>> with autoPagingEach and autoPagingToArray methods like V2ListPromise

See Also

https://jira.corp.stripe.com/browse/DEVSDK-3211

Changelog

  • Adds V2SearchResult and V2SearchResultPromise types for v2 search endpoint responses with next_page_url/previous_page_url pagination and typed total_count

@etienneshi-hub
etienneshi-hub requested a review from a team as a code owner July 21, 2026 19:34
@etienneshi-hub
etienneshi-hub requested review from kidus-stripe and removed request for a team July 21, 2026 19:34
@xavdid
xavdid requested review from jar-stripe and xavdid and removed request for jar-stripe and kidus-stripe July 21, 2026 20:22

@xavdid xavdid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for taking a look! There a few more things we need before we can merge.

In addition to my comments, you should add actual tests, plus type tests to ensure v2 search responses have the properties we expect. We don't have any in the generated methods yet (since you're just adding them here) but you can define one in the types test with a TODO to replace it with a real v2 search later.

Comment thread src/lib.ts
* Opaque cursor to fetch the next page of results.
* Pass back as the `page` request parameter. Null if no more pages.
*/
next_page_url: string | null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are these the only properties a list response will ever have?

Also, is this data available in the openapi spec anywhere? It's the sort of thing we'd like to generate, where possible

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

These are the only fields defined in the API pattern review for v2 search.

The only v2 search endpoint currently is custom objects. I am not familiar enough with how the spec generation works for it in sdk generation, but happy to dig into it if you can point me in the right direction.

Comment thread src/lib.ts Outdated
AsyncIterableIterator<T> {
autoPagingEach(
handler: (item: T) => boolean | void | Promise<boolean | void>,
onDone?: (err: any) => void

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the v1 autoPagingEach and autoPagingToArray doesn't have an onDone property. Why the mismatch?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I was originally modelling it against v2List which seemed to be the pattern we wanted to emulate. The final decision on the shape of v2 search pagination hasn't been made so I removed it for now

Comment thread src/lib.ts Outdated
export interface V2SearchResultPromise<T>
extends Promise<Response<V2SearchResult<T>>>,
AsyncIterableIterator<T> {
autoPagingEach(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You'll need to add these to iterator responses in autoPagination.ts. We currently guard against apiMode !== 'v2', so that'll presumably change

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

When I was looking into this, I saw that V2ListIterator didn't support bidirectional pagination. When we add support for V2SearchIterator would it make sense to create it as a separate method and support bidirection or update (and rename) V2ListIterator to support it as well.

This is assuming that v2 search pagination works the same way as v2 list pagination

Comment thread src/stripe.esm.node.ts
V2List,
V2ListPromise,
V2SearchResult,
V2SearchResultPromise,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These need to be added in the matching cjs files

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@etienneshi-hub

etienneshi-hub commented Aug 5, 2026

Copy link
Copy Markdown
Author

The pagination for V2 search hasn't been gavel yet, but we seem to be close to a resolution soon. I'm cleaning this PR in preparation for it.

Are these sufficient type tests? I'm planning on adding tests after we add pagination as well, are there any other that I'm missing.
sdk-codegen pr: https://github.com/stripe/sdk-codegen/pull/3873
stripe-cli-ts-plugins: https://github.com/stripe/stripe-cli-ts-plugins/pull/105

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.

2 participants