import {z} from 'zod' export type UpdateDataAccessRoleRequest = {name?: (string | null) | undefined, isDefault?: (boolean | null) | undefined, accessMode?: ('read_write' | 'read_only' | null) | undefined}; export type PatchApiV4DataAccessRolesRoleIdArgs = {role_id: string | string, body: UpdateDataAccessRoleRequest}; export type PatchApiV4DataAccessRolesRoleIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const dataAccessRole = z.object({id: z.union([z.string(), z.string()]).nullable().optional(), teamId: z.union([z.string(), z.string()]), name: z.string(), isDefault: z.boolean().optional(), accessMode: z.enum(["read_write", "read_only"]).optional(), createdAt: z.string().nullable().optional()}); export const responseMeta = z.object({requestId: z.string().optional(), timestamp: z.string().optional(), durationMs: z.number().int().nullable().optional()}); export const successResponseDataAccessRole = z.object({success: z.literal(true), data: dataAccessRole, meta: responseMeta.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 data-access role * * PATCH /v4/data-access/roles/{role_id} */ export const patchApiV4DataAccessRolesRoleId = async (args: PatchApiV4DataAccessRolesRoleIdArgs, options: PatchApiV4DataAccessRolesRoleIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v4/data-access/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(successResponseDataAccessRole, await res.json()) };