import {z} from 'zod' export type GetApiClientsContactsCandidateIdArgs = {candidateId: string}; export type GetApiClientsContactsCandidateIdOptions = {baseUrl: string, xApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const locationType = z.enum(["primary_home", "secondary_home", "primary_work", "headquarters", "regional_office"]); export const locationDto = z.object({street1: z.string().nullable(), street2: z.string().nullable(), postalCode: z.string().nullable(), city: z.string().nullable(), region: z.string().nullable(), state: z.string().nullable(), country: z.string().nullable(), rawCityCountry: z.string().nullable(), latitude: z.number().nullable(), longitude: z.number().nullable(), formattedAddress: z.string().nullable(), type: locationType.nullable()}); export const dateISO = z.string(); export const clientContactOverviewUserBadgeDto = z.object({id: z.string().min(1), name: z.string(), avatarUrl: z.string().nullable(), deactivatedAt: dateISO.nullable()}); export const clientContactOverviewCompanyDto = z.object({id: z.string().min(1), name: z.string(), logoUrl: z.string().nullable()}); export const contactEmailDto = z.object({email: z.string(), purpose: z.enum(["personal", "work"]).nullable(), isPrimary: z.boolean()}); export const contactPhoneDto = z.object({phoneNumber: z.string(), purpose: z.enum(["personal", "work"]).nullable(), isPrimary: z.boolean()}); export const clientStageDto = z.object({id: z.string().min(1), order: z.number(), name: z.string(), colorHex: z.string()}); export const dmCurrency = z.enum(["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTC", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLF", "CLP", "CNH", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLE", "SLL", "SOS", "SRD", "SSP", "STD", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", "VES", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XCD", "XCG", "XDR", "XOF", "XPD", "XPF", "XPT", "YER", "ZAR", "ZMW", "ZWG", "ZWL"]); export const monetaryAmountDto = z.object({currency: dmCurrency, amount: z.number()}); export const dateRangeDto = z.object({startDate: dateISO, endDate: dateISO.nullable()}); export const userBadgeDto = z.object({id: z.string(), name: z.string(), avatarUrl: z.string().nullable(), deactivatedAt: dateISO.nullable()}); export const sharedCustomAttributeTypeDto = z.union([z.object({viewType: z.literal("customText"), text: z.string().nullable()}), z.object({viewType: z.literal("customNumber"), number: z.number().nullable()}), z.object({viewType: z.literal("customCheckbox"), checked: z.boolean().nullable()}), z.object({viewType: z.literal("customDate"), date: dateISO.nullable()}), z.object({viewType: z.literal("customTimestamp"), timestamp: dateISO.nullable()}), z.object({viewType: z.literal("customRating"), rating: z.number().nullable()}), z.object({viewType: z.literal("customSelect"), select: z.string().nullable()}), z.object({viewType: z.literal("customMultiSelect"), multiSelect: z.array(z.string())}), z.object({viewType: z.literal("customCurrency"), monetaryAmount: monetaryAmountDto.nullable()}), z.object({viewType: z.literal("customDateRange"), dateRange: dateRangeDto.nullable()}), z.object({viewType: z.literal("customDuration"), duration: z.number().nullable()}), z.object({viewType: z.literal("customUrl"), url: z.string().nullable()}), z.object({viewType: z.literal("customEntity"), type: z.literal("user"), id: z.string().nullable(), entity: userBadgeDto.nullable().optional()}), z.object({viewType: z.literal("customMultiEntity"), type: z.literal("user"), ids: z.array(z.string()), entities: z.array(userBadgeDto).optional()})]); export const customAttributeItemDto = z.object({attributeDefinitionId: z.string().min(1), label: z.string(), aiFillOngoing: z.boolean(), aiOverridden: z.boolean(), isFilledByAI: z.boolean(), value: sharedCustomAttributeTypeDto}); export const clientContactOverviewItemDto = z.object({id: z.string().min(1), company: clientContactOverviewCompanyDto, role: z.string().nullable(), department: z.string().nullable(), startDate: dateISO, endDate: dateISO.nullable(), active: z.boolean(), emailAddresses: z.array(contactEmailDto), phoneNumbers: z.array(contactPhoneDto), stage: clientStageDto, customAttributes: z.array(customAttributeItemDto)}); export const clientContactOverviewNextTaskDueDto = z.object({id: z.string().min(1), dueDate: dateISO.nullable(), content: z.string()}); export const clientContactOverviewUserDto = z.object({userId: z.string().min(1), name: z.string(), email: z.string(), avatarUrl: z.string().nullable(), deactivatedAt: dateISO.nullable()}); export const clientContactOverviewDto = z.object({candidateId: z.string().min(1), firstName: z.string(), lastName: z.string(), avatarUrl: z.string().nullable(), locations: z.array(locationDto), lastInteractionDate: dateISO.nullable(), lastInteractionWith: clientContactOverviewUserBadgeDto.nullable(), nextInteractionDate: dateISO.nullable(), nextInteractionWith: clientContactOverviewUserBadgeDto.nullable(), lastActivityDate: dateISO, clientContacts: z.array(clientContactOverviewItemDto), nextTaskDue: clientContactOverviewNextTaskDueDto.nullable(), mainContact: clientContactOverviewUserDto.nullable()}); 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 }; /** * Get client contact by candidate ID * * GET /clients/contacts/{candidateId} */ export const getApiClientsContactsCandidateId = async (args: GetApiClientsContactsCandidateIdArgs, options: GetApiClientsContactsCandidateIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, xApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (xApiKey !== undefined) headers.set("x-api-key", xApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/clients/contacts/${encodeURIComponent(String(args.candidateId))}${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(clientContactOverviewDto, await res.json()) };