import {z} from 'zod' export type CustomStatusUpdateInput = {active?: boolean | undefined, agent_label?: string | undefined, description?: string | undefined, end_user_description?: string | undefined, end_user_label?: string | undefined}; export type CustomStatusUpdateRequest = {custom_status?: CustomStatusUpdateInput | undefined}; export type UpdateApiApiV2CustomStatusesCustomStatusIdArgs = {custom_status_id: number, body: CustomStatusUpdateRequest}; export type UpdateApiApiV2CustomStatusesCustomStatusIdOptions = {baseUrl?: string | undefined, apiTokenAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const customStatusObject = z.object({active: z.boolean().optional(), agent_label: z.string(), created_at: z.string().optional(), default: z.boolean().optional(), description: z.string().optional(), end_user_description: z.string().optional(), end_user_label: z.string().optional(), id: z.number().int().optional(), raw_agent_label: z.string().optional(), raw_description: z.string().optional(), raw_end_user_description: z.string().optional(), raw_end_user_label: z.string().optional(), status_category: z.enum(["new", "open", "pending", "hold", "solved"]), updated_at: z.string().optional()}); export const customStatusResponse = z.object({custom_status: customStatusObject.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 Custom Ticket Status * * PUT /api/v2/custom_statuses/{custom_status_id} */ export const updateApiApiV2CustomStatusesCustomStatusId = async (args: UpdateApiApiV2CustomStatusesCustomStatusIdArgs, options?: UpdateApiApiV2CustomStatusesCustomStatusIdOptions) => { const {baseUrl = "https://example.zendesk.com", fetch: fetchFn = fetch, apiTokenAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiTokenAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${apiTokenAuth.username}:${apiTokenAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/custom_statuses/${encodeURIComponent(String(args.custom_status_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(customStatusResponse, await res.json()) };