export type UserRole = {roleName?: (string | null) | undefined, enabled?: boolean | undefined}; export type AssignUserRoleRequest = {userId?: string | undefined, userRoles?: (Array | null) | undefined}; export type CreateApiApiVVersionUsersIdRolesArgs = {version: string, id: string, 'X-Tenant': string, body: AssignUserRoleRequest}; export type CreateApiApiVVersionUsersIdRolesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * assign roles * * POST /api/v{version}/users/{id}/roles */ export const createApiApiVVersionUsersIdRoles = async (args: CreateApiApiVVersionUsersIdRolesArgs, options?: CreateApiApiVVersionUsersIdRolesOptions) => { const {baseUrl = "https://api.zrexpress.app", fetch: fetchFn = fetch, bearerAuth, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-Tenant'] != null) headers.set("X-Tenant", String(args['X-Tenant'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) if (apiKey !== undefined) headers.set("X-Api-Key", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/v${encodeURIComponent(String(args.version))}/users/${encodeURIComponent(String(args.id))}/roles${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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 undefined };