import {z} from 'zod' export type GetApiRestapiJsonV1ResourcegroupArgs = {orgName?: string | undefined, INPUT_DATA?: ({operation?: ({Details?: ({limit?: string | undefined, startIndex?: string | undefined, searchType?: ('static' | 'dynamic' | 'all') | undefined, searchValue?: string | undefined, searchColumn?: ('resourceGroupName' | 'resourceGroupDescription' | 'ownerId' | 'all') | undefined}) | undefined}) | undefined}) | undefined}; export type GetApiRestapiJsonV1ResourcegroupOptions = {baseUrl?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const operationResult = z.object({message: z.string().optional(), status: z.string().optional()}); export const getResourceGroupsResponse = z.object({operation: z.object({result: operationResult.optional(), Details: z.array(z.object({resourceGroupDescription: z.string().optional(), accessType: z.string().optional(), resourceGroupName: z.string().optional(), isOwner: z.string().optional(), resourceGroupType: z.string().optional(), resourceGroupId: z.string().optional(), timeCreated: z.string().optional(), subGroupOf: z.string().optional(), ownerId: z.string().optional()})).optional(), name: z.string().optional(), totalRows: z.number().int().optional()}).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 }; /** * Fetch all resource groups * * GET /restapi/json/v1/resourcegroup */ export const getApiRestapiJsonV1Resourcegroup = async (args: GetApiRestapiJsonV1ResourcegroupArgs, options?: GetApiRestapiJsonV1ResourcegroupOptions) => { const {baseUrl = "https://Hostname:Port", fetch: fetchFn = fetch, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.orgName != null) headers.set("orgName", String(args.orgName)) if (args.INPUT_DATA != null) query.append("INPUT_DATA", JSON.stringify(args.INPUT_DATA)) if (AuthToken !== undefined) headers.set("AUTHTOKEN", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/restapi/json/v1/resourcegroup${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(getResourceGroupsResponse, await res.json()) };