import {z} from 'zod' export type PaletteColorOptions = {main: string, light?: string | undefined, dark?: string | undefined, contrastText?: string | undefined}; export type ThemeConfig = {palette?: ({mode?: ('light' | 'dark') | undefined, background?: (string | {default?: string | undefined, paper?: string | undefined}) | undefined, text?: ({primary?: string | undefined, secondary?: string | undefined, disabled?: string | undefined}) | undefined, divider?: string | undefined, primary?: PaletteColorOptions | undefined, secondary?: PaletteColorOptions | undefined, success?: PaletteColorOptions | undefined, annotation?: PaletteColorOptions | undefined, error?: PaletteColorOptions | undefined, info?: PaletteColorOptions | undefined, warning?: PaletteColorOptions | undefined}) | undefined, typography?: ({fontFamily?: string | undefined, fontSize?: (string | number) | undefined, fontWeightRegular?: string | undefined, fontWeightMedium?: string | undefined, fontWeightBold?: string | undefined}) | undefined, borderRadius?: number | undefined, fontUrl?: string | undefined}; export type SearchConfigAction = {label: string, eventName: string}; export type CustomFieldConfig = {dataPoint: string, weight: number}; export type ResumeSearchConfig = {allowPdfDownload?: boolean | undefined, maxResults?: (number | null) | undefined, displayJobTitle?: boolean | undefined, displayLocation?: boolean | undefined, displayYearsExperience?: boolean | undefined, displayOccupationGroup?: boolean | undefined, displayEducation?: boolean | undefined, displaySkills?: boolean | undefined, displayLanguages?: boolean | undefined, displayManagementLevel?: boolean | undefined, displayKeywords?: boolean | undefined, weightJobTitle?: number | undefined, weightLocation?: number | undefined, weightYearsExperience?: number | undefined, weightOccupationGroup?: number | undefined, weightEducation?: number | undefined, weightSkills?: number | undefined, weightLanguages?: number | undefined, weightManagementLevel?: number | undefined, weightKeywords?: number | undefined, indices?: Array | undefined, showIndexDropdown?: (boolean | null) | undefined, searchToolTheme?: (ThemeConfig | null) | undefined, userId?: number | undefined, username?: string | undefined, actions?: (Array | null) | undefined, hideToolbar?: boolean | undefined, hideSidePanel?: boolean | undefined, customFieldsConfig?: (Array | null) | undefined, distanceUnit?: ('mi' | 'km') | undefined}; export type PatchApiV2ResumeSearchConfigArgs = {body: ResumeSearchConfig}; export type PatchApiV2ResumeSearchConfigOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const paletteColorOptions = z.object({main: z.string(), light: z.string().optional(), dark: z.string().optional(), contrastText: z.string().optional()}); export const themeConfig = z.object({palette: z.object({mode: z.enum(["light", "dark"]).optional(), background: z.union([z.string(), z.object({default: z.string().optional(), paper: z.string().optional()})]).optional(), text: z.object({primary: z.string().optional(), secondary: z.string().optional(), disabled: z.string().optional()}).optional(), divider: z.string().optional(), primary: paletteColorOptions.optional(), secondary: paletteColorOptions.optional(), success: paletteColorOptions.optional(), annotation: paletteColorOptions.optional(), error: paletteColorOptions.optional(), info: paletteColorOptions.optional(), warning: paletteColorOptions.optional()}).optional(), typography: z.object({fontFamily: z.string().optional(), fontSize: z.union([z.string(), z.number()]).optional(), fontWeightRegular: z.string().optional(), fontWeightMedium: z.string().optional(), fontWeightBold: z.string().optional()}).optional(), borderRadius: z.number().optional(), fontUrl: z.string().optional()}); export const searchConfigAction = z.object({label: z.string(), eventName: z.string()}); export const customFieldConfig = z.object({dataPoint: z.string(), weight: z.number().gte(0).lte(1)}); export const resumeSearchConfig = z.object({allowPdfDownload: z.boolean().optional(), maxResults: z.number().int().gte(1).nullable().optional(), displayJobTitle: z.boolean().optional(), displayLocation: z.boolean().optional(), displayYearsExperience: z.boolean().optional(), displayOccupationGroup: z.boolean().optional(), displayEducation: z.boolean().optional(), displaySkills: z.boolean().optional(), displayLanguages: z.boolean().optional(), displayManagementLevel: z.boolean().optional(), displayKeywords: z.boolean().optional(), weightJobTitle: z.number().optional(), weightLocation: z.number().optional(), weightYearsExperience: z.number().optional(), weightOccupationGroup: z.number().optional(), weightEducation: z.number().optional(), weightSkills: z.number().optional(), weightLanguages: z.number().optional(), weightManagementLevel: z.number().optional(), weightKeywords: z.number().optional(), indices: z.array(z.string()).optional(), showIndexDropdown: z.boolean().nullable().optional(), searchToolTheme: themeConfig.nullable().optional(), userId: z.number().int().gte(1).optional(), username: z.string().optional(), actions: z.array(searchConfigAction).nullable().optional(), hideToolbar: z.boolean().optional(), hideSidePanel: z.boolean().optional(), customFieldsConfig: z.array(customFieldConfig).nullable().optional(), distanceUnit: z.enum(["mi", "km"]).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 }; /** * Update the config for the logged in user's embeddable resume search tool * * PATCH /v2/resume_search/config */ export const patchApiV2ResumeSearchConfig = async (args: PatchApiV2ResumeSearchConfigArgs, options?: PatchApiV2ResumeSearchConfigOptions) => { const {baseUrl = "https://api.affinda.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set('authorization', `Bearer ${ApiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/resume_search/config${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(resumeSearchConfig, await res.json()) };