import {z} from 'zod' export type CreateApiApiV1EmployeesSyncArgs = {body: {integrationId: string, forceCreate?: boolean | undefined, fullName: string, socialName?: string | undefined, status: 'active' | 'terminated' | 'on-hold', workEmail?: string | undefined, personalEmail?: string | undefined, workPhoneNumber?: string | undefined, personalPhoneNumber?: string | undefined, cpf?: string | undefined, position?: string | undefined, area?: string | undefined, managerFullName?: string | undefined, birthDate?: string | undefined, admittedAt?: string | undefined, terminatedAt?: string | undefined, address?: ({zipCode?: string | undefined, streetName?: string | undefined, streetNumber?: string | undefined, complement?: string | undefined, neighborhood?: string | undefined, city?: string | undefined, state?: string | undefined, country?: string | undefined}) | undefined}}; export type CreateApiApiV1EmployeesSyncOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1EmployeesSyncResponse = z.object({id: z.string(), fullName: z.string(), socialName: z.string().nullable(), status: z.enum(["active", "terminated", "on-hold"]), workEmail: z.string().nullable(), personalEmail: z.string().nullable(), workPhoneNumber: z.string().nullable(), personalPhoneNumber: z.string().nullable(), cpf: z.string().nullable(), cnpj: z.string().nullable(), rg: z.string().nullable(), position: z.string().nullable(), area: z.string().nullable(), managerFullName: z.string().nullable(), birthDate: z.string().nullable(), contractType: z.enum(["pj", "clt", "intern", "apprentice", "temporary", "third-party"]).nullable(), contractEndDate: z.string().nullable(), admittedAt: z.string().nullable(), terminatedAt: z.string().nullable(), address: z.object({zipCode: z.string().nullable(), streetName: z.string().nullable(), streetNumber: z.string().nullable(), complement: z.string().nullable(), neighborhood: z.string().nullable(), city: z.string().nullable(), state: z.string().nullable(), country: z.string().nullable()}).nullable(), customFields: z.array(z.object({label: z.string(), type: z.enum(["text", "select"]), value: z.string()})), bankAccount: z.object({bank: z.string().nullable(), branch: z.string().nullable(), accountNumber: z.string().nullable(), accountType: z.enum(["checking", "savings", "salary", "payment"]).nullable(), pixKey: z.string().nullable()}).nullable(), salaryCents: z.number().nullable(), sources: z.array(z.union([z.object({id: z.literal("manual"), platform: z.literal("manual")}), z.object({id: z.string(), platform: z.literal("sheets")}), z.object({id: z.string(), platform: z.string()})])), createdAt: z.string()}); 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 }; /** * Cria ou atualiza um colaborador. * * POST /api/v1/employees/sync */ export const createApiApiV1EmployeesSync = async (args: CreateApiApiV1EmployeesSyncArgs, options?: CreateApiApiV1EmployeesSyncOptions) => { const {baseUrl = "https://api.salvy.com.br", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/employees/sync${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(createApiApiV1EmployeesSyncResponse, await res.json()) };