import {z} from 'zod' export type CreateApiCompaniesCompanyIdAbsencesArgs = {companyId: string, body: {contractId: string, type: 'fr_conges_payes' | 'fr_rtt' | 'fr_repos' | 'fr_sans_solde' | 'fr_teletravail' | 'fr_ecole' | 'fr_maladie_ordinaire' | 'fr_mariage_salarie' | 'fr_pacs_salarie' | 'fr_mariage_enfant' | 'fr_mariage_frere_ou_soeur' | 'fr_mariage_beau_frere_ou_belle_soeur' | 'fr_mariage_ascendant' | 'fr_mariage_petit_enfant' | 'fr_deces_beau_pere_ou_belle_mere' | 'fr_deces_conjoint' | 'fr_deces_enfant' | 'fr_deces_frere_ou_soeur' | 'fr_deces_grand_parent' | 'fr_deces_pere_ou_mere' | 'fr_deces_beau_frere_ou_belle_soeur' | 'fr_deces_gendre_ou_belle_fille' | 'fr_deces_petit_enfant' | 'fr_demenagement' | 'fr_echographie_prenatale' | 'fr_conjoint_malade_ou_hospitalise' | 'fr_handicap_enfant' | 'fr_examen_professionnel_formation_continue' | 'fr_appel_preparation_defense' | 'fr_ceremonie_enfant_communion_solennelle' | 'fr_demarches_adoption' | 'es_huelga' | 'es_permiso_por_convenio_no_remunerado' | 'es_permiso_parental' | 'es_vacaciones' | 'es_teletrabajo' | 'es_descanso_horas_extras' | 'es_descanso_por_festivo_trabajado' | 'es_visita_medica' | 'es_permiso_por_matrimonio' | 'es_deber_inexcusable' | 'es_examenes_prenatales' | 'es_tecnicas_de_preparacion_al_parto' | 'es_adopcion' | 'es_mudanza' | 'es_permiso_por_examenes' | 'es_permiso_por_formacion' | 'es_asuntos_propios' | 'es_jornada_de_licencia' | 'es_lactancia_acumulada' | 'es_prematuros_hospitalizados' | 'es_permiso_especial_fuerza_mayor' | 'es_otro_asunto_personal' | 'es_fallecimiento_pariente_de_primer_grado_de_consanguinidad' | 'es_fallecimiento_pariente_de_segundo_grado_de_consanguinidad' | 'es_hospitalizacion_de_un_familiar' | 'es_intervencion_quirurgica_sin_hospitalizacion' | 'es_accidente_o_enfermedad_grave' | 'es_permiso_asistencia_a_matrimonio' | 'es_fallecimiento_pariente_de_tercer_grado_de_consanguinidad' | 'es_otro_asunto_familiar' | 'es_permiso_por_horas' | 'uk_annual_leave' | 'uk_remote' | 'uk_sick_leave' | 'uk_unpaid_leave' | 'uk_compassionate_leave' | 'uk_custom_leave_1' | 'uk_custom_leave_2' | 'uk_custom_leave_3' | 'uk_custom_leave_4' | 'uk_custom_leave_5', startDate: {date: string, moment: 'beginning-of-day' | 'middle-of-day' | 'end-of-day'}, endDate: {date: string, moment: 'beginning-of-day' | 'middle-of-day' | 'end-of-day'}}}; export type CreateApiCompaniesCompanyIdAbsencesOptions = {baseUrl?: string | undefined, partnerApiOauth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiCompaniesCompanyIdAbsencesResponse = z.object({id: 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 }; /** * Create a validated absence 🌍 * * POST /companies/{companyId}/absences */ export const createApiCompaniesCompanyIdAbsences = async (args: CreateApiCompaniesCompanyIdAbsencesArgs, options?: CreateApiCompaniesCompanyIdAbsencesOptions) => { const {baseUrl = "https://partner-api.payfit.com", fetch: fetchFn = fetch, partnerApiOauth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") 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: "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(createApiCompaniesCompanyIdAbsencesResponse, await res.json()) };