import {z} from 'zod' export type GetApiV1LogosLogoIdArgs = {'App-ID': string, 'Auth-Token': string, logo_id: string, generate_signed_url?: boolean | undefined}; export type GetApiV1LogosLogoIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const logoSchema = z.object({date_created: z.string().optional(), date_modified: z.string().optional(), filename: z.string().optional(), id: z.string().optional(), name: z.string(), storage_id: z.string().optional(), storage_method: z.string().optional(), system_domain_id: z.string().optional(), upload_credentials: z.record(z.string(), z.unknown()).optional(), upload_headers: z.record(z.string(), z.unknown()).optional(), upload_method: z.string().optional(), upload_url: z.string().optional(), url: z.string().optional(), user_id: 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 }; /** * Returns a particular logo by id * * GET /v1/logos/{logo_id}/ */ export const getApiV1LogosLogoId = async (args: GetApiV1LogosLogoIdArgs, options: GetApiV1LogosLogoIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['App-ID'] != null) headers.set("App-ID", String(args['App-ID'])) if (args['Auth-Token'] != null) headers.set("Auth-Token", String(args['Auth-Token'])) if (args.generate_signed_url != null) query.append("generate_signed_url", String(args.generate_signed_url)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/logos/${encodeURIComponent(String(args.logo_id))}/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(logoSchema, await res.json()) };