-
Notifications
You must be signed in to change notification settings - Fork 0
fix: add pagination support for App Store Connect API list endpoints #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -128,4 +128,4 @@ function createBuildRun( | |
| }, | ||
| }, | ||
| }; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import test from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { BaseAPIClient } from '../src/api/base-client.js'; | ||
| import type { APIResponse } from '../src/api/types.js'; | ||
|
|
||
| /** | ||
| * Testable subclass that overrides request() to return mock data | ||
| * without making real HTTP calls. Since both get() and listAll() | ||
| * (for subsequent pages) call request(), this is the single point | ||
| * of interception needed. | ||
| */ | ||
| class TestableClient extends BaseAPIClient { | ||
| private responses: APIResponse<unknown[]>[] = []; | ||
| private callIndex = 0; | ||
|
|
||
| constructor(responses: APIResponse<unknown[]>[]) { | ||
| super( | ||
| { | ||
| keyId: 'test', | ||
| issuerId: 'test', | ||
| privateKey: '-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEIOBR1JO5H6GH5RF2U8DT0SP9UAXKKO7H5JF7E6U3L2VJoAcGBSuBBAAi\nZW2CAQBEAPnJ5VqvF2i0QzY3N7Y4C7Q3L8KM0N9QF2L8GK5V0Y5H2X1D4W7R9T6M\n-----END EC PRIVATE KEY-----', | ||
| }, | ||
| 'https://api.appstoreconnect.apple.com', | ||
| ); | ||
| this.responses = responses; | ||
| } | ||
|
|
||
| protected override async request<TData, TIncluded = never>( | ||
| _url: string, | ||
| _init?: RequestInit, | ||
| ): Promise<APIResponse<TData, TIncluded>> { | ||
| const response = this.responses[this.callIndex] as unknown as APIResponse<TData, TIncluded>; | ||
| this.callIndex++; | ||
| return response; | ||
| } | ||
|
|
||
| public async testListAll(path: string, params?: Record<string, string>): Promise<unknown[]> { | ||
| return this.listAll(path, params); | ||
| } | ||
| } | ||
|
|
||
| test('listAll collects items from a single page with no next link', async () => { | ||
| const client = new TestableClient([ | ||
| { | ||
| data: [{ id: '1' }, { id: '2' }], | ||
| links: { self: 'https://api.appstoreconnect.apple.com/v1/test' }, | ||
| }, | ||
| ]); | ||
|
|
||
| const result = await client.testListAll('/v1/test'); | ||
|
|
||
| assert.equal(result.length, 2); | ||
| assert.equal((result[0] as { id: string }).id, '1'); | ||
| assert.equal((result[1] as { id: string }).id, '2'); | ||
| }); | ||
|
|
||
| test('listAll follows pagination links across multiple pages', async () => { | ||
| const client = new TestableClient([ | ||
| { | ||
| data: [{ id: '1' }, { id: '2' }], | ||
| links: { | ||
| self: 'https://api.appstoreconnect.apple.com/v1/test?limit=200', | ||
| next: 'https://api.appstoreconnect.apple.com/v1/test?cursor=page2&limit=200', | ||
| }, | ||
| }, | ||
| { | ||
| data: [{ id: '3' }, { id: '4' }], | ||
| links: { | ||
| self: 'https://api.appstoreconnect.apple.com/v1/test?cursor=page2&limit=200', | ||
| next: 'https://api.appstoreconnect.apple.com/v1/test?cursor=page3&limit=200', | ||
| }, | ||
| }, | ||
| { | ||
| data: [{ id: '5' }], | ||
| links: { self: 'https://api.appstoreconnect.apple.com/v1/test?cursor=page3&limit=200' }, | ||
| }, | ||
| ]); | ||
|
|
||
| const result = await client.testListAll('/v1/test'); | ||
|
|
||
| assert.equal(result.length, 5); | ||
| assert.deepEqual( | ||
| result.map((item) => (item as { id: string }).id), | ||
| ['1', '2', '3', '4', '5'], | ||
| ); | ||
| }); | ||
|
|
||
| test('listAll returns empty array when first page has empty data', async () => { | ||
| const client = new TestableClient([ | ||
| { | ||
| data: [], | ||
| links: { self: 'https://api.appstoreconnect.apple.com/v1/test' }, | ||
| }, | ||
| ]); | ||
|
|
||
| const result = await client.testListAll('/v1/test'); | ||
|
|
||
| assert.equal(result.length, 0); | ||
| }); | ||
|
|
||
| test('listAll handles two pages correctly', async () => { | ||
| const client = new TestableClient([ | ||
| { | ||
| data: [{ id: 'a' }], | ||
| links: { | ||
| self: 'https://api.appstoreconnect.apple.com/v1/test', | ||
| next: 'https://api.appstoreconnect.apple.com/v1/test?cursor=2', | ||
| }, | ||
| }, | ||
| { | ||
| data: [{ id: 'b' }], | ||
| links: { self: 'https://api.appstoreconnect.apple.com/v1/test?cursor=2' }, | ||
| }, | ||
| ]); | ||
|
|
||
| const result = await client.testListAll('/v1/test'); | ||
|
|
||
| assert.equal(result.length, 2); | ||
| assert.deepEqual( | ||
| result.map((item) => (item as { id: string }).id), | ||
| ['a', 'b'], | ||
| ); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For long-lived workflows, this now fetches every paginated build run and then returns every matching item from
list_build_runs; before this path passedlimit ?? 20, and the removed schema field leaves callers with no way to keep the MCP response bounded. A workflow with hundreds or thousands of historical runs can make routinelist_build_runscalls slow or exceed response-size limits even when the caller only wants recent builds.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I guess this is debatable. @backslash-f Any take here?