PaginatedResult, Pagination
The shared pagination shapes: the API's cursor block, and the { items, next } result that list functions return.
import { PaginatedResult, Pagination } from '@salla.sa/twilight-theme-engine/api/types';In plain words
Long lists arrive a page at a time. PaginatedResult<T> is what the engine's list functions give you: items for this page and next, which is null on the last page. Pagination is the raw cursor block some API answers carry.
These are types: they describe data for your editor and disappear from the built theme.
Signature
interface PaginatedResult<T> {
items: T[];
next: string | null; // null on the last page
}
interface Pagination {
current: number;
next?: string | null;
previous?: string | null;
}Example
import type { PaginatedResult } from '@salla.sa/twilight-theme-engine/api/types';
import { product } from '@salla.sa/twilight-theme-engine/api/product';
import type { Product } from '@salla.sa/twilight-theme-engine/types';
/** `next` arrives as a whole URL: the next request wants only its cursor parameter. */
function cursorOf(next: string): string | null {
try {
return new URL(next).searchParams.get('cursor');
} catch {
return next;
}
}
export async function firstOfferPages(pages = 3): Promise<Product[]> {
const items: Product[] = [];
let cursor: string | null = null;
for (let i = 0; i < pages; i++) {
const page: PaginatedResult<Product> = await product.list({ source: 'offers', cursor });
items.push(...page.items);
if (!page.next) break;
cursor = cursorOf(page.next);
}
return items;
}
How it behaves
product.listandwishlist.listreturnPaginatedResult<Product>(plusfiltersfor products), the shapeItemsListfrom@salla.sa/twilight-components-reactexpects from itsloader.order.listkeeps the raw shape,{ data, cursor?: Pagination };notification.listhas its own cursor with a numericnextand acount.The module holds types only: import it with
import type, and it adds nothing to the bundle.
Gotchas
The JSDoc calls cursors opaque tokens. The products API sends
nextas a whole URL; send back only itscursorparameter (see product.list).The JSDoc example reads
page1.cursor?.currentfromproduct.list. That result has nocursor(it hasitemsandnext), so the line does not compile.src/api/README.md says every paginated endpoint uses cursors. The wishlist pages by number, and notifications use numeric cursors.