auth0
Version:
Auth0 Node.js SDK for the Management API v2.
83 lines (82 loc) • 3.19 kB
text/typescript
import { HttpResponsePromise, type RawResponse, type WithRawResponse } from "../fetcher/index.mjs";
/**
* Parser function type for custom pagination.
* SDK authors implement this to define how to extract items and determine pagination state.
*
* @template TItem The type of items in the paginated response.
* @template TRequest The type of the request object.
* @template TResponse The type of the API response.
*/
export type CustomPagerParser<TItem, TRequest, TResponse> = (request: TRequest, response: WithRawResponse<TResponse>) => Promise<{
/** The request to use for fetching the next page, if any */
nextRequest?: TRequest;
/** Whether there is a next page available */
hasNextPage: boolean;
/** The request to use for fetching the previous page, if any */
previousRequest?: TRequest;
/** Whether there is a previous page available */
hasPreviousPage: boolean;
/** The items extracted from the current response */
items: TItem[];
}>;
/**
* A custom pager for paginated API responses where the pagination logic
* must be implemented by the SDK author.
*
* SDK authors provide a parser callback to extract items and determine
* pagination state from responses.
*
* @template TItem The type of the items in the page.
* @template TRequest The type of the request object.
* @template TResponse The type of the API response.
*/
export declare class CustomPager<TItem, TRequest, TResponse> implements AsyncIterable<TItem> {
/** The items from the current page */
data: TItem[];
/** The raw HTTP response */
rawResponse: RawResponse;
/** The parsed response object */
response: TResponse;
private context;
private parser;
private nextRequest?;
private previousRequest?;
private _hasNextPage;
private _hasPreviousPage;
private constructor();
/**
* @returns whether there is a next page to load
*/
hasNextPage(): boolean;
/**
* @returns whether there is a previous page to load
*/
hasPreviousPage(): boolean;
/**
* Retrieves the next page of results.
* @returns this pager with updated data
* @throws Error if there is no next page
*/
getNextPage(): Promise<this>;
/**
* Retrieves the previous page of results.
* @returns this pager with updated data
* @throws Error if there is no previous page
*/
getPreviousPage(): Promise<this>;
private iterMessages;
[Symbol.asyncIterator](): AsyncIterator<TItem, void, unknown>;
/**
* Creates a CustomPager by making the initial request and parsing the response.
*
* @param args.sendRequest Function to send a request and get a response
* @param args.initialRequest The initial request to start pagination
* @param args.parse The parser function to extract items and pagination state
* @returns A new CustomPager instance
*/
static create<TItem, TRequest, TResponse>(args: {
sendRequest: (request: TRequest) => HttpResponsePromise<TResponse>;
initialRequest: TRequest;
parse: CustomPagerParser<TItem, TRequest, TResponse>;
}): Promise<CustomPager<TItem, TRequest, TResponse>>;
}