Skip to content

Commit

Permalink
fix passing next cursor for getAllListings/getAllOffers (#1302)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio authored Nov 27, 2023
1 parent 4475b61 commit 03c7c43
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opensea-js",
"version": "6.1.14",
"version": "6.1.15",
"description": "JavaScript SDK for the OpenSea marketplace helps developers build new experiences using NFTs and our marketplace data!",
"license": "MIT",
"author": "OpenSea Developers",
Expand Down
8 changes: 4 additions & 4 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ export class OpenSeaAPI {
): Promise<GetOffersResponse> {
const response = await this.get<GetOffersResponse>(
getAllOffersAPIPath(collectionSlug),
serializeOrdersQueryOptions({
{
limit,
next,
}),
},
);
return response;
}
Expand All @@ -221,10 +221,10 @@ export class OpenSeaAPI {
): Promise<GetListingsResponse> {
const response = await this.get<GetListingsResponse>(
getAllListingsAPIPath(collectionSlug),
serializeOrdersQueryOptions({
{
limit,
next,
}),
},
);
return response;
}
Expand Down
12 changes: 10 additions & 2 deletions src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,27 @@ export type GetOrdersResponse = QueryCursors & {
orders: OrderV2[];
};

/**
* Base query cursors response from OpenSea API.
* @category API Response Types
*/
export type QueryCursorsV2 = {
next?: string;
};

/**
* Response from OpenSea API for fetching offers.
* @category API Response Types
*/
export type GetOffersResponse = QueryCursors & {
export type GetOffersResponse = QueryCursorsV2 & {
offers: Offer[];
};

/**
* Response from OpenSea API for fetching listings.
* @category API Response Types
*/
export type GetListingsResponse = QueryCursors & {
export type GetListingsResponse = QueryCursorsV2 & {
listings: Listing[];
};

Expand Down
19 changes: 19 additions & 0 deletions test/integration/getListingsAndOffers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ suite("SDK: getAllListings", () => {
response.listings[0].protocol_data,
"Protocol data should not be null",
);
assert(response.next, "Cursor for next page should not be null");

// Should get the next page of listings
const responsePage2 = await sdk.api.getAllListings(
slug,
undefined,
response.next,
);
assert(responsePage2, "Response should not be null");
assert.notDeepEqual(
response.listings,
responsePage2.listings,
"Response of second page should not equal the response of first page",
);
assert.notEqual(
response.next,
responsePage2.next,
"Next cursor should change",
);
});
});

Expand Down

0 comments on commit 03c7c43

Please sign in to comment.