-
Notifications
You must be signed in to change notification settings - Fork 57
feat!: Add flag targets and flag target types resources #1683
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
Deborah-Digges
wants to merge
4
commits into
main
from
feature/auth-6891-openapi-spec-sdk-regeneration-for-the-new-flag-target
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
94f594e
Rename runtime poll FlagTarget type to FlagPollTarget
Deborah-Digges f420ac3
Add generated FlagTargets and FlagTargetTypes resources
Deborah-Digges d330879
Format runtime client with Prettier
Deborah-Digges 70767a7
Export flag target interfaces from worker entrypoint
Deborah-Digges 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
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 |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "slug": "workspace" | ||
| } |
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,7 @@ | ||
| { | ||
| "object": "flag_target_type", | ||
| "id": "flag_target_type_01EHZNVPK3SFK441A1RGBFSHRT", | ||
| "slug": "workspace", | ||
| "created_at": "2026-01-15T12:00:00.000Z", | ||
| "updated_at": "2026-01-15T12:00:00.000Z" | ||
| } |
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,15 @@ | ||
| { | ||
| "data": [ | ||
| { | ||
| "object": "flag_target_type", | ||
| "id": "flag_target_type_01EHZNVPK3SFK441A1RGBFSHRT", | ||
| "slug": "workspace", | ||
| "created_at": "2026-01-15T12:00:00.000Z", | ||
| "updated_at": "2026-01-15T12:00:00.000Z" | ||
| } | ||
| ], | ||
| "list_metadata": { | ||
| "before": null, | ||
| "after": null | ||
| } | ||
| } |
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,78 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| import fetch from 'jest-fetch-mock'; | ||
| import { | ||
| fetchOnce, | ||
| fetchURL, | ||
| fetchMethod, | ||
| fetchSearchParams, | ||
| fetchBody, | ||
| } from '../common/utils/test-utils'; | ||
| import { WorkOS } from '../workos'; | ||
|
|
||
| import listFlagTargetTypeFixture from './fixtures/list-flag-target-type.json'; | ||
| import flagTargetTypeFixture from './fixtures/flag-target-type.json'; | ||
|
|
||
| const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); | ||
|
|
||
| function expectFlagTargetType(result: any) { | ||
| expect(result.object).toBe('flag_target_type'); | ||
| expect(result.id).toBe('flag_target_type_01EHZNVPK3SFK441A1RGBFSHRT'); | ||
| expect(result.slug).toBe('workspace'); | ||
| expect(result.createdAt.toISOString()).toBe('2026-01-15T12:00:00.000Z'); | ||
| expect(result.updatedAt.toISOString()).toBe('2026-01-15T12:00:00.000Z'); | ||
| } | ||
|
|
||
| describe('FlagTargetTypes', () => { | ||
| beforeEach(() => fetch.resetMocks()); | ||
|
|
||
| describe('listFlagTargetTypes', () => { | ||
| it('returns paginated results', async () => { | ||
| fetchOnce(listFlagTargetTypeFixture); | ||
|
|
||
| const { data, listMetadata } = | ||
| await workos.flagTargetTypes.listFlagTargetTypes({ order: 'desc' }); | ||
|
|
||
| expect(fetchMethod()).toBe('GET'); | ||
| expect(new URL(String(fetchURL())).pathname).toBe('/flag_target_types'); | ||
| expect(fetchSearchParams()).toHaveProperty('order'); | ||
| expect(Array.isArray(data)).toBe(true); | ||
| expect(listMetadata).toBeDefined(); | ||
| expect(data.length).toBeGreaterThan(0); | ||
| expectFlagTargetType(data[0]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('createFlagTargetType', () => { | ||
| it('sends the correct request and returns result', async () => { | ||
| fetchOnce(flagTargetTypeFixture); | ||
|
|
||
| const result = await workos.flagTargetTypes.createFlagTargetType({ | ||
| slug: 'test_slug', | ||
| }); | ||
|
|
||
| expect(fetchMethod()).toBe('POST'); | ||
| expect(new URL(String(fetchURL())).pathname).toBe('/flag_target_types'); | ||
| expect(fetchBody()).toEqual( | ||
| expect.objectContaining({ slug: 'test_slug' }), | ||
| ); | ||
| expectFlagTargetType(result); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getFlagTargetType', () => { | ||
| it('returns the expected result', async () => { | ||
| fetchOnce(flagTargetTypeFixture); | ||
|
|
||
| const result = await workos.flagTargetTypes.getFlagTargetType({ | ||
| id: 'test_id', | ||
| }); | ||
|
|
||
| expect(fetchMethod()).toBe('GET'); | ||
| expect(new URL(String(fetchURL())).pathname).toBe( | ||
| '/flag_target_types/test_id', | ||
| ); | ||
| expectFlagTargetType(result); | ||
| }); | ||
| }); | ||
| }); |
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,87 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| import type { WorkOS } from '../workos'; | ||
| import { AutoPaginatable } from '../common/utils/pagination'; | ||
| import { fetchAndDeserialize } from '../common/utils/fetch-and-deserialize'; | ||
| import type { ListFlagTargetTypesOptions } from './interfaces/list-flag-target-types-options.interface'; | ||
| import type { CreateFlagTargetTypeOptions } from './interfaces/create-flag-target-type-options.interface'; | ||
| import type { GetFlagTargetTypeOptions } from './interfaces/get-flag-target-type-options.interface'; | ||
| import type { | ||
| FlagTargetType, | ||
| FlagTargetTypeResponse, | ||
| } from './interfaces/flag-target-type.interface'; | ||
| import type { CreateFlagTargetTypeResponse } from './interfaces/create-flag-target-type.interface'; | ||
| import { deserializeFlagTargetType } from './serializers/flag-target-type.serializer'; | ||
| import { serializeCreateFlagTargetType } from './serializers/create-flag-target-type.serializer'; | ||
|
|
||
| export class FlagTargetTypes { | ||
| constructor(private readonly workos: WorkOS) {} | ||
|
|
||
| /** | ||
| * List flag target types | ||
| * | ||
| * Get a list of the custom Flag Target Types registered for the current environment's project. The built-in `user` and `organization` target types are not included. | ||
| * @param options - Pagination and filter options. | ||
| * @returns {Promise<AutoPaginatable<FlagTargetType>>} | ||
| * @throws {BadRequestException} 400 | ||
| */ | ||
| async listFlagTargetTypes( | ||
| options?: ListFlagTargetTypesOptions, | ||
| ): Promise<AutoPaginatable<FlagTargetType, ListFlagTargetTypesOptions>> { | ||
| const paginationOptions = options; | ||
| return new AutoPaginatable( | ||
| await fetchAndDeserialize<FlagTargetTypeResponse, FlagTargetType>( | ||
| this.workos, | ||
| '/flag_target_types', | ||
| deserializeFlagTargetType, | ||
| paginationOptions, | ||
| ), | ||
| (params) => | ||
| fetchAndDeserialize<FlagTargetTypeResponse, FlagTargetType>( | ||
| this.workos, | ||
| '/flag_target_types', | ||
| deserializeFlagTargetType, | ||
| params, | ||
| ), | ||
| paginationOptions, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Create a flag target type | ||
| * | ||
| * Register a custom Flag Target Type, making its slug usable as the `target_type` of a Flag Target anywhere in the project. | ||
| * @returns {Promise<FlagTargetType>} | ||
| * @throws {BadRequestException} 400 | ||
| */ | ||
| async createFlagTargetType( | ||
| options: CreateFlagTargetTypeOptions, | ||
| ): Promise<FlagTargetType> { | ||
| const payload = options; | ||
| const { data } = await this.workos.post< | ||
| FlagTargetTypeResponse, | ||
| CreateFlagTargetTypeResponse | ||
| >('/flag_target_types', serializeCreateFlagTargetType(payload)); | ||
| return deserializeFlagTargetType(data); | ||
| } | ||
|
|
||
| /** | ||
| * Get a flag target type | ||
| * | ||
| * Get the details of an existing Flag Target Type. | ||
| * @param options - The request options. | ||
| * @param options.id - Unique identifier of the Flag Target Type. | ||
| * @example "flag_target_type_01EHZNVPK3SFK441A1RGBFSHRT" | ||
| * @returns {Promise<FlagTargetType>} | ||
| * @throws {NotFoundException} 404 | ||
| */ | ||
| async getFlagTargetType( | ||
| options: GetFlagTargetTypeOptions, | ||
| ): Promise<FlagTargetType> { | ||
| const { id } = options; | ||
| const { data } = await this.workos.get<FlagTargetTypeResponse>( | ||
| `/flag_target_types/${encodeURIComponent(id)}`, | ||
| ); | ||
| return deserializeFlagTargetType(data); | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/flag-target-types/interfaces/create-flag-target-type-options.interface.ts
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,6 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export interface CreateFlagTargetTypeOptions { | ||
| /** A unique key used as the `target_type` of a Flag Target, scoped to the project. May contain lowercase letters, numbers, underscores and hyphens. */ | ||
| slug: string; | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/flag-target-types/interfaces/create-flag-target-type.interface.ts
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,10 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export interface CreateFlagTargetType { | ||
| /** A unique key used as the `target_type` of a Flag Target, scoped to the project. May contain lowercase letters, numbers, underscores and hyphens. */ | ||
| slug: string; | ||
| } | ||
|
|
||
| export interface CreateFlagTargetTypeResponse { | ||
| slug: string; | ||
| } |
22 changes: 22 additions & 0 deletions
22
src/flag-target-types/interfaces/flag-target-type.interface.ts
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,22 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export interface FlagTargetType { | ||
| /** Distinguishes the Flag Target Type object. */ | ||
| object: 'flag_target_type'; | ||
| /** Unique identifier of the Flag Target Type. */ | ||
| id: string; | ||
| /** A unique key used as the `target_type` of a Flag Target, scoped to the project. */ | ||
| slug: string; | ||
| /** An ISO 8601 timestamp. */ | ||
| createdAt: Date; | ||
| /** An ISO 8601 timestamp. */ | ||
| updatedAt: Date; | ||
| } | ||
|
|
||
| export interface FlagTargetTypeResponse { | ||
| object: 'flag_target_type'; | ||
| id: string; | ||
| slug: string; | ||
| created_at: string; | ||
| updated_at: string; | ||
| } |
6 changes: 6 additions & 0 deletions
6
src/flag-target-types/interfaces/get-flag-target-type-options.interface.ts
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,6 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export interface GetFlagTargetTypeOptions { | ||
| /** Unique identifier of the Flag Target Type. */ | ||
| id: string; | ||
| } |
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,7 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export * from './create-flag-target-type-options.interface'; | ||
| export * from './create-flag-target-type.interface'; | ||
| export * from './flag-target-type.interface'; | ||
| export * from './get-flag-target-type-options.interface'; | ||
| export * from './list-flag-target-types-options.interface'; |
5 changes: 5 additions & 0 deletions
5
src/flag-target-types/interfaces/list-flag-target-types-options.interface.ts
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,5 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| import type { PaginationOptions } from '../../common/interfaces/pagination-options.interface'; | ||
|
|
||
| export type ListFlagTargetTypesOptions = PaginationOptions; |
12 changes: 12 additions & 0 deletions
12
src/flag-target-types/serializers/create-flag-target-type.serializer.ts
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,12 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| import type { | ||
| CreateFlagTargetType, | ||
| CreateFlagTargetTypeResponse, | ||
| } from '../interfaces/create-flag-target-type.interface'; | ||
|
|
||
| export const serializeCreateFlagTargetType = ( | ||
| model: CreateFlagTargetType, | ||
| ): CreateFlagTargetTypeResponse => ({ | ||
| slug: model.slug, | ||
| }); |
16 changes: 16 additions & 0 deletions
16
src/flag-target-types/serializers/flag-target-type.serializer.ts
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,16 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| import type { | ||
| FlagTargetType, | ||
| FlagTargetTypeResponse, | ||
| } from '../interfaces/flag-target-type.interface'; | ||
|
|
||
| export const deserializeFlagTargetType = ( | ||
| response: FlagTargetTypeResponse, | ||
| ): FlagTargetType => ({ | ||
| object: response.object, | ||
| id: response.id, | ||
| slug: response.slug, | ||
| createdAt: new Date(response.created_at), | ||
| updatedAt: new Date(response.updated_at), | ||
| }); |
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,4 @@ | ||
| // This file is auto-generated by oagen. Do not edit. | ||
|
|
||
| export * from './create-flag-target-type.serializer'; | ||
| export * from './flag-target-type.serializer'; |
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,5 @@ | ||
| { | ||
| "flag_slug": "new-checkout", | ||
| "target_type": "organization", | ||
| "target_id": "org_01EHWNCE74X7JSDV0X3SZ3KJNY" | ||
| } |
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,13 @@ | ||
| { | ||
| "object": "flag_target", | ||
| "id": "flag_target_01EHZNVPK3SFK441A1RGBFSHRT", | ||
| "flag_id": "flag_01EHZNVPK3SFK441A1RGBFSHRT", | ||
| "flag_slug": "new-checkout", | ||
| "environment_id": "environment_01EHWNCE74X7JSDV0X3SZ3KJNY", | ||
| "target_type": "organization", | ||
| "target_id": "org_01EHWNCE74X7JSDV0X3SZ3KJNY", | ||
| "value_type": "boolean", | ||
| "value": true, | ||
| "created_at": "2026-01-15T12:00:00.000Z", | ||
| "updated_at": "2026-01-15T12:00:00.000Z" | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.