import {z} from 'zod' export type ActionType = 'add' | 'create' | 'edit' | 'delete' | 'clone'; export type ConfigLevel = 'main' | 'global' | 'repository' | 'directory'; export type GetApiUserLogCodeReviewSettingsArgs = {page?: number | undefined, limit?: number | undefined, skip?: number | undefined, teamId?: string | undefined, action?: ActionType | undefined, configLevel?: ConfigLevel | undefined, userId?: string | undefined, userEmail?: string | undefined, repositoryId?: string | undefined, startDate?: string | undefined, endDate?: string | undefined}; export type GetApiUserLogCodeReviewSettingsOptions = {baseUrl?: string | undefined, jwt?: string | undefined, fetch?: typeof fetch | undefined}; export const codeReviewSettingsLogUserInfoDto = z.object({userId: z.string(), userEmail: z.string()}); export const codeReviewSettingsLogRepositoryDto = z.object({id: z.string(), name: z.string().optional()}); export const codeReviewSettingsLogDirectoryDto = z.object({id: z.object({}).optional(), path: z.object({}).optional()}); export const codeReviewSettingsLogChangeDto = z.object({actionDescription: z.string(), previousValue: z.record(z.string(), z.unknown()).optional(), currentValue: z.record(z.string(), z.unknown()).optional(), description: z.string().optional()}); export const codeReviewSettingsLogEntryDto = z.object({_uuid: z.string(), _organizationId: z.string(), _teamId: z.string().optional(), _action: z.string(), _configLevel: z.string(), _userInfo: codeReviewSettingsLogUserInfoDto, _repository: codeReviewSettingsLogRepositoryDto.optional(), _directory: codeReviewSettingsLogDirectoryDto.optional(), _changedData: z.array(codeReviewSettingsLogChangeDto), _createdAt: z.string(), _updatedAt: z.string()}); export const codeReviewSettingsLogDataDto = z.object({logs: z.array(codeReviewSettingsLogEntryDto), total: z.number(), page: z.number(), limit: z.number(), totalPages: z.number()}); export const codeReviewSettingsLogResponseDto = z.object({statusCode: z.number(), type: z.string(), data: codeReviewSettingsLogDataDto}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List code review settings logs * * GET /user-log/code-review-settings */ export const getApiUserLogCodeReviewSettings = async (args: GetApiUserLogCodeReviewSettingsArgs, options?: GetApiUserLogCodeReviewSettingsOptions) => { const {baseUrl = "http://localhost:3001", fetch: fetchFn = fetch, jwt} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.skip != null) query.append("skip", String(args.skip)) if (args.teamId != null) query.append("teamId", String(args.teamId)) if (args.action != null) query.append("action", String(args.action)) if (args.configLevel != null) query.append("configLevel", String(args.configLevel)) if (args.userId != null) query.append("userId", String(args.userId)) if (args.userEmail != null) query.append("userEmail", String(args.userEmail)) if (args.repositoryId != null) query.append("repositoryId", String(args.repositoryId)) if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (jwt !== undefined) headers.set('authorization', `Bearer ${jwt}`) const url = `${baseUrl.replace(/\/+$/, '')}/user-log/code-review-settings${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(codeReviewSettingsLogResponseDto, await res.json()) };