import {z} from 'zod' export type ContactCreate = {person_id?: (string | null) | undefined, name: string, email?: (string | null) | undefined, slack_user_id?: (string | null) | undefined, slack_team_id?: (string | null) | undefined, phone?: (string | null) | undefined, job_title?: (string | null) | undefined, department?: (string | null) | undefined, seniority_level?: (number | null) | undefined, is_required?: boolean | undefined, question_set_id?: (string | null) | undefined}; export type BulkContactsCreate = {contacts: Array}; export type CreateApiV1InterviewsInterviewIdContactsBulkArgs = {interview_id: string, 'X-API-Key'?: (string | null) | undefined, body: BulkContactsCreate}; export type CreateApiV1InterviewsInterviewIdContactsBulkOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const contactOut = z.object({id: z.string(), interview_id: z.string(), person_id: z.string().nullable().optional(), question_set_id: z.string().nullable(), name: z.string(), email: z.string().nullable(), slack_user_id: z.string().nullable().optional(), slack_team_id: z.string().nullable().optional(), slack_dm_channel_id: z.string().nullable().optional(), phone: z.string().nullable(), job_title: z.string().nullable(), department: z.string().nullable(), seniority_level: z.number().int().nullable(), is_required: z.boolean(), process_role_ref: z.string().nullable().optional(), meeting_url: z.string().nullable(), booking_token: z.string().nullable().optional(), status: z.string(), reminder_count: z.number().int().optional(), last_reminder_at: z.string().nullable().optional(), reinvited_from_contact_id: z.string().nullable().optional(), booking_token_expires_at: z.string().nullable().optional(), invitation_status: z.string().optional(), scheduled_at: z.string().nullable(), completed_at: z.string().nullable(), created_at: z.string(), scheduled_session_status: z.string().nullable().optional(), scheduled_session_available_at: z.string().nullable().optional(), scheduled_session_started_at: z.string().nullable().optional(), scheduled_session_expires_at: z.string().nullable().optional(), delivery_failure_reason: z.string().nullable().optional(), delivery_failure_at: z.string().nullable().optional(), last_accessed_at: z.string().nullable().optional(), session_accessibility_message: z.string().nullable().optional()}); export const bulkContactsOut = z.object({created: z.array(contactOut), count: z.number().int(), skipped: z.number().int().optional(), invited_count: z.number().int().optional(), invitations_scheduled_for: z.string().nullable().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 }; /** * Add Contacts Bulk * * POST /v1/interviews/{interview_id}/contacts/bulk */ export const createApiV1InterviewsInterviewIdContactsBulk = async (args: CreateApiV1InterviewsInterviewIdContactsBulkArgs, options: CreateApiV1InterviewsInterviewIdContactsBulkOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-API-Key'] != null) headers.set("X-API-Key", String(args['X-API-Key'])) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/interviews/${encodeURIComponent(String(args.interview_id))}/contacts/bulk${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(bulkContactsOut, await res.json()) };