import {z} from 'zod' export type GetApiCompaniesCompanyIdCollaboratorsArgs = {companyId: string, nextPageToken?: string | undefined, maxResults?: string | undefined, email?: string | undefined}; export type GetApiCompaniesCompanyIdCollaboratorsOptions = {baseUrl?: string | undefined, partnerApiOauth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiCompaniesCompanyIdCollaboratorsResponse = z.object({collaborators: z.array(z.object({id: z.string(), matricule: z.string().nullable(), firstName: z.string(), lastName: z.string(), secondLastName: z.string().nullable(), birthName: z.string().nullable(), birthDate: z.string().nullable(), terminationDate: z.string().nullable(), gender: z.enum(["male", "female", "other", "null"]).nullable(), nationality: z.string().nullable().optional(), countryOfBirth: z.string().nullable().optional(), socialSecurityNumber: z.string().nullable().optional(), temporaryTechnicalNumber: z.string().nullable().optional(), bic: z.string().nullable().optional(), iban: z.string().nullable().optional(), emails: z.array(z.object({email: z.string(), type: z.enum(["professional", "personal", "unknown"])})), phoneNumbers: z.array(z.object({phoneNumber: z.string(), type: z.literal("personal")})).optional(), addresses: z.array(z.object({address: z.string(), postcode: z.string(), city: z.string(), country: z.string().optional(), type: z.literal("personal")})).optional(), managerId: z.string().nullable().optional(), teamName: z.string().nullable().optional(), contracts: z.array(z.object({id: z.string(), startDate: z.string().nullable(), endDate: z.string().nullable(), status: z.enum(["ACTIVE", "ARCHIVED", "PENDING"])})).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 Collaborators 🌍 * * GET /companies/{companyId}/collaborators */ export const getApiCompaniesCompanyIdCollaborators = async (args: GetApiCompaniesCompanyIdCollaboratorsArgs, options?: GetApiCompaniesCompanyIdCollaboratorsOptions) => { 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.email != null) query.append("email", String(args.email)) if (partnerApiOauth !== undefined) headers.set('authorization', `Bearer ${partnerApiOauth}`) const url = `${baseUrl.replace(/\/+$/, '')}/companies/${encodeURIComponent(String(args.companyId))}/collaborators${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(getApiCompaniesCompanyIdCollaboratorsResponse, await res.json()) };