import {z} from 'zod' export type Partner = number; export type BusinessUnit = number; export type Nationality = 'BRASILEIRO' | 'ESTRANGEIRO'; export type BirthState = '0 - AC' | '1 - AL' | '2 - AP' | '3 - AM' | '4 - BA' | '5 - CE' | '6 - DF' | '7 - ES' | '8 - GO' | '9 - MA' | '10 - MT' | '11 - MS' | '12 - MG' | '13 - PA' | '14 - PB' | '15 - PR' | '16 - PE' | '17 - PI' | '18 - RJ' | '19 - RN' | '20 - RS' | '21 - RO' | '22 - RR' | '23 - SC' | '24 - SP' | '25 - SE' | '26 - TO'; export type MonthlyIncome = string; export type CompanyType = number; export type CompanyActivity = string; export type ConstitutionDate = string; export type AddressLine = string; export type AddressLine2 = string; export type ZipCode = string; export type Neighborhood = string; export type CityCode = number; export type CityName = string; export type State = 'AC' | 'AL' | 'AP' | 'AM' | 'BA' | 'CE' | 'DF' | 'ES' | 'GO' | 'MA' | 'MT' | 'MS' | 'MG' | 'PA' | 'PB' | 'PR' | 'PE' | 'PI' | 'RJ' | 'RN' | 'RS' | 'RO' | 'RR' | 'SC' | 'SP' | 'SE' | 'TO'; export type AddressType = number; export type Country = string; export type Complement = string; export type Reference = {name: string, phone: string}; export type AddressesUpdatePersonData = Array<{AddressLine?: AddressLine | undefined, AddressLine2?: AddressLine2 | undefined, ZipCode: ZipCode, Neighborhood?: Neighborhood | undefined, CityCode?: CityCode | undefined, CityName?: CityName | undefined, State: State, AddressType?: AddressType | undefined, Country?: Country | undefined, Complement?: Complement | undefined, Reference?: Reference | undefined}>; export type DocumentFile = string; export type DocumentFormat = number | null; export type DocumentName = string; export type DocumentType = 'SELF' | 'IDENTITY_FRONT' | 'IDENTITY_BACK' | 'ADDRESS_PROOF' | 'INCOME_PROOF' | 'DECLARATION_IR' | 'CORPORATE_BILLING_RELATIONSHIP' | 'PROOF_OF_COMPANY_ADDRESS' | 'SOCIAL_CONTRACT' | 'PROOF_OF_CORPORATE_INCOME'; export type Description = string; export type ExpirationDate = string; export type DocumentsUpdatePersonData = Array<{DocumentFile: DocumentFile, DocumentFormat: DocumentFormat, DocumentName: DocumentName, DocumentType: DocumentType, Description: Description, ExpirationDate?: ExpirationDate | undefined}>; export type Name = string; export type TaxNumber = string; export type Mail = string; export type PhoneNumber = string; export type MotherFullName = string; export type BirthDate = string; export type Nickname = string; export type PersonName = string; export type FatherFullName = string; export type BirthCity = string; export type Gender = 'FEMININO' | 'MASCULINO'; export type MaritalStatus = 'NotMarried = 0' | 'Married = 1' | 'Divorced = 2' | 'Separate = 3' | 'Widower = 4' | 'Single = 5' | 'Other = 6'; export type SpouseName = string; export type IdentityDocument = number; export type Occupation = 'APOSENTADO_PENSIONISTA' | 'AUTONOMO' | 'EMPRESARIO' | 'PROFISSIONAL_LIBERAL' | 'ASSALARIADO' | 'FUNCIONARIO_PUBLICO' | 'DESEMPREGADO'; export type PersonRoleType = number; export type CheckPendingTransfers = boolean | null; export type PubliclyExposedPerson = boolean; export type PersonsUpdatePersonData = Array<{Name: Name, TaxNumber: TaxNumber, Mail: Mail, PhoneNumber: PhoneNumber, MotherFullName?: MotherFullName | undefined, Nationality: Nationality, BirthDate: BirthDate, BirthState: BirthState, Nickname?: Nickname | undefined, PersonName?: PersonName | undefined, FatherFullName?: FatherFullName | undefined, BirthCity?: BirthCity | undefined, Gender?: Gender | undefined, MaritalStatus?: MaritalStatus | undefined, SpouseName?: SpouseName | undefined, IdentityDocument?: IdentityDocument | undefined, Occupation?: Occupation | undefined, PersonRoleType?: PersonRoleType | undefined, CheckPendingTransfers?: CheckPendingTransfers | undefined, PubliclyExposedPerson: PubliclyExposedPerson, PersonDocuments: DocumentsUpdatePersonData}>; export type CreateApiUpdatePersonDataCompanyPersonArgs = {body: {Method: string, PartnerId: Partner, BusinessUnitId: BusinessUnit, PersonName: string, Nickname?: string | undefined, PhoneNumber: string, TaxNumber: string, Mail: string, Nationality: Nationality, BirthState: BirthState, IsCompany?: (boolean | null) | undefined, MonthlyIncome?: MonthlyIncome | undefined, CompanyType?: CompanyType | undefined, CompanyActivity?: CompanyActivity | undefined, ConstitutionDate: ConstitutionDate, WasSigned: boolean, SignatureDate: string, Addresses?: AddressesUpdatePersonData | undefined, Documents: DocumentsUpdatePersonData, Persons?: PersonsUpdatePersonData | undefined}}; export type CreateApiUpdatePersonDataCompanyPersonOptions = {baseUrl?: string | undefined, BASE64UsernamePassword?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const updatePersonDataSuccess = z.object({Success: z.string().optional(), Message: z.string().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 }; /** * Update Person Data for Companies * * POST / UpdatePersonData (Company Person) */ export const createApiUpdatePersonDataCompanyPerson = async (args: CreateApiUpdatePersonDataCompanyPersonArgs, options?: CreateApiUpdatePersonDataCompanyPersonOptions) => { const {baseUrl = "https://sandboxapi.fitbank.com.br/main/execute", fetch: fetchFn = fetch, BASE64UsernamePassword} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BASE64UsernamePassword !== undefined) headers.set('authorization', `Basic ${btoa(`${BASE64UsernamePassword.username}:${BASE64UsernamePassword.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/ UpdatePersonData (Company Person)${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(updatePersonDataSuccess, await res.json()) };