diff --git a/.oagen-manifest.json b/.oagen-manifest.json index ba29803e3..39c320b77 100644 --- a/.oagen-manifest.json +++ b/.oagen-manifest.json @@ -59,6 +59,40 @@ "src/connect/serializers/user-consent-option.serializer.ts", "src/connect/serializers/user-management-login-request.serializer.ts", "src/connect/serializers/user-object.serializer.ts", + "src/directory-sync/directory-sync.spec.ts", + "src/directory-sync/directory-sync.ts", + "src/directory-sync/fixtures/directory-group.json", + "src/directory-sync/fixtures/directory-metadata-user.json", + "src/directory-sync/fixtures/directory-metadata.json", + "src/directory-sync/fixtures/directory-user-with-groups-email.json", + "src/directory-sync/fixtures/directory-user-with-groups.json", + "src/directory-sync/fixtures/directory.json", + "src/directory-sync/fixtures/list-directory-group.json", + "src/directory-sync/fixtures/list-directory-user-with-groups.json", + "src/directory-sync/fixtures/list-directory.json", + "src/directory-sync/fixtures/slim-role.json", + "src/directory-sync/interfaces/delete-directory-options.interface.ts", + "src/directory-sync/interfaces/directory-group.interface.ts", + "src/directory-sync/interfaces/directory-metadata-user.interface.ts", + "src/directory-sync/interfaces/directory-metadata.interface.ts", + "src/directory-sync/interfaces/directory-state.interface.ts", + "src/directory-sync/interfaces/directory-sync-get-group-options.interface.ts", + "src/directory-sync/interfaces/directory-type.interface.ts", + "src/directory-sync/interfaces/directory-user-with-groups-email.interface.ts", + "src/directory-sync/interfaces/directory-user-with-groups-state.interface.ts", + "src/directory-sync/interfaces/directory.interface.ts", + "src/directory-sync/interfaces/get-directory-options.interface.ts", + "src/directory-sync/interfaces/get-user-options.interface.ts", + "src/directory-sync/interfaces/index.ts", + "src/directory-sync/interfaces/slim-role.interface.ts", + "src/directory-sync/serializers.spec.ts", + "src/directory-sync/serializers/directory-group.serializer.ts", + "src/directory-sync/serializers/directory-metadata-user.serializer.ts", + "src/directory-sync/serializers/directory-metadata.serializer.ts", + "src/directory-sync/serializers/directory-user-with-groups-email.serializer.ts", + "src/directory-sync/serializers/directory.serializer.ts", + "src/directory-sync/serializers/index.ts", + "src/directory-sync/serializers/slim-role.serializer.ts", "src/groups/fixtures/create-group-membership.json", "src/groups/fixtures/create-group.json", "src/groups/fixtures/group.json", diff --git a/src/directory-sync/directory-sync.spec.ts b/src/directory-sync/directory-sync.spec.ts index 2f2b6cb17..7f581f69e 100644 --- a/src/directory-sync/directory-sync.spec.ts +++ b/src/directory-sync/directory-sync.spec.ts @@ -1,445 +1,175 @@ +// This file is auto-generated by oagen. Do not edit. + import fetch from 'jest-fetch-mock'; import { fetchOnce, fetchURL, + fetchMethod, fetchSearchParams, } from '../common/utils/test-utils'; -import { ListResponse } from '../common/interfaces/list.interface'; import { WorkOS } from '../workos'; -import { - Directory, - DirectoryGroup, - DirectoryGroupResponse, - DirectoryResponse, - DirectoryUserWithGroups, - DirectoryUserWithGroupsResponse, -} from './interfaces'; + +import listDirectoryFixture from './fixtures/list-directory.json'; +import directoryFixture from './fixtures/directory.json'; +import listDirectoryGroupFixture from './fixtures/list-directory-group.json'; +import directoryGroupFixture from './fixtures/directory-group.json'; +import listDirectoryUserWithGroupsFixture from './fixtures/list-directory-user-with-groups.json'; +import directoryUserWithGroupsFixture from './fixtures/directory-user-with-groups.json'; + +const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); + +function expectDirectory(result: any) { + expect(result.object).toBe('directory'); + expect(result.id).toBe('directory_01ECAZ4NV9QMV47GW873HDCX74'); + expect(result.organizationId).toBe('org_01EHZNVPK3SFK441A1RGBFSHRT'); + expect(result.externalKey).toBe('sPa12dwRQ'); + expect(result.type).toBe('gsuite directory'); + expect(result.state).toBe('active'); + expect(result.name).toBe('Foo Corp'); + expect(result.createdAt.toISOString()).toBe('2026-01-15T12:00:00.000Z'); + expect(result.updatedAt.toISOString()).toBe('2026-01-15T12:00:00.000Z'); +} + +function expectDirectoryGroup(result: any) { + expect(result.object).toBe('directory_group'); + expect(result.id).toBe('directory_group_01E1JJS84MFPPQ3G655FHTKX6Z'); + expect(result.idpId).toBe('02grqrue4294w24'); + expect(result.directoryId).toBe('directory_01ECAZ4NV9QMV47GW873HDCX74'); + expect(result.organizationId).toBe('org_01EZTR6WYX1A0DSE2CYMGXQ24Y'); + expect(result.name).toBe('Developers'); + expect(result.createdAt.toISOString()).toBe('2026-01-15T12:00:00.000Z'); + expect(result.updatedAt.toISOString()).toBe('2026-01-15T12:00:00.000Z'); +} + +function expectDirectoryUserWithGroups(result: any) { + expect(result.object).toBe('directory_user'); + expect(result.id).toBe('directory_user_01E1JG7J09H96KYP8HM9B0G5SJ'); + expect(result.directoryId).toBe('directory_01ECAZ4NV9QMV47GW873HDCX74'); + expect(result.organizationId).toBe('org_01EZTR6WYX1A0DSE2CYMGXQ24Y'); + expect(result.idpId).toBe('2836'); + expect(result.email).toBe('marcelina.davis@example.com'); + expect(result.state).toBe('active'); + expect(result.customAttributes).toEqual({ + department: 'Engineering', + job_title: 'Software Engineer', + }); + expect(result.createdAt.toISOString()).toBe('2026-01-15T12:00:00.000Z'); + expect(result.updatedAt.toISOString()).toBe('2026-01-15T12:00:00.000Z'); +} describe('DirectorySync', () => { beforeEach(() => fetch.resetMocks()); - const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU'); - - const directory: Directory = { - id: 'directory_123', - createdAt: '2020-05-06 04:21:48.649164', - domain: 'foo-corp.com', - externalKey: '9asBRBVHz2ASEkgg', - name: 'Foo', - object: 'directory', - organizationId: 'org_01EXSR7M9QTKCC5D531SMCWMYG', - state: 'active', - type: 'okta scim v2.0', - updatedAt: '2021-12-13 12:15:45.531847', - }; - - const directoryResponse: DirectoryResponse = { - id: 'directory_123', - created_at: '2020-05-06 04:21:48.649164', - domain: 'foo-corp.com', - external_key: '9asBRBVHz2ASEkgg', - name: 'Foo', - object: 'directory', - organization_id: 'org_01EXSR7M9QTKCC5D531SMCWMYG', - state: 'linked', - type: 'okta scim v2.0', - updated_at: '2021-12-13 12:15:45.531847', - }; - - const group: DirectoryGroup = { - id: 'dir_grp_123', - idpId: '123', - directoryId: 'dir_123', - organizationId: 'org_123', - name: 'Foo Group', - createdAt: '2021-10-27 15:21:50.640958', - updatedAt: '2021-12-13 12:15:45.531847', - rawAttributes: { - foo: 'bar', - }, - }; - - const groupResponse: DirectoryGroupResponse = { - id: 'dir_grp_123', - idp_id: '123', - directory_id: 'dir_123', - organization_id: 'org_123', - name: 'Foo Group', - created_at: '2021-10-27 15:21:50.640958', - updated_at: '2021-12-13 12:15:45.531847', - raw_attributes: { - foo: 'bar', - }, - }; - - const userWithGroup: DirectoryUserWithGroups = { - object: 'directory_user', - id: 'user_123', - customAttributes: { - custom: true, - }, - directoryId: 'dir_123', - organizationId: 'org_123', - email: 'jonsnow@workos.com', - firstName: 'Jon', - groups: [group], - idpId: 'idp_foo', - lastName: 'Snow', - rawAttributes: {}, - state: 'active', - createdAt: '2021-10-27 15:21:50.640959', - updatedAt: '2021-12-13 12:15:45.531847', - }; - - const userWithGroupResponse: DirectoryUserWithGroupsResponse = { - object: 'directory_user', - id: 'user_123', - custom_attributes: { - custom: true, - }, - directory_id: 'dir_123', - organization_id: 'org_123', - email: 'jonsnow@workos.com', - first_name: 'Jon', - groups: [groupResponse], - idp_id: 'idp_foo', - last_name: 'Snow', - raw_attributes: {}, - state: 'active', - created_at: '2021-10-27 15:21:50.640959', - updated_at: '2021-12-13 12:15:45.531847', - }; - - const userWithRoles: DirectoryUserWithGroups = { - object: 'directory_user', - id: 'directory_user_456', - customAttributes: { - custom: true, - }, - directoryId: 'dir_123', - organizationId: 'org_123', - email: 'jonsnow@workos.com', - firstName: 'Jon', - groups: [group], - idpId: 'idp_foo', - lastName: 'Snow', - rawAttributes: {}, - state: 'active', - role: { slug: 'super_admin' }, - roles: [{ slug: 'super_admin' }], - createdAt: '2021-10-27 15:21:50.640959', - updatedAt: '2021-12-13 12:15:45.531847', - }; - - const userWithRoleResponse: DirectoryUserWithGroupsResponse = { - object: 'directory_user', - id: 'directory_user_456', - custom_attributes: { - custom: true, - }, - directory_id: 'dir_123', - organization_id: 'org_123', - email: 'jonsnow@workos.com', - first_name: 'Jon', - groups: [groupResponse], - idp_id: 'idp_foo', - last_name: 'Snow', - raw_attributes: {}, - state: 'active', - role: { slug: 'super_admin' }, - roles: [{ slug: 'super_admin' }], - created_at: '2021-10-27 15:21:50.640959', - updated_at: '2021-12-13 12:15:45.531847', - }; - describe('listDirectories', () => { - describe('with options', () => { - it('requests Directories with query parameters', async () => { - const directoryListResponse: ListResponse = { - object: 'list', - data: [directoryResponse], - list_metadata: {}, - }; - - fetchOnce(directoryListResponse); - - const subject = await workos.directorySync.listDirectories({ - organizationId: 'org_1234', - }); - - expect(fetchSearchParams()).toMatchObject({ - organization_id: 'org_1234', - }); - expect(subject).toMatchObject({ - object: 'list', - list: { - object: 'list', - data: [directory], - listMetadata: {}, - }, - apiCall: expect.any(Function), - }); - }); + it('returns paginated results', async () => { + fetchOnce(listDirectoryFixture); + + const { data, listMetadata } = await workos.directorySync.listDirectories( + { + order: 'desc', + organizationId: 'org_01EHZNVPK3SFK441A1RGBFSHRT', + search: 'Foo Corp', + }, + ); + + expect(fetchMethod()).toBe('GET'); + expect(new URL(String(fetchURL())).pathname).toBe('/directories'); + expect(fetchSearchParams()).toHaveProperty('order'); + expect(Array.isArray(data)).toBe(true); + expect(listMetadata).toBeDefined(); + expect(data.length).toBeGreaterThan(0); + expectDirectory(data[0]); }); }); describe('getDirectory', () => { - it(`requests a Directory`, async () => { - fetchOnce(directoryResponse); + it('returns the expected result', async () => { + fetchOnce(directoryFixture); - const subject = await workos.directorySync.getDirectory('directory_123'); + const result = await workos.directorySync.getDirectory({ id: 'test_id' }); - expect(subject).toEqual(directory); + expect(fetchMethod()).toBe('GET'); + expect(new URL(String(fetchURL())).pathname).toBe('/directories/test_id'); + expectDirectory(result); }); }); describe('deleteDirectory', () => { - it('sends a request to delete the directory', async () => { - fetchOnce({}, { status: 202 }); - - await workos.directorySync.deleteDirectory('directory_123'); + it('sends a DELETE request', async () => { + fetchOnce({}, { status: 204 }); - expect(fetchURL()).toContain('/directories/directory_123'); - }); - }); - - describe('getGroup', () => { - it(`requests a Directory Group`, async () => { - fetchOnce(groupResponse); - - const subject = await workos.directorySync.getGroup('dir_grp_123'); + await workos.directorySync.deleteDirectory({ id: 'test_id' }); - expect(subject).toEqual(group); + expect(fetchMethod()).toBe('DELETE'); + expect(new URL(String(fetchURL())).pathname).toBe('/directories/test_id'); }); }); describe('listGroups', () => { - const groupListResponse: ListResponse = { - object: 'list', - data: [groupResponse], - list_metadata: {}, - }; - - describe('with a Directory', () => { - it(`requests a Directory's Groups`, async () => { - fetchOnce(groupListResponse); + it('returns paginated results', async () => { + fetchOnce(listDirectoryGroupFixture); - const subject = await workos.directorySync.listGroups({ - directory: 'directory_123', - }); - - expect(fetchSearchParams()).toMatchObject({ - directory: 'directory_123', - }); - expect(subject).toMatchObject({ - object: 'list', - list: { - object: 'list', - data: [group], - listMetadata: {}, - }, - apiCall: expect.any(Function), - options: { - directory: 'directory_123', - }, - }); + const { data, listMetadata } = await workos.directorySync.listGroups({ + order: 'desc', + directory: 'directory_01ECAZ4NV9QMV47GW873HDCX74', + user: 'directory_user_01E1JG7J09H96KYP8HM9B0G5SJ', }); + + expect(fetchMethod()).toBe('GET'); + expect(new URL(String(fetchURL())).pathname).toBe('/directory_groups'); + expect(fetchSearchParams()).toHaveProperty('order'); + expect(Array.isArray(data)).toBe(true); + expect(listMetadata).toBeDefined(); + expect(data.length).toBeGreaterThan(0); + expectDirectoryGroup(data[0]); }); + }); - describe('with a User', () => { - it(`requests a Directory's Groups`, async () => { - fetchOnce(groupListResponse); + describe('getGroup', () => { + it('returns the expected result', async () => { + fetchOnce(directoryGroupFixture); - const subject = await workos.directorySync.listGroups({ - user: 'directory_usr_123', - }); + const result = await workos.directorySync.getGroup({ id: 'test_id' }); - expect(fetchSearchParams()).toMatchObject({ - user: 'directory_usr_123', - }); - expect(subject).toEqual({ - object: 'list', - list: { - object: 'list', - data: [group], - listMetadata: {}, - }, - apiCall: expect.any(Function), - options: { - user: 'directory_usr_123', - }, - }); - }); + expect(fetchMethod()).toBe('GET'); + expect(new URL(String(fetchURL())).pathname).toBe( + '/directory_groups/test_id', + ); + expectDirectoryGroup(result); }); }); describe('listUsers', () => { - const userWithGroupListResponse: ListResponse = - { - object: 'list', - data: [userWithGroupResponse], - list_metadata: {}, - }; - - describe('with a Directory', () => { - it(`requests a Directory's Users`, async () => { - fetchOnce(userWithGroupListResponse); + it('returns paginated results', async () => { + fetchOnce(listDirectoryUserWithGroupsFixture); - const subject = await workos.directorySync.listUsers({ - directory: 'directory_123', - }); - - expect(fetchSearchParams()).toMatchObject({ - directory: 'directory_123', - }); - expect(subject).toMatchObject({ - object: 'list', - list: { - object: 'list', - data: [userWithGroup], - listMetadata: {}, - }, - apiCall: expect.any(Function), - options: { - directory: 'directory_123', - }, - }); + const { data, listMetadata } = await workos.directorySync.listUsers({ + order: 'desc', + directory: 'directory_01ECAZ4NV9QMV47GW873HDCX74', + group: 'directory_group_01E64QTDNS0EGJ0FMCVY9BWGZT', }); - describe('with custom attributes', () => { - it('returns the custom attributes, using the provided type', async () => { - interface MyCustomAttributes { - managerId: string; - } - - fetchOnce( - { - data: [ - { - object: 'directory_user', - id: 'directory_user_01FBSYNGBVB4Q0GE4PJR328QB6', - directory_id: 'directory_01FBSYNGBN6R6WRMQM47PRCVMH', - idp_id: 'd899102f-86ad-4c14-9629-cd478b6a1971', - username: 'Virginia.Stoltenberg92', - emails: [], - first_name: 'Virginia', - last_name: 'Stoltenberg', - job_title: 'Software Engineer', - state: 'active', - created_at: '2021-10-27 15:21:50.640959', - updated_at: '2021-12-13 12:15:45.531847', - raw_attributes: {}, - custom_attributes: { - managerId: '99f1817b-149c-4438-b80f-a272c3406109', - }, - groups: [ - { - object: 'directory_group', - id: 'directory_group_01FBSYNGC0ASXP1WPA32AF8430', - directory_id: 'directory_01FBSYNGBN6R6WRMQM47PRCVMH', - name: 'Strosin, Luettgen and Halvorson', - raw_attributes: {}, - }, - ], - }, - { - object: 'directory_user', - id: 'directory_user_01FBSYQPYWG0SMTGRFFDS5FRQ9', - directory_id: 'directory_01FBSYQPYN2XMDN7BQHP490M03', - idp_id: '044d1610-7b9f-47bf-8269-9a5774a7a0d7', - username: 'Eli.Leffler', - emails: [], - first_name: 'Eli', - last_name: 'Leffler', - job_title: 'Software Engineer', - state: 'active', - created_at: '2021-10-27 15:21:50.640959', - updated_at: '2021-12-13 12:15:45.531847', - raw_attributes: {}, - custom_attributes: { - managerId: '263c7472-4d3f-4ab4-8162-e768af103065', - }, - groups: [ - { - object: 'directory_group', - id: 'directory_group_01FBSYQPZ101G15H9VJ5AM35Y3', - directory_id: 'directory_01FBSYQPYN2XMDN7BQHP490M03', - name: 'Osinski, Bauch and Rice', - raw_attributes: {}, - }, - ], - }, - ], - }, - { status: 200 }, - ); - - const users = - await workos.directorySync.listUsers({ - directory: 'directory_123', - }); - - expect(fetchSearchParams()).toMatchObject({ - directory: 'directory_123', - }); - - const managerIds = users.data.map( - (user) => user.customAttributes.managerId, - ); - - expect(managerIds).toEqual([ - '99f1817b-149c-4438-b80f-a272c3406109', - '263c7472-4d3f-4ab4-8162-e768af103065', - ]); - }); - }); - }); - - describe('with a Group', () => { - it(`requests a Directory's Users`, async () => { - fetchOnce(userWithGroupListResponse); - - const subject = await workos.directorySync.listUsers({ - group: 'directory_grp_123', - }); - - expect(fetchSearchParams()).toMatchObject({ - group: 'directory_grp_123', - }); - expect(subject).toMatchObject({ - object: 'list', - list: { - object: 'list', - data: [userWithGroup], - listMetadata: {}, - }, - apiCall: expect.any(Function), - options: { - group: 'directory_grp_123', - }, - }); - }); + expect(fetchMethod()).toBe('GET'); + expect(new URL(String(fetchURL())).pathname).toBe('/directory_users'); + expect(fetchSearchParams()).toHaveProperty('order'); + expect(Array.isArray(data)).toBe(true); + expect(listMetadata).toBeDefined(); + expect(data.length).toBeGreaterThan(0); + expectDirectoryUserWithGroups(data[0]); }); }); describe('getUser', () => { - it(`requests a Directory User`, async () => { - fetchOnce(userWithGroupResponse); + it('returns the expected result', async () => { + fetchOnce(directoryUserWithGroupsFixture); - const subject = await workos.directorySync.getUser('dir_usr_123'); + const result = await workos.directorySync.getUser({ id: 'test_id' }); - expect(subject).toEqual(userWithGroup); - }); - - describe('with roles', () => { - it(`requests a Directory User`, async () => { - fetchOnce(userWithRoleResponse); - - const subject = - await workos.directorySync.getUser('directory_user_456'); - - expect(subject).toEqual(userWithRoles); - }); + expect(fetchMethod()).toBe('GET'); + expect(new URL(String(fetchURL())).pathname).toBe( + '/directory_users/test_id', + ); + expectDirectoryUserWithGroups(result); }); }); }); diff --git a/src/directory-sync/directory-sync.ts b/src/directory-sync/directory-sync.ts index 021acf0e6..7b16570ab 100644 --- a/src/directory-sync/directory-sync.ts +++ b/src/directory-sync/directory-sync.ts @@ -1,25 +1,49 @@ -import { WorkOS } from '../workos'; +// This file is auto-generated by oagen. Do not edit. + +import type { WorkOS } from '../workos'; +import type { PaginationOptions } from '../common/interfaces/pagination-options.interface'; import { AutoPaginatable } from '../common/utils/pagination'; -import { - DefaultCustomAttributes, +import { fetchAndDeserialize } from '../common/utils/fetch-and-deserialize'; +import type { ListDirectoriesOptions } from './interfaces/list-directories-options.interface'; +import type { GetDirectoryOptions } from './interfaces/get-directory-options.interface'; +import type { DeleteDirectoryOptions } from './interfaces/delete-directory-options.interface'; +import type { ListDirectoryGroupsOptions } from './interfaces/list-groups-options.interface'; +import type { DirectorySyncGetGroupOptions } from './interfaces/directory-sync-get-group-options.interface'; +import type { Directory, + DirectoryResponse, +} from './interfaces/directory.interface'; +import type { DirectoryGroup, DirectoryGroupResponse, - DirectoryResponse, +} from './interfaces/directory-group.interface'; +import { deserializeDirectory } from './serializers/directory.serializer'; +import { deserializeDirectoryGroup } from './serializers/directory-group.serializer'; +// @oagen-ignore-start +import type { ListDirectoryUsersOptions } from './interfaces/list-directory-users-options.interface'; +import type { GetUserOptions } from './interfaces/get-user-options.interface'; +import type { + DefaultCustomAttributes, DirectoryUserWithGroups, DirectoryUserWithGroupsResponse, - ListDirectoriesOptions, - ListDirectoryGroupsOptions, - ListDirectoryUsersOptions, - SerializedListDirectoriesOptions, -} from './interfaces'; -import { - deserializeDirectory, - deserializeDirectoryGroup, - deserializeDirectoryUserWithGroups, - serializeListDirectoriesOptions, -} from './serializers'; -import { fetchAndDeserialize } from '../common/utils/fetch-and-deserialize'; +} from './interfaces/directory-user.interface'; +import { deserializeDirectoryUserWithGroups } from './serializers/directory-user.serializer'; +// @oagen-ignore-end + +const serializeListDirectoriesOptions = ( + options: ListDirectoriesOptions, +): PaginationOptions => { + const wire: Record = { + limit: options.limit, + before: options.before, + after: options.after, + order: options.order, + }; + if (options.organizationId !== undefined) + wire.organization_id = options.organizationId; + if (options.search !== undefined) wire.search = options.search; + return wire as PaginationOptions; +}; export class DirectorySync { constructor(private readonly workos: WorkOS) {} @@ -29,13 +53,13 @@ export class DirectorySync { * * Get a list of all of your existing directories matching the criteria specified. * @param options - Pagination and filter options. - * @returns {Promise>} - * @throws 403 response from the API. + * @returns {Promise>} + * @throws {AuthorizationException} 403 * @throws {UnprocessableEntityException} 422 */ async listDirectories( options?: ListDirectoriesOptions, - ): Promise> { + ): Promise> { return new AutoPaginatable( await fetchAndDeserialize( this.workos, @@ -58,20 +82,18 @@ export class DirectorySync { * Get a Directory * * Get the details of an existing directory. - * @param id - Unique identifier for the Directory. - * - * @example - * "directory_01ECAZ4NV9QMV47GW873HDCX74" - * + * @param options - The request options. + * @param options.id - Unique identifier for the Directory. + * @example "directory_01ECAZ4NV9QMV47GW873HDCX74" * @returns {Promise} - * @throws 403 response from the API. + * @throws {AuthorizationException} 403 * @throws {NotFoundException} 404 */ - async getDirectory(id: string): Promise { + async getDirectory(options: GetDirectoryOptions): Promise { + const { id } = options; const { data } = await this.workos.get( - `/directories/${id}`, + `/directories/${encodeURIComponent(id)}`, ); - return deserializeDirectory(data); } @@ -79,16 +101,15 @@ export class DirectorySync { * Delete a Directory * * Permanently deletes an existing directory. It cannot be undone. - * @param id - Unique identifier for the Directory. - * - * @example - * "directory_01ECAZ4NV9QMV47GW873HDCX74" - * + * @param options - The request options. + * @param options.id - Unique identifier for the Directory. + * @example "directory_01ECAZ4NV9QMV47GW873HDCX74" * @returns {Promise} - * @throws 403 response from the API. + * @throws {AuthorizationException} 403 */ - async deleteDirectory(id: string) { - await this.workos.delete(`/directories/${id}`); + async deleteDirectory(options: DeleteDirectoryOptions): Promise { + const { id } = options; + await this.workos.delete(`/directories/${encodeURIComponent(id)}`); } /** @@ -97,19 +118,20 @@ export class DirectorySync { * Get a list of all of existing directory groups matching the criteria specified. * @param options - Pagination and filter options. * @returns {Promise>} - * @throws 403 response from the API. + * @throws {AuthorizationException} 403 * @throws {NotFoundException} 404 * @throws {UnprocessableEntityException} 422 */ async listGroups( options: ListDirectoryGroupsOptions, ): Promise> { + const paginationOptions = options; return new AutoPaginatable( await fetchAndDeserialize( this.workos, '/directory_groups', deserializeDirectoryGroup, - options, + paginationOptions, ), (params) => fetchAndDeserialize( @@ -118,17 +140,42 @@ export class DirectorySync { deserializeDirectoryGroup, params, ), - options, + paginationOptions, + ); + } + + /** + * Get a Directory Group + * + * Get the details of an existing Directory Group. + * @param options - The request options. + * @param options.id - Unique identifier for the Directory Group. + * @example "directory_group_01E1JJS84MFPPQ3G655FHTKX6Z" + * @returns {Promise} + * @throws {AuthorizationException} 403 + * @throws {NotFoundException} 404 + */ + async getGroup( + options: DirectorySyncGetGroupOptions, + ): Promise { + const { id } = options; + const { data } = await this.workos.get( + `/directory_groups/${encodeURIComponent(id)}`, ); + return deserializeDirectoryGroup(data); } + // @oagen-ignore-start + // Directory users expose a custom-attributes generic the OpenAPI spec cannot + // model, so listUsers/getUser are hand-owned. oagen preserves this region + // verbatim across regeneration (see directory-user.interface.ts). /** * List Directory Users * * Get a list of all of existing Directory Users matching the criteria specified. * @param options - Pagination and filter options. * @returns {Promise, ListDirectoryUsersOptions>>} - * @throws 403 response from the API. + * @throws {AuthorizationException} 403 * @throws {NotFoundException} 404 * @throws {UnprocessableEntityException} 422 * @throws {RateLimitExceededException} 429 @@ -169,41 +216,22 @@ export class DirectorySync { * Get a Directory User * * Get the details of an existing Directory User. - * @param user - Unique identifier for the Directory User. - * - * @example - * "directory_user_01E1JG7J09H96KYP8HM9B0G5SJ" + * @param options - The request options. + * @param options.id - Unique identifier for the Directory User. + * @example "directory_user_01E1JG7J09H96KYP8HM9B0G5SJ" * @returns {Promise>} - * @throws 403 response from the API. + * @throws {AuthorizationException} 403 * @throws {NotFoundException} 404 */ async getUser( - user: string, + options: GetUserOptions, ): Promise> { + const { id } = options; const { data } = await this.workos.get< DirectoryUserWithGroupsResponse - >(`/directory_users/${user}`); + >(`/directory_users/${encodeURIComponent(id)}`); return deserializeDirectoryUserWithGroups(data); } - - /** - * Get a Directory Group - * - * Get the details of an existing Directory Group. - * @param group - Unique identifier for the Directory Group. - * - * @example - * "directory_group_01E1JJS84MFPPQ3G655FHTKX6Z" - * @returns {Promise} - * @throws 403 response from the API. - * @throws {NotFoundException} 404 - */ - async getGroup(group: string): Promise { - const { data } = await this.workos.get( - `/directory_groups/${group}`, - ); - - return deserializeDirectoryGroup(data); - } + // @oagen-ignore-end } diff --git a/src/directory-sync/fixtures/directory-group.json b/src/directory-sync/fixtures/directory-group.json new file mode 100644 index 000000000..d4005ba45 --- /dev/null +++ b/src/directory-sync/fixtures/directory-group.json @@ -0,0 +1,13 @@ +{ + "object": "directory_group", + "id": "directory_group_01E1JJS84MFPPQ3G655FHTKX6Z", + "idp_id": "02grqrue4294w24", + "directory_id": "directory_01ECAZ4NV9QMV47GW873HDCX74", + "organization_id": "org_01EZTR6WYX1A0DSE2CYMGXQ24Y", + "name": "Developers", + "raw_attributes": { + "key": {} + }, + "created_at": "2026-01-15T12:00:00.000Z", + "updated_at": "2026-01-15T12:00:00.000Z" +} diff --git a/src/directory-sync/fixtures/directory-metadata-user.json b/src/directory-sync/fixtures/directory-metadata-user.json new file mode 100644 index 000000000..0c8d0ae72 --- /dev/null +++ b/src/directory-sync/fixtures/directory-metadata-user.json @@ -0,0 +1,4 @@ +{ + "active": 42, + "inactive": 3 +} diff --git a/src/directory-sync/fixtures/directory-metadata.json b/src/directory-sync/fixtures/directory-metadata.json new file mode 100644 index 000000000..0cfc2d4a7 --- /dev/null +++ b/src/directory-sync/fixtures/directory-metadata.json @@ -0,0 +1,7 @@ +{ + "users": { + "active": 42, + "inactive": 3 + }, + "groups": 5 +} diff --git a/src/directory-sync/fixtures/directory-user-with-groups-email.json b/src/directory-sync/fixtures/directory-user-with-groups-email.json new file mode 100644 index 000000000..994ff49cb --- /dev/null +++ b/src/directory-sync/fixtures/directory-user-with-groups-email.json @@ -0,0 +1,5 @@ +{ + "primary": true, + "type": "work", + "value": "marcelina.davis@example.com" +} diff --git a/src/directory-sync/fixtures/directory-user-with-groups.json b/src/directory-sync/fixtures/directory-user-with-groups.json new file mode 100644 index 000000000..d39d14b97 --- /dev/null +++ b/src/directory-sync/fixtures/directory-user-with-groups.json @@ -0,0 +1,53 @@ +{ + "object": "directory_user", + "id": "directory_user_01E1JG7J09H96KYP8HM9B0G5SJ", + "directory_id": "directory_01ECAZ4NV9QMV47GW873HDCX74", + "organization_id": "org_01EZTR6WYX1A0DSE2CYMGXQ24Y", + "idp_id": "2836", + "email": "marcelina.davis@example.com", + "first_name": "Marcelina", + "last_name": "Davis", + "name": "Marcelina Davis", + "emails": [ + { + "primary": true, + "type": "work", + "value": "marcelina.davis@example.com" + } + ], + "job_title": "Software Engineer", + "username": "mdavis", + "state": "active", + "raw_attributes": { + "key": {} + }, + "custom_attributes": { + "department": "Engineering", + "job_title": "Software Engineer" + }, + "role": { + "slug": "admin" + }, + "roles": [ + { + "slug": "admin" + } + ], + "created_at": "2026-01-15T12:00:00.000Z", + "updated_at": "2026-01-15T12:00:00.000Z", + "groups": [ + { + "object": "directory_group", + "id": "directory_group_01E1JJS84MFPPQ3G655FHTKX6Z", + "idp_id": "02grqrue4294w24", + "directory_id": "directory_01ECAZ4NV9QMV47GW873HDCX74", + "organization_id": "org_01EZTR6WYX1A0DSE2CYMGXQ24Y", + "name": "Developers", + "raw_attributes": { + "key": {} + }, + "created_at": "2026-01-15T12:00:00.000Z", + "updated_at": "2026-01-15T12:00:00.000Z" + } + ] +} diff --git a/src/directory-sync/fixtures/directory.json b/src/directory-sync/fixtures/directory.json new file mode 100644 index 000000000..3f9cc1984 --- /dev/null +++ b/src/directory-sync/fixtures/directory.json @@ -0,0 +1,19 @@ +{ + "object": "directory", + "id": "directory_01ECAZ4NV9QMV47GW873HDCX74", + "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT", + "external_key": "sPa12dwRQ", + "type": "gsuite directory", + "state": "linked", + "name": "Foo Corp", + "domain": "foo-corp.com", + "metadata": { + "users": { + "active": 42, + "inactive": 3 + }, + "groups": 5 + }, + "created_at": "2026-01-15T12:00:00.000Z", + "updated_at": "2026-01-15T12:00:00.000Z" +} diff --git a/src/directory-sync/fixtures/list-directory-group.json b/src/directory-sync/fixtures/list-directory-group.json new file mode 100644 index 000000000..d83487d50 --- /dev/null +++ b/src/directory-sync/fixtures/list-directory-group.json @@ -0,0 +1,21 @@ +{ + "data": [ + { + "object": "directory_group", + "id": "directory_group_01E1JJS84MFPPQ3G655FHTKX6Z", + "idp_id": "02grqrue4294w24", + "directory_id": "directory_01ECAZ4NV9QMV47GW873HDCX74", + "organization_id": "org_01EZTR6WYX1A0DSE2CYMGXQ24Y", + "name": "Developers", + "raw_attributes": { + "key": {} + }, + "created_at": "2026-01-15T12:00:00.000Z", + "updated_at": "2026-01-15T12:00:00.000Z" + } + ], + "list_metadata": { + "before": null, + "after": null + } +} diff --git a/src/directory-sync/fixtures/list-directory-user-with-groups.json b/src/directory-sync/fixtures/list-directory-user-with-groups.json new file mode 100644 index 000000000..dbb44d564 --- /dev/null +++ b/src/directory-sync/fixtures/list-directory-user-with-groups.json @@ -0,0 +1,61 @@ +{ + "data": [ + { + "object": "directory_user", + "id": "directory_user_01E1JG7J09H96KYP8HM9B0G5SJ", + "directory_id": "directory_01ECAZ4NV9QMV47GW873HDCX74", + "organization_id": "org_01EZTR6WYX1A0DSE2CYMGXQ24Y", + "idp_id": "2836", + "email": "marcelina.davis@example.com", + "first_name": "Marcelina", + "last_name": "Davis", + "name": "Marcelina Davis", + "emails": [ + { + "primary": true, + "type": "work", + "value": "marcelina.davis@example.com" + } + ], + "job_title": "Software Engineer", + "username": "mdavis", + "state": "active", + "raw_attributes": { + "key": {} + }, + "custom_attributes": { + "department": "Engineering", + "job_title": "Software Engineer" + }, + "role": { + "slug": "admin" + }, + "roles": [ + { + "slug": "admin" + } + ], + "created_at": "2026-01-15T12:00:00.000Z", + "updated_at": "2026-01-15T12:00:00.000Z", + "groups": [ + { + "object": "directory_group", + "id": "directory_group_01E1JJS84MFPPQ3G655FHTKX6Z", + "idp_id": "02grqrue4294w24", + "directory_id": "directory_01ECAZ4NV9QMV47GW873HDCX74", + "organization_id": "org_01EZTR6WYX1A0DSE2CYMGXQ24Y", + "name": "Developers", + "raw_attributes": { + "key": {} + }, + "created_at": "2026-01-15T12:00:00.000Z", + "updated_at": "2026-01-15T12:00:00.000Z" + } + ] + } + ], + "list_metadata": { + "before": null, + "after": null + } +} diff --git a/src/directory-sync/fixtures/list-directory.json b/src/directory-sync/fixtures/list-directory.json new file mode 100644 index 000000000..e5cb600f5 --- /dev/null +++ b/src/directory-sync/fixtures/list-directory.json @@ -0,0 +1,27 @@ +{ + "data": [ + { + "object": "directory", + "id": "directory_01ECAZ4NV9QMV47GW873HDCX74", + "organization_id": "org_01EHZNVPK3SFK441A1RGBFSHRT", + "external_key": "sPa12dwRQ", + "type": "gsuite directory", + "state": "linked", + "name": "Foo Corp", + "domain": "foo-corp.com", + "metadata": { + "users": { + "active": 42, + "inactive": 3 + }, + "groups": 5 + }, + "created_at": "2026-01-15T12:00:00.000Z", + "updated_at": "2026-01-15T12:00:00.000Z" + } + ], + "list_metadata": { + "before": null, + "after": null + } +} diff --git a/src/directory-sync/fixtures/slim-role.json b/src/directory-sync/fixtures/slim-role.json new file mode 100644 index 000000000..21f8f0419 --- /dev/null +++ b/src/directory-sync/fixtures/slim-role.json @@ -0,0 +1,3 @@ +{ + "slug": "admin" +} diff --git a/src/directory-sync/interfaces/delete-directory-options.interface.ts b/src/directory-sync/interfaces/delete-directory-options.interface.ts new file mode 100644 index 000000000..7ae1c30b5 --- /dev/null +++ b/src/directory-sync/interfaces/delete-directory-options.interface.ts @@ -0,0 +1,6 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface DeleteDirectoryOptions { + /** Unique identifier for the Directory. */ + id: string; +} diff --git a/src/directory-sync/interfaces/directory-group.interface.ts b/src/directory-sync/interfaces/directory-group.interface.ts index 4a320f6f6..0eb27a9fa 100644 --- a/src/directory-sync/interfaces/directory-group.interface.ts +++ b/src/directory-sync/interfaces/directory-group.interface.ts @@ -1,21 +1,34 @@ +// This file is auto-generated by oagen. Do not edit. + export interface DirectoryGroup { + /** Distinguishes the Directory Group object. */ + object?: 'directory_group'; + /** Unique identifier for the Directory Group. */ id: string; + /** Unique identifier for the group, assigned by the Directory Provider. Different Directory Providers use different ID formats. */ idpId: string; + /** The identifier of the Directory the Directory Group belongs to. */ directoryId: string; + /** The identifier for the Organization in which the Directory resides. */ organizationId: string | null; + /** The name of the Directory Group. */ name: string; - createdAt: string; - updatedAt: string; - rawAttributes: any; + /** The raw attributes received from the directory provider. */ + rawAttributes?: Record; + /** An ISO 8601 timestamp. */ + createdAt: Date; + /** An ISO 8601 timestamp. */ + updatedAt: Date; } export interface DirectoryGroupResponse { + object?: 'directory_group'; id: string; idp_id: string; directory_id: string; organization_id: string | null; name: string; + raw_attributes?: Record; created_at: string; updated_at: string; - raw_attributes: any; } diff --git a/src/directory-sync/interfaces/directory-metadata-user.interface.ts b/src/directory-sync/interfaces/directory-metadata-user.interface.ts new file mode 100644 index 000000000..ab57b1dd1 --- /dev/null +++ b/src/directory-sync/interfaces/directory-metadata-user.interface.ts @@ -0,0 +1,14 @@ +// This file is auto-generated by oagen. Do not edit. + +/** Counts of active and inactive directory users. */ +export interface DirectoryMetadataUser { + /** Count of active directory users. */ + active: number; + /** Count of inactive directory users. */ + inactive: number; +} + +export interface DirectoryMetadataUserResponse { + active: number; + inactive: number; +} diff --git a/src/directory-sync/interfaces/directory-metadata.interface.ts b/src/directory-sync/interfaces/directory-metadata.interface.ts new file mode 100644 index 000000000..1f6437afe --- /dev/null +++ b/src/directory-sync/interfaces/directory-metadata.interface.ts @@ -0,0 +1,19 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + DirectoryMetadataUser, + DirectoryMetadataUserResponse, +} from './directory-metadata-user.interface'; + +/** Aggregate counts of directory users and groups synced from the provider. */ +export interface DirectoryMetadata { + /** Counts of active and inactive directory users. */ + users: DirectoryMetadataUser; + /** Count of directory groups. */ + groups: number; +} + +export interface DirectoryMetadataResponse { + users: DirectoryMetadataUserResponse; + groups: number; +} diff --git a/src/directory-sync/interfaces/directory-state.interface.ts b/src/directory-sync/interfaces/directory-state.interface.ts new file mode 100644 index 000000000..17aac60c4 --- /dev/null +++ b/src/directory-sync/interfaces/directory-state.interface.ts @@ -0,0 +1,8 @@ +// This file is auto-generated by oagen. Do not edit. + +export type DirectoryState = + | 'active' + | 'validating' + | 'invalid_credentials' + | 'inactive' + | 'deleting'; diff --git a/src/directory-sync/interfaces/directory-sync-get-group-options.interface.ts b/src/directory-sync/interfaces/directory-sync-get-group-options.interface.ts new file mode 100644 index 000000000..9b265f2ed --- /dev/null +++ b/src/directory-sync/interfaces/directory-sync-get-group-options.interface.ts @@ -0,0 +1,6 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface DirectorySyncGetGroupOptions { + /** Unique identifier for the Directory Group. */ + id: string; +} diff --git a/src/directory-sync/interfaces/directory-type.interface.ts b/src/directory-sync/interfaces/directory-type.interface.ts new file mode 100644 index 000000000..b15e8295f --- /dev/null +++ b/src/directory-sync/interfaces/directory-type.interface.ts @@ -0,0 +1,24 @@ +// This file is auto-generated by oagen. Do not edit. + +export type DirectoryType = + | 'azure scim v2.0' + | 'bamboohr' + | 'breathe hr' + | 'cezanne hr' + | 'cyberark scim v2.0' + | 'fourth hr' + | 'generic scim v2.0' + | 'gsuite directory' + | 'hibob' + | 'sailpoint scim v2.0' + | 'jump cloud scim v2.0' + | 'okta scim v2.0' + | 'onelogin scim v2.0' + | 'people hr' + | 'personio' + | 'pingfederate scim v2.0' + | 'rippling scim v2.0' + | 's3' + | 'sftp' + | 'sftp workday' + | 'workday'; diff --git a/src/directory-sync/interfaces/directory-user-with-groups-email.interface.ts b/src/directory-sync/interfaces/directory-user-with-groups-email.interface.ts new file mode 100644 index 000000000..2f088dea7 --- /dev/null +++ b/src/directory-sync/interfaces/directory-user-with-groups-email.interface.ts @@ -0,0 +1,16 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface DirectoryUserWithGroupsEmail { + /** Whether this is the primary email address. */ + primary?: boolean; + /** The type of email address. */ + type?: string; + /** The email address value. */ + value?: string | null; +} + +export interface DirectoryUserWithGroupsEmailResponse { + primary?: boolean; + type?: string; + value?: string | null; +} diff --git a/src/directory-sync/interfaces/directory-user-with-groups-state.interface.ts b/src/directory-sync/interfaces/directory-user-with-groups-state.interface.ts new file mode 100644 index 000000000..87b2466a9 --- /dev/null +++ b/src/directory-sync/interfaces/directory-user-with-groups-state.interface.ts @@ -0,0 +1,10 @@ +// This file is auto-generated by oagen. Do not edit. + +export const DirectoryUserWithGroupsState = { + Active: 'active', + Suspended: 'suspended', + Inactive: 'inactive', +} as const; + +export type DirectoryUserWithGroupsState = + (typeof DirectoryUserWithGroupsState)[keyof typeof DirectoryUserWithGroupsState]; diff --git a/src/directory-sync/interfaces/directory-user.interface.ts b/src/directory-sync/interfaces/directory-user.interface.ts index 6338a6243..d0933ac77 100644 --- a/src/directory-sync/interfaces/directory-user.interface.ts +++ b/src/directory-sync/interfaces/directory-user.interface.ts @@ -20,11 +20,11 @@ export interface DirectoryUser< firstName: string | null; email: string | null; lastName: string | null; - state: 'active' | 'inactive'; + state: 'active' | 'suspended' | 'inactive'; role?: RoleResponse; roles?: RoleResponse[]; - createdAt: string; - updatedAt: string; + createdAt: Date; + updatedAt: Date; } export interface DirectoryUserResponse< @@ -41,7 +41,7 @@ export interface DirectoryUserResponse< first_name: string | null; email: string | null; last_name: string | null; - state: 'active' | 'inactive'; + state: 'active' | 'suspended' | 'inactive'; role?: RoleResponse; roles?: RoleResponse[]; created_at: string; diff --git a/src/directory-sync/interfaces/directory.interface.ts b/src/directory-sync/interfaces/directory.interface.ts index 30a946fc3..a8f5eb1c6 100644 --- a/src/directory-sync/interfaces/directory.interface.ts +++ b/src/directory-sync/interfaces/directory.interface.ts @@ -1,101 +1,47 @@ -export type DirectoryType = - | 'azure scim v2.0' - | 'bamboohr' - | 'breathe hr' - | 'cezanne hr' - | 'cyberark scim v2.0' - | 'fourth hr' - | 'gsuite directory' - | 'generic scim v2.0' - | 'hibob' - | 'jump cloud scim v2.0' - | 'okta scim v2.0' - | 'onelogin scim v2.0' - | 'people hr' - | 'personio' - | 'pingfederate scim v2.0' - | 'rippling scim v2.0' - | 'sftp' - | 'sftp workday' - | 'workday'; +// This file is auto-generated by oagen. Do not edit. -export type DirectoryState = - | 'active' - | 'deleting' - | 'inactive' - | 'invalid_credentials' - | 'validating'; - -export type DirectoryStateResponse = - | 'deleting' - | 'invalid_credentials' - | 'linked' - | 'unlinked' - | 'validating'; +import type { + DirectoryMetadata, + DirectoryMetadataResponse, +} from './directory-metadata.interface'; +import type { DirectoryType } from './directory-type.interface'; +import type { DirectoryState } from './directory-state.interface'; export interface Directory { /** Distinguishes the Directory object. */ object: 'directory'; /** Unique identifier for the Directory. */ id: string; - /** The URL associated with an Enterprise Client. */ - domain: string; - /** External Key for the Directory. */ - externalKey: string; - /** The name of the directory. */ - name: string; /** The unique identifier for the Organization in which the directory resides. */ organizationId?: string; - /** Describes whether the Directory has been successfully connected to an external provider. */ - state: DirectoryState; + /** External Key for the Directory. */ + externalKey: string; /** The type of external Directory Provider integrated with. */ type: DirectoryType; + /** Describes whether the Directory has been successfully connected to an external provider. */ + state: DirectoryState; + /** The name of the directory. */ + name: string; + /** The URL associated with an Enterprise Client. */ + domain?: string; + /** Aggregate counts of directory users and groups synced from the provider. */ + metadata?: DirectoryMetadata; /** An ISO 8601 timestamp. */ - createdAt: string; + createdAt: Date; /** An ISO 8601 timestamp. */ - updatedAt: string; + updatedAt: Date; } export interface DirectoryResponse { object: 'directory'; id: string; - domain: string; - external_key: string; - name: string; organization_id?: string; - state: DirectoryStateResponse; - type: DirectoryType; - created_at: string; - updated_at: string; -} -interface EventDirectoryDomain { - object: 'organization_domain'; - id: string; - domain: string; -} - -export interface EventDirectory { - object: 'directory'; - id: string; - externalKey: string; - type: DirectoryType; - state: DirectoryState; - name: string; - organizationId?: string; - domains: EventDirectoryDomain[]; - createdAt: string; - updatedAt: string; -} - -export interface EventDirectoryResponse { - object: 'directory'; - id: string; external_key: string; type: DirectoryType; state: DirectoryState; name: string; - organization_id?: string; - domains: EventDirectoryDomain[]; + domain?: string; + metadata?: DirectoryMetadataResponse; created_at: string; updated_at: string; } diff --git a/src/directory-sync/interfaces/event-directory.interface.ts b/src/directory-sync/interfaces/event-directory.interface.ts new file mode 100644 index 000000000..6128d8ebc --- /dev/null +++ b/src/directory-sync/interfaces/event-directory.interface.ts @@ -0,0 +1,34 @@ +import type { DirectoryType } from './directory-type.interface'; +import type { DirectoryState } from './directory-state.interface'; + +interface EventDirectoryDomain { + object: 'organization_domain'; + id: string; + domain: string; +} + +export interface EventDirectory { + object: 'directory'; + id: string; + externalKey: string; + type: DirectoryType; + state: DirectoryState; + name: string; + organizationId?: string; + domains: EventDirectoryDomain[]; + createdAt: string; + updatedAt: string; +} + +export interface EventDirectoryResponse { + object: 'directory'; + id: string; + external_key: string; + type: DirectoryType; + state: DirectoryState; + name: string; + organization_id?: string; + domains: EventDirectoryDomain[]; + created_at: string; + updated_at: string; +} diff --git a/src/directory-sync/interfaces/get-directory-options.interface.ts b/src/directory-sync/interfaces/get-directory-options.interface.ts new file mode 100644 index 000000000..b48b4c3e4 --- /dev/null +++ b/src/directory-sync/interfaces/get-directory-options.interface.ts @@ -0,0 +1,6 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface GetDirectoryOptions { + /** Unique identifier for the Directory. */ + id: string; +} diff --git a/src/directory-sync/interfaces/get-user-options.interface.ts b/src/directory-sync/interfaces/get-user-options.interface.ts new file mode 100644 index 000000000..28dc6d3e3 --- /dev/null +++ b/src/directory-sync/interfaces/get-user-options.interface.ts @@ -0,0 +1,6 @@ +// This file is auto-generated by oagen. Do not edit. + +export interface GetUserOptions { + /** Unique identifier for the Directory User. */ + id: string; +} diff --git a/src/directory-sync/interfaces/index.ts b/src/directory-sync/interfaces/index.ts index 344c60f45..da9888e68 100644 --- a/src/directory-sync/interfaces/index.ts +++ b/src/directory-sync/interfaces/index.ts @@ -1,6 +1,20 @@ -export * from './directory.interface'; +// This file is auto-generated by oagen. Do not edit. + +export * from './delete-directory-options.interface'; export * from './directory-group.interface'; +export * from './directory-metadata-user.interface'; +export * from './directory-metadata.interface'; +export * from './directory-state.interface'; +export * from './directory-sync-get-group-options.interface'; +export * from './directory-type.interface'; +export * from './directory-user-with-groups-email.interface'; +export * from './directory-user-with-groups-state.interface'; +export * from './directory-user.interface'; +export * from './directory.interface'; +export * from './event-directory.interface'; +export * from './get-directory-options.interface'; +export * from './get-user-options.interface'; export * from './list-directories-options.interface'; -export * from './list-groups-options.interface'; export * from './list-directory-users-options.interface'; -export * from './directory-user.interface'; +export * from './list-groups-options.interface'; +export * from './slim-role.interface'; diff --git a/src/directory-sync/interfaces/slim-role.interface.ts b/src/directory-sync/interfaces/slim-role.interface.ts new file mode 100644 index 000000000..72dc7ceb3 --- /dev/null +++ b/src/directory-sync/interfaces/slim-role.interface.ts @@ -0,0 +1,11 @@ +// This file is auto-generated by oagen. Do not edit. + +/** The primary role assigned to the user. */ +export interface SlimRole { + /** The slug of the assigned role. */ + slug: string; +} + +export interface SlimRoleResponse { + slug: string; +} diff --git a/src/directory-sync/serializers.spec.ts b/src/directory-sync/serializers.spec.ts new file mode 100644 index 000000000..572aa8155 --- /dev/null +++ b/src/directory-sync/serializers.spec.ts @@ -0,0 +1,59 @@ +// This file is auto-generated by oagen. Do not edit. + +import { deserializeDirectory } from './serializers/directory.serializer'; +import { deserializeDirectoryGroup } from './serializers/directory-group.serializer'; +import { deserializeDirectoryUserWithGroupsEmail } from './serializers/directory-user-with-groups-email.serializer'; +import { deserializeDirectoryMetadata } from './serializers/directory-metadata.serializer'; +import { deserializeDirectoryMetadataUser } from './serializers/directory-metadata-user.serializer'; +import type { DirectoryResponse } from './interfaces/directory.interface'; +import type { DirectoryGroupResponse } from './interfaces/directory-group.interface'; +import type { DirectoryUserWithGroupsEmailResponse } from './interfaces/directory-user-with-groups-email.interface'; +import type { DirectoryMetadataResponse } from './interfaces/directory-metadata.interface'; +import type { DirectoryMetadataUserResponse } from './interfaces/directory-metadata-user.interface'; +import directoryFixture from './fixtures/directory.json'; +import directoryGroupFixture from './fixtures/directory-group.json'; +import directoryUserWithGroupsEmailFixture from './fixtures/directory-user-with-groups-email.json'; +import directoryMetadataFixture from './fixtures/directory-metadata.json'; +import directoryMetadataUserFixture from './fixtures/directory-metadata-user.json'; + +describe('DirectorySerializer', () => { + it('deserializes correctly', () => { + const fixture = directoryFixture as DirectoryResponse; + const deserialized = deserializeDirectory(fixture); + expect(deserialized).toBeDefined(); + }); +}); + +describe('DirectoryGroupSerializer', () => { + it('deserializes correctly', () => { + const fixture = directoryGroupFixture as DirectoryGroupResponse; + const deserialized = deserializeDirectoryGroup(fixture); + expect(deserialized).toBeDefined(); + }); +}); + +describe('DirectoryUserWithGroupsEmailSerializer', () => { + it('deserializes correctly', () => { + const fixture = + directoryUserWithGroupsEmailFixture as DirectoryUserWithGroupsEmailResponse; + const deserialized = deserializeDirectoryUserWithGroupsEmail(fixture); + expect(deserialized).toBeDefined(); + }); +}); + +describe('DirectoryMetadataSerializer', () => { + it('deserializes correctly', () => { + const fixture = directoryMetadataFixture as DirectoryMetadataResponse; + const deserialized = deserializeDirectoryMetadata(fixture); + expect(deserialized).toBeDefined(); + }); +}); + +describe('DirectoryMetadataUserSerializer', () => { + it('deserializes correctly', () => { + const fixture = + directoryMetadataUserFixture as DirectoryMetadataUserResponse; + const deserialized = deserializeDirectoryMetadataUser(fixture); + expect(deserialized).toBeDefined(); + }); +}); diff --git a/src/directory-sync/serializers/directory-group.serializer.ts b/src/directory-sync/serializers/directory-group.serializer.ts index 1ffe7489a..895a390f0 100644 --- a/src/directory-sync/serializers/directory-group.serializer.ts +++ b/src/directory-sync/serializers/directory-group.serializer.ts @@ -1,28 +1,20 @@ -import { DirectoryGroup, DirectoryGroupResponse } from '../interfaces'; +// This file is auto-generated by oagen. Do not edit. + +import type { + DirectoryGroup, + DirectoryGroupResponse, +} from '../interfaces/directory-group.interface'; export const deserializeDirectoryGroup = ( - directoryGroup: DirectoryGroupResponse, + response: DirectoryGroupResponse, ): DirectoryGroup => ({ - id: directoryGroup.id, - idpId: directoryGroup.idp_id, - directoryId: directoryGroup.directory_id, - organizationId: directoryGroup.organization_id, - name: directoryGroup.name, - createdAt: directoryGroup.created_at, - updatedAt: directoryGroup.updated_at, - rawAttributes: directoryGroup.raw_attributes, -}); - -export const deserializeUpdatedEventDirectoryGroup = ( - directoryGroup: DirectoryGroupResponse & Record<'previous_attributes', any>, -): DirectoryGroup & Record<'previousAttributes', any> => ({ - id: directoryGroup.id, - idpId: directoryGroup.idp_id, - directoryId: directoryGroup.directory_id, - organizationId: directoryGroup.organization_id, - name: directoryGroup.name, - createdAt: directoryGroup.created_at, - updatedAt: directoryGroup.updated_at, - rawAttributes: directoryGroup.raw_attributes, - previousAttributes: directoryGroup.previous_attributes, + object: response.object ?? 'directory_group', + id: response.id, + idpId: response.idp_id, + directoryId: response.directory_id, + organizationId: response.organization_id, + name: response.name, + rawAttributes: response.raw_attributes, + createdAt: new Date(response.created_at), + updatedAt: new Date(response.updated_at), }); diff --git a/src/directory-sync/serializers/directory-metadata-user.serializer.ts b/src/directory-sync/serializers/directory-metadata-user.serializer.ts new file mode 100644 index 000000000..72327e406 --- /dev/null +++ b/src/directory-sync/serializers/directory-metadata-user.serializer.ts @@ -0,0 +1,13 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + DirectoryMetadataUser, + DirectoryMetadataUserResponse, +} from '../interfaces/directory-metadata-user.interface'; + +export const deserializeDirectoryMetadataUser = ( + response: DirectoryMetadataUserResponse, +): DirectoryMetadataUser => ({ + active: response.active, + inactive: response.inactive, +}); diff --git a/src/directory-sync/serializers/directory-metadata.serializer.ts b/src/directory-sync/serializers/directory-metadata.serializer.ts new file mode 100644 index 000000000..133545fd8 --- /dev/null +++ b/src/directory-sync/serializers/directory-metadata.serializer.ts @@ -0,0 +1,14 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + DirectoryMetadata, + DirectoryMetadataResponse, +} from '../interfaces/directory-metadata.interface'; +import { deserializeDirectoryMetadataUser } from './directory-metadata-user.serializer'; + +export const deserializeDirectoryMetadata = ( + response: DirectoryMetadataResponse, +): DirectoryMetadata => ({ + users: deserializeDirectoryMetadataUser(response.users), + groups: response.groups, +}); diff --git a/src/directory-sync/serializers/directory-user-with-groups-email.serializer.ts b/src/directory-sync/serializers/directory-user-with-groups-email.serializer.ts new file mode 100644 index 000000000..8adbbe5df --- /dev/null +++ b/src/directory-sync/serializers/directory-user-with-groups-email.serializer.ts @@ -0,0 +1,14 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + DirectoryUserWithGroupsEmail, + DirectoryUserWithGroupsEmailResponse, +} from '../interfaces/directory-user-with-groups-email.interface'; + +export const deserializeDirectoryUserWithGroupsEmail = ( + response: DirectoryUserWithGroupsEmailResponse, +): DirectoryUserWithGroupsEmail => ({ + primary: response.primary, + type: response.type, + value: response.value ?? null, +}); diff --git a/src/directory-sync/serializers/directory-user.serializer.ts b/src/directory-sync/serializers/directory-user.serializer.ts index 0e62698b5..363484e1c 100644 --- a/src/directory-sync/serializers/directory-user.serializer.ts +++ b/src/directory-sync/serializers/directory-user.serializer.ts @@ -27,8 +27,8 @@ export const deserializeDirectoryUser = < state: directoryUser.state, ...(directoryUser.role !== undefined && { role: directoryUser.role }), ...(directoryUser.roles !== undefined && { roles: directoryUser.roles }), - createdAt: directoryUser.created_at, - updatedAt: directoryUser.updated_at, + createdAt: new Date(directoryUser.created_at), + updatedAt: new Date(directoryUser.updated_at), }); export const deserializeDirectoryUserWithGroups = < @@ -56,7 +56,7 @@ export const deserializeUpdatedEventDirectoryUser = ( state: directoryUser.state, ...(directoryUser.role !== undefined && { role: directoryUser.role }), ...(directoryUser.roles !== undefined && { roles: directoryUser.roles }), - createdAt: directoryUser.created_at, - updatedAt: directoryUser.updated_at, + createdAt: new Date(directoryUser.created_at), + updatedAt: new Date(directoryUser.updated_at), previousAttributes: directoryUser.previous_attributes, }); diff --git a/src/directory-sync/serializers/directory.serializer.ts b/src/directory-sync/serializers/directory.serializer.ts index 91eb45ff6..36b8b3f20 100644 --- a/src/directory-sync/serializers/directory.serializer.ts +++ b/src/directory-sync/serializers/directory.serializer.ts @@ -1,65 +1,37 @@ -import { +// This file is auto-generated by oagen. Do not edit. + +import type { Directory, DirectoryResponse, - DirectoryState, - DirectoryStateResponse, - EventDirectory, - EventDirectoryResponse, -} from '../interfaces'; - -export const deserializeDirectory = ( - directory: DirectoryResponse, -): Directory => ({ - object: directory.object, - id: directory.id, - domain: directory.domain, - externalKey: directory.external_key, - name: directory.name, - organizationId: directory.organization_id, - state: deserializeDirectoryState(directory.state), - type: directory.type, - createdAt: directory.created_at, - updatedAt: directory.updated_at, -}); +} from '../interfaces/directory.interface'; +import { deserializeDirectoryMetadata } from './directory-metadata.serializer'; +import type { DirectoryState } from '../interfaces/directory-state.interface'; -export const deserializeDirectoryState = ( - state: DirectoryStateResponse, -): DirectoryState => { - if (state === 'linked') { +const deserializeDirectoryState = (value: string): DirectoryState => { + if (value === 'linked') { return 'active'; } - - if (state === 'unlinked') { + if (value === 'unlinked') { return 'inactive'; } - - return state; + return value as DirectoryState; }; -export const deserializeEventDirectory = ( - directory: EventDirectoryResponse, -): EventDirectory => ({ - object: directory.object, - id: directory.id, - externalKey: directory.external_key, - type: directory.type, - state: directory.state, - name: directory.name, - organizationId: directory.organization_id, - domains: directory.domains, - createdAt: directory.created_at, - updatedAt: directory.updated_at, -}); - -export const deserializeDeletedEventDirectory = ( - directory: Omit, -): Omit => ({ - object: directory.object, - id: directory.id, - type: directory.type, - state: directory.state, - name: directory.name, - organizationId: directory.organization_id, - createdAt: directory.created_at, - updatedAt: directory.updated_at, +export const deserializeDirectory = ( + response: DirectoryResponse, +): Directory => ({ + object: response.object, + id: response.id, + organizationId: response.organization_id, + externalKey: response.external_key, + type: response.type, + state: deserializeDirectoryState(response.state), + name: response.name, + domain: response.domain, + metadata: + response.metadata != null + ? deserializeDirectoryMetadata(response.metadata) + : undefined, + createdAt: new Date(response.created_at), + updatedAt: new Date(response.updated_at), }); diff --git a/src/directory-sync/serializers/event-directory.serializer.ts b/src/directory-sync/serializers/event-directory.serializer.ts new file mode 100644 index 000000000..717a23b0d --- /dev/null +++ b/src/directory-sync/serializers/event-directory.serializer.ts @@ -0,0 +1,42 @@ +import { + DirectoryGroup, + DirectoryGroupResponse, + EventDirectory, + EventDirectoryResponse, +} from '../interfaces'; +import { deserializeDirectoryGroup } from './directory-group.serializer'; + +export const deserializeEventDirectory = ( + directory: EventDirectoryResponse, +): EventDirectory => ({ + object: directory.object, + id: directory.id, + externalKey: directory.external_key, + type: directory.type, + state: directory.state, + name: directory.name, + organizationId: directory.organization_id, + domains: directory.domains, + createdAt: directory.created_at, + updatedAt: directory.updated_at, +}); + +export const deserializeDeletedEventDirectory = ( + directory: Omit, +): Omit => ({ + object: directory.object, + id: directory.id, + type: directory.type, + state: directory.state, + name: directory.name, + organizationId: directory.organization_id, + createdAt: directory.created_at, + updatedAt: directory.updated_at, +}); + +export const deserializeUpdatedEventDirectoryGroup = ( + directoryGroup: DirectoryGroupResponse & Record<'previous_attributes', any>, +): DirectoryGroup & Record<'previousAttributes', any> => ({ + ...deserializeDirectoryGroup(directoryGroup), + previousAttributes: directoryGroup.previous_attributes, +}); diff --git a/src/directory-sync/serializers/index.ts b/src/directory-sync/serializers/index.ts index f0d3d5ca3..68ac82b6c 100644 --- a/src/directory-sync/serializers/index.ts +++ b/src/directory-sync/serializers/index.ts @@ -1,4 +1,10 @@ +// This file is auto-generated by oagen. Do not edit. + +export * from './directory.serializer'; export * from './directory-group.serializer'; +export * from './directory-metadata.serializer'; +export * from './directory-metadata-user.serializer'; export * from './directory-user.serializer'; -export * from './directory.serializer'; -export * from './list-directories-options.serializer'; +export * from './directory-user-with-groups-email.serializer'; +export * from './event-directory.serializer'; +export * from './slim-role.serializer'; diff --git a/src/directory-sync/serializers/list-directories-options.serializer.ts b/src/directory-sync/serializers/list-directories-options.serializer.ts deleted file mode 100644 index f81a98cf7..000000000 --- a/src/directory-sync/serializers/list-directories-options.serializer.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { - ListDirectoriesOptions, - SerializedListDirectoriesOptions, -} from '../interfaces'; - -export const serializeListDirectoriesOptions = ( - options: ListDirectoriesOptions, -): SerializedListDirectoriesOptions => ({ - organization_id: options.organizationId, - search: options.search, - limit: options.limit, - before: options.before, - after: options.after, - order: options.order, -}); diff --git a/src/directory-sync/serializers/slim-role.serializer.ts b/src/directory-sync/serializers/slim-role.serializer.ts new file mode 100644 index 000000000..6281acac9 --- /dev/null +++ b/src/directory-sync/serializers/slim-role.serializer.ts @@ -0,0 +1,14 @@ +// This file is auto-generated by oagen. Do not edit. + +import type { + SlimRole, + SlimRoleResponse, +} from '../interfaces/slim-role.interface'; + +export const deserializeSlimRole = (response: SlimRoleResponse): SlimRole => ({ + slug: response.slug, +}); + +export const serializeSlimRole = (model: SlimRole): SlimRoleResponse => ({ + slug: model.slug, +}); diff --git a/src/events/events.spec.ts b/src/events/events.spec.ts index 2c9a16685..0139aad7b 100644 --- a/src/events/events.spec.ts +++ b/src/events/events.spec.ts @@ -831,8 +831,8 @@ describe('Event', () => { previousAttributes: { role: { slug: 'member' }, }, - createdAt: '2021-10-27 15:21:50.640959', - updatedAt: '2021-12-13 12:15:45.531847', + createdAt: new Date('2021-10-27 15:21:50.640959'), + updatedAt: new Date('2021-12-13 12:15:45.531847'), }, }; diff --git a/src/webhooks/webhooks.spec.ts b/src/webhooks/webhooks.spec.ts index 697975d26..6532cca88 100644 --- a/src/webhooks/webhooks.spec.ts +++ b/src/webhooks/webhooks.spec.ts @@ -43,8 +43,8 @@ describe('Webhook signatures', () => { lastName: 'Lunchford', firstName: 'Blair', directoryId: 'directory_01F9M7F68PZP8QXP8G7X5QRHS7', - createdAt: '2021-06-25T19:07:33.155Z', - updatedAt: '2021-06-25T19:07:33.155Z', + createdAt: new Date('2021-06-25T19:07:33.155Z'), + updatedAt: new Date('2021-06-25T19:07:33.155Z'), rawAttributes: { name: { givenName: 'Blair',