import {z} from 'zod' export type ProjectGroupStatus = 'active' | 'closed'; export type CreateApiPublicV1ProjectGroupsCompanyIdSearchArgs = {company_id: string, body: {page?: number | undefined, page_size?: number | undefined, sort_by?: ('name' | 'status' | 'project_developer' | 'protocol' | 'country') | undefined, sort_direction?: ('asc' | 'desc') | undefined, filter?: ({name?: string | undefined, status?: ProjectGroupStatus | undefined, project_developer?: string | undefined, protocol?: string | undefined, country?: string | undefined}) | undefined}}; export type CreateApiPublicV1ProjectGroupsCompanyIdSearchOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const projectGroupStatus = z.enum(["active", "closed"]); export const projectGroupPublic = z.object({name: z.string().max(100).optional(), status: projectGroupStatus.optional(), project_developer: z.string().max(256).optional(), start_date: z.string().optional(), end_date: z.string().optional(), protocol: z.string().max(256).optional(), country: z.string().max(256).optional(), id: z.string().optional()}); export const createApiPublicV1ProjectGroupsCompanyIdSearchResponse = z.object({page_number: z.number().optional(), page_size: z.number().optional(), total_entries: z.number().optional(), total_pages: z.number().optional(), data: z.array(projectGroupPublic).optional()}); 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 }; /** * Public search and list ledger entries * * POST /public/v1/project_groups/{company_id}/search */ export const createApiPublicV1ProjectGroupsCompanyIdSearch = async (args: CreateApiPublicV1ProjectGroupsCompanyIdSearchArgs, options?: CreateApiPublicV1ProjectGroupsCompanyIdSearchOptions) => { const {baseUrl = "https://api.validere.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/public/v1/project_groups/${encodeURIComponent(String(args.company_id))}/search${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiPublicV1ProjectGroupsCompanyIdSearchResponse, await res.json()) };