import {z} from 'zod' export type CompanySearchRequestPublicApiDto = {companyName?: string | undefined, country?: string | undefined, number?: string | undefined, sourceId?: string | undefined, state?: string | undefined}; export type CreateApiResourcesApiCompaniesApplicantIdSearchArgs = {applicantId: string, offset?: number | undefined, limit?: number | undefined, body: CompanySearchRequestPublicApiDto}; export type CreateApiResourcesApiCompaniesApplicantIdSearchOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const entityResultError = z.string(); export const companySearchItemPublicApiDto = z.object({address: z.string().optional(), companyName: z.string().optional(), country: z.string().optional(), id: z.string().optional(), registrationNumber: z.string().optional(), state: z.string().optional()}); export const entityPageInfo = z.object({limit: z.number().int().optional(), offset: z.number().int().optional()}); export const entityListCompanySearchItemPublicApiDto = z.object({error: entityResultError.optional(), items: z.array(companySearchItemPublicApiDto).optional(), pageInfo: entityPageInfo.optional(), totalItems: z.number().int().optional()}); export const entityResultCompanySearchItemPublicApiDto = z.object({list: entityListCompanySearchItemPublicApiDto}); 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 }; /** * POST /resources/api/companies/{applicantId}/search */ export const createApiResourcesApiCompaniesApplicantIdSearch = async (args: CreateApiResourcesApiCompaniesApplicantIdSearchArgs, options: CreateApiResourcesApiCompaniesApplicantIdSearchOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) const url = `${baseUrl.replace(/\/+$/, '')}/resources/api/companies/${encodeURIComponent(String(args.applicantId))}/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(entityResultCompanySearchItemPublicApiDto, await res.json()) };