diff --git a/packages/sdk/src/modules/dashboard/dashboard.sdk.ts b/packages/sdk/src/modules/dashboard/dashboard.sdk.ts index bb3e7b06..b0af4d3b 100644 --- a/packages/sdk/src/modules/dashboard/dashboard.sdk.ts +++ b/packages/sdk/src/modules/dashboard/dashboard.sdk.ts @@ -11,12 +11,15 @@ import { ProjectsEmbeddingsSdk } from './projects-embeddings'; import { ProjectsFilesSdk } from './projects-files'; import { S3BucketsSdk } from './s3-buckets'; import { UsersSdk } from './users'; +import { UsersGroupsSdk } from './users-groups'; export class DashboardSdk { public readonly organizations = new OrganizationsSdk(this.config); public readonly users = new UsersSdk(this.config); + public readonly usersGroups = new UsersGroupsSdk(this.config); + public readonly projects = new ProjectsSdk(this.config); public readonly projectsFiles = new ProjectsFilesSdk(this.config); diff --git a/packages/sdk/src/modules/dashboard/index.ts b/packages/sdk/src/modules/dashboard/index.ts index 4af60162..b2d25ebc 100644 --- a/packages/sdk/src/modules/dashboard/index.ts +++ b/packages/sdk/src/modules/dashboard/index.ts @@ -13,3 +13,4 @@ export * from './projects-policies'; export * from './s3-buckets'; export * from './s3-files'; export * from './users'; +export * from './users-groups'; diff --git a/packages/sdk/src/modules/dashboard/users-groups/dto/index.ts b/packages/sdk/src/modules/dashboard/users-groups/dto/index.ts new file mode 100644 index 00000000..0abbc803 --- /dev/null +++ b/packages/sdk/src/modules/dashboard/users-groups/dto/index.ts @@ -0,0 +1,4 @@ +export * from './sdk-create-users-group.dto'; +export * from './sdk-search-users-groups.dto'; +export * from './sdk-update-users-group.dto'; +export * from './sdk-users-group.dto'; diff --git a/packages/sdk/src/modules/dashboard/users-groups/dto/sdk-create-users-group.dto.ts b/packages/sdk/src/modules/dashboard/users-groups/dto/sdk-create-users-group.dto.ts new file mode 100644 index 00000000..c2102974 --- /dev/null +++ b/packages/sdk/src/modules/dashboard/users-groups/dto/sdk-create-users-group.dto.ts @@ -0,0 +1,24 @@ +import { z } from 'zod'; + +import { SdkTableRowWithIdV, ZodOmitArchivedFields, ZodOmitDateFields } from '~/shared'; + +import { SdkUsersGroupV } from './sdk-users-group.dto'; + +export const SdkCreateUsersGroupInputV = SdkUsersGroupV + .omit({ + ...ZodOmitDateFields, + ...ZodOmitArchivedFields, + id: true, + organization: true, + creator: true, + }) + .extend({ + organization: SdkTableRowWithIdV, + users: z.array(SdkTableRowWithIdV), + }); + +export type SdkCreateUsersGroupInputT = z.infer; + +export const SdkCreateUsersGroupOutputV = SdkTableRowWithIdV; + +export type SdkCreateUsersGroupOutputT = z.infer; diff --git a/packages/sdk/src/modules/dashboard/users-groups/dto/sdk-search-users-groups.dto.ts b/packages/sdk/src/modules/dashboard/users-groups/dto/sdk-search-users-groups.dto.ts new file mode 100644 index 00000000..d3341d70 --- /dev/null +++ b/packages/sdk/src/modules/dashboard/users-groups/dto/sdk-search-users-groups.dto.ts @@ -0,0 +1,34 @@ +import type { z } from 'zod'; + +import { + SdkArchivedFiltersInputV, + SdkDefaultSortInputV, + SdkExcludeIdsFiltersInputV, + SdkFilteredPhraseInputV, + SdkIdsArrayV, + SdkIdsFiltersInputV, + SdkOffsetPaginationInputV, + SdkOffsetPaginationOutputV, +} from '~/shared'; + +import { SdkUsersGroupV } from './sdk-users-group.dto'; + +export const SdkSearchUsersGroupItemV = SdkUsersGroupV; + +export type SdkSearchUsersGroupItemT = z.infer; + +export const SdKSearchUsersGroupsInputV = SdkOffsetPaginationInputV + .extend({ + organizationIds: SdkIdsArrayV.optional(), + }) + .merge(SdkDefaultSortInputV) + .merge(SdkArchivedFiltersInputV) + .merge(SdkIdsFiltersInputV) + .merge(SdkExcludeIdsFiltersInputV) + .merge(SdkFilteredPhraseInputV); + +export type SdKSearchUsersGroupsInputT = z.infer; + +export const SdKSearchUsersGroupsOutputV = SdkOffsetPaginationOutputV(SdkSearchUsersGroupItemV); + +export type SdkSearchUsersGroupsOutputT = z.infer; diff --git a/packages/sdk/src/modules/dashboard/users-groups/dto/sdk-update-users-group.dto.ts b/packages/sdk/src/modules/dashboard/users-groups/dto/sdk-update-users-group.dto.ts new file mode 100644 index 00000000..befb3980 --- /dev/null +++ b/packages/sdk/src/modules/dashboard/users-groups/dto/sdk-update-users-group.dto.ts @@ -0,0 +1,19 @@ +import type { z } from 'zod'; + +import { SdkTableRowWithIdV, ZodOmitArchivedFields, ZodOmitDateFields } from '~/shared'; + +import { SdkUsersGroupV } from './sdk-users-group.dto'; + +export const SdkUpdateUsersGroupInputV = SdkUsersGroupV.omit({ + ...ZodOmitDateFields, + ...ZodOmitArchivedFields, + id: true, + organization: true, + creator: true, +}); + +export type SdkUpdateUsersGroupInputT = z.infer; + +export const SdkUpdateUsersGroupOutputV = SdkTableRowWithIdV; + +export type SdkUpdateUsersGroupOutputT = z.infer; diff --git a/packages/sdk/src/modules/dashboard/users-groups/dto/sdk-users-group.dto.ts b/packages/sdk/src/modules/dashboard/users-groups/dto/sdk-users-group.dto.ts new file mode 100644 index 00000000..7645c4d7 --- /dev/null +++ b/packages/sdk/src/modules/dashboard/users-groups/dto/sdk-users-group.dto.ts @@ -0,0 +1,21 @@ +import { z } from 'zod'; + +import { + SdkIdNameUrlEntryV, + SdkTableRowWithArchivedV, + SdkTableRowWithDatesV, + SdkTableRowWithIdNameV, +} from '~/shared'; + +import { SdkUserListItemV } from '../../users/dto/sdk-user-list-item.dto'; + +export const SdkUsersGroupV = z.strictObject({ + organization: SdkIdNameUrlEntryV, + creator: SdkUserListItemV, + users: z.array(SdkUserListItemV), +}) + .merge(SdkTableRowWithIdNameV) + .merge(SdkTableRowWithDatesV) + .merge(SdkTableRowWithArchivedV); + +export type SdkUsersGroupT = z.infer; diff --git a/packages/sdk/src/modules/dashboard/users-groups/index.ts b/packages/sdk/src/modules/dashboard/users-groups/index.ts new file mode 100644 index 00000000..10eac77c --- /dev/null +++ b/packages/sdk/src/modules/dashboard/users-groups/index.ts @@ -0,0 +1,2 @@ +export * from './dto'; +export * from './users-groups.sdk'; diff --git a/packages/sdk/src/modules/dashboard/users-groups/users-groups.sdk.ts b/packages/sdk/src/modules/dashboard/users-groups/users-groups.sdk.ts new file mode 100644 index 00000000..6544e0c8 --- /dev/null +++ b/packages/sdk/src/modules/dashboard/users-groups/users-groups.sdk.ts @@ -0,0 +1,64 @@ +import { AbstractNestedSdkWithAuth } from '~/modules/abstract-nested-sdk-with-auth'; +import { + getPayload, + patchPayload, + postPayload, + putPayload, + type SdkRecordAlreadyExistsError, + type SdkRecordNotFoundError, + type SdkTableRowIdT, + type SdkTableRowWithIdT, +} from '~/shared'; + +import type { + SdkCreateUsersGroupInputT, + SdkCreateUsersGroupOutputT, + SdKSearchUsersGroupsInputT, + SdkSearchUsersGroupsOutputT, + SdkUpdateUsersGroupInputT, + SdkUpdateUsersGroupOutputT, +} from './dto'; + +export class UsersGroupsSdk extends AbstractNestedSdkWithAuth { + protected endpointPrefix = '/dashboard/users/groups'; + + search = (data: SdKSearchUsersGroupsInputT) => + this.fetch({ + url: this.endpoint('/search'), + query: data, + options: getPayload(), + }); + + create = (data: SdkCreateUsersGroupInputT) => + this.fetch({ + url: this.endpoint('/'), + options: postPayload(data), + }); + + unarchive = (id: SdkTableRowIdT) => + this.fetch< + SdkTableRowWithIdT, + SdkRecordNotFoundError | SdkRecordAlreadyExistsError + >({ + url: this.endpoint(`/unarchive/${id}`), + options: patchPayload({}), + }); + + archive = (id: SdkTableRowIdT) => + this.fetch< + SdkTableRowWithIdT, + SdkRecordNotFoundError | SdkRecordAlreadyExistsError + >({ + url: this.endpoint(`/archive/${id}`), + options: patchPayload({}), + }); + + update = ({ id, ...data }: SdkUpdateUsersGroupInputT & SdkTableRowWithIdT) => + this.fetch< + SdkUpdateUsersGroupOutputT, + SdkRecordAlreadyExistsError | SdkRecordNotFoundError + >({ + url: this.endpoint(`/${id}`), + options: putPayload(data), + }); +};