import {z} from 'zod' export type GetApiApiV1PurchaseRequestOrdersArgs = {CustomerTenantId?: number | undefined, Page?: number | undefined, PageSize?: number | undefined, Search?: (string | null) | undefined, OrderState?: (string | null) | undefined, SortBy?: (string | null) | undefined, SortOrder?: (string | null) | undefined}; export type GetApiApiV1PurchaseRequestOrdersOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const purchaseRequestItems = z.object({orderReferenceId: z.number().int().optional(), catalogId: z.string().nullable().optional(), name: z.string().nullable().optional(), quantity: z.number().int().optional(), billingCycle: z.string().nullable().optional(), termDuration: z.string().nullable().optional(), emailReceiver: z.string().nullable().optional(), created: z.string().optional(), orderState: z.string().nullable().optional(), error: z.string().nullable().optional()}); export const getApiApiV1PurchaseRequestOrdersResponse = z.array(purchaseRequestItems); 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/PurchaseRequest/orders */ export const getApiApiV1PurchaseRequestOrders = async (args: GetApiApiV1PurchaseRequestOrdersArgs, options: GetApiApiV1PurchaseRequestOrdersOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.CustomerTenantId != null) query.append("CustomerTenantId", String(args.CustomerTenantId)) 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 (args.OrderState != null) query.append("OrderState", String(args.OrderState)) if (args.SortBy != null) query.append("SortBy", String(args.SortBy)) if (args.SortOrder != null) query.append("SortOrder", String(args.SortOrder)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/PurchaseRequest/orders${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(getApiApiV1PurchaseRequestOrdersResponse, await res.json()) };