import {z} from 'zod' export type CampaignType = 'outbound_call'; export type CampaignStatus = 'not_started' | 'to_be_run' | 'in_progress' | 'paused' | 'cancelled' | 'completed'; export type ICampaignUpdate = {name?: (string | null) | undefined, widget_id?: (string | null) | undefined, type?: (CampaignType | null) | undefined, attributes?: ({[key: string]: unknown} | null) | undefined, status?: (CampaignStatus | null) | undefined, execution_weekdays?: (Array | null) | undefined, time_window_start?: (string | null) | undefined, time_window_end?: (string | null) | undefined, time_zone?: (string | null) | undefined, start_time?: (string | null) | undefined, interval?: (number | null) | undefined, enabled?: (boolean | null) | undefined}; export type UpdateApiApiV1CampaignUpdateCampaignIdArgs = {campaign_id: string, body: ICampaignUpdate}; export type UpdateApiApiV1CampaignUpdateCampaignIdOptions = {baseUrl: string, YourAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const campaignType = z.literal("outbound_call"); export const campaignStatus = z.enum(["not_started", "to_be_run", "in_progress", "paused", "cancelled", "completed"]); export const iCampaignUpdate = z.object({name: z.string().nullable().optional(), widget_id: z.string().nullable().optional(), type: campaignType.nullable().optional(), attributes: z.record(z.string(), z.unknown()).nullable().optional(), status: campaignStatus.nullable().optional(), execution_weekdays: z.array(z.number().int()).nullable().optional(), time_window_start: z.string().nullable().optional(), time_window_end: z.string().nullable().optional(), time_zone: z.string().nullable().optional(), start_time: z.string().nullable().optional(), interval: z.number().int().nullable().optional(), enabled: z.boolean().nullable().optional()}); export const iPutResponseBaseICampaignUpdate = z.object({message: z.string().nullable().optional(), meta: z.union([z.record(z.string(), z.unknown()), z.unknown()]).nullable().optional(), data: iCampaignUpdate.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 }; /** * Update Campaign By Id * * PUT /api/v1/campaign/update/{campaign_id} * * Also accepts auth: HTTPBearer */ export const updateApiApiV1CampaignUpdateCampaignId = async (args: UpdateApiApiV1CampaignUpdateCampaignIdArgs, options: UpdateApiApiV1CampaignUpdateCampaignIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, YourAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (YourAPIKey !== undefined) query.set("api_key", YourAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/campaign/update/${encodeURIComponent(String(args.campaign_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(iPutResponseBaseICampaignUpdate, await res.json()) };