mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-03 22:33:13 +00:00
18 lines
782 B
TypeScript
18 lines
782 B
TypeScript
|
|
import { z } from "zod";
|
||
|
|
import { apiGet } from "@/api/api";
|
||
|
|
import { API_PATHS } from "@/api/api-paths";
|
||
|
|
import { handleApiResponse } from "@/api/handle-api-response";
|
||
|
|
|
||
|
|
export const UNEXPECTED_PERMISSIONS_RESPONSE =
|
||
|
|
"The server sent an unexpected permissions response.";
|
||
|
|
|
||
|
|
const effectivePermissionsSchema = z.object({ permissions: z.array(z.string()) });
|
||
|
|
|
||
|
|
/** Keys the signed-in user holds after role defaults and their individual overrides. */
|
||
|
|
export async function getMyPermissions(): Promise<string[]> {
|
||
|
|
const data = await apiGet<unknown>(API_PATHS.teamMember.myPermissions);
|
||
|
|
const result = effectivePermissionsSchema.safeParse(handleApiResponse<unknown>(data));
|
||
|
|
if (!result.success) throw new Error(UNEXPECTED_PERMISSIONS_RESPONSE);
|
||
|
|
return result.data.permissions;
|
||
|
|
}
|