import {z} from 'zod' export type CreateApiApiV1CampaignsIdLaunchArgs = {id: string, body: {personId: string, ownerEmail?: (string | null) | undefined, variables?: {[key: string]: string} | undefined, aiVariables?: Array<{name: string, value: string}> | undefined, steps?: (Array<{position: number, type: 'email' | 'li_inmail' | 'li_request' | 'phone_call' | 'todo', dispatchType?: ('new_thread' | 'reply_to') | undefined, subject?: string | undefined, body: string, scheduledOn?: string | undefined, intervalTime?: string | undefined, intervalDays?: number | undefined, businessDays?: boolean | undefined, businessHours?: boolean | undefined, timezone?: string | undefined, fileIds?: Array | undefined}>) | undefined}}; export type CreateApiApiV1CampaignsIdLaunchOptions = {baseUrl: string, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1CampaignsIdLaunchResponse = z.object({status: z.literal("ok"), data: z.object({id: z.string(), outreachCampaignId: z.string(), personId: z.string(), ownerId: z.string(), type: z.enum(["candidate_outreach", "prospect_outreach", "speculative"]), status: z.enum(["active", "ready"]), createdAt: z.string().nullable(), steps: z.array(z.object({id: z.string(), position: z.number().int(), type: z.enum(["email", "li_inmail", "li_request", "phone_call", "todo"]), dispatchType: z.enum(["reply_to", "new_thread", "null"]).nullable(), status: z.string().nullable(), subject: z.string().nullable(), body: z.string(), emailAddress: z.string().nullable(), scheduledOn: z.string().nullable(), intervalDays: z.number().int().nullable(), intervalTime: z.string().nullable(), businessDays: z.boolean(), businessHours: z.boolean(), timezone: z.string().nullable(), 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()}))}))})}); 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 }; /** * Launch a campaign for a person * * POST /api/v1/campaigns/{id}/launch */ export const createApiApiV1CampaignsIdLaunch = async (args: CreateApiApiV1CampaignsIdLaunchArgs, options: CreateApiApiV1CampaignsIdLaunchOptions) => { const {baseUrl, fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/campaigns/${encodeURIComponent(String(args.id))}/launch${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(createApiApiV1CampaignsIdLaunchResponse, await res.json()) };