import {z} from 'zod' export type GetApiApiV0MatchingJobsArgs = {Authorization: string}; export type GetApiApiV0MatchingJobsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV0MatchingJobsResponse = z.object({data: z.array(z.object({id: z.string(), type: z.string(), attributes: z.object({title: z.string(), description_headline: z.unknown(), description: z.string(), projects: z.string(), functions_headline: z.unknown(), functions: z.string(), benefits_headline: z.unknown(), benefits: z.string(), desirable_headline: z.unknown(), desirable: z.string(), remote: z.boolean(), remote_modality: z.string(), remote_zone: z.unknown(), countries: z.array(z.string()), lang: z.string(), category_name: z.string(), perks: z.array(z.unknown()), min_salary: z.number().int(), max_salary: z.number().int(), published_at: z.number().int(), response_time_in_days: z.object({min: z.unknown(), max: z.unknown()}), applications_count: z.number().int(), location_regions: z.object({data: z.array(z.unknown())}), location_tenants: z.object({data: z.array(z.unknown())}), location_cities: z.object({data: z.array(z.object({id: z.number().int(), type: z.string()}))}), modality: z.object({data: z.object({id: z.number().int(), type: z.string()})}), seniority: z.object({data: z.object({id: z.number().int(), type: z.string()})}), tags: z.object({data: z.array(z.unknown())}), company: z.object({data: z.object({id: z.number().int(), type: z.string()})})}), links: z.object({public_url: 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 }; /** * List matching jobs * * GET /api/v0/matching_jobs */ export const getApiApiV0MatchingJobs = async (args: GetApiApiV0MatchingJobsArgs, options?: GetApiApiV0MatchingJobsOptions) => { const {baseUrl = "https://www.getonbrd.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v0/matching_jobs${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(getApiApiV0MatchingJobsResponse, await res.json()) };