import {z} from 'zod' export type GetApiApiCareersV1VacanciesArgs = {page?: number | undefined, per_page?: number | undefined, offset?: number | undefined, title?: string | undefined, location_ids?: Array | undefined, employment_type_ids?: Array | undefined, sort_by?: ('opened_at' | 'created_at' | 'updated_at') | undefined, sort_dir?: ('asc' | 'desc') | undefined}; export type GetApiApiCareersV1VacanciesOptions = {baseUrl?: string | undefined, XAPIKEY?: string | undefined, fetch?: typeof fetch | undefined}; export const vacancy = z.object({id: z.string(), title: z.string(), description: z.string(), department: z.string(), location: z.string(), employment_type: z.string(), apply_url: z.string()}); export const metadata = z.object({page: z.string(), per_page: z.string(), total_pages: z.string(), total_count: z.string()}); export const getApiApiCareersV1VacanciesResponse = z.object({data: z.array(vacancy), metadata: metadata}); 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 }; /** * Returns a list of open vacancies * * GET /api/careers/v1/vacancies */ export const getApiApiCareersV1Vacancies = async (args: GetApiApiCareersV1VacanciesArgs, options?: GetApiApiCareersV1VacanciesOptions) => { const {baseUrl = "https://app.peopleforce.io/api/public/v3", fetch: fetchFn = fetch, XAPIKEY} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.title != null) query.append("title", String(args.title)) if (args.location_ids != null) query.append("location_ids", args.location_ids.join(',')) if (args.employment_type_ids != null) query.append("employment_type_ids", args.employment_type_ids.join(',')) if (args.sort_by != null) query.append("sort_by", String(args.sort_by)) if (args.sort_dir != null) query.append("sort_dir", String(args.sort_dir)) if (XAPIKEY !== undefined) headers.set("X-API-KEY", XAPIKEY) const url = `${baseUrl.replace(/\/+$/, '')}/api/careers/v1/vacancies${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(getApiApiCareersV1VacanciesResponse, await res.json()) };