import {z} from 'zod' export type PatchApiPublicV1CampaignsCampaignIdArgs = {campaignId: string, body: {name?: string | undefined, outreachCountPerDay?: number | undefined, autoPilot?: boolean | undefined, withdrawRequestAfter?: number | undefined, reEngagementConfig?: ({r_1?: (1 | 2 | 3 | 5 | 8 | 13 | 21) | undefined, r_2?: (1 | 2 | 3 | 5 | 8 | 13 | 21) | undefined, r_3?: (1 | 2 | 3 | 5 | 8 | 13 | 21) | undefined, r_4?: (1 | 2 | 3 | 5 | 8 | 13 | 21) | undefined, r_5?: (1 | 2 | 3 | 5 | 8 | 13 | 21) | undefined, r_6?: (1 | 2 | 3 | 5 | 8 | 13 | 21) | undefined, r_7?: (1 | 2 | 3 | 5 | 8 | 13 | 21) | undefined, r_8?: (1 | 2 | 3 | 5 | 8 | 13 | 21) | undefined, r_9?: (1 | 2 | 3 | 5 | 8 | 13 | 21) | undefined, r_10?: (1 | 2 | 3 | 5 | 8 | 13 | 21) | undefined, r_11?: (1 | 2 | 3 | 5 | 8 | 13 | 21) | undefined, r_12?: (1 | 2 | 3 | 5 | 8 | 13 | 21) | undefined}) | undefined}}; export type PatchApiPublicV1CampaignsCampaignIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiPublicV1CampaignsCampaignIdResponse = z.object({statusCode: z.number().optional(), status: z.boolean().optional(), message: z.string().optional(), data: z.object({campaign: z.object({id: z.string().optional(), name: z.string().optional(), outreach_count_per_day: z.number().optional(), auto_pilot: z.boolean().optional(), withdraw_request_after: z.number().nullable().optional(), re_engagement_config: z.record(z.string(), z.unknown()).optional(), status: z.string().optional()}).optional()}).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 a campaign's settings. * * PATCH /public/v1/campaigns/{campaignId} */ export const patchApiPublicV1CampaignsCampaignId = async (args: PatchApiPublicV1CampaignsCampaignIdArgs, options?: PatchApiPublicV1CampaignsCampaignIdOptions) => { const {baseUrl = "https://api.joinvalley.co", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/public/v1/campaigns/${encodeURIComponent(String(args.campaignId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(patchApiPublicV1CampaignsCampaignIdResponse, await res.json()) };