import {z} from 'zod' export type GetApiV3SequencesIdContactsContactIdArgs = {id: number, contact_id: number}; export type GetApiV3SequencesIdContactsContactIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV3SequencesIdContactsContactIdResponse = z.object({contactId: z.number().int().optional(), sequenceId: z.number().int().optional(), email: z.string().nullable().optional(), firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), company: z.string().nullable().optional(), title: z.string().nullable().optional(), statusInSequence: z.enum(["active", "paused", "finished", "inactive", "outOfOffice"]).optional(), isOptedOut: z.boolean().optional(), callStatus: z.enum(["none", "toCall", "called"]).optional(), meetingStatus: z.enum(["none", "meetingBooked"]).optional(), emailDisposition: z.object({isReplied: z.boolean(), isBounced: z.boolean()}).nullable().optional(), currentStep: z.object({stepId: z.number().int().nullable(), displayName: z.string().nullable()}).optional(), addingDate: z.string().optional(), emailAccountId: z.number().int().nullable().optional(), linkedInAccountId: z.number().int().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 }; /** * Get a contact in a sequence * * GET /v3/sequences/{id}/contacts/{contact_id} */ export const getApiV3SequencesIdContactsContactId = async (args: GetApiV3SequencesIdContactsContactIdArgs, options?: GetApiV3SequencesIdContactsContactIdOptions) => { const {baseUrl = "https://api.reply.io", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/sequences/${encodeURIComponent(String(args.id))}/contacts/${encodeURIComponent(String(args.contact_id))}${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(getApiV3SequencesIdContactsContactIdResponse, await res.json()) };