import {z} from 'zod' export type RegionList = 0 | 1 | 2; export type GetApiApiV1RegionsArgs = {RegionList?: RegionList | undefined, OrganizationId?: number | undefined, Page?: number | undefined, PageSize?: number | undefined, Search?: (string | null) | undefined}; export type GetApiApiV1RegionsOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const region = z.object({code: z.string().nullable().optional(), name: z.string().nullable().optional()}); export const getApiApiV1RegionsResponse = z.array(region); 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 /api/v1/Regions */ export const getApiApiV1Regions = async (args: GetApiApiV1RegionsArgs, options: GetApiApiV1RegionsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.RegionList != null) query.append("RegionList", String(args.RegionList)) if (args.OrganizationId != null) query.append("OrganizationId", String(args.OrganizationId)) if (args.Page != null) query.append("Page", String(args.Page)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (args.Search != null) query.append("Search", String(args.Search)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/Regions${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(getApiApiV1RegionsResponse, await res.json()) };