import {z} from 'zod' export type GetApiCompaniesCompanyIdContractsFrArgs = {companyId: string, nextPageToken?: string | undefined, maxResults?: string | undefined, fields?: Array<'securite-sociale'> | undefined, includeInProgressContracts?: string | undefined}; export type GetApiCompaniesCompanyIdContractsFrOptions = {baseUrl?: string | undefined, partnerApiOauth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCompaniesCompanyIdContractsFrResponse = z.object({contracts: z.array(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(), firstName: z.string(), lastName: z.string(), birthName: z.string(), birthDate: z.string().nullable(), contactEmail: z.string().nullable().optional(), address: z.string().nullable().optional(), city: z.string().nullable().optional(), postalCode: z.string().nullable().optional(), 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(), numeroTechniqueTemporaire: z.string().nullable(), numeroSecuriteSociale: z.string().nullable()})).optional(), 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 all Contracts 🇫🇷 * * GET /companies/{companyId}/contracts-fr */ export const getApiCompaniesCompanyIdContractsFr = async (args: GetApiCompaniesCompanyIdContractsFrArgs, options?: GetApiCompaniesCompanyIdContractsFrOptions) => { 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)) for (const item of args.fields ?? []) query.append("fields", String(item)) if (args.includeInProgressContracts != null) query.append("includeInProgressContracts", String(args.includeInProgressContracts)) if (partnerApiOauth !== undefined) headers.set('authorization', `Bearer ${partnerApiOauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/companies/${encodeURIComponent(String(args.companyId))}/contracts-fr${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(getApiCompaniesCompanyIdContractsFrResponse, await res.json()) };