Skip to content

Commit 8dfbd71

Browse files
authored
fix: exclude organizationId from autoPagination params in listOrganizationFeatureFlags (#1461)
## 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](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.
1 parent ff2e816 commit 8dfbd71

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/organizations/organizations.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,39 @@ describe('Organizations', () => {
546546
expect(data).toHaveLength(3);
547547
});
548548
});
549+
550+
describe('autoPagination', () => {
551+
it('does not include organizationId in pagination query params', async () => {
552+
const fixtureWithAfter = {
553+
...listOrganizationFeatureFlagsFixture,
554+
list_metadata: {
555+
after: 'flag_next_page',
556+
},
557+
};
558+
// Mock 3 responses:
559+
// 1. Initial fetch in constructor
560+
// 2. First generatePages call (no after)
561+
// 3. Recursive generatePages call (with after)
562+
fetchOnce(fixtureWithAfter);
563+
fetchOnce(fixtureWithAfter);
564+
fetchOnce(listOrganizationFeatureFlagsFixture);
565+
566+
const result = await workos.organizations.listOrganizationFeatureFlags({
567+
organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
568+
});
569+
570+
// Trigger auto-pagination
571+
await result.autoPagination();
572+
573+
// Check that the third request (recursive pagination with after) does not include organizationId
574+
const thirdCallUrl = fetch.mock.calls[2][0];
575+
const thirdCallParams = Object.fromEntries(
576+
new URL(String(thirdCallUrl)).searchParams,
577+
);
578+
expect(thirdCallParams).not.toHaveProperty('organizationId');
579+
expect(thirdCallParams).toHaveProperty('after', 'flag_next_page');
580+
});
581+
});
549582
});
550583

551584
describe('listOrganizationApiKeys', () => {

src/organizations/organizations.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ export class Organizations {
127127

128128
async listOrganizationFeatureFlags(
129129
options: ListOrganizationFeatureFlagsOptions,
130-
): Promise<
131-
AutoPaginatable<FeatureFlag, ListOrganizationFeatureFlagsOptions>
132-
> {
130+
): Promise<AutoPaginatable<FeatureFlag>> {
133131
const { organizationId, ...paginationOptions } = options;
134132

135133
return new AutoPaginatable(
@@ -146,7 +144,7 @@ export class Organizations {
146144
deserializeFeatureFlag,
147145
params,
148146
),
149-
options,
147+
paginationOptions,
150148
);
151149
}
152150

0 commit comments

Comments
 (0)