import {z} from 'zod' export type RoleUpdate = {name?: string | undefined, description?: (string | null) | undefined, permission_set_ids?: Array | undefined, data_access_filter?: ({filter_type?: ('NO_ACCESS' | 'LIMITED_ACCESS' | 'FULL_ACCESS') | undefined, filter_dimensions?: {[key: string]: Array} | undefined, dynamic_filter_dimensions?: ({[key: string]: string | Array} | null) | undefined, attribute_filters?: {[key: string]: Array} | undefined} | null) | undefined}; export type PatchApiV2RolesRoleIdArgs = {'cloudzero-test-key'?: string | undefined, role_id: string, body: RoleUpdate}; export type PatchApiV2RolesRoleIdOptions = {baseUrl?: string | undefined, APIKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const role = z.object({id: z.string(), name: z.string(), description: z.string().nullable().optional(), permission_set_ids: z.array(z.string()), data_access_filter: z.object({name: z.string().optional(), description: z.string().nullable().optional(), filter_type: z.string().optional(), filter_dimensions: z.record(z.string(), z.array(z.string())).optional(), dynamic_filter_dimensions: z.record(z.string(), z.union([z.string(), z.array(z.string())])).nullable().optional(), attribute_filters: z.record(z.string(), z.array(z.string())).optional()}).nullable().optional(), created_at: z.string().optional(), created_by: z.string().optional(), last_updated_at: z.string().optional(), last_updated_by: z.string().optional()}); export const patchApiV2RolesRoleIdResponse = z.object({role: role.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 }; /** * Update a single Role * * PATCH /v2/roles/{role_id} */ export const patchApiV2RolesRoleId = async (args: PatchApiV2RolesRoleIdArgs, options?: PatchApiV2RolesRoleIdOptions) => { const {baseUrl = "https://api.cloudzero.com", fetch: fetchFn = fetch, APIKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['cloudzero-test-key'] != null) headers.set("cloudzero-test-key", String(args['cloudzero-test-key'])) if (APIKeyAuth !== undefined) headers.set("Authorization", APIKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v2/roles/${encodeURIComponent(String(args.role_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(patchApiV2RolesRoleIdResponse, await res.json()) };