import {z} from 'zod' export type GetApiApiV1CampaignsIdArgs = {id: string}; export type GetApiApiV1CampaignsIdOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1CampaignsIdResponse = z.object({status: z.literal("ok"), data: z.object({id: z.string(), name: z.string(), status: z.enum(["active", "inactive"]), type: z.enum(["candidate_outreach", "prospect_outreach", "speculative"]), ownerId: z.string(), projectId: z.string().nullable(), opportunityId: z.string().nullable(), createdAt: z.string().nullable(), updatedAt: z.string().nullable(), steps: z.array(z.object({position: z.number().int(), type: z.enum(["email", "li_inmail", "li_request", "phone_call", "todo"]), dispatchType: z.enum(["new_thread", "reply_to", "null"]).nullable(), subject: z.string().nullable(), body: z.string(), variables: z.array(z.object({type: z.string(), name: z.string().nullable(), value: z.string().nullable()})), aiVariables: z.array(z.object({name: z.string(), value: z.string().nullable()})), scheduledOn: z.string().nullable(), intervalTime: z.string().nullable(), intervalDays: z.number().int().nullable(), businessDays: z.boolean(), businessHours: z.boolean(), timezone: z.string().nullable(), files: z.array(z.object({id: z.string(), name: z.string()}))}))})}); 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 campaign by ID * * GET /api/v1/campaigns/{id} */ export const getApiApiV1CampaignsId = async (args: GetApiApiV1CampaignsIdArgs, options: GetApiApiV1CampaignsIdOptions) => { const {baseUrl, 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(/\/+$/, '')}/api/v1/campaigns/${encodeURIComponent(String(args.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(getApiApiV1CampaignsIdResponse, await res.json()) };