import {z} from 'zod' export type GetApiCompaniesCompanyIdAbsencesArgs = {companyId: string, nextPageToken?: string | undefined, maxResults?: string | undefined, contractId?: string | undefined, status?: string | undefined, beginDate?: string | undefined, endDate?: string | undefined}; export type GetApiCompaniesCompanyIdAbsencesOptions = {baseUrl?: string | undefined, partnerApiOauth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCompaniesCompanyIdAbsencesResponse = z.object({absences: z.array(z.object({id: z.string(), contractId: z.string(), startDate: z.object({date: z.string(), moment: z.enum(["beginning-of-day", "middle-of-day", "end-of-day"])}), endDate: z.object({date: z.string(), moment: z.enum(["beginning-of-day", "middle-of-day", "end-of-day"])}), type: z.enum(["fr_adoption", "fr_conges_payes", "fr_rtt", "fr_absence_remuneree", "fr_repos", "fr_sans_solde", "fr_maladie_ordinaire", "fr_accident_travail", "fr_accident_trajet", "fr_maladie_professionnelle", "fr_temps_partiel_therapeutique", "fr_paternite", "fr_maternite", "fr_second_parent", "fr_pathologique", "fr_naissance", "fr_enfant_malade", "fr_parental_education", "fr_mariage", "fr_deces", "fr_deuil", "fr_mise_a_pied", "fr_activite_partielle", "fr_autre", "fr_ecole", "uk_annual_leave", "uk_maternity", "uk_paternity", "uk_kit", "uk_adoption", "uk_sick_leave", "uk_covid", "uk_paid_leave", "uk_jury_service", "uk_unpaid_leave", "uk_compassionate_leave", "uk_bereavement_leave", "es_vacaciones", "es_visita_medica", "es_asunto_personal", "es_asunto_familiar", "es_cuidado_de_hijos", "es_permisos", "es_compensacion_dias_trabajados", "es_baja_medica", "es_otros", "colleague_leave", "colleague_partial_leave", "colleague_school", "other"]), status: z.enum(["approved", "pending_approval", "declined", "cancelled", "pending_cancellation"])})), meta: z.object({nextPageToken: z.string().nullable().optional(), count: z.number().int().nullable().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 }; /** * List absences 🌍 * * GET /companies/{companyId}/absences */ export const getApiCompaniesCompanyIdAbsences = async (args: GetApiCompaniesCompanyIdAbsencesArgs, options?: GetApiCompaniesCompanyIdAbsencesOptions) => { const {baseUrl = "https://partner-api.payfit.com", fetch: fetchFn = fetch, partnerApiOauth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.nextPageToken != null) query.append("nextPageToken", String(args.nextPageToken)) if (args.maxResults != null) query.append("maxResults", String(args.maxResults)) if (args.contractId != null) query.append("contractId", String(args.contractId)) if (args.status != null) query.append("status", String(args.status)) if (args.beginDate != null) query.append("beginDate", String(args.beginDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (partnerApiOauth !== undefined) headers.set('authorization', `Bearer ${partnerApiOauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/companies/${encodeURIComponent(String(args.companyId))}/absences${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiCompaniesCompanyIdAbsencesResponse, await res.json()) };