import {z} from 'zod' export type CreateApiClientsOnboardingIdPartnersPeopleArgs = {onboarding_id: string, body: {name: string, email: string, birthDate: string, maritalStatus: string, phone: string, documentNumber: string, identityDocumentNumber: string, identityDocumentIssuingAgency?: string | undefined, identityDocument: {filename: string, content: string}, nationality: string, address: {street: string, number: string, complement?: string | undefined, neighborhood: string, city: string, state: string, country: string, zipCode: string, proof?: {filename: string, content: string} | undefined}, parentCompanyId?: string | undefined, shareCapital?: number | undefined, sharePercent: number, administrator?: ('True' | 'False') | undefined, representation?: ('in_isolation' | 'together') | undefined, subscriberKind?: ('Required' | 'Participate' | 'Dont_subscribe') | undefined, pep?: ({name?: string | undefined, documentNumber?: string | undefined, role?: string | undefined, kind?: string | undefined}) | undefined, extraAttachments?: Array<{filename: string, content: string}> | undefined}}; export type CreateApiClientsOnboardingIdPartnersPeopleOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, sec1?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiClientsOnboardingIdPartnersPeopleResponse = z.object({data: z.object({id: z.string().optional(), type: z.string().optional(), attributes: z.object({documentNumber: z.string().optional(), parentCompanyId: z.string().optional(), name: z.string().optional(), birthDate: z.string().optional(), nationality: z.string().optional(), identityDocumentNumber: z.string().optional(), identityDocumentIssuingAgency: z.string().optional(), maritalStatus: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), shareCapital: z.string().optional(), sharePercent: z.string().optional(), administrator: z.boolean().optional(), representation: z.string().optional(), subscriberKind: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), identityDocument: z.object({data: z.object({id: z.string().optional(), type: z.string().optional(), attributes: z.object({filename: z.string().optional(), content: z.string().optional()}).optional()}).optional()}).optional(), extraAttachments: z.unknown(), pep: z.object({data: z.object({id: z.unknown(), type: z.string().optional(), attributes: z.object({kind: z.string().optional(), role: z.unknown(), documentNumber: z.unknown(), name: z.unknown()}).optional()}).optional()}).optional(), address: z.object({data: z.object({id: z.unknown(), type: z.string().optional(), attributes: z.object({zipCode: z.string().optional(), street: z.string().optional(), number: z.string().optional(), complement: z.string().optional(), country: z.string().optional(), state: z.string().optional(), city: z.string().optional(), neighborhood: z.string().optional()}).optional()}).optional()}).optional()}).optional()}).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 }; /** * Criar sócio - PF * * POST /clients/{onboarding_id}/partners/people */ export const createApiClientsOnboardingIdPartnersPeople = async (args: CreateApiClientsOnboardingIdPartnersPeopleArgs, options?: CreateApiClientsOnboardingIdPartnersPeopleOptions) => { const {baseUrl = "https://pagamentos.grafeno.be/api/v2", fetch: fetchFn = fetch, sec0, sec1} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set('authorization', `Basic ${btoa(`${sec0.username}:${sec0.password}`)}`) if (sec1 !== undefined) headers.set("Authorization", sec1) const url = `${baseUrl.replace(/\/+$/, '')}/clients/${encodeURIComponent(String(args.onboarding_id))}/partners/people${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(createApiClientsOnboardingIdPartnersPeopleResponse, await res.json()) };