import {z} from 'zod' export type GetApiApiV1AzureSkusCloudIdPublisherOfferArgs = {cloudId: number, publisher: string, offer: string, SortBy?: string | undefined, SortDirection?: string | undefined, Search?: string | undefined, Limit?: number | undefined, Offset?: number | undefined}; export type GetApiApiV1AzureSkusCloudIdPublisherOfferOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const azureSkusList = z.object({data: z.array(z.string()).nullable(), totalCount: z.number().int()}); 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 }; /** * List Azure skus list by publisher and offer * * GET /api/v1/azure/skus/{cloudId}/{publisher}/{offer} */ export const getApiApiV1AzureSkusCloudIdPublisherOffer = async (args: GetApiApiV1AzureSkusCloudIdPublisherOfferArgs, options: GetApiApiV1AzureSkusCloudIdPublisherOfferOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.SortBy != null) query.append("SortBy", String(args.SortBy)) if (args.SortDirection != null) query.append("SortDirection", String(args.SortDirection)) if (args.Search != null) query.append("Search", String(args.Search)) if (args.Limit != null) query.append("Limit", String(args.Limit)) if (args.Offset != null) query.append("Offset", String(args.Offset)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/azure/skus/${encodeURIComponent(String(args.cloudId))}/${encodeURIComponent(String(args.publisher))}/${encodeURIComponent(String(args.offer))}${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(azureSkusList, await res.json()) };