Skip to content

fix: exclude organizationId from autoPagination params in listOrganizationFeatureFlags#1461

Merged
gjtorikian merged 1 commit intomainfrom
fix/list-organization-feature-flags-autopagination
Feb 3, 2026
Merged

fix: exclude organizationId from autoPagination params in listOrganizationFeatureFlags#1461
gjtorikian merged 1 commit intomainfrom
fix/list-organization-feature-flags-autopagination

Conversation

@gjtorikian
Copy link
Contributor

Description

The organizationId was being passed to AutoPaginatable constructor which caused it to be included as a query parameter in subsequent pagination requests. The API rejects this because organizationId is already part of the URL path.

Fixes #1459

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

@gjtorikian gjtorikian requested a review from nicknisi February 3, 2026 22:07
@gjtorikian gjtorikian requested a review from a team as a code owner February 3, 2026 22:07
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 3, 2026

Greptile Overview

Greptile Summary

Fixed a pagination bug in listOrganizationFeatureFlags where organizationId was incorrectly passed to the AutoPaginatable constructor, causing it to be included as a query parameter in subsequent pagination requests. Since organizationId is already part of the URL path (/organizations/{organizationId}/feature-flags), the API correctly rejects duplicate parameter.

Key changes:

  • Destructured organizationId from options and only passed paginationOptions to AutoPaginatable constructor
  • Removed generic type parameter from return type (now inferred correctly)
  • Added test coverage for auto-pagination behavior

Issues found:

  • Test bug: fetchSearchParams() checks first fetch call instead of second pagination call

Confidence Score: 4/5

  • Safe to merge after fixing the test bug - the core implementation fix is correct and follows existing patterns
  • The implementation fix is clean and matches the pattern used in listOrganizationApiKeys. However, the test has a bug that prevents it from actually verifying the fix works correctly.
  • Fix the test in src/organizations/organizations.spec.ts to check the second fetch call

Important Files Changed

Filename Overview
src/organizations/organizations.ts Fixed pagination bug by excluding organizationId from AutoPaginatable options to prevent it being added to query params
src/organizations/organizations.spec.ts Added test for auto-pagination behavior, but test has a bug - checks first fetch call instead of second pagination call

Sequence Diagram

sequenceDiagram
    participant Client
    participant Organizations
    participant AutoPaginatable
    participant API

    Client->>Organizations: listOrganizationFeatureFlags({organizationId, ...options})
    Organizations->>Organizations: Extract organizationId from options
    Organizations->>API: GET /organizations/{organizationId}/feature-flags?limit=10
    API-->>Organizations: Response with list_metadata.after
    Organizations->>AutoPaginatable: new AutoPaginatable(response, apiCall, paginationOptions)
    Note over AutoPaginatable: paginationOptions excludes organizationId
    AutoPaginatable-->>Client: Return AutoPaginatable instance
    
    Client->>AutoPaginatable: autoPagination()
    AutoPaginatable->>API: GET /organizations/{organizationId}/feature-flags?after=cursor&limit=100
    Note over API: organizationId NOT in query params<br/>(only in URL path)
    API-->>AutoPaginatable: Next page data
    AutoPaginatable-->>Client: All paginated results
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +569 to +571
const secondCallParams = fetchSearchParams();
expect(secondCallParams).not.toHaveProperty('organizationId');
expect(secondCallParams).toHaveProperty('after', 'flag_next_page');
Copy link
Contributor

Choose a reason for hiding this comment

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

fetchSearchParams() returns params from fetch.mock.calls[0][0] (the first call), not the second pagination call. To check the second request:

Suggested change
const secondCallParams = fetchSearchParams();
expect(secondCallParams).not.toHaveProperty('organizationId');
expect(secondCallParams).toHaveProperty('after', 'flag_next_page');
// Check that the second request (pagination) does not include organizationId
const secondCallParams = Object.fromEntries(new URL(String(fetch.mock.calls[1][0])).searchParams);
expect(secondCallParams).not.toHaveProperty('organizationId');
expect(secondCallParams).toHaveProperty('after', 'flag_next_page');
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/organizations/organizations.spec.ts
Line: 569:571

Comment:
`fetchSearchParams()` returns params from `fetch.mock.calls[0][0]` (the first call), not the second pagination call. To check the second request:

```suggestion
        // Check that the second request (pagination) does not include organizationId
        const secondCallParams = Object.fromEntries(new URL(String(fetch.mock.calls[1][0])).searchParams);
        expect(secondCallParams).not.toHaveProperty('organizationId');
        expect(secondCallParams).toHaveProperty('after', 'flag_next_page');
```

How can I resolve this? If you propose a fix, please make it concise.

@gjtorikian gjtorikian force-pushed the fix/list-organization-feature-flags-autopagination branch 2 times, most recently from 7918110 to 6722ae6 Compare February 3, 2026 22:18
@gjtorikian gjtorikian force-pushed the fix/list-organization-feature-flags-autopagination branch from 6722ae6 to 0c325d9 Compare February 3, 2026 22:20
@gjtorikian gjtorikian merged commit 8dfbd71 into main Feb 3, 2026
8 checks passed
@gjtorikian gjtorikian deleted the fix/list-organization-feature-flags-autopagination branch February 3, 2026 22:21
@gjtorikian gjtorikian mentioned this pull request Feb 3, 2026
gjtorikian added a commit that referenced this pull request Feb 3, 2026
## Description

This release has two new features:

* #1458
* #1460

and one bug fix:

* #1461

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

listOrganizationFeatureFlags broken with auto-pagination

2 participants