Skip to content

Commit 8ae6e65

Browse files
authored
Add pagination support to listOrganizationFeatureFlags (#1328)
## Description - Add pagination support to `listOrganizationFeatureFlags` ## 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 3d4c4cd commit 8ae6e65

File tree

3 files changed

+89
-9
lines changed

3 files changed

+89
-9
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
export interface ListOrganizationFeatureFlagsOptions {
1+
import { PaginationOptions } from '../../common/interfaces/pagination-options.interface';
2+
3+
export interface ListOrganizationFeatureFlagsOptions extends PaginationOptions {
24
organizationId: string;
35
}

src/organizations/organizations.spec.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,5 +497,74 @@ describe('Organizations', () => {
497497
},
498498
]);
499499
});
500+
501+
describe('with the before option', () => {
502+
it('forms the proper request to the API', async () => {
503+
fetchOnce(listOrganizationFeatureFlagsFixture);
504+
505+
const { data } =
506+
await workos.organizations.listOrganizationFeatureFlags({
507+
organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
508+
before: 'flag_before_id',
509+
});
510+
511+
expect(fetchSearchParams()).toEqual({
512+
before: 'flag_before_id',
513+
order: 'desc',
514+
});
515+
516+
expect(fetchURL()).toContain(
517+
'/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/feature_flags',
518+
);
519+
520+
expect(data).toHaveLength(3);
521+
});
522+
});
523+
524+
describe('with the after option', () => {
525+
it('forms the proper request to the API', async () => {
526+
fetchOnce(listOrganizationFeatureFlagsFixture);
527+
528+
const { data } =
529+
await workos.organizations.listOrganizationFeatureFlags({
530+
organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
531+
after: 'flag_after_id',
532+
});
533+
534+
expect(fetchSearchParams()).toEqual({
535+
after: 'flag_after_id',
536+
order: 'desc',
537+
});
538+
539+
expect(fetchURL()).toContain(
540+
'/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/feature_flags',
541+
);
542+
543+
expect(data).toHaveLength(3);
544+
});
545+
});
546+
547+
describe('with the limit option', () => {
548+
it('forms the proper request to the API', async () => {
549+
fetchOnce(listOrganizationFeatureFlagsFixture);
550+
551+
const { data } =
552+
await workos.organizations.listOrganizationFeatureFlags({
553+
organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
554+
limit: 10,
555+
});
556+
557+
expect(fetchSearchParams()).toEqual({
558+
limit: '10',
559+
order: 'desc',
560+
});
561+
562+
expect(fetchURL()).toContain(
563+
'/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/feature_flags',
564+
);
565+
566+
expect(data).toHaveLength(3);
567+
});
568+
});
500569
});
501570
});

src/organizations/organizations.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import {
1919
} from './serializers';
2020

2121
import { fetchAndDeserialize } from '../common/utils/fetch-and-deserialize';
22-
import { List, ListResponse } from '../common/interfaces';
23-
import { deserializeList } from '../common/serializers';
2422
import { ListOrganizationRolesResponse, RoleList } from '../roles/interfaces';
2523
import { deserializeRole } from '../roles/serializers/role.serializer';
2624
import { ListOrganizationRolesOptions } from './interfaces/list-organization-roles-options.interface';
@@ -115,13 +113,24 @@ export class Organizations {
115113

116114
async listOrganizationFeatureFlags(
117115
options: ListOrganizationFeatureFlagsOptions,
118-
): Promise<List<FeatureFlag>> {
119-
const { organizationId } = options;
116+
): Promise<AutoPaginatable<FeatureFlag>> {
117+
const { organizationId, ...paginationOptions } = options;
120118

121-
const { data } = await this.workos.get<ListResponse<FeatureFlagResponse>>(
122-
`/organizations/${organizationId}/feature_flags`,
119+
return new AutoPaginatable(
120+
await fetchAndDeserialize<FeatureFlagResponse, FeatureFlag>(
121+
this.workos,
122+
`/organizations/${organizationId}/feature_flags`,
123+
deserializeFeatureFlag,
124+
paginationOptions,
125+
),
126+
(params) =>
127+
fetchAndDeserialize<FeatureFlagResponse, FeatureFlag>(
128+
this.workos,
129+
`/organizations/${organizationId}/feature_flags`,
130+
deserializeFeatureFlag,
131+
params,
132+
),
133+
paginationOptions,
123134
);
124-
125-
return deserializeList(data, deserializeFeatureFlag);
126135
}
127136
}

0 commit comments

Comments
 (0)