import {z} from 'zod' export type CreateApiPublicUserProxyListOptionsArgs = {'Content-Type': string, body: {proxy_ids?: Array | undefined, search_filter?: Record | undefined}}; export type CreateApiPublicUserProxyListOptionsOptions = {baseUrl?: string | undefined, APIPrivateKey?: string | undefined, APIPublicKey?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiPublicUserProxyListOptionsResponse = z.object({data: z.array(z.object({has_access: z.boolean().optional(), proxy_user_id: z.string().optional(), proxy_user_is_default: z.boolean().optional()})).optional(), message: z.string().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 }; /** * Get Proxy User List Options * * POST /public/user/proxy/list/options */ export const createApiPublicUserProxyListOptions = async (args: CreateApiPublicUserProxyListOptionsArgs, options?: CreateApiPublicUserProxyListOptionsOptions) => { const {baseUrl = "https://api.byteful.com/1.0", fetch: fetchFn = fetch, APIPrivateKey, APIPublicKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (APIPrivateKey !== undefined) headers.set("X-API-Private-Key", APIPrivateKey) if (APIPublicKey !== undefined) headers.set("X-API-Public-Key", APIPublicKey) const url = `${baseUrl.replace(/\/+$/, '')}/public/user/proxy/list/options${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(createApiPublicUserProxyListOptionsResponse, await res.json()) };