import {z} from 'zod' export type AttachmentBaseObject = {content_type?: string | undefined, content_url?: string | undefined, deleted?: boolean | undefined, file_name?: string | undefined, height?: number | undefined, id?: number | undefined, inline?: boolean | undefined, malware_access_override?: boolean | undefined, malware_scan_result?: string | undefined, mapped_content_url?: string | undefined, size?: number | undefined, url?: string | undefined, width?: number | undefined}; export type AttachmentObject = {content_type?: string | undefined, content_url?: string | undefined, deleted?: boolean | undefined, file_name?: string | undefined, height?: number | undefined, id?: number | undefined, inline?: boolean | undefined, malware_access_override?: boolean | undefined, malware_scan_result?: string | undefined, mapped_content_url?: string | undefined, size?: number | undefined, url?: string | undefined, width?: number | undefined, thumbnails?: Array | undefined}; export type BrandObject = {active?: boolean | undefined, brand_url?: string | undefined, created_at?: string | undefined, default?: boolean | undefined, has_help_center?: boolean | undefined, help_center_state?: ('enabled' | 'disabled' | 'restricted') | undefined, host_mapping?: string | undefined, id?: number | undefined, is_deleted?: boolean | undefined, logo?: AttachmentObject | undefined, name: string, signature_template?: string | undefined, subdomain: string, ticket_form_ids?: Array | undefined, updated_at?: string | undefined, url?: string | undefined}; export type BrandCreateRequest = {brand?: BrandObject | undefined}; export type CreateApiApiV2BrandsArgs = {body: BrandCreateRequest}; export type CreateApiApiV2BrandsOptions = {baseUrl?: string | undefined, apiTokenAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const attachmentBaseObject = z.object({content_type: z.string().optional(), content_url: z.string().optional(), deleted: z.boolean().optional(), file_name: z.string().optional(), height: z.number().int().optional(), id: z.number().int().optional(), inline: z.boolean().optional(), malware_access_override: z.boolean().optional(), malware_scan_result: z.string().optional(), mapped_content_url: z.string().optional(), size: z.number().int().optional(), url: z.string().optional(), width: z.number().int().optional()}); export const attachmentObject = z.object({content_type: z.string().optional(), content_url: z.string().optional(), deleted: z.boolean().optional(), file_name: z.string().optional(), height: z.number().int().optional(), id: z.number().int().optional(), inline: z.boolean().optional(), malware_access_override: z.boolean().optional(), malware_scan_result: z.string().optional(), mapped_content_url: z.string().optional(), size: z.number().int().optional(), url: z.string().optional(), width: z.number().int().optional(), thumbnails: z.array(attachmentBaseObject).optional()}); export const brandObject = z.object({active: z.boolean().optional(), brand_url: z.string().optional(), created_at: z.string().optional(), default: z.boolean().optional(), has_help_center: z.boolean().optional(), help_center_state: z.enum(["enabled", "disabled", "restricted"]).optional(), host_mapping: z.string().optional(), id: z.number().int().optional(), is_deleted: z.boolean().optional(), logo: attachmentObject.optional(), name: z.string(), signature_template: z.string().optional(), subdomain: z.string(), ticket_form_ids: z.array(z.number().int()).optional(), updated_at: z.string().optional(), url: z.string().optional()}); export const brandResponse = z.object({brand: brandObject.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 }; /** * Create Brand * * POST /api/v2/brands */ export const createApiApiV2Brands = async (args: CreateApiApiV2BrandsArgs, options?: CreateApiApiV2BrandsOptions) => { 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/brands${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(brandResponse, await res.json()) };