import {z} from 'zod' export type GetApiV3ResumeSearchMatchArgs = {resume: string, job_description: string, index?: string | undefined, search_expression?: string | undefined, job_titles_weight?: number | undefined, years_experience_weight?: number | undefined, locations_weight?: number | undefined, languages_weight?: number | undefined, skills_weight?: number | undefined, education_weight?: number | undefined, search_expression_weight?: number | undefined, soc_codes_weight?: number | undefined, management_level_weight?: number | undefined}; export type GetApiV3ResumeSearchMatchOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const jobTitleSearchScoreComponent = z.object({value: z.string().optional(), label: z.string(), score: z.number().nullable().optional()}); export const managementLevelSearchScoreComponent = z.object({value: z.string().optional(), label: z.string(), score: z.number().nullable().optional()}); export const experienceSearchScoreComponent = z.object({value: z.string().optional(), label: z.string(), score: z.number().nullable().optional()}); export const skillsSearchScoreComponent = z.object({value: z.string().optional(), label: z.string(), score: z.number().nullable().optional()}); export const languagesSearchScoreComponent = z.object({value: z.string().optional(), label: z.string(), score: z.number().nullable().optional()}); export const locationSearchScoreComponent = z.object({value: z.string().optional(), label: z.string(), score: z.number().nullable().optional()}); export const educationSearchScoreComponent = z.object({value: z.string().optional(), label: z.string(), score: z.number().nullable().optional()}); export const occupationGroupSearchScoreComponent = z.object({value: z.string().optional(), label: z.string(), score: z.number().nullable().optional()}); export const searchExpressionSearchScoreComponent = z.object({label: z.string(), value: z.string().optional(), score: z.number().nullable().optional()}); export const resumeSearchMatch = z.object({score: z.number().gte(0).lte(1).optional(), details: z.object({jobTitle: jobTitleSearchScoreComponent.optional(), managementLevel: managementLevelSearchScoreComponent.optional(), experience: experienceSearchScoreComponent.optional(), skills: skillsSearchScoreComponent.optional(), languages: languagesSearchScoreComponent.optional(), location: locationSearchScoreComponent.optional(), education: educationSearchScoreComponent.optional(), occupationGroup: occupationGroupSearchScoreComponent.optional(), searchExpression: searchExpressionSearchScoreComponent.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 }; /** * Match a single resume and job description * * GET /v3/resume_search/match */ export const getApiV3ResumeSearchMatch = async (args: GetApiV3ResumeSearchMatchArgs, options?: GetApiV3ResumeSearchMatchOptions) => { const {baseUrl = "https://api.affinda.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.resume != null) query.append("resume", String(args.resume)) if (args.job_description != null) query.append("job_description", String(args.job_description)) if (args.index != null) query.append("index", String(args.index)) if (args.search_expression != null) query.append("search_expression", String(args.search_expression)) if (args.job_titles_weight != null) query.append("job_titles_weight", String(args.job_titles_weight)) if (args.years_experience_weight != null) query.append("years_experience_weight", String(args.years_experience_weight)) if (args.locations_weight != null) query.append("locations_weight", String(args.locations_weight)) if (args.languages_weight != null) query.append("languages_weight", String(args.languages_weight)) if (args.skills_weight != null) query.append("skills_weight", String(args.skills_weight)) if (args.education_weight != null) query.append("education_weight", String(args.education_weight)) if (args.search_expression_weight != null) query.append("search_expression_weight", String(args.search_expression_weight)) if (args.soc_codes_weight != null) query.append("soc_codes_weight", String(args.soc_codes_weight)) if (args.management_level_weight != null) query.append("management_level_weight", String(args.management_level_weight)) if (ApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/resume_search/match${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(resumeSearchMatch, await res.json()) };