import {z} from 'zod' export type GetApiCompaniesCompanyIdContractsFrContractIdArgs = {companyId: string, contractId: string}; export type GetApiCompaniesCompanyIdContractsFrContractIdOptions = {baseUrl?: string | undefined, partnerApiOauth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCompaniesCompanyIdContractsFrContractIdResponse = z.object({standardWeeklyHours: z.number().nullable(), fullTimeEquivalent: z.number().nullable(), isFullTime: z.boolean().nullable(), contractId: z.string(), companyId: z.string(), startDate: z.string().nullable(), endDate: z.string().nullable().optional(), probationEndDate: z.string().nullable().optional(), jobName: z.string().nullable(), status: z.enum(["ACTIVE", "ARCHIVED", "PENDING"]), collaboratorId: z.string(), natureContratDsn: z.enum(["01", "02", "03", "07", "08", "09", "10", "20", "21", "29", "32", "50", "51", "52", "53", "60", "70", "80", "81", "82", "89", "90", "91", "92", "93", "null"]).nullable(), motifRuptureDeContratDsn: z.enum(["011", "012", "014", "015", "020", "025", "026", "031", "032", "033", "034", "035", "036", "037", "038", "039", "040", "043", "058", "059", "065", "066", "070", "071", "081", "082", "083", "084", "085", "086", "087", "088", "089", "091", "092", "093", "094", "095", "096", "097", "098", "099", "100", "110", "111", "112", "113", "114", "115", "116", "998", "999", "null"]).nullable(), statutConventionnelDsn: z.enum(["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "null"]).nullable(), idcc: z.string().nullable(), healthInsuranceContractIds: z.array(z.string()).nullable(), providentFundContractIds: z.array(z.string()).nullable(), estCadreDirigeant: z.boolean(), workingTimeModality: z.enum(["standard", "forfait_heures", "forfait_jours", "forfait_annuel_en_heures", "forfait_sans_reference_horaire", "null"]).nullable()}); 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 }; /** * Get a contract 🇫🇷 * * GET /companies/{companyId}/contracts-fr/{contractId} */ export const getApiCompaniesCompanyIdContractsFrContractId = async (args: GetApiCompaniesCompanyIdContractsFrContractIdArgs, options?: GetApiCompaniesCompanyIdContractsFrContractIdOptions) => { 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 (partnerApiOauth !== undefined) headers.set('authorization', `Bearer ${partnerApiOauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/companies/${encodeURIComponent(String(args.companyId))}/contracts-fr/${encodeURIComponent(String(args.contractId))}${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(getApiCompaniesCompanyIdContractsFrContractIdResponse, await res.json()) };