Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ try {

## Pagination

Some list endpoints are paginated. The SDK provides an iterator so that you can simply loop over the items:
Some list endpoints are paginated. You can manually iterate page-by-page:
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.

Is there a reason we do not document how to explicitly pass pagination data?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have added that example as well!


```typescript
import { ManagementClient } from "auth0";
Expand All @@ -318,15 +318,16 @@ const client = new ManagementClient({
token: "YOUR_TOKEN",
});

const response = await client.actions.list();
for await (const item of response) {
let page = await client.actions.list();
for (const item of page.data) {
console.log(item);
}

// Or you can manually iterate page-by-page
let page = await client.actions.list();
while (page.hasNextPage()) {
page = await page.getNextPage();
for (const item of page.data) {
console.log(item);
}
}
```

Expand Down
1 change: 1 addition & 0 deletions src/management/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { ManagementError, ManagementTimeoutError } from "./errors/index.js";
export { ManagementClient } from "./wrapper/ManagementClient.js";
export { ManagementEnvironment } from "./environments.js";
export { CustomDomainHeader, withTimeout, withRetries, withHeaders, withAbortSignal } from "./request-options.js";
export * from "./exports.js";
60 changes: 35 additions & 25 deletions v5_MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ The tables below show all method changes organized by category. Note these metho

### Pagination and Response Changes

All iterable responses, such as those returned by `*.list()` methods, are auto-paginated. This means that code can directly iterate over them without the need for manual pagination logic.
All iterable responses, such as those returned by `*.list()` methods, return a `Page` object. You can manually iterate through pages to retrieve all data.

#### Accessing Response Data

Expand All @@ -452,12 +452,19 @@ const client = new ManagementClient({
clientSecret: "YOUR_CLIENT_SECRET",
});

// V5: Simple pagination with .data property
const clients = await client.clients.list({ per_page: 5, page: 1 });
for (const client of clients.data) {
// V5: Manual pagination through all pages
let page = await client.clients.list();
for (const client of page.data) {
console.log(`Client ID: ${client.client_id}, Name: ${client.name}`);
}

while (page.hasNextPage()) {
page = await page.getNextPage();
for (const client of page.data) {
console.log(`Client ID: ${client.client_id}, Name: ${client.name}`);
}
}

// V4: Similar structure but different method name
// const clients2 = await legacyClient.clients.getAll({ per_page: 5, page: 1 });
// for (const client of clients2.data) {
Expand Down Expand Up @@ -500,26 +507,7 @@ console.log(`Client ID: ${clientWithResponse.data.client_id}, Name: ${clientWith

#### Advanced Pagination

For more complex pagination scenarios, v5 provides enhanced pagination support:

```ts
// V4: Manual pagination
const allUsers = [];
let page = 0;
while (true) {
const {
data: { actions, total },
} = await client.actions.getAll({
page: page++,
});
allUsers.push(...actions);
if (allUsers.length === total) {
break;
}
}
```

In v5, `client.actions.list()` returns a response of type `Page<Action>`, over which the following pagination code is valid:
For more complex pagination scenarios, v5 provides enhanced pagination support through the `Page` object:

```ts
import { ManagementClient } from "auth0";
Expand All @@ -530,11 +518,33 @@ const client = new ManagementClient({
clientSecret: "YOUR_CLIENT_SECRET",
});

// V5: Manual page-by-page iteration
let page = await client.actions.list();
for (const item of page.data) {
console.log(item);
}

while (page.hasNextPage()) {
page = await page.getNextPage();
console.log(page);
for (const item of page.data) {
console.log(item);
}
}

// V4: Manual pagination
// const allUsers = [];
// let pageNum = 0;
// while (true) {
// const {
// data: { actions, total },
// } = await client.actions.getAll({
// page: pageNum++,
// });
// allUsers.push(...actions);
// if (allUsers.length === total) {
// break;
// }
// }
```

### Management namespace
Expand Down
Loading