Skip to content

Commit 8d8878d

Browse files
authored
Add GET /organizations/:orgId/feature-flags support (#1326)
## Description Add GET /organizations/:orgId/feature-flags support ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [x] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.
1 parent dec50d3 commit 8d8878d

File tree

7 files changed

+142
-0
lines changed

7 files changed

+142
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"object": "list",
3+
"data": [
4+
{
5+
"object": "feature_flag",
6+
"id": "flag_01EHQMYV6MBK39QC5PZXHY59C5",
7+
"name": "Advanced Dashboard",
8+
"slug": "advanced-dashboard",
9+
"description": "Enable advanced dashboard features",
10+
"created_at": "2024-01-01T00:00:00.000Z",
11+
"updated_at": "2024-01-01T00:00:00.000Z"
12+
},
13+
{
14+
"object": "feature_flag",
15+
"id": "flag_01EHQMYV6MBK39QC5PZXHY59C6",
16+
"name": "Beta Features",
17+
"slug": "beta-features",
18+
"description": null,
19+
"created_at": "2024-01-01T00:00:00.000Z",
20+
"updated_at": "2024-01-01T00:00:00.000Z"
21+
},
22+
{
23+
"object": "feature_flag",
24+
"id": "flag_01EHQMYV6MBK39QC5PZXHY59C7",
25+
"name": "Premium Support",
26+
"slug": "premium-support",
27+
"description": "Access to premium support features",
28+
"created_at": "2024-01-01T00:00:00.000Z",
29+
"updated_at": "2024-01-01T00:00:00.000Z"
30+
}
31+
],
32+
"list_metadata": {}
33+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export interface FeatureFlag {
2+
object: 'feature_flag';
3+
id: string;
4+
name: string;
5+
slug: string;
6+
description?: string;
7+
createdAt: string;
8+
updatedAt: string;
9+
}
10+
11+
export interface FeatureFlagResponse {
12+
object: 'feature_flag';
13+
id: string;
14+
name: string;
15+
slug: string;
16+
description?: string;
17+
created_at: string;
18+
updated_at: string;
19+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export * from './create-organization-options.interface';
22
export * from './domain-data.interface';
3+
export * from './feature-flag.interface';
4+
export * from './list-organization-feature-flags-options.interface';
35
export * from './list-organizations-options.interface';
46
export * from './organization.interface';
57
export * from './update-organization-options.interface';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface ListOrganizationFeatureFlagsOptions {
2+
organizationId: string;
3+
}

src/organizations/organizations.spec.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import createOrganization from './fixtures/create-organization.json';
1313
import getOrganization from './fixtures/get-organization.json';
1414
import listOrganizationsFixture from './fixtures/list-organizations.json';
1515
import listOrganizationRolesFixture from './fixtures/list-organization-roles.json';
16+
import listOrganizationFeatureFlagsFixture from './fixtures/list-organization-feature-flags.json';
1617
import updateOrganization from './fixtures/update-organization.json';
1718
import setStripeCustomerId from './fixtures/set-stripe-customer-id.json';
1819
import setStripeCustomerIdDisabled from './fixtures/set-stripe-customer-id-disabled.json';
@@ -449,4 +450,52 @@ describe('Organizations', () => {
449450
]);
450451
});
451452
});
453+
454+
describe('listOrganizationFeatureFlags', () => {
455+
it('returns feature flags for the organization', async () => {
456+
fetchOnce(listOrganizationFeatureFlagsFixture);
457+
458+
const { data, object, listMetadata } =
459+
await workos.organizations.listOrganizationFeatureFlags({
460+
organizationId: 'org_01EHT88Z8J8795GZNQ4ZP1J81T',
461+
});
462+
463+
expect(fetchURL()).toContain(
464+
'/organizations/org_01EHT88Z8J8795GZNQ4ZP1J81T/feature_flags',
465+
);
466+
467+
expect(object).toEqual('list');
468+
expect(listMetadata).toEqual({});
469+
expect(data).toHaveLength(3);
470+
expect(data).toEqual([
471+
{
472+
object: 'feature_flag',
473+
id: 'flag_01EHQMYV6MBK39QC5PZXHY59C5',
474+
name: 'Advanced Dashboard',
475+
slug: 'advanced-dashboard',
476+
description: 'Enable advanced dashboard features',
477+
createdAt: '2024-01-01T00:00:00.000Z',
478+
updatedAt: '2024-01-01T00:00:00.000Z',
479+
},
480+
{
481+
object: 'feature_flag',
482+
id: 'flag_01EHQMYV6MBK39QC5PZXHY59C6',
483+
name: 'Beta Features',
484+
slug: 'beta-features',
485+
description: null,
486+
createdAt: '2024-01-01T00:00:00.000Z',
487+
updatedAt: '2024-01-01T00:00:00.000Z',
488+
},
489+
{
490+
object: 'feature_flag',
491+
id: 'flag_01EHQMYV6MBK39QC5PZXHY59C7',
492+
name: 'Premium Support',
493+
slug: 'premium-support',
494+
description: 'Access to premium support features',
495+
createdAt: '2024-01-01T00:00:00.000Z',
496+
updatedAt: '2024-01-01T00:00:00.000Z',
497+
},
498+
]);
499+
});
500+
});
452501
});

src/organizations/organizations.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,24 @@ import {
88
OrganizationResponse,
99
UpdateOrganizationOptions,
1010
} from './interfaces';
11+
import {
12+
FeatureFlag,
13+
FeatureFlagResponse,
14+
} from './interfaces/feature-flag.interface';
1115
import {
1216
deserializeOrganization,
1317
serializeCreateOrganizationOptions,
1418
serializeUpdateOrganizationOptions,
1519
} from './serializers';
1620

1721
import { fetchAndDeserialize } from '../common/utils/fetch-and-deserialize';
22+
import { List, ListResponse } from '../common/interfaces';
23+
import { deserializeList } from '../common/serializers';
1824
import { ListOrganizationRolesResponse, RoleList } from '../roles/interfaces';
1925
import { deserializeRole } from '../roles/serializers/role.serializer';
2026
import { ListOrganizationRolesOptions } from './interfaces/list-organization-roles-options.interface';
27+
import { ListOrganizationFeatureFlagsOptions } from './interfaces/list-organization-feature-flags-options.interface';
28+
import { deserializeFeatureFlag } from './serializers/feature-flag.serializer';
2129

2230
export class Organizations {
2331
constructor(private readonly workos: WorkOS) {}
@@ -104,4 +112,16 @@ export class Organizations {
104112
data: response.data.map((role) => deserializeRole(role)),
105113
};
106114
}
115+
116+
async listOrganizationFeatureFlags(
117+
options: ListOrganizationFeatureFlagsOptions,
118+
): Promise<List<FeatureFlag>> {
119+
const { organizationId } = options;
120+
121+
const { data } = await this.workos.get<ListResponse<FeatureFlagResponse>>(
122+
`/organizations/${organizationId}/feature_flags`,
123+
);
124+
125+
return deserializeList(data, deserializeFeatureFlag);
126+
}
107127
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {
2+
FeatureFlag,
3+
FeatureFlagResponse,
4+
} from '../interfaces/feature-flag.interface';
5+
6+
export const deserializeFeatureFlag = (
7+
featureFlag: FeatureFlagResponse,
8+
): FeatureFlag => ({
9+
object: featureFlag.object,
10+
id: featureFlag.id,
11+
name: featureFlag.name,
12+
slug: featureFlag.slug,
13+
description: featureFlag.description,
14+
createdAt: featureFlag.created_at,
15+
updatedAt: featureFlag.updated_at,
16+
});

0 commit comments

Comments
 (0)